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);
m_btn1.Invalidate();
m_btn1.UpdateWindow();
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.