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

📄 main.c

📁 rtCell 实时微内核-具有下列功能: 1. 完全抢占的实时微内核结构
💻 C
📖 第 1 页 / 共 2 页
字号:
//------------------------------必须包含的头文件------------------------------//
#include "giCell\Engine\Engine.h" 
#include "giCell\Engine\mcOutLib.h"
#include "giCell\Wins\include\Wins.h"
#include <graphics.h>
//---------------------------------------------------------------------------
void _cdecl_ puttextxy(int x, int y, const char far *textstring) /*此函数内核使用*/
{
    setfillstyle(1,4);
    bar(x-1, y-1, x+textwidth(textstring)+2,y+textheight(textstring)+2);
    setcolor(15);
    outtextxy(x, y%479, textstring);
}

static void SetTimer(WORD freq)
{
    WORD count; 

    count = (WORD)(((DWORD)2386360L / freq + 1) >> 1); 
    
    out_byte(0x43, 0x36);
    out_byte(0x40, count & 0xFF);
    out_byte(0x40, (count >> 8) & 0xFF);
} 
//---------------------------------------------------------------------------

#if !defined(WINDOW_H)
#include "giCell\Wins\include\Window.h"
#endif

#include "giCell\Wins\include\Control.h"
//---------------------------系列子控件事件回调函数---------------------------//

static WINDOW *pGWin;

static void _cdecl_ OnSliderMoveY(const int value, const int min, const int max)
{
    int winx = pGWin->pMainView->viewRect.left;
    MoveViewTo(pGWin->pMainView, winx, value);
}

static void _cdecl_ OnSliderMoveX(const int value, const int min, const int max)
{
    int winy = pGWin->pMainView->viewRect.top;
    MoveViewTo(pGWin->pMainView, value, winy);
}

static void _cdecl_ OnCheckTrans(const CBOOL checked)
{
    SetWindowTrans(pGWin, checked);
} 

static void _cdecl_ OnCheckVisible(const CBOOL checked)
{
    SetWindowVisible(pGWin, checked);
}

static void _cdecl_ OnCheckOnTop(const CBOOL checked)
{
    SetWindowStayOnTop(pGWin, checked);
}

//------------------------------必须包含的头文件------------------------------//
#include "giCell\Wins\include\Label.h"
#include "giCell\Wins\include\Edit.h"
#include "giCell\Wins\include\Slider.h"
#include "giCell\Wins\include\Checkbox.h"
#include "giCell\Wins\include\Botton.h"
#include "giCell\Wins\include\Listbox.h"
//---------------------------------------------------------------------------
#include <stdlib.h>
#include "DateTime.c"
//---------------------------------------------------------------------------


static EDIT *pListEdit = NULL;
static LISTBOX *pList = NULL;

void _cdecl_ keybdHook(const KEY_INF ki)
{
    if (ki.inf.key) {
        if ((ki.inf.key == KEY_ESCAPE) && ki.inf.shift)
            exit (0);
    }
} 
//---------------------------系列子控件事件回调函数---------------------------//
static void _cdecl_ listAddbtn(int x, int y, MOUSE_INF mi)
{
    ListboxInsertCurrent(pList, (BYTE *)GetEditText(pListEdit));
}

static void _cdecl_ listDelbtn(int x, int y, MOUSE_INF mi)
{
    ListboxDelete(pList, pList->ItemSel);
}

static void _cdecl_ treeAddbtn(int x, int y, MOUSE_INF mi)
{
    //TREEITEM *pitem = CreateTreeItem((BYTE *)GetEditText(pListEdit), NULL);
    //InsertTreeItemAtCurrent(pTree, pitem);
}

static void _cdecl_ treeAppbtn(int x, int y, MOUSE_INF mi)
{
    //TREEITEM *pitem = CreateTreeItem((BYTE *)GetEditText(pListEdit), NULL);
    //AppendTreeItem(pTree, pTree->ItemSel, pitem);
}

