首页 > 其他分享 >工作线程基类,静默安装

工作线程基类,静默安装

时间:2023-02-09 16:33:04浏览次数:43  
标签:__ MAP return BaseWorkThread 静默 线程 基类 AFX CDialogLoading

#if !defined(AFX_BASEWORKTHREAD_H__D104C15C_8BCD_475B_91C4_4960EBE866A4__INCLUDED_)
#define AFX_BASEWORKTHREAD_H__D104C15C_8BCD_475B_91C4_4960EBE866A4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// BaseWorkThread.h : header file
#include "DialogLoading.h"
//

/////////////////////////////////////////////////////////////////////////////
// BaseWorkThread window

//iori 多线程
#define WM_ONTHREADFINISHED (WM_USER + 199)

class BaseWorkThread : public CWnd
{
// Construction
public:
    BaseWorkThread(CWnd* cWnd);

// Attributes
public:
    CDialogLoading dlgLoading;
    BOOL bIsShowModal;
// Operations
public:
    CWinThread* startWork();
    static UINT innerBeginThread(BaseWorkThread* instance); //内部静态方法,用于启动工作线程
    virtual LRESULT onWorkerFinished(BaseWorkThread* instance); // 线程加载完成的回调函数体

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(BaseWorkThread)
    //}}AFX_VIRTUAL

// Implementation
public:
    virtual ~BaseWorkThread();

    // Generated message map functions
protected:
    CWinThread *m_pThread;
    virtual UINT worker() ; // 工作线程调用的实现体 2022-03-11
    //{{AFX_MSG(BaseWorkThread)
        // NOTE - the ClassWizard will add and remove member functions here.
        afx_msg LRESULT workder_onFinished(WPARAM wParam, LPARAM lParam);
    //}}AFX_MSG    
    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_BASEWORKTHREAD_H__D104C15C_8BCD_475B_91C4_4960EBE866A4__INCLUDED_)

 

// BaseWorkThread.cpp : implementation file
//

#include "stdafx.h"
#include "BaseWorkThread.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// BaseWorkThread

BaseWorkThread::BaseWorkThread(CWnd* pParent)
{
    this->bIsShowModal = FALSE;
    CWnd::Create(NULL,_T("MySocketManage"),WS_CHILD,CRect(0,0,0,0), pParent,1234);
}

BaseWorkThread::~BaseWorkThread()
{
}

CWinThread* BaseWorkThread::startWork()
{
    CWinThread *m_pThread = NULL;
    if(this->bIsShowModal)
    {
        m_pThread = ::AfxBeginThread((AFX_THREADPROC)BaseWorkThread::innerBeginThread, this);
        dlgLoading.ShowModal();
        return m_pThread;
    }
    BOOL result = dlgLoading.Show();
    if(result)
    {
        m_pThread = ::AfxBeginThread((AFX_THREADPROC)BaseWorkThread::innerBeginThread, this);
    }
    return m_pThread;
}

UINT BaseWorkThread::innerBeginThread(BaseWorkThread* instance)
{
    return instance->worker(); 
}

UINT BaseWorkThread::worker()
{
    Sleep(5000);
    HINSTANCE hInst=0;
     SHELLEXECUTEINFO sInfo;
     sInfo.hwnd=NULL;
     sInfo.lpVerb="open";
     sInfo.lpFile="SETUP.exe";
     sInfo.lpParameters="";
     sInfo.lpDirectory="./debug/";
     sInfo.nShow=SW_SHOWNORMAL;
     sInfo.hInstApp=hInst;
     sInfo.cbSize=sizeof(SHELLEXECUTEINFO);
     sInfo.fMask=SEE_MASK_NOCLOSEPROCESS;
     //ShellExecuteEx(&sInfo);

     //WaitForSingleObject(sInfo.hProcess, INFINITE );
     /*
     如果某个软件是用 Windows Installer 打包的,那你就应该能在文件夹中看到 *.msi 文件。这是最典型的特征,这些文件通常可以使用 /QB 和 /QN 参数进行自动安装。

  /qb 会在窗口中显示一个基本的安装进程。
  /qn 参数则不会显示任何窗口,直接在后台自动安装。

  为了阻止某些程序安装成功后自动重启动(例如 Kerio Personal Firewall 4),你可以在 /qn 或者 /qb参数后使用REBOOT=Suppress标记。

  例如:安装虚拟光驱 DaemonTools:msiexec /i dtools.msi /qb REBOOT=SUPPRESS
*/
    ::PostMessage(this->m_hWnd, WM_ONTHREADFINISHED, 1, 1);
    return 0; //成功返回
}

