combobox problem

  • Thread starter Frederik Vanderhaegen
  • Start date
F

Frederik Vanderhaegen

Hi,

I'm trying change the layout of a combobox when f.e. a certain property is
set to true.
My problem is the following: when I execute the code, the combobox is
repainted but there always stays an area unpainted.
After soms research I discovered that a combobox also contains a textbox.
With the windows api function GetComboBoxInfo I can retrieve a handle to
that textbox.
When I create a graphics object with that handle and try to execute the
method FillRectangle nothing changes.

Here you find an sample of my code.
[DllImport("user32.dll", EntryPoint="SendMessageA")]
private static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr
wParam, object lParam);

[DllImport("user32")]
private static extern IntPtr GetWindowDC (IntPtr hWnd );

[DllImport("user32")]
private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC );

[DllImport("user32")]
private static extern bool GetComboBoxInfo(IntPtr hwndCombo, ref
ComboBoxInfo info);

[StructLayout(LayoutKind.Sequential)]
private struct ComboBoxInfo
{
public int cbSize;
public RECT rcItem;
public RECT rcButton;
public IntPtr stateButton;
public IntPtr hwndCombo;
public IntPtr hwndEdit;
public IntPtr hwndList;
}


const int WM_ERASEBKGND = 0x14;
const int WM_PAINT = 0xF;
const int WM_NC_PAINT = 0x85;
const int WM_PRINTCLIENT = 0x318;

protected override void WndProc(ref Message m)
{
IntPtr hDC = IntPtr.Zero;
Graphics gdc = null;
switch (m.Msg)
{
case WM_NC_PAINT:
hDC = GetWindowDC(m.HWnd);
gdc = Graphics.FromHdc(hDC);
SendMessage(this.Handle, WM_ERASEBKGND, hDC, 0);
SendPrintClientMsg();
SendMessage(this.Handle, WM_PAINT, IntPtr.Zero, 0);

m.Result = (IntPtr) 1;
ReleaseDC(m.HWnd, hDC);
gdc.Dispose();
break;
case WM_PAINT:
base.WndProc(ref m);
hDC = GetWindowDC(m.HWnd);
gdc = Graphics.FromHdc(hDC);
gdc.FillRectangle(new
SolidBrush(Brushes.Desktop),this.ClientRectangle);
ReleaseDC(m.HWnd, hDC);

ComboBoxInfo cbi = new ComboBoxInfo();
cbi.cbSize = Marshal.SizeOf(cbi);
GetComboBoxInfo(handle, ref cbi);

hDC = GetWindowDC(cbi.hwndEdit);
gdc = Graphics.FromHdc(hDC);
gdc.FillRectangle(new
SolidBrush(Brushes.Desktop),this.DisplayRectangle);
ReleaseDC(cbi.hwndEdit, hDC);

gdc.Dispose();
break;
default:
base.WndProc(ref m);
break;
}
}

private void SendPrintClientMsg()
{
Graphics gClient = this.CreateGraphics();
IntPtr ptrClientDC = gClient.GetHdc();
SendMessage(this.Handle, WM_PRINTCLIENT, ptrClientDC, 0);
gClient.ReleaseHdc(ptrClientDC);
gClient.Dispose();
}

Does anybody knows the solution to this problem?
Any help is welcome.

Thx in advance

Regards

Frederik
 
M

Mike Labosh

My problem is the following: when I execute the code, the combobox is
repainted but there always stays an area unpainted.
After soms research I discovered that a combobox also contains a textbox.
With the windows api function GetComboBoxInfo I can retrieve a handle to
that textbox.
When I create a graphics object with that handle and try to execute the
method FillRectangle nothing changes.

I think you need to call InvalidateRect instead of FillRectangle.
InvalidateRect causes Windows to re-render whatever your hWnd points to.
--
Peace & happy computing,

Mike Labosh, MCSD

"When you kill a man, you're a murderer.
Kill many, and you're a conqueror.
Kill them all and you're a god." -- Dave Mustane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top