开发者

Making an owner-draw button transparent against its arbitrary background in WINCE

开发者 https://www.devze.com 2022-12-24 08:03 出处:网络
I am trying to place an owner-draw button transparently onto a background. I have no trouble doing this when the background is a solid colour but if the background is an image I cannot seem to get the

I am trying to place an owner-draw button transparently onto a background. I have no trouble doing this when the background is a solid colour but if the background is an image I cannot seem to get the correct HDC (handle to device context) to Bitblt() the area that button covers.

The HDC that is passed as part of the DRAWITEMSTRUCT gives me a button-default-grey area. If I attempt to get the parent of the HWND and then the device context of that i.e

pdc = GetDC(GetParent(hWnd));

then the background that gets BitBlt'd is the background of the last painted window.

I hope this question makes sense.

this is the code I have:

  pdis = (LPDRAWITEMSTRUCT)(lParam);
  hdc = pdis->hDC;
  button = pdis->CtlID - IDC_BUTOFFSET;

  //pdc = GetDC((hWnd));
  pdc = GetDC(GetParent(hWnd));

  hbm = CreateCompatibleBitmap(pdc,  Buttons_[button]->bc.Size.cx, Buttons_[button]->bc.Size.cy);
  SelectObject(hdc, hbm);
  BitBlt(hdc, 0, 0, Buttons_[button]->bc.Size.cx, Buttons_[button]->bc.Size.cy,开发者_JS百科 
     pdc, Buttons_[button]->bc.Position.x, Buttons_[button]->bc.Position.y, SRCCOPY);

TIA Best regards Ends


It seems that what I have been doing is more or less correct. However Bitblt is copying the section of the window with the button already placed, so what I am in effect doing is copying the default button background and then overlaying that on top of the owner-draw button. A bit dumb but completely logical.

I hate it when computers do what you tell them to do and not what you want them to do. :P

Now I have to figure out how to copy the background as the ownerdraw function does not know what the window under the button is displaying at any given time...

Thanks to those who had a look at the question.

BTW:

pdc = GetDC(GetParent(hWnd)); // NOT CORRECT
pdc = GetDC(hWnd); // better

0

精彩评论

暂无评论...
验证码 换一张
取 消