我的代码如下:
CXyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
   ......
   AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
   ......
}
但运行后,依然是最大化时的样子,怎么解决?
谢谢!

解决方案 »

  1.   

    如何隐藏显示在任务栏中的对话框程序
    作者:NorthTibet下载源代码
        最近有个朋友做了一个基于对话框的小程序,大家知道,一般具有用户界面的 Windows 程序运行起来后,通常都会在任务栏里体现出来。我的这个朋友不想让她做的对话框程序运行的时候显示在任务栏里。问我如何隐藏?我参考了 MSDN 后告诉她说使用 WS_EX_TOOLWINDOW 扩展窗口式样。她按照我说的方法试了一下,结果没有成功。后来我琢磨了半天,发现这件事情并不像文档中说的那么简单。MSDN 里对 WS_EX_APPWINDOW 的描述是这样的:       用 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_FILE
    static 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()
    };
      

  2.   

    //////////////////////////////////////////////////////
    // 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;// Implementation
    protected:
    //{{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
                  // EXCEPTION: OCX Property Pages should return FALSE
    }CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
    : CDialog(IDD_HIDEDLG, pParent)
    {
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    END_MESSAGE_MAP()BOOL CMyDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); m_wndLink.m_link = _T("http://www.vckbase.com");
    m_wndLink.SubclassDlgItem(IDC_VCKBASE, this);//  去掉注释设置对话框的 WS_EX_APPWINDOW 扩展式样
    // ModifyStyleEx(0,WS_EX_APPWINDOW); // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL) {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty()) {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // 设置对话框图标。
    // 当应用程序的主窗口不是对话框时,框架会自动设置图标。
    SetIcon(m_hIcon, TRUE);       // 设置大图标
    SetIcon(m_hIcon, FALSE);      // 设置小图标

    return TRUE;  // return TRUE  unless you set the focus to a control
    }void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    } else {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// 如果在对话框上添加最小化按钮,必须用CMyDlg::OnPaint() 绘制图标,
    // MFC 用文档/视图模型,由框架自动处理。 
    void CMyDlg::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();
    }
    }// 当用户要求最小化窗口时,系统调用此函数获取要显示的图标。 
    HCURSOR CMyDlg::OnQueryDragIcon()
    {
    return (HCURSOR) m_hIcon;
    }
      

  3.   

    在你的对话框的初始化事件中这样:
    ShowWindow(SW_HIDE);就可以了 ShowWindow(SW_SHOW);就有显示了
      

  4.   

    ShowWindow(SW_HIDE)好像不行吧???http://expert.csdn.net/Expert/topic/1401/1401737.xml?temp=.3586389
      

  5.   

    OnCreate是不是非模态对话框。在模态对话框中我试了,ShowWindow(SW_HIDE),是可以的。
      

  6.   

    http://expert.csdn.net/Expert/topic/1401/1401737.xml?temp=.3586389
    看了这个帖子,才知道更简单的方法,有不明白的去看看吧
      

  7.   

    你做个定时器。例如:在OnInitDialog()中加一句SetTimer(1,500,NULL);在OnTimer()中执行
    ShowWindow(SW_HIDE);在把这个定时器杀掉,KillTimer(1);这样可以,试试吧!