Link to home
Start Free TrialLog in
Avatar of RAFAAJ
RAFAAJ

asked on

Setting the BackColor of a Static Window !!!

I have created a Static Window using the "CreateWindowEX" API and it works just fine.

Now, how do I set it's back color to Red  ?

I have tried SetBckColor and other Functions but no luck .

Regards.
Avatar of RAFAAJ
RAFAAJ

ASKER

Anybody ??
You will probably have to subclass that window and when it receives a message to repaint itself, use FillRect() and TextOut() to render your backcolor and text.

Otherwise.. if you do force a one-time backcolor change, it'll be empty when the window repaints itself (ie: minimized then shown again).
Avatar of RAFAAJ

ASKER

Yes But how do you actually do that ?

I have alraedy tried all that but I faild . I must be making some mistake.

Thanks.
Avatar of RAFAAJ

ASKER

I can't beleive I can't get an answer to what seems to be ( and should be ) an easy\basic thing to do.!!!!!

I have somehow managed to do that via the "FillRect" API  but the existing
Text on the Static Window gets burried under the fill and can't be seen !

Anyone has a fix or maybe a better approach to achieve this ?

Here is a small part of the code I have so far:


'\ Goes In an Excel  Standard Module
Sub CreateStaticWnd()

    udtR = GetMyRangeRect(Range("D10"))
   
    lngControlHndl = CreateWindowEx(WS_EX_NOACTIVATE + WS_EX_TOOLWINDOW,
"STATIC", _
    "Hello!", SS_CENTER + WS_CHILD, udtR.left, udtR.top, _
    (udtR.Right - udtR.left), udtR.Bottom - udtR.top, _
    Application.hwnd, 0, Application.hInstance, 0)
   
    SetParent lngControlHndl, Application.hwnd
   
    ShowWindow lngControlHndl, SW_NORMAL
   
    hdc = GetDC(lngControlHndl)
    mBrush = CreateSolidBrush(vbRed)

    '\ this covers up the whole client area and hides the text too !
    FillRect hdc, udtR, mBrush

End Sub

I have also tried trapping the "WM_CTLCOLORSTATIC" Message through
Subclassing but can't make it work either :(

So to recap : How do I set the backgroud Color of the Client Area of a
Custom Window ( in this case it's a Static Wnd) without affecting its
Children or Text ?

Help please.

Regards.

ASKER CERTIFIED SOLUTION
Avatar of zzzzzooc
zzzzzooc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RAFAAJ

ASKER

zzzzzooc .

Thank you very much indeed for the Snipet Code...I have tried it and it DOES WORK !!...Hopefully, it will need some tweaking and should work fine for my project.

Also, I will study this code more closely to help me get an insight into the inner workings of Windows Painting & Graphics.

Can you suggest a good Book or Website Source on Windows Graphics\Painting in VB ?

Again, Thanks for your patience with this.
"Painting and Drawing"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/pantdraw_3wtj.asp

MSDN is primarily the only reference I use. You can locate all of the functions, types and constants used above through that, and it'll provide you documentation on mostly everything you'll need to know (and examples -- usually in C++).