Solved

Putting A Bitmap On A Button In Such A Way

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Is COM supported from Apache 1 81
Microsoft C++ code failing in executable that worked 9 146
GET error with Font Awesome 3 51
Error in Visual Project 10 49
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

751 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