Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
msgbox positioning
From time to time I see people say "don't even try." Yet the KB below
baits you in VB5+... http://support.microsoft.com/default...;EN-US;q180936 I have tried to implement in XL2000 VBA without success. Should I stop even bothering (or make my own form)? The standard msgbox positioning combined with the scroll positioning (e.g. from a Find) is irritatingly adept at obscuring the active cell. In 99% of the cases, if the msgbox was in the upper right corner of screen, I could just hit Y,N,Esc, or whatever without even looking inside it...and there's no obscuring then. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
msgbox positioning
This seems to do what you want. Run ShowMsgBoxInXLTopRight.
-- Jim Rech Excel MVP '--------------------- Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Declare Function UnhookWindowsHookEx Lib "user32" ( _ ByVal hHook As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias _ "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _ As Long Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long Public 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 Public 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 Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd _ As Long, lpRect As RECT) As Long Public Declare Function GetActiveWindow Lib "user32" () As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Const GWL_HINSTANCE = (-6) Public Const SWP_NOSIZE = &H1 Public Const SWP_NOZORDER = &H4 Public Const SWP_NOACTIVATE = &H10 Public Const HCBT_ACTIVATE = 5 Public Const WH_CBT = 5 Public hHook As Long Public hXL As Long Sub ShowMsgBoxInXLTopRight() Dim hInst As Long Dim Thread As Long hXL = FindWindow("XLMAIN", Application.Caption) hInst = GetWindowLong(hXL, GWL_HINSTANCE) Thread = GetCurrentThreadId() hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, hInst, Thread) MsgBox "This message box has been positioned to the top right of Excel's window." End Sub Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, _ ByVal lParam As Long) As Long Dim rectXL As RECT, rectMsg As RECT Dim x As Long, y As Long Dim hMsgbox As Long If lMsg = HCBT_ACTIVATE Then hMsgbox = GetActiveWindow GetWindowRect hXL, rectXL GetWindowRect wParam, rectMsg x = (rectXL.Left + (rectXL.Right - rectXL.Left) * 0.75) - _ ((rectMsg.Right - rectMsg.Left) / 2) y = (rectXL.Top + (rectXL.Bottom - rectXL.Top) * 0.3) - _ ((rectMsg.Bottom - rectMsg.Top) / 2) SetWindowPos wParam, 0, x, y, 0, 0, _ SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE UnhookWindowsHookEx hHook End If WinProc = False End Function |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
msgbox positioning
Thank you kindly. It won't compile in XL97 but I'll try others later.
On Wed, 27 Aug 2003 10:56:34 -0400, "Jim Rech" wrote: This seems to do what you want. Run ShowMsgBoxInXLTopRight. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
msgbox positioning
That's it. [Y.A.] Way to go, Tom.
On Thu, 28 Aug 2003 08:18:59 -0400, "Tom Ogilvy" wrote: xl97 doesn't support "AddressOf" Here is a past posting that should work in xl97: http://groups.google.com/groups?selm... output=gplain |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Forms Positioning | Excel Discussion (Misc queries) | |||
Comment Box Positioning Q | Excel Worksheet Functions | |||
Cursor positioning | Excel Discussion (Misc queries) | |||
Positioning all pictures | Excel Discussion (Misc queries) | |||
AutoShape Positioning? | Excel Discussion (Misc queries) |