MessageRequester centré sur la fenêtre !
Publié : lun. 12/oct./2009 21:13
Voilà un petit code (pour windows) permettant de centrer la fenêtre d'un MessageRequester par rapport à votre fenêtre plutôt qu'au centre de l'écran.
je l'ai trouvé sur le site : http://gushh.net/blog/
Voilou 
je l'ai trouvé sur le site : http://gushh.net/blog/
Code : Tout sélectionner
; This snippet was based on the following code by Microsoft:
; http://support.microsoft.com/kb/180936
EnableExplicit
Procedure.i CenterMsgCallBack( uMsg.i, wParam.i, lParam.i )
Select uMsg
Case #HCBT_ACTIVATE
Define.RECT typFormRect, typRectMsg
Define.i plMsgHook, hwnd
Define.i lxPos, lyPos
hwnd = GetParent_(wParam)
If hwnd
plMsgHook = GetWindowLong_( hwnd, #GWL_USERDATA )
If plMsgHook
GetWindowRect_( hwnd, typFormRect )
GetWindowRect_( wParam, typRectMsg )
lxPos = (typFormRect\left + (typFormRect\right - typFormRect\left) / 2) - ((typRectMsg\right - typRectMsg\left) / 2)
lyPos = (typFormRect\top + (typFormRect\bottom - typFormRect\top) / 2) - ((typRectMsg\bottom - typRectMsg\top) / 2)
SetWindowPos_( wParam, 0, lxPos, lyPos, 0, 0, #SWP_NOSIZE | #SWP_NOZORDER | #SWP_NOACTIVATE )
UnhookWindowsHookEx_(plMsgHook)
SetWindowLong_( hwnd, #GWL_USERDATA, #Null )
EndIf
EndIf
EndSelect
EndProcedure
Procedure.i CenteredMessageRequester( Title.s, Text.s, flags.i=#Null, hwnd.i=#Null )
Define.i lInstance, lThreadID, plMsgHook
If Not hwnd
hwnd = WindowID( GetActiveWindow() )
EndIf
If hwnd
lInstance = GetWindowLong_( hwnd, #GWL_HINSTANCE )
lThreadID = GetCurrentThreadId_()
If lInstance And lThreadID
plMsgHook = SetWindowsHookEx_(#WH_CBT, @CenterMsgCallBack(), lInstance, lThreadID)
SetWindowLong_( hwnd, #GWL_USERDATA, plMsgHook )
ProcedureReturn MessageBox_( hwnd, Text, Title, flags )
EndIf
EndIf
EndProcedure
;- Exemple du CenteredMessageRequester
OpenWindow( 0, 200, 200, 400, 200, "test" )
MessageRequester( ":(", "MessageRequester au centre de l'ecran (comme d'hab quoi)", #MB_APPLMODAL | #MB_ICONERROR )
CenteredMessageRequester( ":)", "MessageRequester au centre de votre fenêtre ! (yeah)", #MB_APPLMODAL | #MB_ICONEXCLAMATION )
