Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Putting A Bitmap On A Button In Such A Way

Posted on 2002-05-09
5
Medium Priority
?
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
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…

722 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