Setting focus to a dialog box?

Started by
2 comments, last by Dookie 19 years, 3 months ago
Hey guys, I have a stoopid question... I'm writing an editor for my breakout-style game, and one part of that editor is for a dialog box to pop up for the user to manually input some properties for a selected entity. I can code C++ OK, but I'm really not that good at Windows programming. I've created a Direct3D game window and it operates alright. But when I create a properties dialog box using 'CreateDialog()', the dialog box pops up OK but the focus is still on my main Direct3D window. If I try to click anywhere on that dialog box, nothing happens and the box never goes into focus... Sorta hard to explain, but imagine two windowed programs running where one is 'in focus' and the other is 'out of focus'; the 'in focus' window has the colored bar at the top of the window, and the 'out of focus' window has the greyscaled bar at the top of the window. Now when I'm running my Direct3D editor, the Direct3D main window always has the colored bar at the top of its window (in focus) but the dialog box is ALWAYS greyscaled and cannot be clicked into focus! Here's how I'm creating my dialog box:

int CreateBlockPropertiesMenu(HWND hWndParent, HINSTANCE hInstance)
{

	HWND dlg = CreateDialog(hInstance,							// instance handle;
						MAKEINTRESOURCE(IDD_PROPPAGE_BLOCKS),		// dialog identifier;
						hWndParent,					// parent/owner handle;
						DlgBlockPropProc);				// window procedure;

	if(dlg==NULL)
		return 0;
	else
	{
		ShowWindow( dlg, SW_SHOW);
	}

	return 0;
}
...and here's how I'm calling up my dialog box:

CreateBlockPropertiesMenu(DXStuff.hWnd, wc.hInstance);
I do have a 'DlgBlockPropProc' message processor, but it isn't being called at all since the properties window never goes into focus. Argh! 'DXStuff.hWnd' is the handler to my main Direct3D window, and 'wc.hInstance' is gotten from the window class of my main Direct3D window. Anyways, when I use 'CreateBlockPropertiesMenu' to create the dialog box, the dialog box appears but is not in focus. And if I add 'SetFocus(dlg)' in my 'CreateBlockPropertiesMenu' function, it returns NULL (MSDN website: "If the hWnd parameter is invalid or the window is not attached to the calling thread's message queue, the return value is NULL.") When you try to respond to this post, remember that I'm a complete DUMMY when it comes to Windows programming. In other words, my problem is most likely because I've left out something OBVIOUS that everybody else knows to use! If you need to see any more code, lemme know and I'll post it. Thanks in advance for the help!
"The crows seemed to be calling his name, thought Caw"
Advertisement
Could you please post the contents of DlgBlockPropProc?
I had what I suspect is exactly the same problem not so long ago.

Here is the discussion; the punchline is right at the end.

Hope it helps,
Jim.
Thanks for the replies, guys! And sorry about posting a question about something that has such a large scope; it's almost like asking how to write a collision routine for a 3D game (and not being very specific about it!).

I've been searching the 'net for any help on this and found out that learning how to put up a child (popup) window is a little more involved than just creating a dialog box... I looked at your thread JimPrice, and that definitely was one of the problems! I happened upon that one by accident, while looking at code that I wrote for an editor for an older game (that editor didn't work very well either, but at least I could type stuff into the properties window). But then a new problem happened - only the OK and CANCEL buttons had tab priority and anywhere in that popup window I clicked (even over the OK and CANCEL buttons) I would get a Windows error 'ding' sound... I had to alt-tab to go back to VisualC++ and stop the debugger to get out of my editor.

Anyways, I'm rewriting my editor from the ground up and I'm going to write it from the other direction... First I started with a working game and tried to merge the editor into it, but that's where all of my problems happened. So I'm going to start with the raw editor first (which currently works; tab stops and mouse clicks are all properly registered) and THEN merge the game into it... I almost think that some component of DirectX is stealing priority from my popup 'properties' window, but I'll be able to better know exactly whether that's the problem after I start merging the game code into the editor.

I'll keep y'all posted about this one! Because if it IS something about DirectX that's keeping popup windows from properly working and I find a fix for it, I'll be sure to post what got it working. Here's the website where I'm getting all of my window programming help from, be sure to check it out because it's a great start for anyone at my level of programming (someone who can code C++, but doesn't know much about Windows programming).

http://www.winprog.org/tutorial/index.html

Thanks again for the help! :)
"The crows seemed to be calling his name, thought Caw"

This topic is closed to new replies.

Advertisement