Jump to content
  • Advertisement
DividedByZero

C++ Modeless dialogbox Win32 question

Recommended Posts

Hi Guys,

I have a modeless dialog box that I have created with CreateDialog() being called from the parent window.

According to the docs, being modeless, I should be able to select the window below it to give it focus. But for some reason the dialog box always retains focus until closed.

The dialog box is created using the 'Add resource' option in the resources in Visual Studio 2017, if that information is of any use.

How do I go about allowing the parent window to be selected again? I am using the Dialog box as a tool bar, so I'd like to still have it on top but allow other windows within the same application to gain focus.

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement

It might be something to do with how I am handling my message events.

Once the dialog box is open, the main window no longer responds to any events.

My main loop is pretty basic;

	while (bContinue)
	{
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);

			if (msg.message == WM_QUIT)
				bContinue = false;
		}
	}

If I click on the main window, the title bar of the dialog box greys out like as if it has lost focus, but the events continue to function as per normal on the dialog box. 

When I close the dialog box the main window is happily on control again.

Edited by DividedByZero

Share this post


Link to post
Share on other sites

Honestly I'm not a fan of CreateDialog(), according to the docs it just uses the CreateWindowEx() function anyway, just do it manually and have a lot more control.  I'm sure you read this already but here is an example from Microsoft themselves.  Here is an older example too.

Edited by CrazyCdn
Formatting errors

Share this post


Link to post
Share on other sites

Strange, even if I manually override the resource file like in the example above, the parent window still not respond unless the dialog box is closed.

STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION

 

 

Just found it!

I was doing this in the dialog box procedure 

DefWindowProc(hWnd, msg, wParam, lParam);

 

I have changed it to...

return FALSE;

...and all is happy.

 

Thanks for your help guys! :)

Share this post


Link to post
Share on other sites

Yup, that would do it.  In the future post as much code as you can.  But try and first make the smallest working example of your problem.  No one wants to read 3000 lines of code 😉  Glad you got it figured out though.

Share this post


Link to post
Share on other sites

Will do.

I thought I'd post what seemed to be the obvious section to start with, as I don't have much experience when it comes to intermediate window handling. I have always dealt with a single simple window up until today. But now I am feeling adventurous - LOL.

Thanks again.

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!