Re: CTL_COLORSTATIC problems

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: serge gubenko (serge_gubenko_at_hotmail.com)
Date: 12/08/04


Date: Wed, 8 Dec 2004 12:03:11 +0200

Hi,

Looks like internal edit control of the combobox handles WM_CTLCOLORSTATIC
message results wrong when its not enabled, I guess, you could solve the
problem if this edit control will be always enabled. I tried this idea and
it seemed to work well, below is source code of my class:
_______________________________________________
public class MyComboBox : ComboBox
{
    [DllImport("gdi32",CharSet=CharSet.Auto)]
    internal static extern int SetTextColor(IntPtr hdc, int crColor);
    [DllImport("gdi32",CharSet=CharSet.Auto)]
    internal static extern int SetBkColor(IntPtr hdc, int crColor);
    [DllImport("gdi32",CharSet=CharSet.Auto)]
    internal static extern IntPtr CreateSolidBrush(int crColor);
    [DllImport("user32", CharSet=CharSet.Auto)]
    internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr
hwndChildAfter,
    [MarshalAs(UnmanagedType.LPTStr)] string lpszClass,
    [MarshalAs(UnmanagedType.LPTStr)] string lpszWindow);
    [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Auto)]
    internal static extern bool EnableWindow (IntPtr hWnd, bool bEnable);

    public const int WM_CTLCOLORSTATIC = 0x0138;
    public const int WM_CTLCOLOREDIT = 0x0133;

    protected override void WndProc(ref Message m)
    {
        IntPtr xBrush;
        switch (m.Msg)
        {
            case WM_CTLCOLORSTATIC:
                IntPtr xEditHandle = FindWindowEx(this.Handle, IntPtr.Zero,
null, null);
                EnableWindow(xEditHandle, true);
                return;
            case WM_CTLCOLOREDIT:
                if (!Enabled)
                {
                    xBrush =
CreateSolidBrush(ColorTranslator.ToWin32(Color.Black));
                    SetTextColor(m.WParam,
ColorTranslator.ToWin32(Color.White));
                    SetBkColor(m.WParam,
ColorTranslator.ToWin32(Color.Black));
                }
                else
                {
                    xBrush =
CreateSolidBrush(ColorTranslator.ToWin32(BackColor));
                    SetTextColor(m.WParam,
ColorTranslator.ToWin32(ForeColor));
                    SetBkColor(m.WParam,
ColorTranslator.ToWin32(BackColor));
                }
                m.Result = xBrush;
                return;
        }
    base.WndProc(ref m);
    }

    protected override void OnEnabledChanged(EventArgs e)
    {
        if (Enabled) Invalidate(true);
        base.OnEnabledChanged(e);
    }
}
_______________________________________________

hope this helps

Best regards, Serge Gubenko

"Rigga" <s@v.c> wrote in message
news:41b59abe$0$50865$ed2619ec@ptn-nntp-reader01.plus.net...
> Hi all,
>
> I have an overridden ComboBox that i wish to change the colour of when it
is
> disabled.
>
> I have overridden the WNDPROC and caught the CTL_COLORSTATIC message.
>
> I can now change the background colour to any colour i wish using the
> external GDI routine SetBkColor which all works fine.
>
> However the external SetTextColor routine seems to do nothing, the text
> still appears to be greyed out.
>
> Does anyone have any thoughts on what could be going wrong?
>
> Thanks in advance,
> R.
>
>



Relevant Pages

  • Re: CTL_COLORSTATIC problems
    ... Looks like internal edit control of the combobox handles WM_CTLCOLORSTATIC ... internal static extern int SetTextColor ... internal static extern IntPtr FindWindowEx(IntPtr hwndParent, ... internal static extern bool EnableWindow ...
    (microsoft.public.dotnet.languages.vb.controls)
  • Re: Drawing on top of a form (including drawing over its controls)
    ... You can always create a control which sets the WS_EX_TRANSPARENT style in CreateParams. ... NativeMethods.UpdateLayeredWindow(this.Handle, screenDC, ref ptDst, ref szDst, memDC, ref ptSrc, 0, ref blend, NativeMethods.ULW_ALPHA); ... internal static extern IntPtr SetWindowTheme; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Loading dlls dynamically
    ... In order to compile, you'll need to have an available version of a library ... > How do I load and run dll functions dynamically please? ... > internal static extern IntPtr GetProcAddress(IntPtr hModule, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Vista Late Binding Security Problem
    ... internal static extern IntPtr GetProcAddress(IntPtr hModule, ... private static void lateBindingVistaTest() ...
    (microsoft.public.dotnet.languages.csharp)