嵌入式开发工具越来越强大,但目前还是比不上VC方便,至少需要下载,所以很多嵌入式开发工具都提供PC机上模拟的功能。
在console程序上实现lcd模拟也很简单,本文实现了对framebuffer的模拟,当然,因为简单,所以粗糙
#ifdef BS_LCD_SUPPORT
#define fb_w 320
#define fb_h 240
#define fb_s (fb_w*fb_h*2)
HDC g_hDC;
void * g_pFrameBuffer = NULL;
//thread to simulator LCD
DWORD SimLCD(void)
{
DWORD dwInfos[300]={0};
BITMAPINFOHEADER * pMapHeader = (BITMAPINFOHEADER *)dwInfos;
BYTE paaPixel[fb_s];
g_pFrameBuffer = paaPixel;
LibPrintf(" Virtual lcd begin at 0x%x ",g_pFrameBuffer);
pMapHeader -> biSize = sizeof(BITMAPINFOHEADER);
pMapHeader -> biWidth = fb_w;
pMapHeader -> biHeight = -fb_h; //top down
pMapHeader -> biPlanes = 1;
pMapHeader -> biBitCount = 16;
while(TRUE)
{
SetDIBitsToDevice(g_hDC, 320, 0, fb_w, fb_h, 0, 0, 0, fb_h, g_pFrameBuffer, (BITMAPINFO *)dwInfos, 0);
Sleep(300);
}
}
#endif
int main(int argc, char* argv[])
{
#ifdef BS_LCD_SUPPORT
HWND hWnd;
char arg[200]={0};
arg[0]='"';
strcpy(arg+1,argv[0]);
arg[strlen(arg)]='"';
hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
g_hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE )SimLCD,NULL,0,NULL);
Sleep(100);
#endif
//其他代码
#ifdef BS_LCD_SUPPORT
ReleaseDC( hWnd, g_hDC );
#endif
return 0;
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/116625/viewspace-931247/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/116625/viewspace-931247/