日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【转】Win32 SDK 实现带图片的 Button 控件BM_SETIMAGE(Disable时图片不显示)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【转】Win32 SDK 实现带图片的 Button 控件BM_SETIMAGE(Disable时图片不显示) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在編寫對話框程序時,希望能在按鈕控件里顯示一個小插圖,如圖所示

最初使用的方法是使用 BM_SETIMAGE 消息,但卻不能達到滿意的效果,在網上查了一通資料,最后終于實現了,現在把實現的方法記下來。

首先來到MSDN上,查得如下資料

?

BM_SETIMAGE message

Associates a new image (icon or bitmap) with the button.

Parameters

wParam

The type of image to associate with the button. This parameter can be one of the following values:

  • IMAGE_BITMAP
  • IMAGE_ICON

lParam

A handle (HICON?or?HBITMAP) to the image to associate with the button.

Return value

不重要,略

Remarks

The appearance of text, an icon, or both on a button control depends on the?BS_ICON?and?BS_BITMAP?styles, and whether the?BM_SETIMAGE?message is called. The possible results are as follows:

?

BS_ICON or BS_BITMAP Set?BM_SETIMAGE Called?Result
YesYesShow icon only.
NoYesShow icon and text.
YesNoShow text only.
NoNoShow text only

?

既然希望同時顯示圖片和文字,那么就應該采取上表中的第二行設置(藍色)。

故控件屬性設置為:

?

然后在 OnInitDialog() 函數中添加如下語句:

?

SendDlgItemMessage(hwnd,IDC_BUTTON1,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)LoadBitmap(hIn,MAKEINTRESOURCE(IDB_BITMAP1)));

?

但是效果卻是這樣的:

如果把控件屬性中的Bitmap項改為 True ,效果又成了這個樣子:

真的很讓人抓狂。在一通搜索后,發現解決方案就在MSDN中。在BM_SETIMAGE詞條的下面,有一條老外的評論,是這樣的:

?

Community Additions

Icon with text solution

I had the same problem for the icon + text in the button and I solved using the version 6 of the common controls.
You can make this by adding the library (if I?understand it, I'm not sure).

However I've added it with the preprocessor directive:

#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")

"EDIT:" This preprocessor directive go on a single line, I don't know why It force me to put a line break after "#pragma"

?

Linkinf94
1/14/2013

也就是說,使用6.0.0.0版本的 Common-Controls 就好了,所以在程序里加上這么一句話:

?

?

#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")


就萬事OK了(64位平臺,改為AMD64)

?

關于 Common-Controls 還可以參考:


http://blog.csdn.net/thirdprince/article/details/6336010

總結

以上是生活随笔為你收集整理的【转】Win32 SDK 实现带图片的 Button 控件BM_SETIMAGE(Disable时图片不显示)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。