• Advertisement

Archived

This topic is now archived and is closed to further replies.

Create a modeless dialogbox

This topic is 5720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The dialogbox is created but I can´t see it on the screen. I´ve even tryed to set focus on the dialogbox, without result. Have I missed anything or what´s wrong?
        
HWND InitDialog( HINSTANCE	hInst, 
		 HWND		hWndDlg, 
		 LPCTSTR	lpTemplate, 
		 DLGPROC	lpDialogFunc )
{
	CreateDialog(hInst, lpTemplate, hWndDlg, lpDialogFunc);

	if( !hWndDlg )
	{
		MessageBox(NULL, "Couldn´t create dialogbox!", "Ch2Exc1", MB_ICONSTOP);
		return 0;
	}

	ShowWindow(hWndDlg, SW_SHOW);  // I haven´t missed this one


	return hWndDlg;
}
// And in WinMain()

hWndDialog = InitDialog(hInstance, hWndDialog, MAKEINTRESOURCE(IDD_COLOR), DialogProc);
    
[edited by - peter86 on June 27, 2002 12:12:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
Yes, here´s my message pump:


  
while(1)
{
MSG msg;
if( PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
{
int result = GetMessage(&msg, NULL, 0, 0);
if( !result )
return msg.wParam;

if (!IsWindow(hWndDlg) || !IsDialogMessage(hWndDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}

Share this post


Link to post
Share on other sites
erm. i''m no expert on the winAPI, but doesn''t this if check explicitely PREVENT dialoge boxes from being pumped?


if (!IsWindow(hWndDlg) || !IsDialogMessage(hWndDlg, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}



i.e. the !ISDialogMessage part means if this is a DialogMessage neither translate nor dispatch the message.

-me

Share this post


Link to post
Share on other sites
Is hWndDlg ever initialized? Do you initialize it every time you create a dialog box or just once?

Share this post


Link to post
Share on other sites
seriously have you tried removing the if block around Translate and DispatchMessage, even if that check is there for good reason? it looks suspiciously guilty.

alternatively if someone could let me know why you could want to restrict dispatching of messages that would be cool too. if only to shut me up

-me

[edited by - Palidine on June 27, 2002 4:37:13 PM]

Share this post


Link to post
Share on other sites
It dosen´t work if I remove the if block either, but if I make it as an modal dialogbox, it work. WM_INITDIALOG is never reached when I make it as an modeless dialog box, why?

[edited by - peter86 on June 27, 2002 4:43:39 PM]

Share this post


Link to post
Share on other sites
The CreateDialog() function returns a handle to the dialog, if successful, but you do not use this (assuming you did not just mistype the code by mistake). Actually it should look like this:

hWndDlg = CreateDialog(hInst, lpTemplate, hParent, lpDialogFunc);

If there''s no parent window simply pass NULL as the parent handle.

Share this post


Link to post
Share on other sites
This code should initialize your dialog box correctly:


  

HWND InitDialog( HINSTANCE hInst,
HWND ParentHwnd, //handle to parent window

LPCTSTR lpTemplate,
DLGPROC lpDialogFunc )
{
HWND hWndDlg = CreateDialog(hInst, lpTemplate, ParentHwnd, lpDialogFunc);
return hWndDlg;
}

// And in WinMain():

HWND hWndDialog = InitDialog(hInstance, main_parent_hwnd, MAKEINTRESOURCE(IDD_COLOR), (DLGPROC)DialogProc);



Make sure that you set the visible dialog property in the resource editor, under "more styles".

-Mike

Share this post


Link to post
Share on other sites
Hehe, well IF your Dialog gets created it will never get a message dispatched (you''re only dispatching if it has not been created The check for IsDialogMessage() is alright though, so simply removing the IsWindow() check should work well.

Share this post


Link to post
Share on other sites
Palidine:

...
When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selections for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group.

Because the IsDialogMessage function performs all necessary translating and dispatching of messages, a message processed by IsDialogMessage MUST NOT BE PASSED to the TranslateMessage or DispatchMessage function.
...


Platform SDK -> Windows User Interface -> Dialog Box Reference

Share this post


Link to post
Share on other sites

  • Advertisement