static void _cdecl_ treeDelbtn(int x, int y, MOUSE_INF mi)
{
    //if (pTree->ItemSel)
        //DeleteTreeItem(pTree, pTree->ItemSel);
}

static void _cdecl_ CreateWinbtn(int x, int y, MOUSE_INF mi)
{
    WINDOW *pLWin = CreateWindow(10, 10, 500, 300, NULL,
				     "main window 2", (PCREATE)NULL, WIN_RESIZE|WIN_3D_CLIENT|WIN_MAX_BTN|WIN_MIN_BTN);
    if (pLWin == NULL) return;
    CreateCheckbox(50, 50, 160, 30, pLWin->pClientView,
				     "Set Win 5 Trans", OnCheckTrans, CTRL_ALIGN_VCENTER);
    CreateCheckbox(50, 80, 160, 30, pLWin->pClientView,
				     "Set Win 5 Visible", OnCheckVisible, CTRL_ALIGN_VCENTER);
    CreateCheckbox(50, 110, 160, 30, pLWin->pClientView,
				     "Set Win 5 Stay on top", OnCheckOnTop, CTRL_ALIGN_VCENTER);
}
//---------------------------下面通过GDC来重绘窗口----------------------------//
/* for clock */
static GDC *pGdc;
static int cx, cy;
static double theta, min, hour;
/* for 3D cube */
static double rho, phi, d,s1, s2, c1, c2, ox, oy, oz;
static int cx, cy;
static int xr, yr;
static int fromX, fromY;

#include <math.h>

static void to2D(double x, double y, double z)
{
    double xe, ye, ze;

    x += ox; y += oy; z += oz;
    xe = -x*s1 + y*c1;
    ye = -x*c1*c2 - y*s1*c2 +  z*s2;
    ze = -x*s2*c1 - y*s2*s1 - z*c2 + rho;
    xr = (int)(d*xe/ze) + cx;
    yr = cy - (int)(d*ye/ze);
}

static void from3D(double x, double y, double z)
{
    to2D(x, y, z);
    fromX = xr;
    fromY = yr;
}

static void Lineto3D(double x, double y, double z, COLOR clr)
{
    to2D(x, y, z);
    DrawGDCLine(pGdc, xr, yr, fromX, fromY, clr);
    fromX = xr; fromY = yr;
}

static void draw3D(RECT *pR)
{
    RECT r = (*pR);
    int x0,y0;
    double pi = 3.1415926;
    double adegree = pi/30;

    theta += adegree;
    phi += adegree;

    if (theta > (2*pi)) {
        theta -= (2*pi);
        phi -= (2*pi);
    } 

    if (pGdc != NULL) {
        BYTE *pbuf = pGdc->pMem;

        for (y0 = 0; y0 < 120; y0++) {
            for (x0 = 0; x0 < pGdc->BytesPerLine; x0++) {
                (*pbuf) = 0;
                pbuf ++;
            }
        }

        cx = (r.right-r.left) / 2;
        cy = (r.bottom-r.top) / 2;
        
        d = cx * 6;
        s1 = sin(theta);
        c1 = cos(theta);
        s2 = sin(phi);
        c2 = cos(phi);

        from3D(0, 0, 0);
        Lineto3D(1, 0, 0, GD_GREEN);
        Lineto3D(1, 1, 0, GD_GREEN);
        Lineto3D(0, 1, 0, GD_GREEN);
        Lineto3D(0, 0, 0, GD_GREEN);
        from3D(0, 0, 1);
        Lineto3D(1, 0, 1, GD_GREEN);
        Lineto3D(1, 1, 1, GD_GREEN);
        Lineto3D(0, 1, 1, GD_GREEN);
        Lineto3D(0, 0, 1, GD_GREEN);

        from3D(1, 0, 0);
        Lineto3D(1, 0, 1, GD_GREEN);
        from3D(1, 1, 0);
        Lineto3D(1, 1, 1, GD_GREEN);
        from3D(0, 1, 0);
        Lineto3D(0, 1, 1, GD_GREEN);
        from3D(0, 0, 0);
        Lineto3D(0, 0, 1, GD_GREEN);

        from3D(0.3, 0.3, 0);
        Lineto3D(0.7, 0.7, 0, GD_LIGHTRED);
        from3D(0.7, 0.3, 0);
        Lineto3D(0.3, 0.7, 0, GD_LIGHTRED);
    }
} 

