ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Screen Positioning of a Dialogue Box ! (https://www.excelbanter.com/excel-programming/332508-screen-positioning-dialogue-box.html)

RAFAAJ2000[_2_]

Screen Positioning of a Dialogue Box !
 
Hi all,

Is it possible to have an XL builtin Dialogue Box ( For Ex ' Format Cells ')
displayed at the Bottom Right of the Screen instead of the Center ?

Jaafar.
Regards.



keepITcool

Screen Positioning of a Dialogue Box !
 

Hi Jaafar :)

it is possible, but .. there we go again.. only with api's

michel pierron has published a few examples for msgbox positioning that
you may want to adapt to your dialog situation.

and ofcourse you;ll need to add some code
to read the screensize,dialogsize and compute the new x,y of the dialog
iso hardcoding it like in next example:

michel is apt to replace the constants with numbers..
making it a bit harder to see what he does :)

he SETS the hook with &H5,
read that as WH_CBT (window hook computer based training)

his WinProc reacts to lMsg=5
read that as HCBT_ACTIVATE the hooked window is being Activated..

he moves the window with &H15
read that as SWP_NOSIZE OR SWP_NOZORDER OR SWP_NOACTIVATE


Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long _
, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long _
, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long _
, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private lgHook As Long

Sub Positionned_MsgBox()
lgHook = SetWindowsHookEx(&H5, AddressOf WinProc, 0, GetCurrentThreadId)
MsgBox "Special msgbox (Left = 100 / Top = 100) !", 64
End Sub

Private Function WinProc(ByVal lMsg As Long, ByVal wParam As Long) As
Long
If lMsg = 5 Then
SetWindowPos wParam, 0, 100, 100, 0, 0, &H15
UnhookWindowsHookEx lgHook
End If
WinProc = False
End Function




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is it possible to have an XL builtin Dialogue Box ( For Ex ' Format
Cells ') displayed at the Bottom Right of the Screen instead of the
Center ?

Jaafar.
Regards.


RAFAAJ2000[_2_]

Screen Positioning of a Dialogue Box !
 
Thanks KeepItCool,

I'll have a look into this and get back to you.

Jaafar.
Regards.



"keepITcool" wrote:


Hi Jaafar :)

it is possible, but .. there we go again.. only with api's

michel pierron has published a few examples for msgbox positioning that
you may want to adapt to your dialog situation.

and ofcourse you;ll need to add some code
to read the screensize,dialogsize and compute the new x,y of the dialog
iso hardcoding it like in next example:

michel is apt to replace the constants with numbers..
making it a bit harder to see what he does :)

he SETS the hook with &H5,
read that as WH_CBT (window hook computer based training)

his WinProc reacts to lMsg=5
read that as HCBT_ACTIVATE the hooked window is being Activated..

he moves the window with &H15
read that as SWP_NOSIZE OR SWP_NOZORDER OR SWP_NOACTIVATE


Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long _
, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long _
, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long _
, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private lgHook As Long

Sub Positionned_MsgBox()
lgHook = SetWindowsHookEx(&H5, AddressOf WinProc, 0, GetCurrentThreadId)
MsgBox "Special msgbox (Left = 100 / Top = 100) !", 64
End Sub

Private Function WinProc(ByVal lMsg As Long, ByVal wParam As Long) As
Long
If lMsg = 5 Then
SetWindowPos wParam, 0, 100, 100, 0, 0, &H15
UnhookWindowsHookEx lgHook
End If
WinProc = False
End Function




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is it possible to have an XL builtin Dialogue Box ( For Ex ' Format
Cells ') displayed at the Bottom Right of the Screen instead of the
Center ?

Jaafar.
Regards.




All times are GMT +1. The time now is 10:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com