// tongzhiqudlg.cpp: importation file // mainly tells how to put the dialog program into the notification bar, and hide the dialog program and status bar
// The Hide Dialog is mainly used to setwindowPos.
Hidden status bar to use ModifyStyleex
#include "stdafx.h" #include "tongzhiqu.h" #include "tongzhiqudlg.h" #include
#ifdef _Debug
#define new debug_new
#undef this_file
Static char this_file [] = __file__;
#ENDIF
// uint wm_showtask;
#define wm_showtask 0x11
/
// Caboutdlg Dialog Used for App About
Class Caboutdlg: public cdialog {public: capoutdlg ();
// Dialog Data // {{AFX_DATA (Caboutdlg) Enum {IDD = IDD_ABOUTBOX}; //}} AFX_DATA
// classwizard generated virtual function overrides // {{AFX_VIRTUAL (Caboutdlg) protected: Virtual Void DodataExchange (CDATAEXCHANGE * PDX); // DDX / DDV Support //}} AFX_VIRTUAL
// ImplementationProtace: // {{AFX_MSG (Caboutdlg) //}} AFX_MSG DECLARE_MESSAGE_MAP ()};
Caboutdlg :: Caboutdlg (): cdialog (caboutdlg :: IDD) {/ {{AFX_DATA_INIT (Caboutdlg) //}} AFX_DATA_INIT}
Void Caboutdlg :: DODATAEXCHANGE (CDataExchange * PDX) {cdialog :: DODATAEXCHANGE (PDX); // {{AFX_DATA_MAP (CaboutDLG) //}} AFX_DATA_MAP}
Begin_MESSAGE_MAP (Caboutdlg, cdialog) // {{AFX_MSG_MAP (Caboutdlg) // No Message Handlers //}} AFX_MSG_MAPEND_MESSAGE_MAP ()
/// CTongzhiquDLG Dialog
CTongzhiquDlg :: CTongzhiquDlg (CWnd * pParent / * = NULL * /): CDialog (CTongzhiquDlg :: IDD, pParent) {// {{AFX_DATA_INIT (CTongzhiquDlg) // NOTE: the ClassWizard will add member initialization here //}} AFX_DATA_INIT // Note That Loadicon Does Not Require A Subsequent Destroyicon in Win32 M_HICON = AFXGetApp () -> loadicon (iDR_mainframe);
void CTongzhiquDlg :: DoDataExchange (CDataExchange * pDX) {CDialog :: DoDataExchange (pDX); // {{AFX_DATA_MAP (CTongzhiquDlg) //}} AFX_DATA_MAP} void CTongzhiquDlg :: toTray () {// UINT WM_SHOWTASK; NOTIFYICONDATA nid; nid .cbSize = (DWORD) sizeof (NOTIFYICONDATA); nid.hWnd = this-> m_hWnd; nid.uID = IDI_ICON1; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_SHOWTASK; // the name of the custom message nid .hicon = loading (), makeintresource (iDi_icon1)); strcpy (nid.sztip, "notification bar"); // Information prompt is "notification" shell_notifyicon (NIM_ADD, & NID); // Add icon in the tray area } void CTongzhiquDlg :: DelIcon () // delete icon {NOTIFYICONDATA nid; nid.cbSize = (DWORD) sizeof (NOTIFYICONDATA); nid.hWnd = this-> m_hWnd; nid.uID = IDI_ICON1; Shell_NotifyIcon (NIM_DELETE, & nid); }
BEGIN_MESSAGE_MAP (CTongzhiquDlg, CDialog) // {{AFX_MSG_MAP (CTongzhiquDlg) ON_MESSAGE (WM_SHOWTASK, onShowTask) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () ON_COMMAND (IDM_EXIT, OnExit) ON_COMMAND (IDM_ABOUT, OnAbout) //}} AFX_MSG_MAPEND_MESSAGE_MAP ()
/// CTongzhiquDlg message handlersLRESULT CTongzhiquDlg :: onShowTask (WPARAM wParam, LPARAM lParam) // wParam is received icon ID, rather lParam behavior of the mouse is received {if return 1 (wParam = IDI_ICON1!); Switch (lParam) {CASE WM_RBUTTONUP: / / Right-click Pop-up shortcut menu {// Display floating menu cmenu * Pt, T; Cpoint PP (Loword (Loword (Loword (iDi_icon1); Pt = TgetSubmenu (0); getCursorpos (& PP); // Get mouse position Pt-> TRACKPOPUPMENU (TPM_RightAlign | TPM_LEFTBUTTON, PP.X, PP.Y, this);
} Break; Case WM_LBUTTONDBLCLK: / / Double-click the left button to process {setWindowPos (& Wndnotopmost, 250, 200, 500, 300, swp_showwindow); // Simple display main window finisher} Break;} Return 0;
}
BOOL CTongzhiquDlg :: OnInitDialog () {CDialog :: OnInitDialog (); CTongzhiquDlg :: toTray (); ASSERT ((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT (IDM_ABOUTBOX <0xF000); CMenu * pSysMenu = GetSystemMenu (FALSE); if (pSysMenu = NULL!) {CString strAboutMenu; strAboutMenu.LoadString (IDS_ABOUTBOX); if {pSysMenu-> AppendMenu (MF_SEPARATOR) (strAboutMenu.IsEmpty ()!); pSysMenu-> AppendMenu (MF_STRING, IDM_ABOUTBOX, strAboutMenu);}} SetWindowPOS (& WNDTOP, 0, 0, 0, 0, NULL); // With the hidden purpose by setting the window size, the effect is good ModifyStyleex (WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);
// Todo: Add Extra Initialization Here Return True; // Return True Unless}
void CTongzhiquDlg :: OnSysCommand (UINT nID, LPARAM lParam) {if ((nID & 0xFFF0) == IDM_ABOUTBOX) {CAboutDlg dlgAbout; dlgAbout.DoModal ();} else {CDialog :: OnSysCommand (nID, lParam);}}
// if you add a minimize button to your dialog, you will need the code Below // to draw the icon. For mfc Applications Using the document / view model, // this is automaticly done for you by the framework.
Void Ctongzhiqudlg :: onpaint () {if (isiconic ()) {cpaintdc DC (this); // device context for Painting
SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.getsafehdc (), 0);
// Center icon in client rectangle int cxIcon = GetSystemMetrics (SM_CXICON); int cyIcon = GetSystemMetrics (SM_CYICON); CRect rect; GetClientRect (& rect); int x = (rect.Width () - cxIcon 1) / 2; int y = (Rect.height () - Cyicon 1) / 2;
// Draw the icon dc.drawicon (x, y, m_hicon);} else {cdialog :: onpaint ();} // showwindow (sw_hide);} // the system calls this to obtain the cursor to display while the user Drags // the minimized window.hcursor ctongzhiqudlg :: ONQUERYDRAGICON () {Return (hcursor) m_hicon;} void ctongzhiqudlg :: oneXit () {DELICON (); enddialog (true);
Void CTongzhique :: onain ()
{// Display dialog SetWindowPos (& Wndnotopmost, 250, 200, 500, 300, swp_showwindow); // centerwindow ();}
Void Ctongzhiqudlg :: Onok () {// Todo: Add extra validation he CDIALOG :: Onok ();
Void Ctongzhiqudlg :: oncancel () {Delicon (); enddialog (true); cdialog :: oncancel ();
VC 6.0 2003 compiled
Source program download
Program example
Author Blog:
http://blog.9cbs.net/netsh/