如何在c ++ win32中使用位图作为按钮 [英] how to use bitmap as a button in c++ win32

查看:82
本文介绍了如何在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消息处理程序中调用该函数,成功创建它,现在我不知道将它用作按钮。

解决方案

按钮类实际上支持这个。所以不需要使用静态控件。这个链接应该让你去...



我该如何创建按钮显示图标和文本使用BS_ICON并发送BM_SETIMAGE? [ ^ ]


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