Archived

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

Enselic

Dialog Box as main window

Recommended Posts

If I have a resource dialog and want to attach that one to the main window i.e. ...well i think what you mean... how do I do that? Until now I''ve always on init set the main window to be invisible and then used either DialogBox() or CreateDialog() but that feels a bit unnecsecary since then I have two windows where there is only one visible of them.

Share this post


Link to post
Share on other sites
Don''t create a main window.


int APIENTRY WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR ComLine,int nShowCmd)
{
hWnd = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_MAINWND),NULL,(DLGPROC)WndProc);
SendMessage(hWnd,WM_SETICON,(WPARAM)ICON_SMALL,(LPARAM)LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1)));

ShowWindow(hWnd,SW_SHOWNORMAL);
MSG msg;
while(GetMessage(&msg, NULL,0,0) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}


My Site

Share this post


Link to post
Share on other sites
I used that code to try to load a dialog as my main window... The dialog is kind of cut off, and I can't click the X on it, and the buttons don't work... what did I do wrong, or fail to do?

P.S. I also can't drag the window around
-- malakite
-- www.chrysb.com


[edited by - malakite on February 3, 2003 9:10:30 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
are you using a WndProc or a DlgProc for your msg processing? the structure of a dialog box''s msg processing function is a bit different than that of a *normal* window''s msg processing function.

also, that code shown above is missing a call to the IsDialogMessage function within the msg pump, which means that the *dialog box* keyboard keys won''t be handled properly.

here''s a template you can use that provides the basic functionality for a main window dialog box:

  
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include "resource.h"

BOOL CALLBACK DlgProc( HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
InitCommonControls();

// NOTE

// make sure the visible style is set in the dialog resource

// NOTE


HWND hDlg = CreateDialog( hInstance, MAKEINTRESOURCE( IDD_DIALOG ), NULL, DlgProc );
if( !hDlg ) return -1;

MSG msg;
while( GetMessage( &msg, 0, 0, 0 ) == TRUE )
{
if( !IsDialogMessage(hDlg, &msg) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return msg.wParam;
}

BOOL CALLBACK DlgProc( HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message )
{
case WM_INITDIALOG:
// do control initialization here

return TRUE;

case WM_COMMAND:
switch( LOWORD(wParam) )
{
case IDOK:
PostMessage(hdlg, WM_CLOSE, 0, 0);
break;
case IDCANCEL:
PostMessage(hdlg, WM_CLOSE, 0, 0);
break;
// put additional control command processing here

}
break;

case WM_CLOSE:
DestroyWindow( hdlg );
break;

case WM_DESTROY:
PostQuitMessage(0);
break;
}

return FALSE;
}

Share this post


Link to post
Share on other sites
Thanks for the reply, though I just figured out it was because I was addressing it to the wrong dialog proc... I have a seperate proc for my dialog box, thanks though!!

-- malakite
-- www.chrysb.com

Share this post


Link to post
Share on other sites