//bmp.cppconst unsigned char* gImage_bmp=Image_bmp;//////////////////////////////////////ReadBmpArray.cpp#include <windows.h> #include <stdio.h>#include <stdlib.h>#include <math.h> extern HWND g_hwnd; // generic window handleextern HDC g_hdc; // graphics device context /*void LCD_Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[]){int x,y;unsigned int c;int p = 0;for( y = y0 ; y < l ; y++ ){for( x = x0 ; x < h ; x++ ){//RGB888c = (bmp[p]) | (bmp[p+1]<<8) | bmp[p+2]<<16;if ( ( (x0+x) < LCD_XSIZE) && ( (y0+y) <LCD_YSIZE) )LCD_BUFFER[y0+y][x0+x] = c ;p = p+3; }}}*//* int index; for (index=0; index < 100; index++) { int x = rand()%400;int y = rand()%300;COLORREF color = RGB(rand()%255,rand()%255,rand()%255);SetPixel(hdc, x,y, color); } ReleaseDC(hwnd, hdc);*/void LCD_Paint_Bmp(int x0,int y0,int h,int l,const unsigned char bmp[]){int x,y;//unsigned int c;int p = 0;for( y = y0 ; y < l ; y++ ){for( x = x0 ; x < h ; x++ ){//RGB888//c = (bmp[p]) | (bmp[p+1]<<8) | bmp[p+2]<<16;//if ( ( (x0+x) < LCD_XSIZE) && ( (y0+y) <LCD_YSIZE) )//LCD_BUFFER[y0+y][x0+x] = c ;//COLORREF color = RGB(bmp[p],bmp[p+1],bmp[p+2]);COLORREF color = RGB(bmp[p+2],bmp[p+1],bmp[p]);SetPixel(g_hdc, x,y, color);p = p+3; }} ReleaseDC(g_hwnd, g_hdc);}////////////////////////////////////SetPixel.cpp/*file:SetPixel.cillustrate the usage of SetPixel() compile: gcc SetPixel.c -lgdi32 -luser32*/#include <windows.h> #include <stdio.h>#include <stdlib.h>#include <math.h> #define WINDOW_CLASS_NAME "WINCLASS1"#define WINDOW_WIDTH 400#define WINDOW_HEIGHT 300#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEYUP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)HWND main_window_handle = NULL; // globally track main windowHINSTANCE hinstance_app = NULL; // globally track hinstanceHWND g_hwnd; // generic window handleHDC g_hdc; // graphics device context /////////////////////////////////////////////////extern const unsigned char gImage_bmp[];//391680extern const unsigned char* gImage_bmp;void LCD_Paint_Bmp(int x0,int y0,int h,int l,const unsigned char bmp[]);///////////////////////////////////////////////int main(){WinMain(GetModuleHandle(0),NULL,NULL,0);return 0;} LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ PAINTSTRUCT ps; // used in WM_PAINTHDC &hdc=g_hdc; // handle to a device contextswitch(msg){ case WM_CREATE: { // do initialization stuff here} break;case WM_PAINT: { // simply validate the window //hdc = BeginPaint(hwnd,&ps); printf("WM_PAINT\n");hdc = GetDC(hwnd); RECT rc;SetRect(&rc,0,0, WINDOW_WIDTH, WINDOW_HEIGHT);FillRect(hdc,&rc,(HBRUSH)GetStockObject(BLACK_BRUSH));//清屏LCD_Paint_Bmp(0, 0, 480, 272, gImage_bmp); // end painting//EndPaint(hwnd,&ps);} break; case WM_DESTROY: { PostQuitMessage(0);} break; default:break;} // end switch return (DefWindowProc(hwnd, msg, wparam, lparam));} // end WinProc int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline,int ncmdshow){WNDCLASSEX winclass; // this will hold the class we createMSG msg; // generic messageHWND & hwnd= g_hwnd; // generic window handleHDC & hdc= g_hdc; // graphics device context winclass.cbSize = sizeof(WNDCLASSEX);winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;winclass.lpfnWndProc = WindowProc;winclass.cbClsExtra = 0;winclass.cbWndExtra = 0;winclass.hInstance = hinstance;winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);winclass.lpszMenuName = NULL;winclass.lpszClassName = WINDOW_CLASS_NAME;winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);// save hinstance in globalhinstance_app = hinstance;// register the window classif (!RegisterClassEx(&winclass))return (0);// create the windowif (!(hwnd = CreateWindowEx(0, // extended styleWINDOW_CLASS_NAME, // class"Pixel Plotting Demo", // titleWS_OVERLAPPEDWINDOW | WS_VISIBLE,0,0, // initial x,yWINDOW_WIDTH, // initial widthWINDOW_HEIGHT,// initial height0, // handle to parent 0, // handle to menuhinstance,// instance of this application0))) // extra creation parmsreturn (0); // save main window handlemain_window_handle = hwnd;// enter main event loop, but this time we use PeekMessage()// instead of GetMessage() to retrieve messages//while(TRUE)while(GetMessage(&msg,NULL,0,0)){//Sleep(200);// test if there is a message in queue, if so get it//if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)){ if (msg.message == WM_QUIT)break; TranslateMessage(&msg);DispatchMessage(&msg);} /* hdc = GetDC(hwnd); RECT rc;SetRect(&rc,0,0, WINDOW_WIDTH, WINDOW_HEIGHT);FillRect(hdc,&rc,(HBRUSH)GetStockObject(BLACK_BRUSH));//清屏 int index; for (index=0; index < 100; index++) { int x = rand()%400;int y = rand()%300;COLORREF color = RGB(rand()%255,rand()%255,rand()%255);SetPixel(hdc, x,y, color); } ReleaseDC(hwnd, hdc);*///LCD_Paint_Bmp(0, 0, 480, 272, gImage_bmp); if (KEYDOWN(VK_ESCAPE))SendMessage(hwnd, WM_CLOSE, 0,0);//发送一个退出消息 } // end while return (msg.wParam);} // end WinMain