Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default MsgBox Screen Position

Hi,
Can you control the displayed position of the following MsgBox and a more
simple one below that
Thanks,
James

(Message Box 1)
Dim Msg, Style, Title, Response
Msg = "Do you want to copy this file" & Chr(13) & Chr(13) & _
"Choose ""YES"" to proceed." & Chr(13) & _
"Choose ""NO"" to cancel & quit"
Style = vbYesNo + vbInformation + vbDefaultButton1
Title = "Export"

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else
If Response = vbNo Then Exit Sub
End If

(Message Box 2)
MsgBox Title:=("Error "), prompt:= "Sorry"


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default MsgBox Screen Position

Previously posted by Jim Rech:

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------------< end of Jim's post------------- Regards,Tom Ogilvy

----------------------------------------------------------------------------
----

"James Montgomery" wrote in message
...
Hi,
Can you control the displayed position of the following MsgBox and a

more
simple one below that
Thanks,
James

(Message Box 1)
Dim Msg, Style, Title, Response
Msg = "Do you want to copy this file" & Chr(13) & Chr(13) & _
"Choose ""YES"" to proceed." & Chr(13) & _
"Choose ""NO"" to cancel & quit"
Style = vbYesNo + vbInformation + vbDefaultButton1
Title = "Export"

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else
If Response = vbNo Then Exit Sub
End If

(Message Box 2)
MsgBox Title:=("Error "), prompt:= "Sorry"




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default MsgBox Screen Position

Hi,
WOW, not as easy as the inpuBox when it comes to the X and Y position
control?
Thanks for the post and code
James

"Tom Ogilvy" wrote in message
...
Previously posted by Jim Rech:

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------------< end of Jim's post------------- Regards,Tom

Ogilvy

--------------------------------------------------------------------------

--
----

"James Montgomery" wrote in message
...
Hi,
Can you control the displayed position of the following MsgBox and a

more
simple one below that
Thanks,
James

(Message Box 1)
Dim Msg, Style, Title, Response
Msg = "Do you want to copy this file" & Chr(13) & Chr(13) & _
"Choose ""YES"" to proceed." & Chr(13) & _
"Choose ""NO"" to cancel & quit"
Style = vbYesNo + vbInformation + vbDefaultButton1
Title = "Export"

Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
Else
If Response = vbNo Then Exit Sub
End If

(Message Box 2)
MsgBox Title:=("Error "), prompt:= "Sorry"






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I fix the position of an object on the screen? Bob Arnett Excel Discussion (Misc queries) 0 October 27th 09 06:46 PM
MsgBox position RJH Excel Programming 2 August 19th 04 08:49 AM
MsgBox position Jeff[_33_] Excel Programming 2 June 14th 04 10:14 PM
Determine the position of a MsgBox Tom Excel Programming 0 August 9th 03 02:36 PM
Position of MsgBox Konrad[_2_] Excel Programming 0 August 7th 03 05:27 PM


All times are GMT +1. The time now is 11:45 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"