MFC button picture according to the specified picture display ball help!

czyroy 注册会员
2023-02-25 19:11

The problem is that the code is not added properly. Here add
m_btn1.LoadBitmaps(IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1, IDB_BITMAP1); // Do not press the picture

m_btn1.LoadBitmaps(IDB_BITMAP2, IDB_BITMAP2, IDB_BITMAP2, IDB_BITMAP2); // Pressed image

loadstar_kun 注册会员
2023-02-25 19:11

Using gpt and your own ideas, you can use the SetBitmaps() function provided by the CBmpButton control to set the image of the button in different states. To achieve the button picture switch. The specific steps are as follows:

Add the "not pressed" and "pressed" bitmap images to the resource view and give them ids, such as IDB_BITMAP1 and IDB_BITMAP2.
In the OnInitDialog() function of the Dialog class, subclass the Button1 control to type CBmpButton by calling the SubclassDlgItem() function of the CBmpButton control, and set the default bitmap image for it. For example:

m_btn1.SubclassDlgItem(IDC_BUTTON1, this);
m_btn1.SetBitmaps(IDB_BITMAP1, IDB_BITMAP2);

In the Click event of the Button1 control, first send the serial port online signal and wait for the confirmation reply before switching the button picture, for example:

// 发送串口联机信号

// 等待确认回复

// 切换按钮图片
m_btn1.SetBitmaps(IDB_BITMAP2, IDB_BITMAP2);

Where the first argument of the SetBitmaps() function is the ID of the image when the button is not pressed, and the second argument is the ID of the image when the button is pressed. The Invalidate() function is used to invalidate the button, and the UpdateWindow() function is used to update the button's display.

Please note that the above code is only an example. The specific implementation method may need to be adjusted according to your specific application scenario.

dyb6918 注册会员
2023-02-25 19:11

Part of the answer refers to GPT, GPT_Pro for better problem solving
To implement this function, first add code to the button's message response function:

void CMyDlg::OnBnClickedButton1()
    // TODO: 在此添加控件通知处理程序代码    
    // 发送联机信号
    // 接收确认回复
    // 其他代码...

Where the SetBitmap() function is used to set the button image to IDB_BITMAP2, the "pressed" image, then send an online signal, and finally receive a confirmation reply. This button can realize the function of displaying two pictures.
If the answer is helpful, please accept it.

dq89163756 注册会员
2023-02-25 19:11
< div class = "md_content_show e397 data - v - 3967" = "" >

add m_btn1. SetBitmap(IDB_BITMAP2); Post-compilation error C2664: "HBITMAP CButton::SetBitmap(HBITMAP)" : Unable to convert argument 1 from "int" to "HBITMAP"

About the Author

Question Info

Publish Time
2023-02-25 19:10
Update Time
2023-02-25 19:10