|
-
Jan 22nd, 2006, 07:32 AM
#1
Thread Starter
Member
MsgBox BackColor !!!!
Hi there,
Is there a way to change the background color of the standard MsgBox without subclassing it ?
When I use the SetBkColor API without first subclassing the MsgBox, nothing seems to happen !
I have used the FillRect API with a Windows Brush but this unfortuantly covers up the whole MsgBox Client Area and hides any Buttons on the MsgBox as well as any text !
Any insights on this ?
Last edited by BLUE_SEA; Jan 22nd, 2006 at 07:36 AM.
-
Jan 22nd, 2006, 08:06 AM
#2
Re: MsgBox BackColor !!!!
The easiest way to do anything you want with a message box is to make your own from a standard VB form.
My whole development team uses a custom message that was created a long time ago, and we just pop it into each of our projects when we start them.
-
Jan 22nd, 2006, 08:24 AM
#3
Thread Starter
Member
Re: MsgBox BackColor !!!!
Hack,
Thanks but I really want to know how this is done for a standard MsgBox.
I am needing this for learning purposes.
Any takers ?
Regards.
-
Jan 22nd, 2006, 09:58 AM
#4
Re: MsgBox BackColor !!!!
I don't think you can do this without subclassing it.
Show us the code you used to try the things you mentioned.
-
Jan 22nd, 2006, 10:19 AM
#5
Thread Starter
Member
Re: MsgBox BackColor !!!!
Thanks moeur,
Below is the code I am testing . Note that the I commented out the SetBkColor line because it just doesn't work. Instead the FillRect does color the background but covers up all children windows ie(BUTTON & STATIC) Controls nd looks horrible.
VB Code:
Declare Function FillRect Lib "user32" _
(ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" _
(ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Declare Function killtimerAPI Lib "user32" Alias "KillTimer" _
(ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, _
ByVal crColor As Long) As Long
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim udtR As RECT
Dim lngTimerID, lngMsgboxHwnd, lngMsgBoxDC, mBrush As Long
Sub killTimer()
killtimerAPI 0, lngTimerID
End Sub
Sub ShowMsgBox()
lngTimerID = SetTimer(0, 0, 100, AddressOf TimerCallBack)
MsgBox "HELLO!"
ReleaseDC lngMsgboxHwnd, lngMsgBoxDC
DeleteObject mBrush
End Sub
Sub TimerCallBack()
killTimer
lngMsgboxHwnd = FindWindow("#32770", vbNullString)
GetClientRect lngMsgboxHwnd, udtR
lngMsgBoxDC = GetDC(lngMsgboxHwnd)
mBrush = CreateSolidBrush(vbYellow)
'SetTextColor lngMsgBoxDC, mBrush '\ this doesn't work !
FillRect lngMsgBoxDC, udtR, mBrush '\ this covers up the whole client area
'\ including OK button and prompt text !!
End Sub
Regards.
-
Jan 22nd, 2006, 10:30 AM
#6
Re: MsgBox BackColor !!!!
If you were willing to do all this, why are you avoiding subclassing?
-
Jan 22nd, 2006, 10:51 AM
#7
Lively Member
Re: MsgBox BackColor !!!!
Can someone post up the code for subclassing?
Im interested in seeing it.
-
Jan 22nd, 2006, 10:59 AM
#8
Thread Starter
Member
Re: MsgBox BackColor !!!!
 Originally Posted by moeur
If you were willing to do all this, why are you avoiding subclassing?
moeur,
I am just experimenting with this API stuff to understand how it all works... So for instance : If the SetBKColor function doesn't work to change the color of the MsgBox in my code, I would like to know why and if I figure out then I know I have learnt something in the process which I can then apply to other different scenarios.
I have seen this codehttp://64.233.161.104/search?q=cache...ORDLG%3D&hl=en that uses a WH_CALLWNDPROC Hook to detect the creation of the MsgBox by capturing the WM_CREATE message. Once it is captured it subclasses the MsgBox and traps the WM_CTLCOLORDLG message before calling the SetBkColor function . This works fine but I want to know why this SetBKColor works for some windows without the need for subclassing and for some other like in this particular MsgBox scenario subclassing is required !!!
Regarding the WH_CALLWNDPROC Hook, I thought it worked only for watching messages sent to a window via the SendMessage API function NOT for messages generated by the user through the UI. Can you confirm if this is true ?
Thanks for your help with this .
Last edited by BLUE_SEA; Jan 22nd, 2006 at 11:03 AM.
-
Jan 22nd, 2006, 05:36 PM
#9
Re: MsgBox BackColor !!!!
Regarding the WH_CALLWNDPROC Hook, I thought it worked only for watching messages sent to a window via the SendMessage API function NOT for messages generated by the user through the UI. Can you confirm if this is true ?
The WH_CALLWNDPROC hook intercepts messages that were "sent" to a window whether they were sent by a user with sendmessage or sent by the system.
Another type of useful hook is the WH_GETMESSAGE hook which intercepts "posted" messages.
-
Jan 23rd, 2006, 04:59 AM
#10
Thread Starter
Member
Re: MsgBox BackColor !!!!
 Originally Posted by moeur
The WH_CALLWNDPROC hook intercepts messages that were "sent" to a window whether they were sent by a user with sendmessage or sent by the system.
Another type of useful hook is the WH_GETMESSAGE hook which intercepts "posted" messages.
Thanks.
-
Jan 24th, 2006, 09:42 AM
#11
-
Jan 27th, 2006, 02:53 PM
#12
Frenzied Member
Re: MsgBox BackColor !!!!
blue sea, I think maybe its because it is being called within the applications 'process memory'; when the application's messages are hooked, SetBkColor is being called within the target application's process memory. I think.
For instance, if you create an application(vb.net) with a textbox, and if you make the textbox in a way that if you type something on it, it would be "*". Basically, change the passwordchar property to "*". Then you call:
SendMessage(hwndOfTxtBox, WM_GETTEXT,....) within that same application.
it will get the actual characters(not the "*") that you typed. But if you call that SendMessage() code from a different application, it will not give you the actual characters. But if you can call that SendMessage() code within the target application's 'process memory' (by hooking for instance), then it will show the actual characters.
But then again, it may not be the reason for why SetBkColor does not work the way you want it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|