954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Another dialog not showing thread

Hey guys, I'm new to this forum so nice to meet you all :D

I'm really bugged by a weird bug that prevents my dialog from showing up, however the buttons show up twice, one overlapping the other. I saw other threads that discusses about this but I'm afraid I can't find a way out through them.

I have already found the problem ( i hope) and (sort of) fixed itby copying and pasting the DialogProcedure code from winprog which i have used as my reference for the project.

here's the code from winprog:

BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{	
		case WM_INITDIALOG:

		return TRUE;
		case WM_COMMAND:
			switch(LOWORD(wParam))
			{
				case IDCANCEL:
					EndDialog(hwnd, IDCANCEL);
				break;
			}
		break;
		default:
			return FALSE;
	}
	return TRUE;
}


and here's mine:

BOOL CALLBACK CalculatorProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{	
		case WM_INITDIALOG:

		return TRUE;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
			case ID_CANCEL:
				EndDialog(hwnd,ID_CANCEL);
				break;
			}
			break;
	}
	return TRUE;
}


i tried replacing my codes for the WinMain and WinProc on the tutorial's solution and the dialog still worked finely. The difference appeared when i replaced my dialog procedure with the tutorial's. When i pasted the tutorial's procedure, I only changed the name of the variables to match mine, in the end, it completely matches mine. Is there something i missed or am i going blind? :(

Lyandor
Newbie Poster
17 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

sorry for double posting, I forgot to mention that i created the dialog in resource view. the dialog is called IDD_DIALOG1 whereas the dialog button is ID_CANCEL :)

Lyandor
Newbie Poster
17 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

If you created the dialog using the CreateDialog function the last function argument should be a pointer to the callback function CalculatorProc.Don't forget to modify that too.

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

hmm I didn't create using CreateDialog function. I used DialogBox function instead. here's what I did in my WinProc:

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
			case ID_HOME_KELUAR:
				PostQuitMessage(0);
				break;

			case ID_KALKULATOR_KALKULATOR:
				{
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(DLG_KALKULATOR),hwnd,CalculatorProc);
				}
				break;
			}
		}
		break;
	default:
		return DefWindowProc(hwnd,message,wParam,lParam);
	}

	return 0;

}
Lyandor
Newbie Poster
17 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

Try creating a modeless dialogbox.

LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static hwnd Dialog; 
    switch (message)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
     
    case WM_COMMAND:
    {
    switch (LOWORD(wParam))
    {
    case ID_HOME_KELUAR:
    PostQuitMessage(0);
    break;
     
    case ID_KALKULATOR_KALKULATOR:
    {
    Dialog=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(DLG_KALKULATOR),hwnd,&CalculatorProc);
    }
    break;
    }
    }
    break;
    default:
    return DefWindowProc(hwnd,message,wParam,lParam);
    }
     
    return 0;
     
    }
caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

Thanks for pointing that out, I'll eventually try out the modeless dialog, however, for this project I'd like to use modal. I want to know where I went wrong with my code :( I don't see any difference with my dialog procedure with the tutorial's that could make my dialog not appearing like it is supposed to @.@

Lyandor
Newbie Poster
17 posts since Jul 2011
Reputation Points: 10
Solved Threads: 2
 

I think you must have a static handle of the dialog box otherwise it get's destroyed.The DialogBox does not return a HWDN so i suggested using CreateDialog instead. Just a hunch .. it think it is much like when you declare a child window in a window procedure.

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: