-
Dialog Box Resources
So I used a dialog box resource editor to create a template resource for my win32 application. I wrote this code:
#include<windows.h>
#include "resource.h" // defines DD_FORMVIEW
LRESULT CALLBACK DialogProcedure(HWND hdlg,UINT msg
WPARAM wparm, LPARAM lparm){
switch(msg){
case WM_COMMAND:
EndDialog(hdlg,0); // to end the dialog if a button is clicked
break;
default:
return DefDlgProc(hdlg,msg,wparam,lparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hinst,HINSTANCE phinst,
LPSTR commline,int showstyle){
DialogBox(hinst,MAKEINTRESOURCE(DD_FORMVIEW),
NULL, (DLGPROC) DialogProcedure);
// the second parameter is my dialog box resource I created
// the third parameter (should be a window handle, but the
// application should consist only of the dialog box
return 0;
}
So: The application is built without complaints of compiler or linker. But starting the executable DOES NOT DISPLAY THE DIALOG BOX! Nothing happens. It seems the DialogBox function is totally ignored. If you could give me an example code of a working Dialog Box this would help me.
-
Code:
BOOL CALLBACK MyDlg(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return(1);
/*
or return(TRUE); it's the same.
here you init the dialog box, and it will appear .
this spot also could be used to send things to the controls,
place static controls... etc.
*/
case WM_COMMAND:
switch(LOWORD(wParam)) // the control's ID is been passed only in the low order (LOWORD) of the wParam!
{
case ID_OK: // control's ID (ID_OK) - like a button.
MessageBox (hDlg, "Message" , "!!!", 0);
EndDialog(hDlg, ID_OK); // makes the Dialog to close.
return(1);
}
break;
}
return(0); // or return(FALSE);
}
I can see you're really new to this... read some here: WinProg.net it's nice, but not enough, so you better buy a book... also you should get the MSDN, check microsoft.com
-
Has DD_FORMVIEW got the style WS_VISIBLE?
Have you included the script.rc file containing the resource DD_FORMVIEW?
Or try a call to
ShowWindow(hdlg,SW_SHOW);
UpdateWindow(hdlg);
when you init the dlg WM_INITDIALOG
AFAIK you do not need to return TRUE to the WM_INITDIALOG msg to make the dlg appear.