LRESULT BaseWorkThread::workder_onFinished(WPARAM wParam, LPARAM lParam)
{
    if(this->dlgLoading)
    {
        if(this->bIsShowModal)
        {
            this->dlgLoading.EndDialog(1);
        }
        else
        {
            this->dlgLoading.ShowWindow(0);
            //this->dlgLoading.DestroyWindow(); 非模式执行完一次扣 对话框的 Hwnd 被清除,导至下次产生不了窗口
        }
    }
    return this->onWorkerFinished(this);
}

LRESULT BaseWorkThread::onWorkerFinished(BaseWorkThread* instance)
{
    ::AfxMessageBox("线程完成!", 0, 0);
    return 0;
}

BEGIN_MESSAGE_MAP(BaseWorkThread, CWnd)
    //{{AFX_MSG_MAP(BaseWorkThread)
        // NOTE - the ClassWizard will add and remove mapping macros here.
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_ONTHREADFINISHED, workder_onFinished)
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// BaseWorkThread message handlers

 

#if !defined(AFX_DIALOGLOADING_H__73F5F815_CCC7_42AF_B8C1_99B4F2A993E5__INCLUDED_)
#define AFX_DIALOGLOADING_H__73F5F815_CCC7_42AF_B8C1_99B4F2A993E5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DialogLoading.h : header file
//
#include "Resource.h"
/////////////////////////////////////////////////////////////////////////////
// CDialogLoading dialog

class CDialogLoading : public CDialog
{
    DECLARE_DYNAMIC(CDialogLoading)
// Construction
public:
    //CDialogLoading::CDialogLoading(); //下面的构造函数参数可为NULL, 所以可代表无参构造
    CDialogLoading(CWnd* pParent = NULL);   // standard constructor
    CDialogLoading::~CDialogLoading();
    BOOL Show();
    int ShowModal();

// Dialog Data
    //{{AFX_DATA(CDialogLoading)
    enum { IDD = IDD_DIALOGLoading };
        // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA


// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CDialogLoading)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL

// Implementation
protected:
    BOOL bAlreadyInit;
    // Generated message map functions
    //{{AFX_MSG(CDialogLoading)
    virtual BOOL OnInitDialog();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DIALOGLOADING_H__73F5F815_CCC7_42AF_B8C1_99B4F2A993E5__INCLUDED_)

 

// DialogLoading.cpp : implementation file
//

#include "stdafx.h"
#include "ex08a.h"
#include "DialogLoading.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNAMIC(CDialogLoading, CDialog)
/////////////////////////////////////////////////////////////////////////////
// CDialogLoading dialog

CDialogLoading::CDialogLoading(CWnd* pParent /*=NULL*/)
: CDialog(CDialogLoading::IDD, pParent),bAlreadyInit(FALSE)
{
    //{{AFX_DATA_INIT(CDialogLoading)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}

CDialogLoading::~CDialogLoading()
{
}

int CDialogLoading::ShowModal()
{
    return this->DoModal();
}

BOOL CDialogLoading::Show()
{
    BOOL bResult = FALSE;
    if(this->bAlreadyInit != TRUE)
    {
        bResult = CDialog::Create(CDialogLoading::IDD);
        if(bResult)
        {
            bAlreadyInit = TRUE;
            this->CenterWindow();
            this->ShowWindow(1);
        }
    }
    else
    {
        if(this->m_hWnd)
        {
            this->ShowWindow(1);
            return TRUE;
        }
        else 
        {
            return FALSE;
        }
    }    
    return bResult;
}

void CDialogLoading::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CDialogLoading)
        // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialogLoading, CDialog)
    //{{AFX_MSG_MAP(CDialogLoading)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogLoading message handlers

