fireseed (奶油狗) 等 级: #include \"ZImage.h \" LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); void OnLButtonDown(); HBITMAP g_hComBmp; HDC g_hComDC; HWND g_hWnd; RECT g_BmpRect; iCmdShow) { static TCHAR szAppName[] = TEXT( \"HelloWin \"); MSG msg; WNDCLASS wndclass; ZeroMemory( &wndclass, sizeof(wndclass) ); wndclass.lpfnWndProc = WndProc; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH); wndclass.lpszClassName = szAppName; int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstancif(!RegisterClass(&wndclass)) { MessageBox(NULL,TEXT( \"注册窗体类失败! \"),szAppName,MB_ICONERROR); return 0; } CreateWindow(szAppName, TEXT( \"打开图像 \"), WS_OVERLAPPEDWINDOW, ShowWindow(g_hWnd, iCmdShow); UpdateWindow(g_hWnd); // 创建内存设备环境 g_hComDC = CreateCompatibleDC( GetDC( g_hWnd ) ); if ( NULL == g_hComDC ) { return 0; } while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } lParam) { PAINTSTRUCT ps; HDC hdc; switch(message) { case WM_LBUTTONDOWN: OnLButtonDown(); break; case WM_CREATE: g_hWnd = hwnd; break; 200, 200, 400, 300, NULL, NULL, hInstance, NULL); MessageBox( g_hWnd, \"内存设备环境创建失败 \ \"错误 \ MB_ICONLRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAcase WM_DESTROY: // 释放资源 if ( g_hComBmp ) { DeleteObject( g_hComBmp ); } PostQuitMessage(0); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); BitBlt( hdc, g_BmpRect.left, g_BmpRect.top, EndPaint(hwnd, &ps); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } void OnLButtonDown() { OPENFILENAME ofn; ZeroMemory( &ofn, sizeof(ofn) ); char szFile[MAX_PATH]; ZeroMemory( szFile, sizeof(szFile) ); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = \"所有文件(*.*)\\0*.* \"; ofn.lpstrTitle = \"打开文件 \"; ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER; if ( !GetOpenFileName( &ofn ) ) { return; } LPVOID pBuf; char szBiBuf[1024]; g_BmpRect.right, g_BmpRect.bottom, g_hComDC, 0, 0, SRCCOPYLPBITMAPINFO pbi = (LPBITMAPINFO)szBiBuf; if ( g_hComBmp ) { DeleteObject( g_hComBmp ); } LOADDZIMAGE( pBuf, szFile, pbi ); if ( NULL == pBuf ) { MessageBox( g_hWnd, GetZImageLastError(), \"错误 \ MB_ICONHANreturn; } g_hComBmp = CreateCompatibleBitmap( GetDC( g_hWnd ), pbi-> bmiHeader.biWidth, pbi-> bmiHeader.biHeight ); SetDIBits( NULL, g_hComBmp, 0, pbi-> bmiHeader.biHeight, pBuf, pbi, DIB_RGB_COLORS ); SelectObject( g_hComDC, g_hComBmp ); FreeZImage( pBuf ); g_BmpRect.right = pbi-> bmiHeader.biWidth; g_BmpRect.bottom = pbi-> bmiHeader.biHeight; InvalidateRect( g_hWnd, NULL, TRUE ); }