static void drawClock(RECT *pR)
{
    RECT r = (*pR);
    int x0,y0;
    double t, m, h, pi = 3.1415926;
    rt_time_t cur_time;
    
    time_read(&cur_time);
    theta = (double)(cur_time.Sec);
    t = theta/30.0*pi;
    min = (double)(cur_time.Min);
    m = (min+theta/60.0)/30.0*pi;
    if (m > 2.0*pi) m -= 2.0*pi;
    hour = (double)(cur_time.Hour);
    h = (hour+min/60.0)/6.0*pi;
    if (h > 2.0*pi) h -= 2.0*pi;

    t -= pi/2.0; m -= pi/2.0; h -= pi/2.0;

    if (pGdc != NULL) {
        BYTE *pbuf = pGdc->pMem;
        for (y0 = 0; y0 < 120; y0++) {
            for (x0 = 0; x0 < pGdc->BytesPerLine; x0++) {
                (*pbuf) = 0;
                pbuf ++;
            }
        }

        cx = (r.right-r.left) / 2;
        cy = (r.bottom-r.top) / 2;

        for (x0 = 0; x0 < 60; x0++) {
            double a = ((double)x0)/30.0*pi;
            if ((x0 % 5) == 0) {
                DrawGDCLine(pGdc, cx+(int)(41*cos(a)),
                                  cy+(int)(41*sin(a)),
                                  cx+(int)(45*cos(a)),
                                  cy+(int)(45*sin(a)), GD_LIGHTRED);
            } else {
                DrawGDCLine(pGdc, cx+(int)(44*cos(a)),
                                  cy+(int)(44*sin(a)),
                                  cx+(int)(45*cos(a)),
                                  cy+(int)(45*sin(a)), GD_WHITE);
            }
        }
        
        DrawGDCText(pGdc, 0, 0, "Clock", GD_GREEN);

        DrawGDCLine(pGdc, cx, cy,
                    cx+(int)(39*cos(t)), cy+(int)(39*sin(t)), GD_CYAN);
        DrawGDCLine(pGdc, cx, cy,
                    cx+(int)(30*cos(m)), cy+(int)(30*sin(m)), GD_YELLOW);
        DrawGDCLine(pGdc, cx, cy,
                    cx+(int)(20*cos(h)), cy+(int)(20*sin(h)), GD_LIGHTRED);    
        
        DrawGDCHLine(pGdc, cy-1, cx-1, cx+1, GD_LIGHTBLUE);
        DrawGDCHLine(pGdc, cy  , cx-1, cx+1, GD_LIGHTBLUE);
        DrawGDCHLine(pGdc, cy+1, cx-1, cx+1, GD_LIGHTBLUE);  
    }
}

static VIEW *pGDCView = NULL;
static CBOOL _cdecl_ GDCViewMSG(VMSG *pMsg)
{
    VIEW *pView = pMsg->pView ;
    POINT pt;

    switch (pMsg->MsgID) {
    case VMSG_PAINT:
        pt.x=pView->viewRect.left;
        pt.y=pView->viewRect.top;

        GDCToScreen(pGdc, &pt, &(pView->viewRect));
        return (true);
    case MSM_MS_ENTER:
        SetMouseCursor(ARROW);
        return (true);
    }

    return (true);
}

⌨️ 快捷键说明

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