如何在c ++ win32中使用位图作为按钮 [英] how to use bitmap as a button in c++ win32
问题描述
您好,任何人都可以告诉我如何使用位图作为按钮,实际上我可以创建一个静态控件并可以设置图片但事情是我不知道如何将它用作按钮,我正在使用c ++ win32。
这就是我创建位图的方式
代码:
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, < span class =code-string>加载图片时出错, 错误 ,MB_OK | MB_ICONERROR);
}
SendMessage(Profile_Pic,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBmp);
return 0 ;
}
然后我在主窗口wm_create消息处理程序中调用该函数,成功创建它,现在我不知道将它用作按钮。
按钮类实际上支持这个。所以不需要使用静态控件。这个链接应该让你去...
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:
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.
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?[^]
这篇关于如何在c ++ win32中使用位图作为按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!