Click to See Complete Forum and Search --> : [RESOLVED] Ws_drawitem


Edge_Master
May 25th, 2006, 07:17 PM
Hi, i'm trying use a BS_OWNERDRAW button without MFC.
I tried in many ways but the last code is this:

void Pintar(HWND hwnd)
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc;

hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);//-/-/-/-
SelectObject(hdcMem, Fondo);
GetObject(Fondo, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
EndPaint(hwnd, &ps);
DeleteDC(hdcMem);

}
void CambiarImagen(HWND hwnd, LPDRAWITEMSTRUCT Draw)
{
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc;
HDC hdcMem;
char state[3];
itoa(Draw->itemState,&state[0],10);


if(Draw->itemState & ODS_SELECTED)
{
hdc=BeginPaint(BtnSalir, &ps);
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, Cerrar1);
GetObject(Cerrar1, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
}
else
{
MessageBox(hwnd,state,"hola",MB_OK);

}
EndPaint(BtnSalir, &ps);
DeleteDC(hdcMem);
}


Where "Pintar" is called in WM_PAINT and "CambiarImagen" is called in WM_DRAWITEM. The problem is that a messagebox should appear when i realise the button but it appear when i press it. Another problem is that if i call "Pintar" in WM_PAINT when "CambiarImagen" is called in WM_DRAWITEM the image of the button doesn't change, if i don't call "Pintar" the image change when i press the button but i need to call "Pintar" to set the bitmap for the window Background. I hope that you could help me.
Sorry for my English,i'll be thankful if somebody corrects my mistakes.
Thanks in advance.

Edge_Master
May 25th, 2006, 07:23 PM
i wanted to say WM_DRAWITEM not Ws_drawitem, in the thread title

kirants
May 25th, 2006, 11:31 PM
First, please use code tags while posting code snippets. Makes it readable. Please see my signature on how to do it.
It would be interesting to know what you are trying to achieve.
It would also be interesting to know for window procedure you are implementing all this code. Note that WM_DRAWITEM (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/comboboxes/comboboxreference/comboboxmessages/wm_drawitem.asp) message is sent to the parent window and not to the control window
You do not have to call BeginPaint and EndPaint in a WM_DRAWITEM handler.

Edge_Master
May 26th, 2006, 01:42 AM
WOW!!!!
in a few word you gave me the solution.

I change this:

void CambiarImagen(HWND hwnd, LPDRAWITEMSTRUCT Draw)
{
BITMAP bm;
HDC hdcMem;

char state[3];
itoa(Draw->itemState,&state[0],10);

if(Draw->itemState & ODS_SELECTED)
{

hdcMem = CreateCompatibleDC(Draw->hDC);
SelectObject(hdcMem, Cerrar1);
GetObject(Cerrar1, sizeof(bm), &bm);
BitBlt(Draw->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
}
else
{
hdcMem = CreateCompatibleDC(Draw->hDC);
SelectObject(hdcMem, Cerrar);
GetObject(Cerrar, sizeof(bm), &bm);
BitBlt(Draw->hDC, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

}
DeleteDC(hdcMem);

}

The problem was that the button's image doesn't change, but the unique problem was that i wasn't used the HDC that PAINTSTRUCT has. Thank again a sorry for my English and for the post that i haven't used code blocks.