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

📄 header.c

📁 MDE 图形引擎
💻 C
字号:
//// Written by You Huayun.// 2000/2/26//#include <stdio.h>#include <stdlib.h>#include <dirent.h>#include <time.h>#include <string.h>#include <sys/time.h>#include <pthread.h>#include <semaphore.h>#include <unistd.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/vcongui.h>#include "vacs.h"#include "gui.h"#include "header.h"#include "footer.h"#include "splash.h"#define NUM_HEADER_CELLS        4#define INDEX_TIME_CELL         3#define TEXT_CELL1              "文件"#define TEXT_CELL2              "循环"#define TEXT_CELL3              "行号"#define TEXT_CELL4              "时间"/************************** Global Variables  *******************************/static HWND sg_hHeaderWin = HWND_INVALID;static char* Xinqi [] = {    "日",    "一",    "二",    "三",    "四",    "五",    "六",};/****************************** Interfaces ***********************************/int InitHeader (HWND hSplash){    SetSplashInfo (hSplash, "Init header ...");     SetSplashInfo (hSplash, "Init header OK.");    return VACS_OK;}void HeaderCleanUp (void){    // do nothing.}void SetHeadInfo (int id, int fc, int bc, char* szText, BOOL fUpdate){    RECT rcInv;    struct HeadInfo *cells;        if (sg_hHeaderWin == HWND_INVALID)        return;    cells = (struct HeadInfo*)GetWindowAdditionalData (sg_hHeaderWin);    if (cells == NULL)        return;    if (id >= NUM_HEADER_CELLS || id < 0)        return;    cells [id].fc = fc;    cells [id].bc = bc;    strncpy (cells [id].szText, szText, LEN_HEADER_CELL_TEXT);        memcpy (&rcInv, cells + id, sizeof (RECT));    InvalidateRect (sg_hHeaderWin, &rcInv, FALSE);    if (fUpdate)        PostMessage (sg_hHeaderWin, MSG_PAINT, 0, 0L);}/****************************** Window Handling ******************************/static int HeaderWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam);static void InitCreateInfo(PMAINWINCREATE pCreateInfo){    char path_name [PATH_MAX +1 ];        pCreateInfo->dwStyle = WS_BORDER | WS_CAPTION | WS_THINFRAME;    pCreateInfo->dwExStyle = WS_EX_NONE | WS_EX_IMECOMPOSE;    pCreateInfo->spCaption = "VACSIII 型虚拟轴机床数控系统";    pCreateInfo->hMenu = 0;    pCreateInfo->hCursor = GetSystemCursor(0);    pCreateInfo->hIcon = LoadIconFromFile (HDC_SCREEN,                GetAbsolutePathName ("res/mill.ico", path_name), 2);    pCreateInfo->MainWindowProc = HeaderWinProc;    pCreateInfo->lx = 0;     pCreateInfo->ty = 0;    pCreateInfo->rx = GetGDCapability (HDC_SCREEN, GDCAP_MAXX) + 1;    pCreateInfo->by = 45;    pCreateInfo->iBkColor = COLOR_blue;     pCreateInfo->dwAddData = 0;    pCreateInfo->hHosting = HWND_DESKTOP;}static void DrawTextFrame (HDC hdc, struct HeadInfo* info){    SetPenColor (hdc, COLOR_lightgray);    Rectangle (hdc, info->l, info->t, info->r, info->b);    SetBrushColor (hdc, info->bc);    FillBox (hdc, info->l + 1, info->t + 1,                   info->r - info->l - 1, info->b - info->t - 1);     SetBkColor (hdc, info->bc);    SetTextColor (hdc, info->fc);    TextOut (hdc, info->l + 2, info->t + 2, info->szText);}static int HeaderWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    int i;    static struct HeadInfo cells [NUM_HEADER_CELLS] = {            {40,  0, 200, 20},            {240, 0, 320, 20},            {360, 0, 505, 20},            {545, 0, 800, 20}    };    switch (message) {    case MSG_CREATE:        // Init HeaderInfo structs.        for (i = 0; i < NUM_HEADER_CELLS; i++) {            strcpy (cells [i].szText, "  无");            cells [i].fc = COLOR_cyan;            cells [i].bc = COLOR_blue;        }        SetTimer (hWnd, ID_HEADER_TIMER, 100);        SetWindowAdditionalData (hWnd, (DWORD)cells);        break;    case MSG_LBUTTONDOWN:            break;    case MSG_RBUTTONDOWN:        break;    case MSG_NCLBUTTONDOWN:    case MSG_NCLBUTTONUP:{        if (wParam == HT_CAPTION)            return 0;        else            break;    }	case MSG_PAINT:    {        HDC hdc;        RECT rcClient;        struct HeadInfo title;                    GetClientRect (hWnd, &rcClient);        hdc = BeginPaint (hWnd);        title.fc = COLOR_cyan; title.bc = COLOR_blue;        title.l = 0; title.t = 0; title.r = 40; title.b = HEIGHT_HEADER_CELL;        if (RectVisible (hdc, (RECT*)(&title))) {            strcpy (title.szText, TEXT_CELL1);            DrawTextFrame (hdc, &title);         }        title.l = 200; title.t = 0; title.r = 240; title.b = HEIGHT_HEADER_CELL;        if (RectVisible (hdc, (RECT*)(&title))) {            strcpy (title.szText, TEXT_CELL2);            DrawTextFrame (hdc, &title);         }        title.l = 320; title.t = 0; title.r = 360; title.b = HEIGHT_HEADER_CELL;        if (RectVisible (hdc, (RECT*)(&title))) {            strcpy (title.szText, TEXT_CELL3);            DrawTextFrame (hdc, &title);         }        title.l = 505; title.t = 0; title.r = 545; title.b = HEIGHT_HEADER_CELL;        if (RectVisible (hdc, (RECT*)(&title))) {            strcpy (title.szText, TEXT_CELL4);            DrawTextFrame (hdc, &title);         }        for (i = 0; i < NUM_HEADER_CELLS; i++) {            if (RectVisible (hdc, (RECT*)(cells + i)))                DrawTextFrame (hdc, cells + i);        }        EndPaint (hWnd, hdc);        break;    }    case MSG_TIMER:         if (wParam == ID_HEADER_TIMER) {            time_t t;            struct tm* tm;                        time (&t);            tm = localtime (&t);            sprintf (cells[INDEX_TIME_CELL].szText,                 "%d年%02d月%02d日 %02d:%02d:%02d 星期%s",                 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,                 tm->tm_hour, tm->tm_min, tm->tm_sec,                 Xinqi[tm->tm_wday]);            InvalidateRect (hWnd, (RECT*)(cells + INDEX_TIME_CELL), FALSE);         }         break;    case MSG_CLOSE:        KillTimer (hWnd, ID_HEADER_TIMER);        DestroyMainWindow (hWnd);        PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}void* Header(void* data){    MSG Msg;    MAINWINCREATE CreateInfo;    int col_widths [5];    InitCreateInfo(&CreateInfo);    sg_hHeaderWin = CreateMainWindow(&CreateInfo);    if (sg_hHeaderWin == HWND_INVALID)        return NULL;    ShowWindow(sg_hHeaderWin, SW_SHOWNORMAL);    SetHeadInfo (0, COLOR_cyan, COLOR_blue, "Mill.pmc", 1);    SetHeadInfo (1, COLOR_cyan, COLOR_blue, "100/100", 1);    SetHeadInfo (2, COLOR_cyan, COLOR_blue, "10000/10000", 1);    SetHeadInfo (3, COLOR_cyan, COLOR_blue, "", 1);    CreateFooter (sg_hHeaderWin);    col_widths [0] = 200;    col_widths [1] = 300;    col_widths [2] = 300;    SetFooterRowInfo (0, 3, col_widths, FALSE);    SetFooterCellInfo (0, 0, COLOR_lightwhite, COLOR_blue, "FEED", FALSE);    SetFooterCellInfo (0, 1, COLOR_black, COLOR_darkgray,  "CELL1", FALSE);    SetFooterCellInfo (0, 2, COLOR_black, COLOR_darkgray,  "CELL2", FALSE);//    SetFooterCellStyle (0, 0, CS_INVERT, FALSE);    SetFooterCellStyle (0, 1, CS_INVERT, FALSE);        // Change the width of the cells in the second row.    col_widths [0] = 800;    SetFooterRowInfo (1, 1, col_widths, FALSE);    SetFooterCellInfo (1, 0, COLOR_red, COLOR_yellow, "", TRUE);    while( GetMessage(&Msg, sg_hHeaderWin) ) {        DispatchMessage(&Msg);    }    MainWindowThreadCleanup (sg_hHeaderWin);    return NULL;}void CloseHeaderFooter (void){    SendMessage (sg_hHeaderWin, MSG_CLOSE, 0, 0L);}

⌨️ 快捷键说明

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