allanmb
allanmb

Reputation: 321

How do I add an icon to the taskbar for a simple win32 dialog?

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.

Upvotes: 4

Views: 1491

Answers (2)

4LegsDrivenCat
4LegsDrivenCat

Reputation: 1361

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.

Upvotes: 3

David Heffernan
David Heffernan

Reputation: 612964

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.

Upvotes: 6

Related Questions