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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息

發布時間:2025/3/15 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?

對話框中添加工具欄及工具欄上的Button響應UPDATE_COMMAND_UI消息

在對話框程序中添加工具欄其實很簡單,網上能找到很多的例子。一般的步驟就是:1、在資源中添加工

具欄資源;2、在對話框類中定義一個工具欄變量;3、在對話框的OnInitDialog函數中Create工具欄。程

序如下:
在對話框類中定義工具欄成員變量:
CToolBar m_ToolBar;
在OnInitDialog函數中Create之:
if(!m_ToolBar.CreateEx(this, TBSTYLE_FLAT,

WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_SIZE_DYNAMIC)
??||!m_ToolBar.LoadToolBar(IDR_TOOLBAR_GRAPHICS))
?{
??TRACE0(_T("創建工具條失敗/n"));
??return FALSE;
?}
?RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

但是要讓對話框中的工具欄響應UPDATE_COMMAND_UI消息,做到按下保持的狀態僅僅重載

UPDATE_COMMAND_UI消息并使用SetCheck是不行的,因為此時的工具欄上的按鈕屬性為普通的按鈕,可以

通過下面的方法測試:
????? if(m_ToolBar.GetButtonStyle(0) == TBBS_BUTTON)
?{
??AfxMessageBox("This is Button Style");
?}
必須添加以下的設置:
????? m_ToolBar.SetButtonStyle(0,TBBS_CHECKBOX);
?m_ToolBar.SetButtonStyle(1,TBBS_CHECKBOX);
SetButtonStyle函數的原型及其相關的說明:(引自MSDN)
1、void SetButtonStyle( int nIndex, UINT nStyle );

Parameters

nIndex

Index of the button or separator whose information is to be set.

nStyle

The button style. The following button styles are supported:

TBBS_BUTTON?? Standard pushbutton (default)


TBBS_SEPARATOR?? Separator


TBBS_CHECKBOX?? Auto check-box button


TBBS_GROUP?? Marks the start of a group of buttons


TBBS_CHECKGROUP?? Marks the start of a group of check-box buttons
Remarks

Call this member function to set the style of a button or separator, or to group buttons. A

button's style determines how the button appears and how it responds to user input.

2、還有一種修改Button屬性的函數
void SetButtonInfo( int nIndex, UINT nID, UINT nStyle, int iImage );

Parameters

nIndex

Index of the button or separator whose information is to be set.

nID

The value to which the button’s command ID is set.

nStyle

The new button style. The following button styles are supported:

TBBS_BUTTON?? Standard pushbutton (default)


TBBS_SEPARATOR?? Separator


TBBS_CHECKBOX?? Auto check-box button


TBBS_GROUP?? Marks the start of a group of buttons


TBBS_CHECKGROUP?? Marks the start of a group of check-box buttons
iImage

New index for the button’s image within the bitmap.

Remarks

Call this member function to set the button's command ID, style, and image number. For

separators, which have the style TBBS_SEPARATOR, this function sets the separator's width in

pixels to the value stored in iImage.

For information on bitmap images and buttons, see the CToolBar Overview and

CToolBar::LoadBitmap.

總結

以上是生活随笔為你收集整理的MFC对话框程序中添加工具栏及工具栏上的Button响应UPDATE_COMMAND_UI消息的全部內容,希望文章能夠幫你解決所遇到的問題。

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