Solved

Putting A Bitmap On A Button In Such A Way

Posted on 2002-05-09
5
464 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now