📄 paint.c
字号:
/***************************************************************************** 文件名:paint.c* 功能:MiniGUI应用例子。* 创建一个主窗口,对窗口的MSG_PAINT消息进行计数,并在窗口* 中显示计数值。有按键按下时,让窗口重绘。****************************************************************************//* 包含MiniGUI头文件 */#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>/* 主窗口起始位置及大小 */#define MWINDOW_LX 10 /* 窗口左边框的x值 */#define MWINDOW_TY 50 /* 窗口上边框的y值 */#define MWINDOW_RX 230 /* 窗口右边框的x值 */#define MWINDOW_BY 180 /* 窗口下边框的y值 */HWND hMainWnd; // 主窗口句柄/***************************************************************************** 名称:WinProc()* 功能:主窗口过程函数。* 处理MSG_PAINT消息,先对计数变量进行加一计数,然后将计数值输* 出到窗口中显示。* 入口参数:hWnd 窗口句柄* message 消息* wParam 消息附加参数1* lParam 消息附加参数2* 出口参数:消息已处理则返回0。****************************************************************************/static int WinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ HDC hdc; char disp_buf[50]; static int no = 0; switch(message) { case MSG_PAINT: hdc = BeginPaint(hWnd); no++; sprintf(disp_buf, "MSG_PAINT消息次数:%d", no); TextOut(hdc, 10, 35, disp_buf); EndPaint(hWnd, hdc); break; case MSG_CHAR: // 字符消息 //InvalidateRect(hWnd, NULL, TRUE); // 重绘整个窗口 (可以用UpdateWindow函数) UpdateWindow(hWnd, TRUE); break; case MSG_CLOSE: DestroyMainWindow(hWnd); PostQuitMessage(hWnd); break; default: return(DefaultMainWinProc(hWnd, message, wParam, lParam)); } return(0);}/***************************************************************************** 名称:InitMainWindow()* 功能:建立主窗口。* 入口参数:无* 出口参数:建立成功返回1,否则返回0。****************************************************************************/int InitMainWindow(void){ MAINWINCREATE window_info; window_info.dwStyle = WS_VISIBLE | WS_BORDER | WS_CAPTION; window_info.dwExStyle = WS_EX_NONE; window_info.spCaption = "MSG_PAINT消息"; window_info.hMenu = 0; window_info.hCursor = GetSystemCursor(0); window_info.hIcon = GetSmallSystemIcon(IDI_APPLICATION); window_info.MainWindowProc = WinProc; window_info.lx = MWINDOW_LX; window_info.ty = MWINDOW_TY; window_info.rx = MWINDOW_RX; window_info.by = MWINDOW_BY; window_info.iBkColor = COLOR_lightwhite; window_info.dwAddData = 0; window_info.hHosting = HWND_DESKTOP; hMainWnd = CreateMainWindow(&window_info); if(hMainWnd == HWND_INVALID) return(0); else return(1);}/***************************************************************************** 名称:MiniGUIMain()* 功能:MiniGUI程序入口点。* 入口参数:argc 参数个数* argv 参数字符串指针* 出口参数:返回0。****************************************************************************/int MiniGUIMain(int argc, const char *argv[]){ MSG Msg;#ifdef _LITE_VERSION SetDesktopRect(0,0, 800,600);#endif InitMainWindow(); ShowWindow(hMainWnd, SW_SHOWNORMAL); /* 消息循环 */ while(GetMessage(&Msg, hMainWnd)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup(hMainWnd); return(0);}#ifndef _LITE_VERSION #include <minigui/dti.c>#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -