Jump to content
  • Advertisement
Sign in to follow this  
nekobasu33

WIN32 creating System Tray program with pop-up Dialog Boxes

This topic is 4191 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to create a program that I can minimize to the Windows system tray using Win32 programming, VS and C++. My plan is when I click on the program icon in the system tray, a pop up menu containing a list, for example: "About", "Configuration..." and "Exit" will appear. Then when you click on any entry of the list, a dialog box will pop up. I have successfully minimize my program to the system tray and be able to do left and right click to show some dialog boxes. However, if fells like it's a HACK to get it to work. Here's why: - First of all: When you create a Win32 program using VS .net, by default, you will be provided with a menu window with "File", "About". Then, you can click on the "About" on the menu window and a pop up Dialog Box will show up. - The way I am solve my problem is: 1. minimize the default menu window to the system tray 2. when I click on the program icon on the system tray, a list will pop up and then dialog box will appear when I choose any of the entry in the list. I am using "AppendMenu" function to create each of the list entries. 3. here's the part where it feels like it's a hack: I HIDE the menu window and not using it at all. I did this because I need buttons, and I cannot use/create button on the menu window. Is there any suggestion on how to tackle this problem better instead of hiding the menu window? Instead of using AppendMenu function, is there I way to access one of the drop down menu in the menu window (that I never used) so it pop up on the system tray when I click on the program icon. Any help would be appreciated. Thank you in advance. [Edited by - nekobasu33 on June 26, 2007 1:37:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
I am having a bit of difficulty following what you are doing. What is the menu window? Maybe you can post a relevant sample of code?

Share this post


Link to post
Share on other sites
Sorry for the confusion. What I mean by menu window is the default win32 window that is provided when we are using the new-project wizard in Visual Studio. It's the window that will appear when we do the following:


hwnd = CreateWindowEX(...);

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);




My intentions:

1. To store my application/program in the system tray, so only the icon appear on it.
2. To be able to do right and left-click operation on the icon (that I store in the system tray), and a list will pop up. It can have "Configuration", "About", and what not.
3. To be able to choose one of the items in the pop-up list and a window will pop up with some buttons that I can click on.


However, since I cannot add button on the default window, I'm using Dialog Box for whenever I choose anything on the pop-up list. And then I hide the main window by using:


ShowWindow(hwnd, SW_HIDE);




Here's how I do my pop up list on the system tray:


HMENU myMenu = NULL;
myMenu = CreatePopupMenu();

AppendMenu(myMenu, MF_STRING, IDM_CONFIG, _T("Configuration..."));
AppendMenu(myMenu, MF_STRING, IDM_TRAYABOUT, _T("About"));
AppendMenu(myMenu, MF_SEPARATOR, 0, _T(""));
AppendMenu(myMenu, MF_STRING, IDM_TRAYEXIT, _T("Exit"));




These whole thing feels like a hack, though, because I am hiding and not using the main window at all.
I hope I don't make you more confuse with my explanation.

Share this post


Link to post
Share on other sites
Have you tried that using a menu defined in the .rc file?

Here's a snippet used with a context menu (ie a right mouse click popup)



case WM_CONTEXTMENU:
{
HMENU hmenu = LoadMenu(GetModuleHandle(NULL), "context"); // GetMenu(hWnd);
HMENU hsub = GetSubMenu(hmenu, 0);
SetForegroundWindow(hwnd);
TrackPopupMenuEx(hsub,
TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON,
LOWORD(lparam), HIWORD(lparam), hwnd, NULL);
DestroyMenu(hsub);
DestroyMenu(hmenu);
}
return 0;

/* and this is the menu in the .rc file

context MENU
BEGIN
POPUP ""
BEGIN
MENUITEM "Fountain", IDM_FOUNTAIN
MENUITEM "Warp Speed", IDM_WARP
MENUITEM "Galaxy", IDM_GALAXY
MENUITEM SEPARATOR
MENUITEM "Track Mouse", IDM_TRACK
MENUITEM "Reset Params", IDM_RESET
MENUITEM SEPARATOR
MENUITEM "Exit", IDM_EXIT
END
END

*/





The rest of this cheesy little program can be found here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!