?? timeeditor.c
字號(hào):
/* ** $Id: timeeditor.c,v 1.11 2007-08-30 01:20:10 xwyan Exp $**** Listing 12.1**** timeeditor.c: Sample program for MiniGUI Programming Guide** A time editor, use SpinBox and Edit controls.**** Copyright (C) 2004 ~ 2007 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#define IDC_EDIT 100#define IDC_SPINBOX 110static PLOGFONT timefont;static WNDPROC old_edit_proc;static void on_down_up (HWND hwnd, int offset){ char time [10]; int caretpos; int hour, minute, second; GetWindowText (hwnd, time, 8); caretpos = SendMessage (hwnd, EM_GETCARETPOS, 0, 0); hour = atoi (time); minute = atoi (time + 3); second = atoi (time + 6); if (caretpos > 5) { /* change second */ second += offset; if (second < 0) second = 59; if (second > 59) second = 0; } else if (caretpos > 2) { /* change minute */ minute += offset; if (minute < 0) minute = 59; if (minute > 59) minute = 0; } else { /* change hour */ hour += offset; if (hour < 0) hour = 23; if (hour > 23) hour = 0; } sprintf (time, "%02d:%02d:%02d", hour, minute, second); SetWindowText (hwnd, time); SendMessage (hwnd, EM_SETCARETPOS, 0, caretpos);}static int TimeEditBox (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){ if (message == MSG_KEYDOWN) { switch (wParam) { case SCANCODE_CURSORBLOCKUP: on_down_up (hwnd, 1); return 0; case SCANCODE_CURSORBLOCKDOWN: on_down_up (hwnd, -1); return 0; case SCANCODE_PAGEUP: on_down_up (hwnd, 10); return 0; case SCANCODE_PAGEDOWN: on_down_up (hwnd, -10); return 0; case SCANCODE_CURSORBLOCKLEFT: case SCANCODE_CURSORBLOCKRIGHT: break; default: return 0; } } if (message == MSG_KEYUP || message == MSG_CHAR) return 0; return (*old_edit_proc) (hwnd, message, wParam, lParam);}static int TimeEditorWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_CREATE: { HWND hwnd; HDC hdc; HWND timeedit, spin; SIZE size; hwnd = CreateWindow (CTRL_STATIC, "This is a time editor.\n\n" "Pressing <Down-Arrow>, <Up-Arrow>, <PgDn>, and <PgUp> keys" " when the box has input focus will change the time.\n\n" "You can also change the time by clicking the SpinBox.\n", WS_CHILD | WS_VISIBLE | SS_LEFT, IDC_STATIC, 10, 10, 220, 200, hWnd, 0); timefont = CreateLogFont (NULL, "Arial", "ISO8859-1", FONT_WEIGHT_BOOK, FONT_SLANT_ROMAN, FONT_SETWIDTH_NORMAL, FONT_SPACING_CHARCELL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE, 30, 0); hdc = GetClientDC (hWnd); SelectFont (hdc, timefont); GetTextExtent (hdc, "00:00:00", -1, &size); ReleaseDC (hdc); timeedit = CreateWindow (CTRL_SLEDIT, "00:00:00", WS_CHILD | WS_VISIBLE | ES_BASELINE, IDC_EDIT, 40, 220, size.cx + 4, size.cy + 4, hWnd, 0); SetWindowFont (timeedit, timefont); old_edit_proc = SetWindowCallbackProc (timeedit, TimeEditBox); spin = CreateWindow (CTRL_SPINBOX, "", WS_CHILD | WS_VISIBLE, IDC_SPINBOX, 40 + size.cx + 6, 220 + (size.cy - 14) / 2, 0, 0, hWnd, 0); SendMessage (spin, SPM_SETTARGET, 0, timeedit); break; } case MSG_DESTROY: DestroyAllControls (hWnd); DestroyLogFont (timefont); return 0; case MSG_CLOSE: DestroyMainWindow (hWnd); PostQuitMessage (hWnd); return 0; } return DefaultMainWinProc (hWnd, message, wParam, lParam);}int MiniGUIMain (int argc, const char* argv[]){ MSG Msg; HWND hMainWnd; MAINWINCREATE CreateInfo;#ifdef _MGRM_PROCESSES JoinLayer(NAME_DEF_LAYER , "timeeditor" , 0 , 0);#endif#ifdef _LITE_VERSION if (!InitVectorialFonts ()) { printf ("InitVectorialFonts: error.\n"); return 1; }#endif if (!InitMiniGUIExt()) { return 2; } CreateInfo.dwStyle = WS_CAPTION | WS_BORDER | WS_VISIBLE; CreateInfo.dwExStyle = WS_EX_IMECOMPOSE; CreateInfo.spCaption = "Time Editor"; CreateInfo.hMenu = 0; CreateInfo.hCursor = GetSystemCursor(0); CreateInfo.hIcon = 0; CreateInfo.MainWindowProc = TimeEditorWinProc; CreateInfo.lx = 0; CreateInfo.ty = 0; CreateInfo.rx = 240; CreateInfo.by = 320; CreateInfo.iBkColor = PIXEL_lightwhite; CreateInfo.dwAddData = 0; CreateInfo.hHosting = HWND_DESKTOP; hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return 3; ShowWindow(hMainWnd, SW_SHOWNORMAL); while (GetMessage(&Msg, hMainWnd)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } MainWindowThreadCleanup (hMainWnd); MiniGUIExtCleanUp ();#ifdef _LITE_VERSION TermVectorialFonts ();#endif return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -