C语言封装MessageBox函数创建自定义消息框
在C语言中,可以使用Windows API函数MessageBox来创建一个消息框(Message Box)。下面是一个封装MessageBox函数的示例代码:
#include <windows.h>
int showMsgBox(HWND hwnd, LPCSTR text, LPCSTR caption, UINT type) {
return MessageBox(hwnd, text, caption, type);
}
int main() {
HWND hwnd = NULL; // 窗口句柄,可以设置为NULL
LPCSTR text = 'Hello, World!'; // 消息框中显示的文本
LPCSTR caption = 'Message Box'; // 消息框的标题
UINT type = MB_OK; // 消息框的类型,这里使用OK按钮
int result = showMsgBox(hwnd, text, caption, type);
if (result == IDOK) {
printf('OK button clicked.\n');
}
return 0;
}
在上述代码中,showMsgBox函数封装了MessageBox函数,并通过传递参数来实现自定义消息框的显示。在main函数中,调用showMsgBox函数来创建一个消息框,并检查用户点击的按钮是否为OK按钮。
原文地址: https://www.cveoy.top/t/topic/qvKc 著作权归作者所有。请勿转载和采集!