www.pudn.com > microwindows.example10.rar > demomwpic.c
/***************************************************************** ****Win32 API demos:bmp,gif,jpg picture support in Microwindows ****by zhang kaohua 2004,2,23 *****************************************************************/ #include "windows.h" #include "wintern.h" #include "device.h" //#include "wintools.h" //#include//#include //#include //extern MWINMAGHDR img; extern MWIMAGEHDR image_car8; extern MWIMAGEHDR image_penguin; extern MWIMAGEHDR image_microwin; #define APPCLASS "test" LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wp, LPARAM lp); //LRESULT CALLBACK WndbtProc(HWND bt, UINT bMsg, WPARAM wp, LPARAM lp); int RegisterAppClass(void) { WNDCLASS wc; wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = 0; /*LoadIcon(GetHInstance(), MAKEINTRESOURCE( 1));*/ wc.hCursor = 0; /*LoadCursor(NULL, IDC_ARROW);*/ wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = APPCLASS; RegisterClass( &wc); return 1; } HWND CreateAppWindow(void) { HWND hwnd; int width, height; RECT r; static int nextid = 0; GetWindowRect(GetDesktopWindow(), &r); //width = height = r.right / 2; width=300; height=210; hwnd = CreateWindowEx(WS_EX_LAYERED, APPCLASS, "Microwindows Win32 API picture demo", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, width, height, NULL, (HMENU)++nextid, NULL, NULL); return hwnd; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { PAINTSTRUCT ps; HWND sibwp; HDC hdcMem,hdc; HBITMAP hbmp, hbmpOrg; HBRUSH hbr; RECT rc; //kh HGDIOBJ oldfont; HDC mydc; //HBITMAP hpic; extern int mwpaintSerial; switch(msg) { case WM_ERASEBKGND: /* don't erase with screen dc, must alpha blend bkgnd*/ return 1; case WM_PAINT: mwforceNCpaint = TRUE; /* repaint lower windows before alpha blending this window*/ ++hwnd->unmapcount; /* tricky don't clip this window*/ SendMessage(rootwp, WM_PAINT, 0, 0); for(sibwp=hwnd->siblings; sibwp; sibwp=sibwp->siblings) SendMessage(sibwp, WM_PAINT, 0, 0); --hwnd->unmapcount; /* then queue repaint for higher windows*/ for(sibwp=hwnd->parent->children; sibwp != hwnd; sibwp=sibwp->siblings) /* don't paint if already painted by above code*/ if(sibwp->paintSerial != mwpaintSerial) PostMessage(sibwp, WM_PAINT, 0, 0); /* now paint this window offscreen and blend with screen*/ hdc=BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rc); /* redirect painting to offscreen dc*/ hdcMem = CreateCompatibleDC(ps.hdc); hbmp = CreateCompatibleBitmap(hdcMem, rc.right, rc.bottom); hbmpOrg = SelectObject(hdcMem, hbmp); /* paint window to offscreen*/ hbr = (HBRUSH)GetClassLong(hwnd, GCL_HBRBACKGROUND); FillRect(hdcMem, &rc, hbr); /*SelectObject(hdcMem, GetStockObject(DEFAULT_GUI_FONT)); SetBkMode(hdcMem, TRANSPARENT); #define TEXTSTRING "This demonstrates alpha blending" TextOut(hdcMem, 20, 20, TEXTSTRING, strlen(TEXTSTRING)); */ //kh oldfont=SelectObject(hdcMem,CreateFont(16, 0,0,0,0,0,0,0,0,0,0,0, FF_DONTCARE|DEFAULT_PITCH, "HZKFONT")); TextOut(hdcMem,5,10,"Alpha混和演示: ",-1); SetBkColor(hdcMem,0x00ff00); SetTextColor (hdcMem,0xff00ff); TextOut(hdcMem, 60, 120, "我是透明的窗口,发现了吗?", -1); /* alpha blend blit offscreen map with physical screen*/ BitBlt(ps.hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, MWROP_BLENDCONSTANT | 150); MwRegisterButtonControl(NULL); CreateWindowEx(0L, "BUTTON", "CAR", WS_CHILD | WS_VISIBLE, 20, 160, 50, 20, hwnd, (HMENU)1, NULL, NULL); CreateWindowEx(0L, "BUTTON", "PENGUIN", WS_CHILD | WS_VISIBLE, 125, 160, 50, 20, hwnd, (HMENU)2, NULL, NULL); //SendMessage(bt, MW_LBUTTONDOWN, 0, 0); CreateWindowEx(0L, "BUTTON", "CLEAR", WS_CHILD | WS_VISIBLE, 230, 160, 50, 20, hwnd, (HMENU)3, NULL, NULL); DeleteObject(SelectObject(hdcMem, hbmpOrg)); DeleteObject(SelectObject(hdc,oldfont)); DeleteDC(hdcMem); EndPaint(hwnd, &ps); break; //kh case WM_COMMAND: switch(LOWORD(wp)) { case 1: mydc=GetDC(hwnd); DrawDIB(mydc, 0, 0, &image_car8); ReleaseDC(hwnd,mydc); break; case 2: mydc=GetDC(hwnd); DrawDIB(mydc, 100, 5, &image_penguin); ReleaseDC(hwnd,mydc); break; case 3: SendMessage(hwnd, WM_PAINT, 0, 0); //pic=LoadBitmap(hInstace,""); break; default: break; } break; default: return DefWindowProc( hwnd, msg, wp, lp); } return( 0); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { MSG msg; /* Force XORMOVE window redraw algorithm, required * for this version of alpha blend painting */ mwERASEMOVE = FALSE; RegisterAppClass(); /* set background wallpaper*/ MwSetDesktopWallpaper(&image_microwin); /* must update root window until alpha blend blitting * uses off screen memory for hidden windows, rather than * screen memory*/ UpdateWindow(GetDesktopWindow()); // CreateAppWindow(); CreateAppWindow(); /* type ESC to quit...*/ while( GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }