首頁>Club>
18
回覆列表
  • 1 # 小陳學不停

    用C語言編寫介面程式要用到以下幾種東西

    1. C語言的編輯器,例如Microsoft visual C++ 6.0

    2. UCGUI原始碼,包含各種窗體以及控制元件,直接在主函式呼叫就好了

    下面進行程式碼的編寫

    1. 引用系統圖形庫函式

    #include<windows.h>

    #include "io.h"

    #include "wingdi.h"

    複製以下程式碼到你的主函式中

    #define LCD_XSIZE 800

    #define LCD_YSIZE 480

    #define LENGTHOF(A) (sizeof(A)/sizeof(A[0]))#define FRAME_SIZE LCD_XSIZE*LCD_YSIZE

    uint16_t LCD_Frame[FRAME_SIZE];

    HDC hDC;// 獲取控制檯視窗控制代碼

    HWND GetConsoleHwnd(void)

    {

    #define MY_BUFSIZE 1024 // Buffer size for console window titles.

    HWND hwndFound;// This is what is returned to the caller.

    char pszNewWindowTitle[MY_BUFSIZE];

    // Contains fabricated

    char pszOldWindowTitle[MY_BUFSIZE];

    // Contains original GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE); wsprintf(pszNewWindowTitle,"%d/%d", GetTickCount(), GetCurrentProcessId()); SetConsoleTitle(pszNewWindowTitle); Sleep(40); hwndFound=FindWindow(NULL, pszNewWindowTitle); SetConsoleTitle(pszOldWindowTitle); return(hwndFound);

    }

    BITMAPINFOHEADER bmiHeader;

    void LCD_Init(){

    bmiHeader.biSize =sizeof(BITMAPINFOHEADER); bmiHeader.biWidth = LCD_XSIZE; bmiHeader.biHeight = -LCD_YSIZE; bmiHeader.biPlanes = 1; bmiHeader.biBitCount = 16; bmiHeader.biCompression = BI_RGB; bmiHeader.biSizeImage = 0; bmiHeader.biXPelsPerMeter = 0; bmiHeader.biYPelsPerMeter = 0; bmiHeader.biClrUsed = 0; bmiHeader.biClrImportant = 0; SetDIBitsToDevice (hDC, // hDC 0,0,LCD_XSIZE,LCD_YSIZE, 0,0,0,LCD_YSIZE, LCD_Frame,&bmiHeader,DIB_RGB_COLORS );// wUsage*/}

    void LCD_Repain(){/*StretchDIBits(bufferHDC, 0,0,0-m_nVideoW,0-m_nVideoH, 0,0,m_nVideoW, m_nVideoH, szFrame,&BmpInfo,DIB_RGB_COLORS,SRCCOPY); */ StretchDIBits(hDC, 0,0,LCD_XSIZE,LCD_YSIZE, 0,0,LCD_XSIZE,LCD_YSIZE, LCD_Frame,&bmiHeader,DIB_RGB_COLORS,SRCCOPY );

    }

    2. 移植UCGUI程式碼到你的工程裡,主要是修改畫點函式:

    #define FRAME_SIZE LCD_XSIZE*LCD_YSIZEextern uint16_t LCD_Frame[FRAME_SIZE];#define GETDATAPTR(xPhys,yPhys) (uint16_t*)((uint32_t)LCD_Frame + 2*(xPhys+yPhys*LCD_XSIZE))#define SETPIXEL _SetPixel#define XORPIXEL _XorPixel //{*(uint16_t)GETDATAPTR(xPhys,yPhys) = 0XFFFF - *(uint16_t*)GETDATAPTR(xPhys,yPhys);} //extern uint16_t *pFrameBuffer; static void _SetPixel(int x, int y, uint16_t Pixel){ *(uint16_t*)GETDATAPTR(x,y) = Pixel;// printf("_SetPixel\r\n");} uint16_t _GetPixel(int x, int y) {uint16_t Pixel; Pixel = *GETDATAPTR(x,y);

    return Pixel;

    }

    3. 在主函式中呼叫初始化,在迴圈中呼叫重新整理函式

    4. 執行函式後,會在控制檯顯示你定義的視窗畫面

  • 中秋節和大豐收的關聯?
  • 選購電視,高效能、大記憶體、真4K這些商家推銷的名詞是不是有必要?