How would a person change the "x" to minmize the application instead of closing it?
![]()
This is a discussion on Changing X within the Windows Programming forums, part of the Platform Specific Boards category; How would a person change the "x" to minmize the application instead of closing it?...
How would a person change the "x" to minmize the application instead of closing it?
![]()
SpEcIeS
Just override the WM_CLOSE message.
Code:LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); { switch (uMsg) { case WM_CLOSE: { ShowWindow(hwnd, SW_MINIMIZE); return 0; /* Don't call DefWindowProc, which would call DestroyWindow. */ } } return DefWindowProc(hwnd, uMsg, wParam, lParam); }
Thank-you anonytmouse for the reply, but I did try to play with the WM_CLOSE and it did not seem to work for me. Perhaps I was using the wrong coding.![]()
Anyway, I did come up with a resolve. Since the program that I am building minimizes to the system tray, and it is a toolbar window, I accessed the WM_SYSCOMMAND. Here is the code that I came up with:
Now everytime the toolbar "x" is used the application minimizes to the system tray. Within the WM_SIZE I have a call to a procedure that sets up the icon.Code:case WM_SYSCOMMAND: if (LOWORD (wParam) == SC_CLOSE) { SendMessage(hWnd,WM_SIZE,SIZE_MINIMIZED,NULL); return 1; } break;
And just for completion sake, here is the NotifySysIcon proc:Code:case WM_SIZE: if(wParam==SIZE_MINIMIZED) { ShowWindow(hWnd,SW_HIDE); NotifySysIcon(hWnd,IDI_ICON,ToolTip,NIM_MODIFY); } else if(wParam==SIZE_RESTORED) { ShowWindow(hWnd,SW_NORMAL); NotifySysIcon(hWnd,IDI_ICON1,ToolTipNew,NIM_MODIFY); } break;
Hopefully this will be useful to someone.Code:int NotifySysIcon (HWND hWnd,int IconNum,PSTR ToolTip,DWORD NimType) { Nicon.cbSize=sizeof(NOTIFYICONDATA); Nicon.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IconNum)); Nicon.hWnd = hWnd; Nicon.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP; Nicon.uCallbackMessage = WM_TRAYMESSAGE; Nicon.uID = ICONIDENT; strcpy(Nicon.szTip,ToolTip); Shell_NotifyIcon(NimType,&Nicon); return 0; }![]()
SpEcIeS