Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, anyone can tell me how to use a bitmap as a button, actually i can create a static control and could set a picture to it but the thing is that i don't know how to use it as a button, i am using c++ win32.
This is how i create the bitmap

Code:
C#
HWND Profile_Stuff(HWND hWnd, HINSTANCE hInst)
{
        HWND Profile_Pic;

Profile_Pic = CreateWindow("STATIC", NULL, SS_BITMAP|WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER, 5,5,33,33, hWnd, NULL, hInst, NULL);
	HBITMAP hBmp = (HBITMAP)LoadImage(NULL, "camera1.jpg", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
	if(hBmp == NULL){
		MessageBox(NULL, "Error while loading image", "Error", MB_OK|MB_ICONERROR);
	}
	SendMessage(Profile_Pic, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
	return 0;
    }


then i call the function in main window wm_create message handler which creates it successfully, now i don't know to use it as a button.
Posted

1 solution

The button class actually suports this. So no need to use a static control. This link should get you going...


How can I create button showing icon and text using BS_ICON and sending BM_SETIMAGE?[^]

 
Share this answer
 
Comments
Member 11593571 5-Aug-15 14:41pm    
oh man the thing you recommended works perfect but now there is another problem, how do i change the picture when the mouse cursor is on the button. like when you bring your mouse pointer on a normal button the color changes a to a little blue, how am going to do that in my bitmap kind of button. and thank
Member 11593571 7-Aug-15 0:26am    
hey can anybody answer me?
Jeremy Falcon 7-Aug-15 9:51am    
Look into the WM_MOUSEHOVER and WM_MOUSELEAVE messages. You can use a similar mechanism to set one bitmap on entry and revert it to the original upon exit. The only thing different to note is you'd now want to store your bitmaps in memory and keep them there for the life of the control rather than load them with every event.
Member 11593571 8-Aug-15 0:32am    
well how am i going to store bitmaps in memory, if i create a bitmap in resources of my project would it store it in memory
Jeremy Falcon 10-Aug-15 10:07am    
Use this as a point of reference.

http://www.codeproject.com/Articles/530/A-Better-Bitmap-Button-Class

It's in MFC, but it should get you pointed in the right direction to port it to pure API.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900