Solved

Putting A Bitmap On A Button In Such A Way

Posted on 2002-05-09
5
470 Views
Last Modified: 2013-12-03
Hello Experts,

I have designed an application completely made in SDK (no MFC). I like to create a button and put a bitmap on it for that I used,

HWNDBUTTON=CreateWindow("BUTTON",NULL,WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON | BS_BITMAP | BS_FLAT,..,..,..,..,HWND,NULL,....,NULL);

SendMessage(HWNDBUTTON,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM) (HANDLE)BITMAPHANDLE);

But here, whatsoever I do whether it is increasing size of bitmap or decreasing button size or whatever I do, I am not able to get the way I want that Button to appear on screen. Grey Edges or something else is always there.

I want that, It should appear as only seeing bitmap to the users, The Button Should Be Flat and Bitmap Should completely cover the Button so that it appears that a bitmap has been displayed as if not a button to users

Please suggest me as to how to accomplish this.

Best Regards
Sudhaom

0
Comment
Question by:sudhaom
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Yechezkel
ID: 6998739
I would suggest using a static control. If you want to receive messages (button clicks etc.), make sure to set the SS_NOTIFY style (and perhaps the WS_TABSTOP style).
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6999717
Buttons with BS_BITMAP still have the 3d border / focus rect etc. For complete control over the rendering of a button use the BS_OWNERDRAW style instead.

With BS_OWNERDRAW it is up to you to handle the WM_DRAWITEM message that is sent to the *parent* window.
Upon reciept of the message you would draw to the DC.

Eg.

case WM_DRAWITEM:
  pDIS = (DRAWITEMSTRUCT*)lParam;
  if (pDIS->hwndItem==hMyButtonWnd)
  {
    HDC hdc=CreateCompatibleDC(pDIS->hDC);
    SelectObject(hdc,hMyBitmap);
    BitBlt(pDIS->hdc,x,y,hdc,0,0,w,h,SRCCOPY);
    DeleteDC(hdc);
  }


0
 
LVL 1

Author Comment

by:sudhaom
ID: 7001264
Thanks Yechezkel and robpitt for prompt reply.
Robpitt, I did as you told but nothing happens, the button comes blank gray, no bitmap on it. Following is the code::

HWNDCOMMANDBUTTON=CreateWindow("BUTTON",NULL,WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_PUSHBUTTON | BS_OWNERDRAW | BS_FLAT,60,127,28,28,MAINWINDOW,NULL,(HINSTANCE)GetWindowLong(MAINWINDOW,GWL_HINSTANCE),NULL);

BITMAPHANDLE=LoadBitmap(ghInst,(LPCTSTR)IDB_BITMAP);
...
...


case WM_DRAWITEM:
pDIS=(DRAWITEMSTRUCT*)lParam;
if (pDIS->hwndItem==HWNDCOMMANDBUTTON)
{
hdc=CreateCompatibleDC(pDIS->hDC);
SelectObject(hdc,(LPARAM)(HANDLE)BITMAPHANDLE);
BitBlt(pDIS->hDC,0,0,hdc,0,0,28,28,SRCCOPY);
DeleteDC(hdc);
}
break;

Please suggest what to do.

Best Regards
Sudhaom

0
 
LVL 5

Accepted Solution

by:
robpitt earned 100 total points
ID: 7001317
A reference for you:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/CommCtls/winui/buttons_4icz.asp


Also try removing all the other BS_* styles except BS_OWNERDRAW - thought I doubt that'll make much difference.
0
 
LVL 1

Author Comment

by:sudhaom
ID: 7002918
Thanks robpitt,
At last it worked, I was making some silly mistakes. But BS_* doesnot have to do anything. Thanks.

Best Regards
Sudhaom

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question