4

I have a very simple app which has a few buttons and text fields. I want to be able to add an icon to it, as you cant see if it is running when it is behind other windows. What is the simplest way of doing this?

I tried creating a window which was hidden which kinda works but you can see that other window blink when you click on the taskbar icon and I can't seem to make it focus on the dialog box.

allanmb
  • 321
  • 3
  • 14
  • A top-level unowned window will, by default, have an associated taskbar button. What have you done with your app to stop that happening. – David Heffernan Mar 04 '14 at 12:17
  • What I have is a basic WinMain which calls RegisterClassEx/CreateWindowEx. Once this is created I then show my dialog box which is created using VS resource editor. I can get it to show the icon, but clicking on the icon doesn't minimize/maximize the dialog box, instead it does that on the window created with CreateWindowEx – allanmb Mar 04 '14 at 12:48
  • What you are expected to do is use the window you create with `CreateWindowEx` as your application's main window. Why are you using a dialog box as your main window? That seems to be the problem. – David Heffernan Mar 04 '14 at 12:51
  • I just want to use the resource editor to create my GUI. Can I use this window in CreateWindowEx? – allanmb Mar 04 '14 at 13:07
  • I've added an answer that explains my understanding of how you should tackle this. Essentially you need to make the dialog be the only top level window in your app. – David Heffernan Mar 04 '14 at 13:16

2 Answers2

6

I think the fundamental problem is that you have a hidden top-level window which owns your dialog. The dialog is acting as the main window, but the taskbar shows a button associated with the hidden window.

So I guess what you need to do is remove the hidden window altogether. That means getting rid of the RegisterClass and CreateWindow calls.

I'm assuming you show the dialog modeless. In which case you use CreateDialog and ShowWindow to show it. Take heed particularly of this section of the documentation:

After CreateDialog returns, the application displays the dialog box (if it is not already displayed) by using the ShowWindow function. The application destroys the dialog box by using the DestroyWindow function. To support keyboard navigation and other dialog box functionality, the message loop for the dialog box must call the IsDialogMessage function.

Of course if you are showing the dialog modally you can probably carry on doing that. In which case your WinMain function is very simple. It's just a call to DialogBox. No message loop needed because the modal dialog's message loop handles the messages.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    Thank you very much, that works a treat! For some reason I had it in my head that I needed to use CreateWindowEx to get my message loop. I just removed the code to RegsiterClassEx/CreateWindowEx and added the IsDialogMessage to the message loop and it now all works. My PlayList creator is now complete with a separate thread so that the GUI always remains responsive :) – allanmb Mar 04 '14 at 13:49
  • 1
    @allanmb: If this answer solved your problem, consider accepting and upvoting it so others who view this post can find it helpful **more easily**. Best regards. – AlwaysLearningNewStuff Mar 04 '14 at 14:16
2

You can add WS_EX_APPWINDOW extended window style to your dialog. In this case task bar application button will show up even if dialog's owner/parent window is hidden.

4LegsDrivenCat
  • 1,247
  • 1
  • 15
  • 24