Solved

Putting A Bitmap On A Button In Such A Way

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…

862 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

27 Experts available now in Live!

Get 1:1 Help Now