MFC program minimized to Pallet

Source: Internet
Author: User
Tags response code

1, in the resources of the icon to import a favorite icons, the ID named Idr_mainframe, the previous idr_mainframe icon removed;

2, in their own dialog header file defined a variable notifyicondata m_nid, about the structure of the specific information can be consulted MSDN;

3. Add the message response function OnInitDialog () and add the following code to the function, so that when the program starts, it displays its own application icon in the tray.

1   //---------------------------Tray Display---------------------------------//2 3M_nid.cbsize = (DWORD)sizeof(notifyicondata);4 5M_nid.hwnd = This-m_hwnd;6 7M_nid.uid =Idr_mainframe;8 9M_nid.uflags = Nif_icon | Nif_message |Nif_tip;Ten  OneM_nid.ucallbackmessage = Wm_showtask;//Custom message name A  -M_nid.hicon =LoadIcon (AfxGetInstanceHandle (), Makeintresource (Idr_mainframe)); -  thestrcpy (M_nid.sztip,"Server Programs");//Informational Cue bar is "server program", VS2008 Unicode Encoding with wcscpy_s () function -  -Shell_NotifyIcon (Nim_add, &m_nid);//Add an icon to the tray area

Compile at this time, will report Wm_showtask's mistake, because this message wants to define itself.

4. Declare the message function prototype in the dialog header file

LRESULT Onshowtask (WPARAM WPARAM, LPARAM LPARAM);

5. Message mapping in the dialog source file

On_message (Wm_showtask,onshowtask)

6, add a custom message response code in the dialog source file, left-click the pop-up application main window and right-click the pop-up menu.

1 LRESULT cserverdlg::onshowtask (WPARAM WPARAM, LPARAM LPARAM)2     {3            if(WParam! =idr_mainframe)4                   return 1;5            Switch(LParam)6            {7             CaseWm_rbuttonup://pop-up menu when right-click8                   {                9Lppoint Lpoint =NewTagpoint;Ten:: GetCursorPos (Lpoint);//Get mouse position One CMenu menu; AMenu. CreatePopupMenu ();//declaring a pop-up menu -Menu. AppendMenu (mf_string, Wm_destroy,"Close"); -Menu. TrackPopupMenu (Tpm_leftalign, lpoint->x, Lpoint->y, This); theHMENU HMENU =menu. Detach (); - menu. DestroyMenu (); - Delete lpoint; -                   } +                    Break; -             CaseWM_LBUTTONDBLCLK://left-click Processing +                   { A                           This->showwindow (SW_SHOWNORMAL);//Show main Window at                   } -  -                    Break; -            } -            return 0; -}

7, add OnSize message response function, handle the operation when minimizing.

 1  void  cserverdlg::onsize (UINT NType, int  cx,  CY)  2   { 3   Cdialog::onsize (NType, CX, CY);  4  if  (nType == size_minimized)  5   { 6  ShowWindow (sw_hide); //  7   8< /span>} 

8. Add the message response function when closing the window, remove the application icon from the Tray

1 BOOL Cserverdlg::D estroywindow () 2       3            // Remove icon in pallet area 4            Shell_NotifyIcon (Nim_delete, &M_nid);              5            return CDialog::D Estroywindow (); 6     }

MFC program minimized to Pallet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.