顯示消息框的程序
2019-11-17 05:45:31
供稿:網友
有些時候,為了滿足一些非凡的需要,我們需要自己編寫自定義的消息對話框。這里提供了一個典型的消息框的編程范例,叫做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