OMG Help me I cant find the Error

Started by
5 comments, last by streamer 15 years, 11 months ago

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
Advertisement
Have you tried step-by-step debugging?
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.

THank you, I'll try to do something in the WM_INITDIALOG.
I already debug step by step and msg.message=18=WM_QUIT right in the first time it enters the loop
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
Even I delete All things and just Put
MessageBox(NULL,"Hello","12234",0);

the Box didnt even show up ,what's wrong
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.

This topic is closed to new replies.

Advertisement