1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
HHOOK hHook;
///////////////////////////////////////////////////////////////
LRESULT CALLBACK HookProc(UINT code , WPARAM wParam, LPARAM lParam)
{
if (code == HCBT_ACTIVATE)
{
CRect RectFrame;
BOOL bRect = ::GetWindowRect((HWND) wParam,&RectFrame);
// Lecture de la résolution de l'écran
int nResolution = GetSystemMetrics(SM_CXSCREEN); if( nResolution > 0 )
{
// Lecture de la hauteur de l'écran
CWnd* pWnd = CWnd::GetDesktopWindow();
CRect RectEcran;
pWnd->GetWindowRect(&RectEcran);
// Coordonnées du coin haut gauche de la boite de dialogue
int nOffsetGauche = (nResolution - RectFrame.Width())/2;
int nOffsetHaut = (RectEcran.Height() - RectFrame.Height()) / 2 ;
// Mise à jour de la position de la fenêtre
BOOL b = ::SetWindowPos((HWND)wParam,HWND_TOP,nOffsetGauche,nOffsetHaut,RectFrame.Width(),RectFrame.Height(),SWP_NOZORDER);
}
UnhookWindowsHookEx (hHook);
}
return 0;
}
///////////////////////////////////////////////////////////////
int CentreAfxMessageBox(LPCTSTR lpszText, UINT nType, UINT nIDHelp)
{
hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)HookProc, 0, GetCurrentThreadId() );
int nRetour = AfxMessageBox ( lpszText,nType, nIDHelp);
UnhookWindowsHookEx (hHook);
return nRetour;
} |
Partager