Minimizing to tray

Started by
12 comments, last by slippnslide 17 years, 9 months ago
Quote:Original post by slippnslide
Yes, I see it, but it's not working when I implement it into my code.


That's not very specific. What does the compiler say? Does it compile at all?
Advertisement
Well, I'm not using your class because it's more than I need. I just wrote my own few lines of code to create the icon and display it based off of MSDN and some of your code. After that, I don't see anywhere where it detects if the window was minimized. I see where it checks if the icon was clicked, ect. What I tried was what I thought was the code to detect the minimized window, but I was wrong.

Edit: Got it. For those that care, put this in your message loop:

case WM_SYSCOMMAND:        {            if(wParam == SC_MINIMIZE)            {                ShowWindow(hWnd, SW_HIDE);            } break;

But, apparantly the window doesn't stay hidden. So, does anyone know why?

[Edited by - slippnslide on July 12, 2006 12:19:37 PM]
You need to respond to the WM_SIZE message. Check it out on MSDN.

For quick reference, try this:


if(uMsg == WM_SIZE)
{
switch(wParam)
{
case SIZE_MAXIMIZED:
break;
case SIZE_MINIMIZED:
break;
case SIZE_RESTORED:
break;
}
}
Great! That fixed that problem, but I have another. I don't understand why it's not working. I have the window minimizing to the tray icon, but when I click on it, the window won't maximize. This is the error I'm getting. If somebody is willing to take a look at my error and my code to see if you can see why it won't maximize, it would be greatly appreciated (you don't need to do it for me, just a few pointers would do). If not, that's fine too.
Quote:Project : Win32 Application
Compiler : GNU GCC Compiler (called directly)
Directory : C:\Documents and Settings\John\Desktop\derp--------------------------------------------------------------------------------
Switching to target: default
Compiling: main.cpp
main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
main.cpp:57: warning: passing NULL used for non-pointer converting 1 of `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)'
Compiling: Win32GUI.rc
Linking executable: C:\Documents and Settings\John\Desktop\derp\Win32GUI.exe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 1 warnings


And this is my basic code. It's not neat because I'm trying to just get this to work.

// include the basic windows header file#include <windows.h>#include <windowsx.h>#include <shellapi.h>#include "resource.h"#define WM_TRAYMESSAGE (WM_USER + 1)// for NOTIFYICONDATANOTIFYICONDATA nid;// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd,                         UINT message,                         WPARAM wParam,                         LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,                   HINSTANCE hPrevInstance,                   LPSTR lpCmdLine,                   int nCmdShow){    // the handle for the window, filled by a function    HWND hWnd;    // this struct holds information for the window class    WNDCLASSEX wc;    // clear out the window class for use    ZeroMemory(&wc, sizeof(WNDCLASSEX));    // fill in the struct with the needed information    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = (WNDPROC)WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;    wc.lpszClassName = "WindowClass1";    // register the window class    RegisterClassEx(&wc);    // create the window and use the result as the handle    hWnd = CreateWindowEx(NULL,                          "WindowClass1",    // name of the window class                          "Our First Windowed Program",   // title of the window                          WS_OVERLAPPEDWINDOW,    // window style                          300,    // x-position of the window                          300,    // y-position of the window                          500,    // width of the window                          400,    // height of the window                          NULL,    // we have no parent window, NULL                          NULL,    // we aren't using menus, NULL                          hInstance,    // application handle                          NULL);    // used with multiple windows, NULL    // fill the struct for NOTIFYICONDATA with the needed info    nid.cbSize = sizeof(NOTIFYICONDATA);    nid.hWnd = hWnd;    nid.uID = 0;    nid.uFlags = NIF_ICON | NIF_TIP;    nid.uCallbackMessage = WM_TRAYMESSAGE;    HICON hIco = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));    nid.hIcon = hIco;    strncpy( nid.szTip, "App name", 64 );    // display the window on the screen    ShowWindow(hWnd, nCmdShow);    Shell_NotifyIcon(NIM_ADD, &nid);    if(hIco) { DestroyIcon(hIco); }    // enter the main loop:    // this struct holds Windows event messages    MSG msg;    // wait for the next message in the queue, store the result in 'msg'    while(GetMessage(&msg, NULL, 0, 0))    {        // translate keystroke messages into the right format        TranslateMessage(&msg);        // send the message to the WindowProc function        DispatchMessage(&msg);    }    // return this part of the WM_QUIT message to Windows    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    // sort through and find what code to run for the message given    switch(message)    {        // this message is read when the window is closed        case WM_DESTROY:            {                // close the application entirely                Shell_NotifyIcon(NIM_DELETE, &nid);                PostQuitMessage(0);                return 0;            } break;       /*  case WM_TRAYMESSAGE:         {            if(lParam == WM_LBUTTONDOWN)            {                Shell_NotifyIcon(NIM_DELETE, &nid);            }         } break;*/         case WM_SIZE:         {             if(wParam == SIZE_MINIMIZED)             {                 ShowWindow(hWnd, SW_HIDE);             }         } break;    }    // Handle any messages the switch statement didn't    return DefWindowProc (hWnd, message, wParam, lParam);}


The error points to the last NULL in CreateWindowEx.

Thanks in advance to anyone who is willing to help.

Edit: I got the warning fixed. Right now, I'm just trying to figure out why my window won't maximize. I have the code to remove the icon from the tray there for testing purposes.

Edit 2: It seems my case WM_TRAYMESSAGE: statement isn't working.

Edit 3: Solved. Just forgot to add in NIF_MESSAGE to my nid.uFlags variable. Such a stupid mistake.

[Edited by - slippnslide on July 12, 2006 11:46:00 PM]

This topic is closed to new replies.

Advertisement