Sign in to follow this  
PenguinGLX

OMG Help me I cant find the Error

Recommended Posts

BOOL CALLBACK WindowProcA(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    
    HWND hWnd=NULL;
  
	
    
	hWnd=CreateDialogParam(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,WindowProcA,1);
	if(hWnd)
		MessageBox(NULL,"AAAA",0,0);
    ShowWindow(hWnd, SW_SHOWNORMAL);
	UpdateWindow(hWnd);
	
    MSG msg;

    
	while(1)
	{
		
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if(msg.message==WM_QUIT)
				break;
			
			
			IsDialogMessage(hWnd,&msg);
		
		}
		
    }
	
  
    return int(msg.wParam);
}


BOOL CALLBACK WindowProcA(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   
    switch(message)
    {
		case WM_INITDIALOG:
			return 1;
		case WM_CLOSE:
			DestroyWindow(hWnd);
			return 1;
		case WM_DESTROY:
			PostQuitMessage(0);
		    return 1;

    };
    return 0;
} 
[/Source]
I coundnt find the mistakes . It was compiled fine ,but the exe file just couldnt run . IDD_DIALOG1 is A normal Dialog includes 1 Button If I take out the button then it works very well ,but if I put the button on the dialogbox or some other child windows , I just doesnt work I ve been spending 3 hours on this , but still couldnt figure it out Thank you

Share this post


Link to post
Share on other sites
Hi
in WM_INITDIALOG you are returning 1, meaning dialog is trying to set focus to child window(button for example) that is specified in wParam.
If you put there return 0 you are preventing setting of default focus button.

Meaning, if you have invalid handle to default button, it will crash (i.e. trying to set non-existent button to default focus).

Hope this helps.

Share this post


Link to post
Share on other sites
OK I tried , hWnd is always 0 after CreateDialogParam

I try to either set return 0 in WM_INIDIALOG or return 1 and set CreateDialogParam(......, IDC_BUTTON1). Still doesnt work

Any other cases shoud I try

THank you

Share this post


Link to post
Share on other sites
One more thing, message pump loop, should look something like this:


while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
if(!IsDialogMessage(hWnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}




but yours is also ok.

If the program doesn't start, then it is possible that program can't initialize some of the controls.
Surely your hWnd didn't initialize normally, it is NULL because CreateDialogParam failed. You can get more information on last error calling GetLastError() function.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this