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

📄 miniguidemo.c

📁 s3c44b0上用的MINIGUI源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ** $Id: miniguidemo.c,v 1.7 2003/06/13 07:15:49 weiym Exp $**** Listing 2.1**** helloworld.c: Sample program for MiniGUI Programming Guide**      The first MiniGUI application.**** Copyright (C) 2003 Feynman Software.**** License: GPL*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <signal.h>#include <time.h>#include <sys/types.h>#include <sys/wait.h>#include <math.h>/* This isn't in the headers */#ifndef M_PI#define M_PI        3.14159265358979323846#endif#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include "miniguidemo.h"/////////////////////////////////////////////////////////////////Controls Liststatic int p_offset = 0;static int offset = 0;static int offset_v = 0;static RECT rcCircle = {0,0, 320, 240};static void prompt (HWND hDlg){    int i;    char files [1024] = "你选择要删除的文件是:\n";    for (i = 0; i < SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETCOUNT, 0, 0L); i++) {	char file [MAX_NAME + 1];        int status = SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETCHECKMARK, i, 0);        if (status == CMFLAG_CHECKED) {            SendDlgItemMessage (hDlg, IDL_DEMO2, LB_GETTEXT, i, (LPARAM)file);	    strcat (files, file);	    strcat (files, "\n");	}    }    MessageBox (hDlg, files, "确认删除", MB_OK | MB_ICONINFORMATION);}static int ListDemoFilesBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){    switch (message) {    case MSG_INITDIALOG:    {	char demo1 [20]= "Hello,demo1";	SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)demo1);	SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)"demo1 string1");	SendMessage (GetDlgItem (hDlg, IDL_DEMO1), LB_ADDSTRING,0,(LPARAM)"demo1 string2");	return 1;     }            case MSG_COMMAND:        switch (wParam) {        case IDOK:            prompt (hDlg);	break;        case IDCANCEL:            EndDialog (hDlg, wParam);            break;        }        break;            }        return DefaultDialogProc (hDlg, message, wParam, lParam);}/////////////////////////////////////////////////////////////////////////////static int ProgressBarProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){    int i, sum;#if 1    switch(message){    case MSG_INITDIALOG:	SendDlgItemMessage (hDlg, 100, PBM_SETRANGE, 50, 500);	return 1;    case MSG_KEYDOWN:	printf("Press  %d\n",wParam);	printf("p_offset  %d\n",p_offset);	switch(wParam) {	    case SCANCODE_CURSORBLOCKLEFT:/*    for (i = 0; i < 2000; i++) {        unsigned long j;                if (i % 100 == 0) {            SendDlgItemMessage (hDlg, 100, PBM_SETPOS, i, 0L);            while (HavePendingMessage (hDlg)) {                MSG msg;                GetMessage (&msg, hDlg);                DispatchMessage (&msg);            }        }        sum = i*5000;        for (j = 0; j < 500000; j++)            sum *= j;        sum += sum;    }*/		p_offset -= 10;		SendDlgItemMessage (hDlg, 100, PBM_SETPOS, p_offset, 0L);		break;	    case SCANCODE_CURSORBLOCKRIGHT:		p_offset += 10;		SendDlgItemMessage (hDlg, 100, PBM_SETPOS, p_offset, 0L);//		SendMessage (GetDlgItem (hDlg, IDC_PROGRESS1), PBM_SETSTEP,p_offset,(LPARAM)p_offset);//		SendMessage (hDlg, PBM_SETSTEP, p_offset, 0);		break;	}    case MSG_COMMAND:	switch (wParam) {	case IDOK:	case IDCANCEL:	    EndDialog (hDlg, wParam);	    break;	}	break;    }#endif    return DefaultDialogProc (hDlg, message, wParam, lParam);}/////////////////////////////////////////////////////////////static int InputCharDialogBoxProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){    static PLOGFONT my_font;    HWND hwnd;    switch (message) {    case MSG_INITDIALOG:        my_font = CreateLogFont (NULL, "Arial", "ISO8859-1",                         FONT_WEIGHT_REGULAR, FONT_SLANT_ROMAN, FONT_SETWIDTH_NORMAL,                        FONT_SPACING_CHARCELL, FONT_UNDERLINE_NONE, FONT_STRUCKOUT_NONE,                         30, 0);	hwnd = GetDlgItem (hDlg, IDC_CHAR);	SetWindowFont (hwnd, my_font);	SendMessage (hwnd, MSG_KEYDOWN, SCANCODE_INSERT, 0L);        return 1;            case MSG_COMMAND:        switch (wParam) {        case IDOK:        case IDCANCEL:	    DestroyLogFont (my_font);            EndDialog (hDlg, wParam);            break;        }        break;    }        return DefaultDialogProc (hDlg, message, wParam, lParam);}static int radius = 10;static void my_notif_proc (HWND hwnd, int id, int nc, DWORD add_data){    if (nc == TBN_CHANGE) {        radius = SendMessage (hwnd, TBM_GETPOS, 0, 0);        InvalidateRect (GetParent (hwnd), &rcCircle, TRUE);    }}static int TrackDemoProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    HWND hwnd;    switch (message) {    case MSG_CREATE:        hwnd = CreateWindow (CTRL_TRACKBAR,                           "",                           WS_VISIBLE | TBS_NOTIFY | TBS_TIP,                           100,                           10, 10, 280, 50, hWnd, 0);	//zhaoic	SetFocusChild (hwnd);        SendMessage (hwnd, TBM_SETRANGE, 0, 100);        SendMessage (hwnd, TBM_SETLINESIZE, 1, 0);        SendMessage (hwnd, TBM_SETPAGESIZE, 10, 0);        SendMessage (hwnd, TBM_SETTICKFREQ, 10, 0);        SendMessage (hwnd, TBM_SETPOS, radius, 0);        SetNotificationCallback (hwnd, my_notif_proc);        break;    case MSG_PAINT:    {        HDC hdc = BeginPaint (hWnd);        ClipRectIntersect (hdc, &rcCircle);        Circle (hdc, 140, 120, radius);        EndPaint (hWnd, hdc);        return 0;    }    case MSG_DESTROY:        DestroyAllControls (hWnd);        return 0;    case MSG_CLOSE:        DestroyMainWindow (hWnd);        PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}///gdidemo procstatic void TellSpeed (HWND hwnd, unsigned int start_tick, unsigned int end_tick, const char* drawing, unsigned int count){        char buff [1024];        unsigned int seconds = (end_tick - start_tick)/100;        sprintf (buff, "Draw %u %s(s) whthin %u seconds. \n\n"                        "Spend %f second for per-drawing.",                         count, drawing, seconds, (end_tick - start_tick) / (count * 100.0));        MessageBox (hwnd, buff, drawing, MB_OK | MB_ICONINFORMATION);}static void TellNotImplemented (HWND hwnd, const char* drawing){    char buff [1024];    sprintf (buff, "%s: not implemented. \n", drawing);    MessageBox (hwnd, buff, drawing, MB_OK | MB_ICONINFORMATION);}#define CHECK_MSG#define DEFAULT_WIDTH   320#define DEFAULT_HEIGHT  240#define DEFAULT_X       320#define DEFAULT_Y       240static void GDIDemo_NormalLines (HWND hwnd, HDC hdc){    int x = DEFAULT_X, y = DEFAULT_Y;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);    /* Line */    start_tick = GetTickCount ();    count = 30000;    SetPenColor (hdc, PIXEL_yellow);    while (count--) {        SetPenColor (hdc, rand() % nr_colors);        MoveTo (hdc, x, y);        LineTo (hdc, tox, toy);        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Line", 100000);    /* Circle */    start_tick = GetTickCount ();    count = 30000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetPenColor (hdc, rand() % nr_colors);        Circle (hdc, tox, toy, rand() % DEFAULT_X);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Circle", 10000);}static void GDIDemo_Filling (HWND hwnd, HDC hdc){    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);    /* Filled Box */    start_tick = GetTickCount ();    count = 30000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetBrushColor (hdc, rand() % nr_colors);        FillBox (hdc, tox, toy, rand() % DEFAULT_X, rand() % DEFAULT_Y);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Box", 500);    TellNotImplemented (hwnd, "Filled Circle");}static void GDIDemo_MemDC (HWND hwnd, HDC hdc){    HDC mem_dc;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);        /* Compatible DC */    mem_dc = CreateCompatibleDC (hdc);    SetBrushColor (mem_dc, 0);    FillBox (mem_dc, 0, 0, 65535, 65535);    start_tick = GetTickCount ();    count = 30000;    while (count--) {        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        MoveTo (mem_dc, tox, toy);        SetPenColor (mem_dc, rand() % nr_colors);        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        LineTo (mem_dc, tox, toy);        Circle (mem_dc, tox, toy, rand() % DEFAULT_X);        BitBlt (mem_dc, 0, 0, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, hdc,                         rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Blit", 200);    DeleteCompatibleDC (mem_dc);    TellNotImplemented (hwnd, "Alpha Blit");}int GDIDemoProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    unsigned int start_tick, end_tick;    HDC hdc;    switch (message) {        case MSG_CHAR:            srand (time (NULL));            hdc = GetClientDC (hWnd);            switch (wParam) {            case '0':                GDIDemo_NormalLines (hWnd, hdc);                break;            case '1':                GDIDemo_Filling (hWnd, hdc);                break;            case '2':                GDIDemo_MemDC (hWnd, hdc);                break;            case '3':                PostMessage (hWnd, MSG_CLOSE, 0, 0);                break;            }            ReleaseDC (hdc);            InvalidateRect (hWnd, NULL, TRUE);        break;        case MSG_PAINT:            hdc = BeginPaint (hWnd);            SetTextColor (hdc, PIXEL_black);            SetBkColor (hdc, PIXEL_lightwhite);            SetBkMode (hdc, BM_TRANSPARENT);            TabbedTextOut (hdc, 50, 20,                                  "Type '0': Drawing normal lines and curves.\n"                                 "Type '1': Drawing filled areas.\n"                                 "Type '2' Memory DC and blitting.\n"                                 "\nType '3' to quit.");            EndPaint (hWnd, hdc);            return 0;        case MSG_CLOSE:            DestroyMainWindow (hWnd);            PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}static int DrawDemoProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    HDC hdc;    switch (message) {        case MSG_PAINT:            hdc = BeginPaint (hWnd);	    SetBrushColor (hdc, PIXEL_red);	    FillCircle (hdc, 140+offset, 120+offset_v, 50);            EndPaint (hWnd, hdc);            return 0;        case MSG_CLOSE:            DestroyMainWindow (hWnd);            PostQuitMessage (hWnd);            return 0;	case MSG_KEYDOWN:	    printf("Press  %d\n",wParam);	    switch(wParam) {		case SCANCODE_CURSORBLOCKLEFT:		    offset -= 10;		    InvalidateRect (hWnd, &rcCircle, TRUE);		    break;		case SCANCODE_CURSORBLOCKRIGHT:		    offset += 10;		    InvalidateRect (hWnd, &rcCircle, TRUE);		    break;		case SCANCODE_CURSORBLOCKUP:		    offset_v -= 10;		    InvalidateRect (hWnd, &rcCircle, TRUE);		    break;		case SCANCODE_CURSORBLOCKDOWN:		    offset_v += 10;		    InvalidateRect (hWnd, &rcCircle, TRUE);		    break;

⌨️ 快捷键说明

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