In VC ++, to minimize MFC to the system tray, you need to call the yyicondata class and register the corresponding message. The following describes how to implement it in detail:
Step 1: declare a policyicondata class, that is Notifyicondata notifyicon; This statement can be placed in the declaration of the DLG class as a member of the DLG class, or in the implementation of the DLG class and used as a global variable. Step 2: declare a Response Function Afx_msg void onnotifyicon (wparam, lparam iparam ); Used to respond to mouse operations. Put this function into the declaration of the DLG class as a member of the DLG class. Step 3: Define the message name as the message number and register the message. This step is very important! Because I did not register the message, I could not find the problem after debugging for a long time. This step is performed in DLG. cpp (implementation of DLG. Define the message name and message number : # Define wm_nc (wm_user + 1001 ), 1001 is only used to specify a message number and can be specified at will. Registration is added between begin_message_map (DLG, cdialog) and end_message_map (). On_message (wm_nc, onpolicyicon ). Step 4: add the following to the function that minimizes MFC to the system tray: Code : Policyicon. cbsize = sizeof (policyicondata );
Policyicon. hicon = afxgetapp ()-> loadicon (idr_mainframe );
Policyicon. hwnd = m_hwnd;
Lstrcpy (policyicon. sztip, "policyicon test ");
Policyicon. ucallbackmessage = wm_nc;
Notifyicon. uflags = nif_icon | nif_message | nif_tip;
Shell_policyicon (nim_add, & policyicon ); With the above Code, when Program When running a function containing the above Code, an icon will be added to the system tray. To hide the Main Dialog Box, add another sentence. Showwindow (sw_hide );In this way, the MFC is minimized to the system tray. However, you also need to add a function that responds to the mouse when you click the tray icon, that is, the onpolicyicon function in step 2. Step 5: The onpolicyicon function is as follows: void cdlg: onpolicyicon (wparam, lparam iparam)
{< br> If (iparam = wm_lbuttondown) | (iparam = wm_rbuttondown)
{< br> modifystyleex (0, ws_ex_topmost );
showwindow (sw_show);
// shell_policyicon (nim_delete, & policyicon);
}< BR >} The above function is very simple to write, because I defined the Dialog Box Based on the MFC, without adding a menu, so simply click the tray icon to bring up the main dialog box. Right-click the tray icon to bring up a small menu, and then select the operation. It is better to select menu-based MFC when creating the project. This will be much easier. I have not studied the details yet, let's not talk about it. For the shell_policyicon (nim_delete, & policyicon) in the above function, it is to clear the tray icon, which can not be found here, but it must be added when exiting the entire program, or the program exits, there is also an icon at the tray. The system will find that the process is left and cleared only when the mouse points there. This is not a good practice! Transferred from: bytes? See the following
VC responds to the event or message of the maximized Minimize button
Method 1. Processing in onsize message event
Minimize size_minimized,
Maximize size_maximized,
Restore size_restored,
For example:
Void cmaindlg: onsize (uint ntype, int CX, int CY)
{
Cdialog: onsize (ntype, CX, CY );
// Todo: add your message handler code here
//: Sendmessage (g_hmain, wm_form_resize, 0, 0 );
If (ntype = size_maximized)
{
// Add the event to be minimized here
//: Sendmessage (g_hmain, wm_form_resize, 0, 0 );
}
If (ntype = size_restored)
{
// Add the event to be processed during restoration.
//: Sendmessage (g_hmain, wm_form_resize, 0, 0 );
}
}
Method 2
Processing in onsyscommand
Nid = SC _maximize is maximized
Nid = SC _minimize is minimized
From: http://www.ieee.org.cn/dispbbs.asp? Boardid = 61 & id = 55404