Jump to content
  • Advertisement

Archived

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

Enselic

CreateDialog fails

This topic is 5683 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

This program won't create a window. I post the whole code since there not much...
    
#include <windows.h>
#include <windowsx.h>

#include "resource.h"

HWND		g_hWnd = NULL;
HWND		g_hSlider = NULL;

LRESULT CALLBACK MsgHandler( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam );

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

	g_hWnd = CreateDialog( hInstance, MAKEINTRESOURCE( IDD_DIALOG1 ), NULL, (DLGPROC)MsgHandler );
	DWORD temp = GetLastError();
	ShowWindow( g_hWnd, nCmdShow );
	UpdateWindow( g_hWnd );

	g_hSlider = GetDlgItem( g_hWnd, IDC_TIME_SLIDE );

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

	return msg.wParam;
}

LRESULT CALLBACK MsgHandler( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	switch( message )
	{
	case WM_INITDIALOG:
		ScrollBar_SetRange( g_hSlider, 0, 24 * 60, true );
		break;

	case WM_CLOSE:
		DestroyWindow( g_hWnd );
		break;

	default:
		return FALSE;

	}

	return TRUE;
}
    
Any tips wanted EDIT: GetLastError() returns 0. that is the strange part.... [edited by - Enselic on January 22, 2003 1:34:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
the only thing obvious i see is the return value of MsgHandler. try changing it to a BOOL.

unrelated to your problem, but a problem anyway, your ScrollBar_SetRange call won''t work since at that point you have not yet set the value of g_hSlider.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yes. WM_INITDIALOG gets sent as part of the dialog window creation process by CreateDialog. it gets sent to the msg handler function by a direct call, not put into the msg queue. there''s a few others that happen that way as well, especially during window creation (WM_NCCREATE and WM_CREATE come to mind off hand.)

Share this post


Link to post
Share on other sites
Could anyone make me a big favour and see if the code works for him/her?

Just make a simple dialog named IDD_DIALOG1 and you should be ready to compile. My compiler seems *****d up..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ok, what was killing your dialog box window was that, since a progress bar is part of the common controls library, a call to InitCommonControls was needed in the WinMain. i''ll refrain from giving my opinion on MS error checking/codes.

there''s also a few other things you need to do in order to get a dialog box to work correctly as your main window. here''s the code i came up with. hth (you''ll also need to add comctl32.lib as part of your link lib list):

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

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

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

HWND hDlg = CreateDialog( hInstance, MAKEINTRESOURCE( IDD_DIALOG1 ), NULL, MsgHandler );
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 MsgHandler( HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch( message )
{
case WM_INITDIALOG:
ScrollBar_SetRange(GetDlgItem(hdlg, IDC_TIME_SLIDE), 0, 24 * 60, true);
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;
}
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
I had a similar problem (getting the dialog box to display) and it turned out that the visible option was not set (seems like it should be, by default... whatever ) That might very well be the problem here as well.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
comctl32.lib

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!