c语言如何编写界面程序

c语言如何编写界面程序

首页维修大全综合更新时间:2023-06-25 00:43:10

c语言如何编写界面程序

用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 ");} uint16_t _GetPixel(int x, int y) {uint16_t Pixel; Pixel = *GETDATAPTR(x,y);

return Pixel;

}

3. 在主函数中调用初始化,在循环中调用刷新函数

4. 执行函数后,会在控制台显示你定义的窗口画面

大家还看了
也许喜欢
更多栏目

© 2021 3dmxku.com,All Rights Reserved.