Thread: Changing X

  1. #1
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56

    Question Changing X

    How would a person change the "x" to minmize the application instead of closing it?

    SpEcIeS

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    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);
    }

  3. #3
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    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:

    Code:
    case WM_SYSCOMMAND:
          if (LOWORD (wParam) == SC_CLOSE) {
                SendMessage(hWnd,WM_SIZE,SIZE_MINIMIZED,NULL);
                return 1;
          }
          break;
    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_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;
    And just for completion sake, here is the NotifySysIcon proc:

    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;
    }
    Hopefully this will be useful to someone.
    SpEcIeS

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing errno - legal?
    By EVOEx in forum C Programming
    Replies: 6
    Last Post: 02-27-2009, 12:56 PM
  2. Changing windows without changing?
    By Lionmane in forum Windows Programming
    Replies: 7
    Last Post: 10-19-2005, 11:41 AM
  3. [C++/WinAPI] Changing bitmap contrast
    By jagi in forum Windows Programming
    Replies: 0
    Last Post: 03-27-2005, 03:51 PM
  4. changing file formats
    By darfader in forum C Programming
    Replies: 3
    Last Post: 09-26-2003, 02:13 AM
  5. Changing the pallete in allegro?
    By Brian in forum Game Programming
    Replies: 1
    Last Post: 03-02-2002, 01:57 PM