VC问题,求大神怎么加延时。
想用MFC做一个弹出窗口,要求弹出窗口显示几秒钟后消失,可是不知在哪加延时,问题代码如下:DWORDWINAPICPopView::ThreadProc(LPVOIDlp...
想用MFC做一个弹出窗口,要求弹出窗口显示几秒钟后消失,可是不知在哪加延时,问题代码如下:
DWORD WINAPI CPopView::ThreadProc(LPVOID lpParam)
{
HBRUSH hBrush = (HBRUSH)::GetStockObject(WHITE_BRUSH);
LPCSTR lpClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,NULL,hBrush,NULL);
CWnd * pWnd = new CWnd;
CWnd * pParent = GetDesktopWindow();
pWnd->Create(lpClassName,NULL,WS_CHILD,CRect(0,0,0,0),pParent,1000);
pWnd->SetWindowPos(&wndTopMost,0,0,100,40,0);
pWnd->CenterWindow((CWnd*)lpParam);
pWnd->ShowWindow(SW_SHOW);
CDC* pDC = pWnd->GetDC();
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText("HELLO",CRect(0,0,100,40),DT_VCENTER|DT_SINGLELINE|DT_CENTER);
//for(int i = 0;i < 1000000;i++);
return 0;
}
void CPopView::OnPopup()
{
// TODO: Add your command handler code here
DWORD dwId;
HANDLE hThread = ::CreateThread(NULL,0,ThreadProc,this,0,&dwId);
//Sleep(3000);
CloseHandle(hThread);
}
OnPop()是菜单响应函数,如果在这里加延时,那多线程就没意义了,在线程函数中加延时,窗口是显示出来了,可是文字就没了,昨晚弄了一晚也没解决,请大神指教一下小弟 展开
DWORD WINAPI CPopView::ThreadProc(LPVOID lpParam)
{
HBRUSH hBrush = (HBRUSH)::GetStockObject(WHITE_BRUSH);
LPCSTR lpClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,NULL,hBrush,NULL);
CWnd * pWnd = new CWnd;
CWnd * pParent = GetDesktopWindow();
pWnd->Create(lpClassName,NULL,WS_CHILD,CRect(0,0,0,0),pParent,1000);
pWnd->SetWindowPos(&wndTopMost,0,0,100,40,0);
pWnd->CenterWindow((CWnd*)lpParam);
pWnd->ShowWindow(SW_SHOW);
CDC* pDC = pWnd->GetDC();
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText("HELLO",CRect(0,0,100,40),DT_VCENTER|DT_SINGLELINE|DT_CENTER);
//for(int i = 0;i < 1000000;i++);
return 0;
}
void CPopView::OnPopup()
{
// TODO: Add your command handler code here
DWORD dwId;
HANDLE hThread = ::CreateThread(NULL,0,ThreadProc,this,0,&dwId);
//Sleep(3000);
CloseHandle(hThread);
}
OnPop()是菜单响应函数,如果在这里加延时,那多线程就没意义了,在线程函数中加延时,窗口是显示出来了,可是文字就没了,昨晚弄了一晚也没解决,请大神指教一下小弟 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询