BOOL CDialogLoading::OnInitDialog() 
{
    CDialog::OnInitDialog();
    
    // TODO: Add extra initialization here

    this->bAlreadyInit = FALSE;
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

 

void CEx08aView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    
    //CView::OnLButtonDown(nFlags, point);
    w = new BaseWorkThread(AfxGetMainWnd()/*this*/);
    w->bIsShowModal = FALSE;

    w->startWork();

}

 


 

Adding Dialog Controls at Runtime

You've seen how to use the resource editor to create dialog controls at build time. If you need to add a dialog control at runtime, here are the programming steps:

 

  1. Add an embedded control window data member to your dialog class. The MFC control window classes include CButton, CEdit, CListBox, and CComboBox. An embedded control C++ object is constructed and destroyed along with the dialog object.

     

  2. Choose Resource Symbols from Visual C++'s View menu. Add an ID constant for the new control.

     

  3. Use ClassWizard to map the WM_INITDIALOG message, thus overriding CDialog::OnInitDialog. This function should call the embedded control window's Create member function. This call displays the new control in the dialog. Windows will destroy the control window when it destroys the dialog window.

     

  4. In your derived dialog class, manually add the necessary notification message handlers for your new control.

     

In Chapter 13, you'll be adding a rich edit control to a view at runtime. 

 

 

int CEx13aView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    CRect rect(0, 0, 0, 0);
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;
    m_rich.Create(ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN |
                  WS_CHILD | WS_VISIBLE | WS_VSCROLL, rect, this, 1);
    return 0;
}

 

标签:__,MAP,return,BaseWorkThread,静默,线程,基类,AFX,CDialogLoading
From: https://www.cnblogs.com/ioriwellings/p/16113815.html

相关文章

  • 03.关于线程你必须知道的8个问题(中)
    大家好,我是王有志。关注​​王有志​​,一起聊技术,聊游戏,聊在外漂泊的生活。原计划是今天结束线程的部分,但是写完后才发现,光Thread类的核心方法分析就写了5000多字了,所以不得......
  • Qt多线程编程之QThreadPool 和 QRunnable使用
     说到线程通常会想到QThread,但其实Qt中创建线程的方式有多种,这里主要介绍其中一种QRunnable,QRunnable和QThread用法有些不同,并且使用场景也有区别。要介绍QRunnable的用......
  • 创建 Java 多线程有哪几种方式?
    本文首发自「慕课网」,想了解更多IT干货内容,程序员圈内热闻,欢迎关注!作者|慕课网精英讲师ColorfulCJava多线程本篇文章我们介绍一下如何创建线程,创建线程有哪几种方式,线程......
  • 前端报表如何实现无预览打印解决方案或静默打印
    在前端开发中,除了将数据呈现后,我们往往需要为用户提供,打印,导出等能力,导出是为了存档或是二次分析,而打印则因为很多单据需要打印出来作为主要的单据来进行下一环节的票据支撑......
  • 进程与线程
    一、进程与线程的概念;           进程的解释:     二、进程和线程之间的关系:         谷歌浏览器的架构图:   ......
  • 线程问题<3>
    有N张火车票,每张票都有一个编号,同时有10个窗口对外售票,请写一个模拟程序1.使用锁缺点:效率不高publicclassTest7{privateLinkedListlist=newLinkedList();......
  • 线程安全的单列模式(4种)
    1.不使用同步锁publicclassSingleton{privatestaticSingletons=newSingleton();//直接初始化一个实例对象privateSingleton(){///private类型的构造函数......
  • ThreadLocal: 线程独享
    ThreadLocal线程局部变量ThreadLocal是使用空间换时间,synchronized是使用时间换空间比如在hibernate中session就存在与ThreadLocal中,避免synchronized的使用packagecom.mo;......
  • 线程问题<2>
    面试题:写一个固定容量同步容器,拥有put和get方法,以及getCount方法能够支持2个生产者线程以及10个消费者线程的阻塞调用1.使用wait和notify/notifyAll来实现publicclassTest......
  • 线程问题<1>
    实现一个容器,提供两个方法,add,size写两个线程,线程1添加10个元素到容器中,线程2实现监控元素的个数,当个数到5个时,线程2给出提示并结束1.第一种方法是......