编程论坛's Archiver

vfdff 发表于 2008-5-25 20:44

程序隐藏运行

大家指教下,如何让一个程序在后台隐藏运行呢 ??

随心 发表于 2008-5-25 21:10

ShowWindow(SW_HIDE); , 这个行吧?

p1s 发表于 2008-5-25 22:27

打算不在任务栏上显示还是打算不在任务管理器的进程列表中显示?
方法都挺多的,不知道你偏好哪一种。

vfdff 发表于 2008-5-25 22:45

回复 2# 随心 的帖子

这个我试过了 不行 (我是在对话框初始化部分加入的)

BOOL CDialogExampleApp::InitInstance()
{
        // Standard initialization
        // If you are not using these features and wish to reduce the size
        //  of your final executable, you should remove from the following
        //  the specific initialization routines you do not need.

#ifdef _AFXDLL
        Enable3dControls();                        // Call this when using MFC in a shared DLL
#else
        Enable3dControlsStatic();        // Call this when linking to MFC statically
#endif

        CDialogExampleDlg dlg;
        m_pMainWnd = &dlg;
   
        int nResponse = dlg.DoModal();
        if (nResponse == IDOK)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with OK
        }
        else if (nResponse == IDCANCEL)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with Cancel
        }

      ShowWindow(SW_HIDE);  // 添加在这里 ,好像ShowWindow要两个参数
   
        return FALSE;
}
提示 error C2660: 'ShowWindow' : function does not take 1 parameters

vfdff 发表于 2008-5-25 22:47

回复 3# p1s 的帖子

如果你方便的话,两个都给讲讲吧@
我一点思绪也没有 ,谢谢了

随心 发表于 2008-5-26 00:16

这样吧,重写下面这两个函数:

BOOL CDsdfDlg::PreCreateWindow(CREATESTRUCT& cs)
{
        // TODO: Add your specialized code here and/or call the base class

        cs.style = WS_POPUP;                                //使主窗口不可见
    cs.dwExStyle |=WS_EX_TOOLWINDOW;        //不显示任务按钮

        return CDialog::PreCreateWindow(cs);
}

LRESULT CDsdfDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
        // TODO: Add your specialized code here and/or call the base class
       
        if(message==WM_NCPAINT )
    ShowWindow(SW_HIDE);
        return CDialog::DefWindowProc(message, wParam, lParam);
}

[[it] 本帖最后由 随心 于 2008-5-26 00:21 编辑 [/it]]

随心 发表于 2008-5-26 00:18

[quote][bo][un]vfdff[/un] 在 2008-5-25 22:45 的发言:[/bo]

这个我试过了 不行 (我是在对话框初始化部分加入的)

ShowWindow(SW_HIDE);  // 添加在这里 ,好像ShowWindow要两个参数  ... [/quote]

谁让你在那里加的了,还说少一个参数 [em10]

vfdff 发表于 2008-5-26 00:21

回复 7# 随心 的帖子

那应该哪里添加的呢 ?

随心 发表于 2008-5-26 00:24

加OnPaint里,一定行[em12]

随心 发表于 2008-5-26 00:25

[em14] LS是我第一千零一个帖子,纪念一下

vfdff 发表于 2008-5-26 00:26

回复 6# 随心 的帖子

LRESULT CMainFrame::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    // TODO: Add your specialized code here and/or call the base class
   
    if(message==133 )
        ShowWindow(SW_HIDE);
    return CDialog::DefWindowProc(message, wParam, lParam);
}
有什么吗作用?我好像单单使用了
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
        // TODO: Add your specialized code here and/or call the base class

        cs.style = WS_POPUP;                                //使主窗口不可见
    cs.dwExStyle |=WS_EX_TOOLWINDOW;        //不显示任务按钮

        return CDialog::PreCreateWindow(cs);
}
就发现已经是实现了隐藏功能?

随心 发表于 2008-5-26 00:33

说明一下吧,重写的第一个函数是当接收到WM_NCPAINT(重绘非客户区)消息时隐藏当前窗口;第二个是在创建窗口的时候设置一些窗口属性,当然你可以在对话框资源属性页上去设置

随心 发表于 2008-5-26 00:39

明白了吧[em01]
没问题偶去觉觉了
新的一周新的一天已经开始了

vfdff 发表于 2008-5-26 12:27

回复 10# 随心 的帖子

第一千零一添,也希望像第一千零一夜一样,终于找到自己的爱情

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.