用C語言編寫界面程序要用到以下幾種東西
1.C語言的編輯器,例如MicrosoftvisualC++6.0
2.UCGUI源碼,包含各種窗體以及控件,直接在主函數(shù)調(diào)用就好了
下面進(jìn)行代碼的編寫
1.引用系統(tǒng)圖形庫函數(shù)
#include<windows.h>
#include"io.h"
#include"wingdi.h"
復(fù)制以下代碼到你的主函數(shù)中
#defineLCD_XSIZE800
#defineLCD_YSIZE480
#defineLENGTHOF(A)(sizeof(A)/sizeof(A[0]))#defineFRAME_SIZELCD_XSIZE*LCD_YSIZE
uint16_tLCD_Frame[FRAME_SIZE];
HDChDC;//獲取控制臺窗口句柄
HWNDGetConsoleHwnd(void)
{
#defineMY_BUFSIZE1024//Buffersizeforconsolewindowtitles.
HWNDhwndFound;//Thisiswhatisreturnedtothecaller.
charpszNewWindowTitle[MY_BUFSIZE];
//Containsfabricated
charpszOldWindowTitle[MY_BUFSIZE];
//ContainsoriginalGetConsoleTitle(pszOldWindowTitle,MY_BUFSIZE);wsprintf(pszNewWindowTitle,"%d/%d",GetTickCount(),GetCurrentProcessId());SetConsoleTitle(pszNewWindowTitle);Sleep(40);hwndFound=FindWindow(NULL,pszNewWindowTitle);SetConsoleTitle(pszOldWindowTitle);return(hwndFound);
}
BITMAPINFOHEADERbmiHeader;
voidLCD_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,//hDC0,0,LCD_XSIZE,LCD_YSIZE,0,0,0,LCD_YSIZE,LCD_Frame,&bmiHeader,DIB_RGB_COLORS);//wUsage*/}
voidLCD_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代碼到你的工程里,主要是修改畫點(diǎn)函數(shù):
#defineFRAME_SIZELCD_XSIZE*LCD_YSIZEexternuint16_tLCD_Frame[FRAME_SIZE];#defineGETDATAPTR(xPhys,yPhys)(uint16_t*)((uint32_t)LCD_Frame+2*(xPhys+yPhys*LCD_XSIZE))#defineSETPIXEL_SetPixel#defineXORPIXEL_XorPixel//{*(uint16_t)GETDATAPTR(xPhys,yPhys)=0XFFFF-*(uint16_t*)GETDATAPTR(xPhys,yPhys);}//externuint16_t*pFrameBuffer;staticvoid_SetPixel(intx,inty,uint16_tPixel){*(uint16_t*)GETDATAPTR(x,y)=Pixel;//printf("_SetPixel\r\n");}uint16_t_GetPixel(intx,inty){uint16_tPixel;Pixel=*GETDATAPTR(x,y);
returnPixel;
}
3.在主函數(shù)中調(diào)用初始化,在循環(huán)中調(diào)用刷新函數(shù)
4.執(zhí)行函數(shù)后,會在控制臺顯示你定義的窗口畫面