Dialog window grayed out

I'm working on a small program and I have a dialog box that is grayed out and I can't figure out why. The only thing on the window that will highlight is the X (close) button but clicking on it doesn't do anything and I have to use the Task Manager to close the program. In my program, I have a menu item at the top of the window. When I select the option, it brings up another dialog window and it works just fine. From that window, you click on a button for another window to add something to the program. It is this 3rd window that I am having trouble with.

Here is my code for the window. It is based on my other dialog window which works fine. Right now it is very bare-bones because I am trying to get it working. I have a textbox on the dialog with two buttons. They aren't coded to do anything but they are grayed out and you can't even click the buttons or put a cursor in the textbox. I also can't click on the title of the window to have it selected...it stays grayed out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
BOOL CALLBACK
NewOrthographyDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{

	switch (msg)
	{
	case WM_INITDIALOG:
		

		return true;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{

		

		}

		

		return 0;

	// If the dialog was closed (user pressed "x" button)
	// then terminate the dialog.
	case WM_CLOSE:
		EndDialog(hDlg, 0);
		return true;
	}

	// Return any messages we didn't handle to the default windows procedure.
	return DefWindowProc(hDlg, msg, wParam, lParam);
}


This window is called via this code from the previous window:

DialogBox(ghAppInst, MAKEINTRESOURCE(IDD_NEW_ORTHOGRAPHY), hDlg, NewOrthographyDlgProc);
Dialog boxes must not call DefWindowProc.

Instead you should return TRUE if you processed the message and FALSE if you did not.

EDIT: I'm not sure if this is the actual cause of your problem, but it might be... so that's the first thing I'd try.
Last edited on
That worked! At first, replacing that line with "return false;" didn't do anything. So I went to my other dialog that I said was working fine and did the same thing and it started working :).

I'm still pretty new at this so thanks for the info! But what about my main window? I created it as a dialog via Add Resource and it uses that same DefWindowProc line. Is it ok for that one to use it?
But what about my main window?


If it's a dialog box, it shouldn't call DefWindowProc. Whether or not it's the main window doesn't matter.
Ok, thank you!
But what about my main window?

According to Petzold HEXCALC sample, if a dialog is the main app window it should be using a WndProc rather and a DialogProc and therefore calling DefWindowProc. While I don't think it is mandatory, it is pretty common practice.

(Just in case you don't have the book to hand:
hexcalc.c - Charles Petzold
ftp://ftp.charlespetzold.com/ProgWin95/CHAP11/HEXCALC.C‎ )

Nowadays you can use DefDlgProc (introduced in Windows 2000) rather than DefWindowProc. The advantage of using DefDlgProc is that it handles tab stops and other routine dialog stuff for you.

DefDlgProc function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645450%28v=vs.85%29.aspx

Andy

PS Petzold's approach does assume you have (a) given the dialog template a distinct window class (the dialog template has a CLASS statement) and (b) created the dialog using CreateDialog or CreateDialogParam passing NULL for the dialog proc (as that's handled by the class.)

Custom Dialog Boxes
An application can create custom dialog boxes by using an application-defined window class for the dialog boxes instead of using the predefined dialog box class. Applications typically use this method when a dialog box is their main window, but it is also useful for creating modal and modeless dialog boxes for applications that have standard overlapping windows.

etc.

From: Dialog Box Programming Considerations
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644995%28v=vs.85%29.aspx
Last edited on
Topic archived. No new replies allowed.