zoukankan      html  css  js  c++  java
  • 隐藏基于对话框程序

     
    定义托盘响应消息:
    #define WM_SYSTRAY WM_USER + 120
     
    在头文件中定义变量:
    WINDOWPLACEMENT m_wp;   // 以便在恢复时使用
    NOTIFYICONDATA m_tmid;     // 托盘结构
    CRect       m_rectWnd;       // 保存窗口区域
     
    在初始化函数中加入:
                  GetWindowRect(&m_rectWnd); // 恢复时使用
                  GetWindowPlacement(&m_wp); //恢复时用
                  ModifyStyleEx (WS_EX_APPWINDOW, WS_EX_TOOLWINDOW); // 不在工具栏显示
                               
                  WINDOWPLACEMENT wp;
                 
                  wp.length = sizeof(WINDOWPLACEMENT);
                  wp.flags = WPF_RESTORETOMAXIMIZED;
                  wp.showCmd = SW_HIDE;
                  SetWindowPlacement(&wp);
                 
                  m_tmid.cbSize = sizeof (NOTIFYICONDATA);
                  m_tmid.hWnd = this->m_hWnd;
                  m_tmid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
                  m_tmid.uCallbackMessage = WM_SYSTRAY;
                  m_tmid.uID = IDR_MAINFRAME;
                 
                  CString sz = _T("");
                  strcpy(m_tmid.szTip, "");
                  HICON hIcon;
                  hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
                  m_tmid.hIcon = hIcon;
                  PNOTIFYICONDATA m_ptnid = &m_tmid;
                  ::Shell_NotifyIcon(NIM_ADD, m_ptnid);
                  if (hIcon)
                         ::DestroyIcon(hIcon);
     
    增加窗口消息函数 WM_DESTROY 增加如下
    void CClientDlg::OnDestroy()
    {
           CDialog::OnDestroy();
           ::Shell_NotifyIcon(NIM_DELETE ,&m_tmid);   
    }
    响应WindowProc消息
    LRESULT CClientDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
            switch (message)
              {
              case WM_SYSTRAY:
                     if (lParam == WM_LBUTTONDBLCLK)
                     {
                            // 恢复窗口
                            ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW);
                            SetWindowPlacement(&m_wp);
                            MoveWindow(m_rectWnd, TRUE);
                            CenterWindow();
                     }
                     break;
              case WM_SYSCOMMAND:
                     if (wParam == SC_MINIMIZE)
                     {
                            AfxGetMainWnd()->ShowWindow (SW_HIDE);
                            return 0;
                     }
     
                     if (wParam == SC_CLOSE)
                     {
                            OnCancel();
                            return 0;
                     }
                     break;
              }
          
           return CDialog::WindowProc(message, wParam, lParam);
    }
     
  • 相关阅读:
    多表关联查询(ORACLE版)
    开发中可能会用到的几个 jQuery 小提示和技巧 (转)
    让jquery easyui datagrid列支持绑定嵌套对象
    java图片处理工具类
    如何为Myeclipse手工添加dtd支持
    二进制与运算
    彻底卸载MYSQL,windows版
    Win7系统安装MySQL5.5.21图解教程
    Rust 资源整理
    【译】我的阅读习惯
  • 原文地址:https://www.cnblogs.com/tyjsjl/p/2156084.html
Copyright © 2011-2022 走看看