Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateDialog and WM_INITDIALOG

Status
Not open for further replies.

DeCoDeR

Programmer
Jun 4, 2002
37
US
Hi,
I create a dialog with resource editor, i also open the resource.rc as text and add CLASS tag.
Then i try to use CreateDialog api to show this window and do some processing.
Although i expect to receive WM_INITDIALOG message to initialize some variables i never get this message.
some part of code is below, and i will appreciate who tries to help me,
Kind Regards
---------

MSG msg;
static TCHAR szApp[]="Deneme";
HWND hwnd;
WNDCLASS wcl;

wcl.cbClsExtra = 0;
wcl.cbWndExtra = DLGWINDOWEXTRA;
wcl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hInstance = hInst;
wcl.lpfnWndProc = WndProc;
wcl.lpszClassName = szApp;
wcl.lpszMenuName = NULL;
wcl.style = CS_VREDRAW|CS_HREDRAW;

if(!RegisterClass(&wcl)) return 1;

hwnd = CreateDialog(hInst,MAKEINTRESOURCE(IDD_INFO_ADAPTERS),0,NULL);

ShowWindow(hwnd,nShow);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam ;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
BOOL bReturn;

switch(msg)
{
// i never get WM_INITDIALOG msg
case WM_INITDIALOG:
MessageBox(hwnd,"initial","initial",MB_OK);

SetDlgItemText(hwnd,IDC_EDIT_NAME,"Volkan Uzun");
return TRUE;

Read between the lines
 
Hi,


Your problem is the fourth parameter of CreateDialog:
hwnd = CreateDialog(hInst,MAKEINTRESOURCE(IDD_INFO_ADAPTERS),0,NULL);

It should be the address of a callback procedure. In this callback procedure you receive messages belonging to the dialog box and you must process them there, and not in the window procedure.

Your code must be something like:
Code:
INT_PTR CALLBACK MyDlgProc ( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
  switch ( uMsg )
     { case WM_INITDIALOG : ...
                            return ... ;
       case ... : ... ;
     }
  return FALSE; }

...

hwnd = CreateDialog(hInst,MAKEINTRESOURCE(IDD_INFO_ADAPTERS),0,(DLGPROC)MyDlgProc);

And remove the WM_INITDIALOG piece from the window procedure WndProc.


Marcel
 
If you want a Dialog as your main window, it might be best to call DialogBox( instead of CreateDialog(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top