今天有人问VC如何移动MesageBox, 所以简单写一下(当然也可以移动任何窗口了):
struct BoxInfo
{
BoxInfo()
{
boxname = "";
boxrect = CRect(0,0,0,0);
};
CString boxname;
CRect boxrect;
};
UINT MoveMessageBoxProc(PVOID P)
{
BoxInfo * pboxinfo = (BoxInfo*)P ;
while(1)
{
HWND hwndMessageBox = ::FindWindow( NULL, (LPCSTR)(pboxinfo->boxname) );
CWnd * pmessagewnd = CWnd::FromHandle(hwndMessageBox);
if (pmessagewnd != NULL )
{
pmessagewnd->MoveWindow( &(pboxinfo->boxrect ) ); //
break;
}
}
return 0;
}
void CDlg::OnButtonMoveMessageBox()
{
// TODO: Add your control notification handler code here
BoxInfo boxinfo;
boxinfo.boxname = "2";
boxinfo.boxrect = CRect(0,0,100,100);
AfxBeginThread(MoveMessageBoxProc , &boxinfo);
::MessageBox(this->GetSafeHwnd(),"1" ,"2", MB_OK);