当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 如何隐藏显示在任务栏中的对话框程序
| 如何隐藏显示在任务栏中的对话框程序 下载源代码 用 WS_EX_TOOLWINDOW 可以创建一个工具窗口,被作为浮动工具栏使用。工具窗口的标 题栏比常规标题栏短,并且使用的窗口字体更小。工具窗口不会出现在任务栏里;当用户 按下 ALT+TAB 健后,也不会出现在任务表中......显然,按照上面的文档所讲的方法无法实现对话框的隐藏。那么答案在哪里?下面就让我将诀窍和技巧告诉你吧: 第一、创建对话框时必须将它作为某个不可见框架窗口的子窗口; 第二、这个不可见窗口的扩展式样必须设置 WS_EX_TOOLWINDOW; 第三、保证对话框的扩展式样没有设置 WS_EX_APPWINDOW; 下面是例子代码的实现细节说明,这个例子程序(HideDlg)很简单,头文件和实现文件都在同一个文件中: ////////////////////////////////////////////////////////////////// HideDlg.cpp 声明部分// ////////////////////////////////////////////////////////////////#include "stdafx.h"#include "resource.h"#include "statlink.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifclass CMainFrame : public CFrameWnd {protected: CString m_sClassName; virtual BOOL PreCreateWindow(CREATESTRUCT& cs);public: CMainFrame() { } ~CMainFrame() { }};class CMyDlg : public CDialog {public: CMyDlg(CWnd* pParent = NULL); // 标准构造函数protected: HICON m_hIcon; CStaticLink m_wndLink; virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP()};class CMyApp : public CWinApp {public: CMyApp(); virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP()};//////////////////////////////////////////////////////// HideDlg.cpp 实现部分////////////////////////////////////////////////////////// 创建不可见框架窗口:设置 WS_EX_TOOLWINDOW 式样BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs){ /* // 设置 WS_EX_TOOLWINDOW 扩展式样 if (CFrameWnd::PreCreateWindow(cs)) { cs.dwExStyle |= WS_EX_TOOLWINDOW; return TRUE; } return FALSE;*/ // 不设置 WS_EX_TOOLWINDOW 扩展式样 return CFrameWnd::PreCreateWindow(cs);}BEGIN_MESSAGE_MAP(CMyApp, CWinApp) ON_COMMAND(ID_HELP, CWinApp::OnHelp)END_MESSAGE_MAP()CMyApp::CMyApp(){}CMyApp theApp;////////////////////////////////////////////////////////////////////////// InitInstance: 创建对话框时,把它作为不可见主框架窗口的子窗口对待//////////////////////////////////////////////////////////////////////////BOOL CMyApp::InitInstance(){ CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPED, NULL, NULL); CMyDlg dlg(pFrame); int nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } return FALSE;}class CAboutDlg : public CDialog {public: CAboutDlg(); enum { IDD = IDD_ABOUTBOX };protected: CStaticLink m_wndLink1; CStaticLink m_wndLink2; CStaticLink m_wndLink3;// Implementationprotected: //{{AFX_MSG(CAboutDlg) virtual BOOL OnInitDialog(); //}}AFX_MSG DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)END_MESSAGE_MAP()BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); m_wndLink1.m_link = _T("http://www.vckbase.com"); m_wndLink2.m_link = _T("http://www.vckbase.com"); m_wndLink3.m_link = _T("http://www.vckbase.com"); m_wndLink1.SubclassDlgItem(IDC_STATIC_ICON, this); m_wndLink2.SubclassDlgItem(IDC_VCKBASE, this); m_wndLink3.SubclassDlgItem(IDB_STATIC_IMG, this); return TRUE; // return TRUE unless you set the focus to a control |