有些时候,为了满足一些特殊的需要,我们需要自己编写自定义的消息对话框。这里提供了一个典型的消息框的编程范例,叫做mbox。它是由4个文件组成,可以方便的加入到某个工程中,而不需要通过繁琐的库调用方式。这个C语言的程序是在GCC和CodeWarrior环境下开发的,但是仅仅在GCC环境下进行了测试。如果您是CodeWarrior用户,您需要将文件转化为PilRC格式:
文件1:mobox.c,采用了类似windows API 的消息框的函数
#include #include "mbox.h" #include "mbox.rh"
//// MessageBox //////////////////////////////////////////////////////// // 一个类似windows messagebox的函数
void MessageBox(const char* pc, MessageBoxType eType) { switch (eType) { case kMBOK: FrmCustomAlert(MessageBoxInfoAlert, pc, 0, 0); break;
case kMBWarning: FrmCustomAlert(MessageBoxWarningAlert, pc, 0, 0); break;
case kMBError: FrmCustomAlert(MessageBoxErrorAlert, pc, 0, 0); break; } } 文件2:mbox.h
#if !defined(MBOX_H) #define MBOX_H
// 用于定义消息框类型的常量 typedef enum { kMBOK, kMBWarning, kMBError } MessageBoxType;
extern void MessageBox(const char* pc, MessageBoxType eType);
#endif // !defined(MBOX_H) 文件3:mbox.rcp,类似于警告的消息框
ALERT ID MessageBoxInfoAlert INFORMATION BEGIN TITLE "信息" MESSAGE "^1" BUTTONS "确定" END
ALERT ID MessageBoxWarningAlert WARNING BEGIN TITLE "警告" MESSAGE "^1" BUTTONS "确定" END
ALERT ID MessageBoxErrorAlert ERROR BEGIN TITLE "错误" MESSAGE "^1" BUTTONS "确定" END 文件4:mbox.rh
#define MessageBoxInfoAlert 3201 #define MessageBoxWarningAlert 3202 #define MessageBoxErrorAlert 3203
(出处:清风网络学院)
上一篇:关于拷贝构造函数和赋值运算符
下一篇:Win32下两种用于C++的线程同步类(上)
|