00001 #include "monitor-win.h"
00002 static LRESULT CALLBACK windowProc(HWND hwnd,
00003 UINT uMsg,
00004 WPARAM wParam,
00005 LPARAM lParam
00006 )
00007 {
00008 return DefWindowProc(hwnd, uMsg, wParam, lParam);
00009 }
00010 Monitor::Monitor(int w, int h, const char * title)
00011 {
00012 this->w = w;
00013 this->h = h;
00014 WNDCLASS wc;
00015 wc.style = CS_OWNDC | CS_NOCLOSE;
00016 wc.lpfnWndProc = &windowProc;
00017 wc.cbClsExtra = 0;
00018 wc.cbWndExtra = 0;
00019 wc.hInstance = NULL;
00020 wc.hIcon = NULL;
00021 wc.hCursor = NULL;
00022 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
00023 wc.lpszMenuName = NULL;
00024 wc.lpszClassName = "Monitor";
00025 RegisterClass(&wc);
00026 window = CreateWindow("Monitor",title, WS_OVERLAPPED | WS_VISIBLE,
00027 CW_USEDEFAULT, CW_USEDEFAULT, w, h+40, NULL, NULL, NULL, NULL);
00028
00029
00030
00031
00032 }
00033
00034 int Monitor::setImage(unsigned char * tdata, int size)
00035 {
00036
00037 MSG msg;
00038 while (PeekMessage(&msg, window, 0, 0, PM_REMOVE))
00039 DispatchMessage(&msg);
00040 BITMAPINFO bmi;
00041 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
00042 bmi.bmiHeader.biWidth = w;
00043 bmi.bmiHeader.biHeight = -h;
00044 bmi.bmiHeader.biPlanes = 1;
00045 bmi.bmiHeader.biBitCount = 24;
00046 bmi.bmiHeader.biCompression = BI_RGB;
00047 bmi.bmiHeader.biSizeImage = 0;
00048 SetDIBitsToDevice(GetDC(window), 0, 0, w, h, 0, 0, 0, h, tdata, &bmi, DIB_RGB_COLORS);
00049 return 0;
00050 }