|
Richard MacCutchan wrote: The DialogBox does start, but because your code is invalid it terminates (almost) immediately. I have changed your DialogProc to the following just to make it work:
The DialogBox does start, but it's procedure Dlg_Proc doesn't start, you can modify this procedeure over and over for
one thousand times, is not the problem there. How invalid the code will be, if I put a break point inside of Dlg_Proc
should stop there, but the program never goes there.
Please listen to me, help me to understand why the MessageBox doesn't start DlgProc procedeure. Maybe are project setings or I don't know. The problem is that the Dlg_Proc is never reched and never executed.
Please take my code where I copied all my file apart .cpp .rc the resource file to see that I am right.
Something is missing to me, I don't know why. Maybe somwthing more is need it but please listen on what I am saying,
the problem is that the MessageBox function doesn't start the Dlg_Proc
modified 19-Aug-22 12:23pm.
|
|
|
|
|
I told you how to fix it, copy the code from my previous message into your DialogProc. I know that works because I have tested it.
If it still does not work for you then there is something else that you are not showing us.
|
|
|
|
|
Richard MacCutchan wrote: I told you how to fix it, copy the code from my previous message into your DialogProc.
I have a lot of respect for people who waste their time to help me, so obviously I tryied what you had said to me.
Richard MacCutchan wrote: If it still does not work for you then there is something else that you are not showing us.
I don't have nothing to not show, so I started over again:
I had created a new "empty" VC++ w32 project and added just these files below(those file are all I got to show ):
.cpp file:
#include <windows.h> // tipul BOOL este definit in windows.h
#include "resource.h"
#include "WindowsX.h"
BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
RECT rc;
SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM)LoadIcon(GetWindowInstance(hwnd),MAKEINTRESOURCE(IDI_DIRWALK)));
SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)LoadIcon(GetWindowInstance(hwnd),MAKEINTRESOURCE(IDI_DIRWALK)));
GetClientRect(hwnd, &rc);
SetWindowPos(GetDlgItem(hwnd, IDC_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP_NOZORDER);
return(TRUE);
}
void Dlg_OnSize ( HWND hwnd, UINT state, int cx, int cy)
{
SetWindowPos(GetDlgItem(hwnd, IDC_TREE), NULL, 0, 0, cx, cy, SWP_NOZORDER);
}
INT_PTR CALLBACK Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
HANDLE_WM_INITDIALOG(hwnd, wParam, lParam, Dlg_OnInitDialog);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDCANCEL)
{
EndDialog(hwnd, IDCANCEL);
break;
}
return FALSE;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE hinstPrev, LPSTR pszCmdLine, int nCmdShow)
{
DialogBox(hinstExe, MAKEINTRESOURCE(IDD_DIRWALK), NULL, Dlg_Proc);
return(0);
}
.rc file:
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#ifdef APSTUDIO_INVOKED
IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|
WS_VISIBLE| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME
CAPTION "Directory Walk"
FONT 8, "System"
BEGIN
LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
LBX_NOINTEGRAL_HEIGHT | NOT WS_BORDER |
WS_VSCROLL | WS_HSCROLL | WS_GROUP |
WS_TABSTOP
END
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
#ifndef APSTUDIO_INVOKED
#endif // not APSTUDIO_INVOKED
resource.h file:
#define IDI_DIRWALK 400
#define IDC_TREE 401
#define IDD_DIRWALK 402
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
I repeat, I had created a new win32 VC++ empty project and added just these 3 files.
I have to make more settings in VC++ project? Are missing some .h header files that I have to add?
( While posting these, I observed your response Richard about the compiler resource object, thank you very much
for your time trying to help me, I will continue making a hybrid application with my knowledge to continue, in meantime I hope I will find and my need it explanations about this situation, because all I want is to know the basics and then
to start with tones of wrappers and lybraries and so on )
Thank you very much.
|
|
|
|
|
One thing I did notice in your Dialog resource definition was the use of the style value LBX_NOINTEGRAL_HEIGHT . I cannot find a definition of that value anywhere in the Windows header file; I suspect it should be LBS_NOINTEGRAL_HEIGHT .
I don't have time to look at the rest of the above code today, but may be able to get to it tomorrow or next week.
|
|
|
|
|
I would be grateful.
Thank you,
|
|
|
|
|
I just built your program from the code in your previous message. I had to add a couple of minor things in the .rc file because of changes in the Win32 libraries. After building the code it runs successfully; i.e. it shows the main dialog with an empty ListView.
|
|
|
|
|
Can you please tell me where these adjustments were? So I can take a look at me? Teach me how to fix that problems, where to look. Because it can be from the dialog resource to not load properly the DialogBox and not to go to the Dialog procedure from that reason.
Where can be the problem on me? ( I am using VS 2010 and I did't had problems with it until now).
Thank you,
|
|
|
|
|
I do not think they will help since they are just there to simulate what is provided by VS2010. However you can add them to the beginning of the .rc file to see what happens:
#include <winresrc.h>
#define APSTUDIO_INVOKED
#define LBX_NOINTEGRAL_HEIGHT LBS_NOINTEGRALHEIGHT
|
|
|
|
|
Hmmm....
When I am creating a new empty project, when I choose to add a new .rc file, in this .rc file it's added automatically some code in that file, I was glad to see that, BUT!!! , it's appears that somewhere here was some problems or I wasn't pay attention on something, now I have copied exactly the content of the .rc file provided with the book, and now when I run the project, it's appearing an empty dialog box, it is emty, without the ListWiew, but it's a great start.
I will put tomorrow the content of the file from the book because I am very tired now, and for shure we will see the
critical diferences and for shure I will learn from that.
Whoa, I am so glad, we will find and figure out what the clue is, thank you Richard for your patience.
Thank you,
|
|
|
|
|
Comed back with the differences:
Automated .rc file produced by VC with code introduced by me in bad position:
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#ifdef APSTUDIO_INVOKED
IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
<---*******THIS BOLDED TEXT IS IN THE APSTUDIO_INVOKED DEFINITION
<---***** it shouln not be here
<---***** THIS WAS THE FATAL ERROR
|
|
V
IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP|
WS_VISIBLE| WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME
CAPTION "Directory Walk"
FONT 8, "System"
BEGIN
LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
LBX_NOINTEGRAL_HEIGHT | NOT WS_BORDER |
WS_VSCROLL | WS_HSCROLL | WS_GROUP |
WS_TABSTOP
END
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
#ifndef APSTUDIO_INVOKED
#endif // not APSTUDIO_INVOKED
So, the dialog definition was placed wrong, inside the APSTUDIO definition and for this reason the DialogBox were failing.
That was the super thing that was busted my brains and others time.
And that LBX_NOINTEGRALHEIGHT generated from VC must transformed in LBS_NOINTEGRALHEIGHT, as you were saying Richard
I almost forgot, this is the code from the book:
#include "Resource.h"
#define APSTUDIO_READONLY_SYMBOLS
#include "afxres.h"
#undef APSTUDIO_READONLY_SYMBOLS
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif // _WIN32
IDI_DIRWALK ICON DISCARDABLE "DirWalk.Ico"
IDD_DIRWALK DIALOG DISCARDABLE 10, 18, 250, 250
STYLE WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP |
WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Directory Walk"
FONT 8, "System"
BEGIN
LISTBOX IDC_TREE,0,0,0,0,NOT LBS_NOTIFY |
LBS_NOINTEGRALHEIGHT | NOT WS_BORDER |
WS_VSCROLL | WS_HSCROLL | WS_GROUP |
WS_TABSTOP
END
#ifdef APSTUDIO_INVOKED
1 TEXTINCLUDE DISCARDABLE
BEGIN
"Resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // U.S. English Resources
#ifndef APSTUDIO_INVOKED
#endif // not APSTUDIO_INVOKED
Remains still the listbox, that is't displayed yet, I don't still know why but now I have hope.
Thank you,
|
|
|
|
|
I just added your corrected .rc file to the project I have and it builds correctly. And when I run it, it shows the (empty) ListBox as expected.
|
|
|
|
|
I have now modified the Dlg_OnInitDialog function as below and the ListBox gets populated with file and directory names.
BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
RECT rc;
char szPath[MAX_PATH];
SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI_DIRWALK)));
SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(IDI_DIRWALK)));
GetClientRect(hwnd, &rc);
SetWindowPos(GetDlgItem(hwnd, IDC_TREE), NULL, 0, 0, rc.right, rc.bottom, SWP_NOZORDER);
strcpy(szPath, "< path to the directory to search >");
DlgDirList(hwnd, szPath, IDC_TREE, 0, DDL_DIRECTORY | DDL_READWRITE);
return(TRUE);
}
Note that the DlgDirList function needs to write into szPath so it must be created in the way I have shown.
|
|
|
|
|
Yes,
My Listbox was empty and I was't observed that it was a Listbox.
Thank you, see you soon with new topics.
|
|
|
|
|
I ran a further test and discovered that the resource compiler did not generate the correct output file. The resulting resource object was missing the dialog, so that was why your code immediately terminated. However, I cannot reproduce your environment as I do not have the old version of Visual Studio. So the corrections I made are to make use of the Visual Studio 2022 environment.
As I keep saying, stop wasting time with this out of date code (and book) and move on to the latest version of Visual Studio, and the associated documentation.
|
|
|
|
|
|
Hi,
I am trying implementing this function:
BOOL Dlg_OnInitDialog (HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
RECT rect;
chSETDLGICONS(hwnd, IDI_DIRWALK, IDI_DIRWALK);
return(TRUE);
}
But the compiler give me this error: error C2065: 'strucure' : undeclared identifier, suggesting me that
the error is at the chSETDLGICONS.
The chSETDLGICONS is defined as a macro in a .h file:
#define chINITSTRUCT(structure, fInitSize) \
(ZeroMemory(&(strucure), sizeof(structure)), \
fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)
#define chSETDLGICONS(hwnd, idiLarge, idiSmall) \
{ \
OSVERSIONINFO VerInfo; \
chINITSTRUCT(VerInfo, TRUE); \
GetVersionEx(&VerInfo); \
if ((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) && \
(VerInfo.dwMajorVersion <=3 && \
VerInfo.dwMinorVersion <= 51)) \
{ \
SetClassLong(hwnd, GCL_HICON, (LONG) \
LoadIcon(GetWindowInstance(hwnd), \
MAKEINTRESOURCE(idiLarge))); \
} \
else \
{ \
SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM) \
LoadIcon(GetWindowInstance(hWnd), \
MAKEINTRESOURCE(idilarge))); \
SendMessage(hWnd, WM_SECTION, FALSE, (LPARAM) \
LoadIcon(GetWindowInstance(hwnd), \
MAKEINTRESOURCE(idiSmall))); \
} \
}
From what I am seeing, structure is an identifier used in chINITSTRUCT function that is used in chSETDLGICONS, and I don't know how to repair that error.
Please help me with this.
Thank you in advance.
|
|
|
|
|
Small typo: strucure instead of structure in first argument to ZeroMemeory
Mircea
|
|
|
|
|
|
Found it, found it,
coco243 wrote: #define chINITSTRUCT(structure, fInitSize) \
(ZeroMemory(&(strucure), sizeof(structure)), \
fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)
I have eaten an "t" letter on second row.
But I have another errors, I will repost after I look over.
Thak you.
|
|
|
|
|
Are you seriously targeting Windows versions prior to 3.5 ?
All the fluff chSETDLGICONS goes through is completely useless. My advice would be to replace it with the last 2 SendMessage calls:
SendMessage(hwnd, WM_SETICON, TRUE, (LPARAM) \
LoadIcon(GetWindowInstance(hWnd), \
MAKEINTRESOURCE(idilarge))); \
SendMessage(hWnd, WM_SECTION, FALSE, (LPARAM) \
LoadIcon(GetWindowInstance(hwnd), \
MAKEINTRESOURCE(idiSmall)));
Mircea
|
|
|
|
|
Don't laugh about me I am learning WINAPI from an old book . ( I have understand it that is no sense
to check if windows is less than 3.5 )
Until now, I had to compile code that was written with WindProc procedure, but the author has now been found to shoot me
in the knee with message crackers ( now I am google it for them to understand them ).
I hope to go with this code until the finish, because I have to handle and with those macro funcions now.
Aniway I am confident because I have your help.
|
|
|
|
|
Honestly, I don't think it's that useful to learn Win32 API. World has moved over to other technologies in the last 20-25 years. Whatever books you find, they are old (not much money to be made by authors writing about a dead subject) and the skills you acquire they are not in high demand.
Mircea
|
|
|
|
|
I am feeling too that I am not quite on the right path. I wanted to enter in the world of programming and I started to
learn C++. Then I said that C++ is a tool, and I realized that I have to do something with this tool and I have start
to learn WINAPI beacause I wanted to be capable to design some interfaces from scrap. This was the path that I choose to
walk through and I keept going, good or bad that was what I knew to do. Now I am at the finish of this WINAPI book and I am
planning to learn and some data bases.
I want to enter in the world of programming and to be able to work on my own, if you have advices for me I am more than
glad to count on them.
Thank you very much,
|
|
|
|
|
coco243 wrote: if you have advices for me I am more than
glad to count on them. Well, I am sorry to say that you have probably wasted your time learning the Windows API. Especially so if you now want to learn database programming. You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction. Beyond that there are plenty of free tutorials online, for advanced C# and database programming. A word of warning: stay clear of youtube tutorials as they tend to be less than good quality.
|
|
|
|
|
Richard MacCutchan wrote: Well, I am sorry to say that you have probably wasted your time learning the Windows API
I saw in that a possibility to learn making an user interface in my desire to make stand alone applications.
Richard MacCutchan wrote: Especially so if you now want to learn database programming
I don't necessary want to learn database programming but I consider that when you build applications you would need to use databases at some time.
Richard MacCutchan wrote: You really need to move into the .NET field if you expect to make a career in programming. .NET Book Zero by Charles Petzold[^] is an excellent introduction.
Thank you for the advice, and for the resource link.
|
|
|
|
|