How can I create child dialog from an existing dialog (windows api)?
How can I create child dialog from an existing dialog?
Declaration(global scope)
HINSTANCE hInst;
HWND hWnd;
WinMain
:
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN),hWnd, (DLGPROC)DlgProc);
//MessageBox (NULL, TEXT ("Hello, Windows 98!"), TEXT ("HelloMsg"), 0);
return 0;
}
DlgProc
:
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_ABOUT:
//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT),hWnd, (DLGPROC)AboutDlgProc);
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUT),hWndDlg, (DLGPROC)AboutDlgProc); //changed to this...
return 0;
}
break;
}
}
AboutDlgProc
:
BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
return 0;
case WM_INITDIALOG :
ShowWindow (hDlg, SW_HIDE);
return TRUE ;
case WM_COMMAND :
switch (LOW开发者_高级运维ORD (wParam))
{
case IDOK :
case IDCANCEL :
EndDialog (hDlg, 0) ;
return TRUE ;
}
break ;
}
return FALSE ;
}
When I click a menu item called About(IDM_ABOUT), but nothing happened. So how can I create an about dialog ?
EDIT
The about dialog can be poped out now. the reason why the about dialog cannot poped out before is me drag a MFC Link control the the dialog box. As my win32 sdk application do not support MFC , so it just failed. LOL .
If you are not initializing the hInst
that you're using in the call to DialogBox
, the call will fail because it can't find the dialog resource. You really should be checking the return values of system calls when tracking down errors like this.
Your code doesn't declare or initialize hwnd
, yet it passes it as the parent to both the dialog box and the about box. In the latter case, you probably want to pass hWndDlg
so that the about box is modal to the main dialog.
精彩评论