zoukankan      html  css  js  c++  java
  • 一个失败的案例,一个线程创建非模态对话框,主线程做其它事,对话框按钮不能响应鼠标

    #include "afxwin.h"
    #include "STOPDialog.h"
    class UIWorker :
    public CWinThread
    {
    DECLARE_DYNCREATE(UIWorker);



    public:
    UIWorker(void);
    ~UIWorker(void);
    bool CreateMyDlg( void );

    void SetOwnerWnd( HWND hWnd );

    void DestroyMyDlg( void );

    bool GetDoneFlag();

    BOOL InitInstance();
    int ExitInstance();


    private:

    STOPDialog* m_pDlgTest;

    HWND m_hOwnerWnd;
    bool b_isShow;


    };

    #include "UIWorker.h"
    #include "Resource.h"
    IMPLEMENT_DYNCREATE(UIWorker,CWinThread)


    UIWorker::UIWorker(void)
    {
    b_isShow=false;

    }

    UIWorker::~UIWorker(void)
    {
    }
    bool UIWorker::GetDoneFlag()
    {
    return b_isShow;

    }
    bool UIWorker::CreateMyDlg( void )

    {

    m_pDlgTest = new STOPDialog;

    if ( NULL == m_pDlgTest )

    {

    return false;

    }

    CWnd* pWnd = NULL;

    /* if ( NULL != m_hOwnerWnd )

    {

    pWnd = reinterpret_cast<CWnd*>( CWnd::FromHandle( m_hOwnerWnd ));

    if ( NULL == pWnd )

    {

    return false;

    }

    }*/

    //BOOL bSuccess = m_pDlgTest->Create( IDD_DIALOG_STOP, pWnd );
    BOOL bSuccess = m_pDlgTest->Create( IDD_DIALOG_STOP, NULL );

    b_isShow=true;

    if ( bSuccess )

    {

    bSuccess = m_pDlgTest->ShowWindow( SW_SHOW );
    b_isShow=bSuccess;

    }

    MSG msg;
    while(GetMessage(&msg,0,0,0))
    {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
    }

    return bSuccess?true:false;

    }

    void UIWorker::DestroyMyDlg( void )

    {

    if ( NULL != m_pDlgTest )

    {

    delete m_pDlgTest;

    m_pDlgTest = NULL;

    }

    }

    BOOL UIWorker::InitInstance()
    {
    return CreateMyDlg();

    }
    int UIWorker::ExitInstance()
    {
    DestroyMyDlg();
    return 0;
    }

    void UIWorker::SetOwnerWnd( HWND hWnd )
    {
    m_hOwnerWnd=hWnd;
    }

    void CcudamfcView::On32797()
    {
    // TODO: 在此添加命令处理程序代码
    //if(m_pUIWorker!=NULL) delete m_pUIWorker;

    m_pUIWorker = static_cast<UIWorker*>( AfxBeginThread(

    RUNTIME_CLASS( UIWorker )));
    //
    while ( !m_pUIWorker->GetDoneFlag())

    {

    MSG msg;

    ::GetMessage( &msg, this->m_hWnd, NULL, NULL );

    ::TranslateMessage( &msg );

    ::DispatchMessage( &msg );

    }
    double m=0.0;
    for(int i=1;i<100000;i++)
    for(int j=1;j<1000000;j++)
    for(int k=1;k<100000;k++)
    m=i*j*k;

    }

    创建的对话框无法响应按钮事件

  • 相关阅读:
    tomcat配置多实例
    内存溢出的三种情况及解决办法分析
    se最佳设置
    Squid 3.1.7通过mysql_auth方式认证
    java在linux下显示中文解决方法
    AD域批量的导入导出账号 转
    JSP技术分享:常用禁止缓存的四种方法
    大幅优化myeclipse的速度&关闭自动更新
    迷你图标集大集合:5000+ 30套免费的图标(不得不下,设计必备)
    【转】开发实战:舍得网44587行代码开发经验
  • 原文地址:https://www.cnblogs.com/qwcbeyond/p/2945097.html
Copyright © 2011-2022 走看看