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.
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.