📄 msgbox.c
字号:
/*************************************************************************
*
* Copyright 2000 National ASIC Center, All right Reserved
*
* FILE NAME: msgbox.c
* PROGRAMMER: Lingming
* Date of Creation: 2001/03/08
*
* DESCRIPTION: message box. The parameters are same as MS Windows' system
*
* NOTE:
*
* FUNCTIONS LIST:
* MessageBox(U32 wndid, char *inforstr, char *caption, U16 type)
*
*
*
*
* GLOBAL VARS LIST:
*
*
**************************************************************************
* MODIFICATION HISTORY
*
* 2001/03/08 by Lingming Creation of this file
*
*
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
//#include <math.h>
#include <string.h>
#include "asixwin.h"
//#include <bitmap.h>
#include "disp.h"
//#include <hc.h>
const char mb_ok[]="确定";
const char mb_cancel[] = "取消";
const char mb_abort[] = "放弃";
const char mb_retry[] = "重试";
const char mb_ignore[] = "忽略";
const char mb_yes[] = "是";
const char mb_no[] = "否";
//defined in bmpdata.c
extern const U8 infor_icon[];
extern const U8 note_icon[];
extern const U8 stop_icon[];
extern const U8 err_icon[];
extern const U8 question_icon[];
U16 MessageBox( U32 wndid, char *inforstr, char *caption, U16 type )
{
U32 boxid, bt1, bt2, bt3;
static MSG Msg;
U16 boxtype, boxicon, boxdefault;
U8 quit = FALSE;
U8 float_time = 0;
U16 bt1x;
const char *bt1str = NULL, *bt2str = NULL, *bt3str = NULL;
const U8 *bitmap = NULL;
U16 bt1rv = 0, bt2rv = 0, bt3rv = 0;
U16 rv = 0;
U16 lcd_w, lcd_h;
U32 pGC;
pGC = GetGC();
////////////We discard CurWindow Now//////////////////////////////////////////
//if ( wndid != (U32)CurWindow ) return 0;
/////////////////By Lingming 2002/03/20///////////////////////////////////////
boxtype = type & MB_TYPEMASK;
boxicon = type & MB_ICONMASK;
boxdefault = type & MB_DEFMASK;
lcd_w = ASIX_LCD_W;
lcd_h = ASIX_LCD_H;
if ( boxtype != MB_FLOAT ) {
boxid = CreateWindow( WNDCLASS_WIN, caption, WS_POPUPWINDOW /*| WS_SAVESCREEN*/,
1, (U16)(lcd_h/3), (U16)(lcd_w-2), (U16)(CHINESE_CHAR_HEIGHT*7), 0, 0, NULL );
//DisplayMsg(inforstr, 35, lcd_h/3+CHINESE_CHAR_HEIGHT+4+6, lcd_w-2,lcd_h/3+CHINESE_CHAR_HEIGHT*4+4+6, OR_STYLE);
DrawText(pGC, inforstr, 33, (U16)(lcd_h/3+CHINESE_CHAR_HEIGHT+4+6), (U16)(lcd_w-3), (U16)(lcd_h/3+CHINESE_CHAR_HEIGHT*4+4+6), \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
//ClearRec(LIGHT_GREY, 35, lcd_h/3+CHINESE_CHAR_HEIGHT+4+6, lcd_w-35, CHINESE_CHAR_HEIGHT*3, OR_STYLE);
} else {
//boxid = CreateWindow( WNDCLASS_WIN, NULL, WS_BORDER | WS_SAVESCREEN,
// lcd_w/6, lcd_h/2, lcd_w*2/3, CHINESE_CHAR_HEIGHT*3, 0, 0, NULL );
//DisplayMsg(inforstr, lcd_w/6+1, lcd_h/2+1, lcd_w/6+lcd_w*2/3 - 1 ,
//lcd_h/2+CHINESE_CHAR_HEIGHT*3-1 ,REPLACE_STYLE);
}
if (boxid == 0 ) return 0;
PopUpWindow( boxid, 0 );
switch (boxtype)
{
case MB_OK:
bt1x = (lcd_w-35)/2;
bt1str = mb_ok;
bt1rv = IDOK;
break;
case MB_OKCANCEL:
bt1x = (lcd_w-70-10)/2;
bt1str = mb_ok;
bt2str = mb_cancel;
bt1rv = IDOK;
bt2rv = IDCANCEL;
break;
case MB_YESNO:
bt1x = (lcd_w-70-10)/2;
bt1str = mb_yes;
bt2str = mb_no;
bt1rv = IDYES;
bt2rv = IDNO;
break;
case MB_ABORTRETRYIGNORE:
bt1x = (lcd_w-105-10)/2;
bt1str = mb_abort;
bt2str = mb_retry;
bt3str = mb_ignore;
bt1rv = IDABORT;
bt2rv = IDRETRY;
bt3rv = IDIGNORE;
break;
case MB_YESNOCANCEL:
bt1x = (lcd_w-105-10)/2;
bt1str = mb_yes;
bt2str = mb_no;
bt3str = mb_cancel;
bt1rv = IDYES;
bt2rv = IDNO;
bt3rv = IDCANCEL;
break;
case MB_RETRYCANCEL:
bt1x = (lcd_w-70-10)/2;
bt1str = mb_retry;
bt2str = mb_cancel;
bt1rv = IDRETRY;
bt2rv = IDCANCEL;
break;
case MB_FLOAT:
break;
default:
goto destroy ;
break;
}
switch (boxicon)
{
case MB_ICONSTOP:
bitmap = stop_icon;
break;
case MB_ICONQUESTION:
bitmap = question_icon;
break;
case MB_ICONEXCLAMATION:
bitmap = note_icon;
break;
case MB_ICONINFORMATION:
bitmap = infor_icon;
break;
case MB_ICONERROR:
bitmap = err_icon;
break;
}
if ( boxtype != MB_FLOAT && bitmap != NULL )
//switchonetotwo(bitmap, 6, lcd_h/3+CHINESE_CHAR_HEIGHT+4+6, 24, 24);
// DrawMonoImage(pGC, bitmap, 6, lcd_h/3+CHINESE_CHAR_HEIGHT+4+6,\
// 24, 24, GPC_LIGHTBLUE, GPC_WHITE);
{
U32 hbmp;
//U32 trColor;
U16 lx = 6;
U16 ly = lcd_h/3+CHINESE_CHAR_HEIGHT+4+6;
U32 palette[] = { GPC_WHITE, GPC_LIGHTBLUE };
hbmp = LoadBitmap( bitmap, palette );
if( hbmp != 0 )
{
SetBMPPalette( hbmp, palette, NULL );
//SetBkFillMode( pGC, MAKELONG( GPC_REPLACE_STYLE, GPC_TRANSPARENT_STYLE ) );
//GetBMPPixel( pGC, 0, 0, hbmp, &trColor );
//DisplayBMPEx( pGC, x, y, hbmp, GPC_TRANSPARENT_STYLE, trColor );
DisplayBMP( pGC, lx, ly, hbmp );
FreeBitmap( hbmp );
}
}
if ( bt1str != NULL) {
/* 2001-11-24 16:24 */
bt1 = CreateWindow( WNDCLASS_BUTTON, (char *)bt1str, WS_CHILD | BS_BOARD | BS_ICON,
bt1x, (U16)(lcd_h/3+65) , 35, 18, boxid, 0, NULL );
if (bt1 == 0) goto destroy;
}
if (bt2str != NULL) {
/* 2001-11-24 16:24 */
bt2 = CreateWindow( WNDCLASS_BUTTON, (char *)bt2str, WS_CHILD | BS_BOARD | BS_ICON,
(U16)(bt1x+35+5), (U16)(lcd_h/3+65) , 35, 18, boxid, 0, NULL );
if (bt2 == 0) goto destroy;
}
if (bt3str != NULL) {
/* 2001-11-24 16:24 */
bt3 = CreateWindow( WNDCLASS_BUTTON, (char *)bt3str, WS_CHILD | BS_BOARD | BS_ICON,
(U16)(bt1x+70+10), (U16)(lcd_h/3+65) , 35, 18, boxid, 0, NULL );
if (bt3 == 0) goto destroy;
}
if (boxtype != MB_FLOAT) {
if ( boxdefault == MB_DEFBUTTON1 ) SetFocus(bt1);
else if (boxdefault == MB_DEFBUTTON2 ) SetFocus(bt2);
else if (boxdefault == MB_DEFBUTTON3 ) SetFocus(bt3);
}
while ( !quit )
{
ASIXGetMessage(&Msg,NULL,0,0);
switch (Msg.message )
{
case ASIX_RTC:
if (boxtype == MB_FLOAT){
float_time ++;
if (float_time >= 3 )
quit = TRUE;
}
break;
case WM_COMMAND:
if ( Msg.lparam == bt1 ) rv = bt1rv;
else if (Msg.lparam == bt2 ) rv = bt2rv;
else if (Msg.lparam == bt3 ) rv = bt3rv;
if ( rv != 0 )
quit = TRUE;
break;
case WM_QUIT:
if ( boxdefault == MB_DEFBUTTON1 ) rv = bt1rv;
else if (boxdefault == MB_DEFBUTTON2 ) rv = bt2rv;
else if (boxdefault == MB_DEFBUTTON3 ) rv = bt3rv;
quit = TRUE;
break;
default:
break;
}
DefWindowProc(Msg.message, Msg.lparam, Msg.data, Msg.wparam);
}
destroy:
DestroyWindow(boxid);
return rv;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -