zoukankan      html  css  js  c++  java
  • [VC/MFC]一条语句实现程序运行时隐藏窗口

    因为受到经济危机的影响,我在 bokee.com 的博客可能随时出现无法访问的情况;因此将2005年到2006年间在 bokee.com 撰写的博客文章全部迁移到 csdn 博客中来,本文正是其中一篇迁移的文章。

     

          因为最近我的不良网页过滤引擎--上帝之手的开发进入实际开发阶段,因此开始了很多方面的系统编程比如说进程隐藏,窗口隐藏等等,因为这是监控类的软件,最好是运行在用户不知情的情况下,所以最好是把窗口隐藏起来,然后通过hotkey来呼唤.在如何实现窗口隐藏的时候,我可以说是费尽周章.

          一开始,我想到的是在CMainFrame里的OnCreate写上一句this->ShowWindow(SW_HIDE);,问题倒是得到了解决,但是却出现一闪而过的现象,的确是很不完美.然后我开始在网上找资料,但都有这样的问题,而且有关于窗口隐藏的很多都是基于Dialog.我决定自己再研究研究.

         于是我建立了一个新的空项目,仔细的看代码,发现在CXXApp::InitInstance()里有这么一句:m_pMainWnd->ShowWindow(SW_SHOW);,这不是显示主窗口的意思吗?我把它注释掉不就得了,说干就干,注释,编译,运行,我靠,窗口还是正常出现似乎跟这个语句无关啊.

         这么说来就是在执行这个语句之前窗口已经显示出来了.因此我在这个语句前面的如下代码段设了断点:

          if (!ProcessShellCommand(cmdInfo))

               return FALSE;

     

          跟踪进去,发现:

     

    BOOL CWinApp::ProcessShellCommand(CCommandLineInfo& rCmdInfo)

    {

     BOOL bResult = TRUE;

     switch (rCmdInfo.m_nShellCommand)

     {

     case CCommandLineInfo::FileNew:

     ///////////////////////////////////////////////.

     

    ............

      break;

     

      // If we've been asked to open a file, call OpenDocumentFile()

     

     case CCommandLineInfo::FileOpen:

    .......................

      break;

     

      // If the user wanted to print, hide our main window and

      // fire a message to ourselves to start the printing

     

     case CCommandLineInfo::FilePrintTo:

     case CCommandLineInfo::FilePrint:

      m_nCmdShow = SW_HIDE;

      ASSERT(m_pCmdInfo == NULL);

      OpenDocumentFile(rCmdInfo.m_strFileName);

      m_pCmdInfo = &rCmdInfo;

      m_pMainWnd->SendMessage(WM_COMMAND, ID_FILE_PRINT_DIRECT);

      m_pCmdInfo = NULL;

      bResult = FALSE;

      break;

      // If we're doing DDE, hide ourselves

       请注意红色的那句,我发现 case CCommandLineInfo::FileNew:时是没有这执行这一句的,因此我想能不能通过这一句实现窗口隐藏呢?

       于是我在

           if (!ProcessShellCommand(cmdInfo))

                return FALSE;

    的面面加上一句  m_nCmdShow = SW_HIDE;

    然后编译,运行,窗口不见了!!!也没有出现一闪而过的情况,我成功了!

  • 相关阅读:
    第4月第1天 makefile automake
    第3月30天 UIImage imageWithContentsOfFile卡顿 Can't add self as subview MPMoviePlayerControlle rcrash
    第3月第27天 uitableviewcell复用
    learning uboot fstype command
    learning uboot part command
    linux command dialog
    linux command curl and sha256sum implement download verification package
    learning shell script prompt to run with superuser privileges (4)
    learning shell get script absolute path (3)
    learning shell args handing key=value example (2)
  • 原文地址:https://www.cnblogs.com/aiwz/p/6154437.html
Copyright © 2011-2022 走看看