⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeeditor.c

📁 ucos移植到arm_s3c2410的全套代码
💻 C
字号:
/* ** $Id: timeeditor.c,v 1.4 2003/11/23 13:09:22 weiym Exp $**** Listing 21.2**** timeeditor.c: Sample program for MiniGUI Programming Guide**      A time editor, use SpinBox and Edit controls.**** Copyright (C) 2003 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 tiem 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,                         60, 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,                         60 + 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 _LITE_VERSION    SetDesktopRect(0, 0, 1024, 768);    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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -