![]() |
Centering the text in a message box
Does anyone know if it's possible to center align the text in a standar VB message box? Currently it's all aligned to the right and I can't se any way of changing it. It's not an important thing, I just think it would make the messag look neater :rolleyes: Any help appreciated. Ro -- Rob_ ----------------------------------------------------------------------- Rob_T's Profile: http://www.excelforum.com/member.php...nfo&userid=495 View this thread: http://www.excelforum.com/showthread.php?threadid=26647 |
Centering the text in a message box
Hi
AFAIK this is not possible -- Regards Frank Kabel Frankfurt, Germany "Rob_T" schrieb im Newsbeitrag ... Does anyone know if it's possible to center align the text in a standard VB message box? Currently it's all aligned to the right and I can't see any way of changing it. It's not an important thing, I just think it would make the message look neater :rolleyes: Any help appreciated. Rob -- Rob_T --------------------------------------------------------------------- --- Rob_T's Profile: http://www.excelforum.com/member.php...fo&userid=4952 View this thread: http://www.excelforum.com/showthread...hreadid=266474 |
Centering the text in a message box
See another approach of your desire...
http://groups.google.com/groups?q=me...*&hl=en&lr= & ie=UTF-8&c2coff=1&selm=%23eCUqkkHCHA.2684%40tkmsftngp09&r num=1 Jorge "Rob_T" escreveu na mensagem ... Does anyone know if it's possible to center align the text in a standard VB message box? Currently it's all aligned to the right and I can't see any way of changing it. It's not an important thing, I just think it would make the message look neater :rolleyes: Any help appreciated. Rob -- Rob_T ------------------------------------------------------------------------ Rob_T's Profile: http://www.excelforum.com/member.php...fo&userid=4952 View this thread: http://www.excelforum.com/showthread...hreadid=266474 |
Centering the text in a message box
Hi Rob_T,
Private Declare Function GetCurrentThreadId& Lib "kernel32" () Private Declare Function GetClassName& Lib "user32" Alias _ "GetClassNameA" (ByVal hwnd&, ByVal lpClassName$, ByVal nMaxCount&) Private Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook&) Private Declare Function SetWindowsHookEx& Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&) Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&) Private Declare Function IsWindow& Lib "user32" (ByVal hwnd&) Private Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd&, ByVal lpString$, ByVal cch&) Private Type CWPSTRUCT lParam As Long wParam As Long Message As Long hwnd As Long End Type Private Const WM_CREATE& = &H1 Private Const GWL_STYLE& = (-16) ' GetWindowLong Private Const SS_LEFT& = &H0& ' Static control left alignment Private Const SS_CENTER& = &H1& ' Static control center alignment Private Const SS_RIGHT& = &H2& ' Static control right alignment Private Const WH_CALLWNDPROC& = 4 ' SetWindowsHookEx (Hook type) Private msgHook& Sub SpecialMsgBox() msgHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookMsg, 0, GetCurrentThreadId) MsgBox "For your information," & vbLf _ & "the text of this message box" & vbLf & "is centered !", 64, "User info" End Sub Private Function HookMsg&(ByVal nCode&, ByVal wParam&, msgStruct As CWPSTRUCT) If msgStruct.Message < WM_CREATE Then Exit Function Dim hwnd&: Static z& hwnd = msgStruct.hwnd Select Case GetWindowClass(hwnd) Case "#32770": z = z + 1 '// Windows-Dialogs Class Case "static" '// Windows-Labels Class If HasText(hwnd) Then SetWindowLong hwnd, GWL_STYLE, SS_CENTER z = z + 1 Case "button": z = z + 1 '// Windows-Buttons Class End Select If z = 4 Then Call UnhookWindowsHookEx(msgHook): z = 0 End Function Private Function GetWindowClass$(ByVal hwnd&) If IsWindow(hwnd) Then Dim Buffer$, i% Buffer = String(255, 0) GetClassName hwnd, Buffer, 256 i = InStr(Buffer, Chr(0)) Buffer = IIf(i, Left(Buffer, i - 1), Buffer) GetWindowClass = LCase(Buffer) End If End Function Private Function HasText&(ByVal hwnd&) Dim Buffer As String Buffer = String(100, Chr$(0)) GetWindowText hwnd, Buffer, 100 HasText = Len(Left$(Buffer, InStr(Buffer, Chr$(0)) - 1)) End Function Regards, MP "Rob_T" a écrit dans le message de ... Does anyone know if it's possible to center align the text in a standard VB message box? Currently it's all aligned to the right and I can't see any way of changing it. It's not an important thing, I just think it would make the message look neater :rolleyes: Any help appreciated. Rob -- Rob_T ------------------------------------------------------------------------ Rob_T's Profile: http://www.excelforum.com/member.php...fo&userid=4952 View this thread: http://www.excelforum.com/showthread...hreadid=266474 |
Centering the text in a message box
Now that's class!
-- Rob van Gelder - http://www.vangelder.co.nz/excel "Michel Pierron" wrote in message ... Hi Rob_T, Private Declare Function GetCurrentThreadId& Lib "kernel32" () Private Declare Function GetClassName& Lib "user32" Alias _ "GetClassNameA" (ByVal hwnd&, ByVal lpClassName$, ByVal nMaxCount&) Private Declare Function UnhookWindowsHookEx& Lib "user32" (ByVal hHook&) Private Declare Function SetWindowsHookEx& Lib "user32" Alias "SetWindowsHookExA" _ (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&) Private Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" _ (ByVal hwnd&, ByVal nIndex&, ByVal dwNewLong&) Private Declare Function IsWindow& Lib "user32" (ByVal hwnd&) Private Declare Function GetWindowText& Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd&, ByVal lpString$, ByVal cch&) Private Type CWPSTRUCT lParam As Long wParam As Long Message As Long hwnd As Long End Type Private Const WM_CREATE& = &H1 Private Const GWL_STYLE& = (-16) ' GetWindowLong Private Const SS_LEFT& = &H0& ' Static control left alignment Private Const SS_CENTER& = &H1& ' Static control center alignment Private Const SS_RIGHT& = &H2& ' Static control right alignment Private Const WH_CALLWNDPROC& = 4 ' SetWindowsHookEx (Hook type) Private msgHook& Sub SpecialMsgBox() msgHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookMsg, 0, GetCurrentThreadId) MsgBox "For your information," & vbLf _ & "the text of this message box" & vbLf & "is centered !", 64, "User info" End Sub Private Function HookMsg&(ByVal nCode&, ByVal wParam&, msgStruct As CWPSTRUCT) If msgStruct.Message < WM_CREATE Then Exit Function Dim hwnd&: Static z& hwnd = msgStruct.hwnd Select Case GetWindowClass(hwnd) Case "#32770": z = z + 1 '// Windows-Dialogs Class Case "static" '// Windows-Labels Class If HasText(hwnd) Then SetWindowLong hwnd, GWL_STYLE, SS_CENTER z = z + 1 Case "button": z = z + 1 '// Windows-Buttons Class End Select If z = 4 Then Call UnhookWindowsHookEx(msgHook): z = 0 End Function Private Function GetWindowClass$(ByVal hwnd&) If IsWindow(hwnd) Then Dim Buffer$, i% Buffer = String(255, 0) GetClassName hwnd, Buffer, 256 i = InStr(Buffer, Chr(0)) Buffer = IIf(i, Left(Buffer, i - 1), Buffer) GetWindowClass = LCase(Buffer) End If End Function Private Function HasText&(ByVal hwnd&) Dim Buffer As String Buffer = String(100, Chr$(0)) GetWindowText hwnd, Buffer, 100 HasText = Len(Left$(Buffer, InStr(Buffer, Chr$(0)) - 1)) End Function Regards, MP "Rob_T" a écrit dans le message de ... Does anyone know if it's possible to center align the text in a standard VB message box? Currently it's all aligned to the right and I can't see any way of changing it. It's not an important thing, I just think it would make the message look neater :rolleyes: Any help appreciated. Rob -- Rob_T ------------------------------------------------------------------------ Rob_T's Profile: http://www.excelforum.com/member.php...fo&userid=4952 View this thread: http://www.excelforum.com/showthread...hreadid=266474 |
All times are GMT +1. The time now is 12:12 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com