Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. LRESULT CALLBACK PictViewWndProc(HWND, UINT, UINT, LONG);
  4.  
  5. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow) {
  6.     HWND hWnd;
  7.     WNDCLASS WndClass;
  8.     MSG Msg;
  9.  
  10.     WndClass.style = CS_HREDRAW | CS_VREDRAW;
  11.     WndClass.lpfnWndProc = PictViewWndProc;
  12.     WndClass.cbClsExtra = 0;
  13.     WndClass.cbWndExtra = 0;
  14.     WndClass.hInstance = hInstance;
  15.     WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  16.     WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  17.     WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  18.     WndClass.lpszMenuName = NULL;
  19.     WndClass.lpszClassName = L"TEST";
  20.  
  21.     if (!RegisterClass(&WndClass)) {
  22.         MessageBox(NULL, L"Can't register class", L"Error", MB_OK);
  23.         return 0;
  24.     }
  25.  
  26.     hWnd = CreateWindow(L"TEST", L"Picture View", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
  27.         CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  28.     if (!hWnd) {
  29.         MessageBox(NULL, L"Can't create window", L"Error", MB_OK);
  30.         return 0;
  31.     }
  32.  
  33.     ShowWindow(hWnd, nCmdShow);
  34.     UpdateWindow(hWnd);
  35.  
  36.     while (GetMessage(&Msg, NULL, 0, 0)) {
  37.         TranslateMessage(&Msg);
  38.         DispatchMessage(&Msg);
  39.     }
  40.     return Msg.wParam;
  41. }
  42.  
  43. LRESULT CALLBACK PictViewWndProc(HWND hWnd, UINT Message, UINT wParam, LONG lParam) {
  44.     HDC hDC, hCompatibleDC;
  45.     PAINTSTRUCT PaintStruct;
  46.     HANDLE hBitmap, hOldBitmap;
  47.     RECT Rect;
  48.     BITMAP Bitmap;
  49.  
  50.     switch (Message) {
  51.     case WM_PAINT:
  52.         hDC = BeginPaint(hWnd, &PaintStruct);
  53.         hBitmap = LoadImage(NULL, L"1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  54.         GetObject(hBitmap, sizeof(BITMAP), &Bitmap);
  55.         hCompatibleDC = CreateCompatibleDC(hDC);
  56.         hOldBitmap = SelectObject(hCompatibleDC, hBitmap);
  57.         GetClientRect(hWnd, &Rect);
  58.         StretchBlt(hDC, 0, 0, Rect.right, Rect.bottom, hCompatibleDC, 0, 0, Bitmap.bmWidth,
  59.             Bitmap.bmHeight, SRCCOPY);
  60.         SelectObject(hCompatibleDC, hOldBitmap);
  61.         DeleteObject(hBitmap);
  62.         DeleteDC(hCompatibleDC);
  63.         EndPaint(hWnd, &PaintStruct);
  64.         return 0;
  65.     case WM_DESTROY:
  66.         PostQuitMessage(0);
  67.         return 0;
  68.     }
  69.  
  70.     return DefWindowProc(hWnd, Message, wParam, lParam);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement