MFC 多线程编程 程序重启解决办法
MFC 多线程编程 程序重启
RT 现在做了个MFC对话框的程序 用到了多线程编程 当我修改配置信息后需要让程序重新启动如何实现呢 求教大牛 谢谢!!
------解决方案--------------------
------解决方案--------------------
If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.
work线程别用AfxGetMainWnd,AfxGetApp->m_pMainWnd->SendMessage(),或者其他方法
------解决方案--------------------
简单的说就是出错的原因8成应该是你调用AfxGetMainWnd()返回了一个空指针,然后用空指针去发送消息出错了。为什么会返回空指针,因为如果在子线程里调用,返回的并不一定是主窗口的指针,详细看MSDN或者上面我贴的。
AfxGetMainWnd()->SendMessage(WM_CLOSE,0,0);你调用这句无非就是获取主窗口指针,并向主窗口发送WM_CLOSE消息。类似的方法还有很多,比如把主窗口指针作为参数传到线程,比如直接用
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
另外MFC中创建线程最好用Afxbeginthread,少用CreateThread
------解决方案--------------------
把主窗口句柄HWND hWnd传入线程,然后 ::SendMessage(hWnd,WM_COLSE,0,0);
RT 现在做了个MFC对话框的程序 用到了多线程编程 当我修改配置信息后需要让程序重新启动如何实现呢 求教大牛 谢谢!!
------解决方案--------------------
ShellExecute(NULL,"open","***.exe",NULL,NULL,SW_SHOW);
AfxGetMainWnd()->SendMessage(WM_CLOSE,0,0);
------解决方案--------------------
If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.
work线程别用AfxGetMainWnd,AfxGetApp->m_pMainWnd->SendMessage(),或者其他方法
------解决方案--------------------
简单的说就是出错的原因8成应该是你调用AfxGetMainWnd()返回了一个空指针,然后用空指针去发送消息出错了。为什么会返回空指针,因为如果在子线程里调用,返回的并不一定是主窗口的指针,详细看MSDN或者上面我贴的。
AfxGetMainWnd()->SendMessage(WM_CLOSE,0,0);你调用这句无非就是获取主窗口指针,并向主窗口发送WM_CLOSE消息。类似的方法还有很多,比如把主窗口指针作为参数传到线程,比如直接用
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
另外MFC中创建线程最好用Afxbeginthread,少用CreateThread
------解决方案--------------------
把主窗口句柄HWND hWnd传入线程,然后 ::SendMessage(hWnd,WM_COLSE,0,0);