Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.59 KB | None | 0 0
  1. // Win32Project1.cpp : Defines the entry point for the application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Win32Project1.h"
  6. // dodatkowe pliki naglowkowe
  7. #include <emmintrin.h>
  8. #include <xmmintrin.h>
  9.  
  10. #define MAX_LOADSTRING 100
  11.  
  12. // Global Variables:
  13. HINSTANCE hInst;                                // current instance
  14. WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
  15. WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
  16.                                                 // dodatkowe zmienne globalne
  17. HBITMAP hBitmap;
  18. LPCWSTR szFileName = __T("test.bmp"); // nazwa wczytywanego pliku
  19.  
  20. // Forward declarations of functions included in this code module:
  21. ATOM                MyRegisterClass(HINSTANCE hInstance);
  22. BOOL                InitInstance(HINSTANCE, int);
  23. LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
  24. INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
  25.  
  26. int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
  27.                      _In_opt_ HINSTANCE hPrevInstance,
  28.                      _In_ LPWSTR    lpCmdLine,
  29.                      _In_ int       nCmdShow)
  30. {
  31.     UNREFERENCED_PARAMETER(hPrevInstance);
  32.     UNREFERENCED_PARAMETER(lpCmdLine);
  33.  
  34.     // TODO: Place code here.
  35.  
  36.     // Initialize global strings
  37.     LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  38.     LoadStringW(hInstance, IDC_WIN32PROJECT1, szWindowClass, MAX_LOADSTRING);
  39.     MyRegisterClass(hInstance);
  40.  
  41.     // wczytywanie mapy bitowej
  42.     hBitmap = (HBITMAP)::LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0,
  43.         LR_LOADFROMFILE);
  44.     // Weryfikacja ładowania
  45.         if (hBitmap == NULL) {
  46.             ::MessageBox(NULL, __T("Ladowanie bledne"), __T("Error"), MB_OK);
  47.                 return false;
  48.         }
  49.  
  50.     // Perform application initialization:
  51.     if (!InitInstance (hInstance, nCmdShow))
  52.     {
  53.         return FALSE;
  54.     }
  55.  
  56.     HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT1));
  57.  
  58.     MSG msg;
  59.  
  60.     // Main message loop:
  61.     while (GetMessage(&msg, nullptr, 0, 0))
  62.     {
  63.         if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  64.         {
  65.             TranslateMessage(&msg);
  66.             DispatchMessage(&msg);
  67.         }
  68.     }
  69.  
  70.     return (int) msg.wParam;
  71. }
  72.  
  73.  
  74.  
  75. //
  76. //  FUNCTION: MyRegisterClass()
  77. //
  78. //  PURPOSE: Registers the window class.
  79. //
  80. ATOM MyRegisterClass(HINSTANCE hInstance)
  81. {
  82.     WNDCLASSEXW wcex;
  83.  
  84.     wcex.cbSize = sizeof(WNDCLASSEX);
  85.  
  86.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  87.     wcex.lpfnWndProc    = WndProc;
  88.     wcex.cbClsExtra     = 0;
  89.     wcex.cbWndExtra     = 0;
  90.     wcex.hInstance      = hInstance;
  91.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT1));
  92.     wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
  93.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  94.     wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_WIN32PROJECT1);
  95.     wcex.lpszClassName  = szWindowClass;
  96.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  97.  
  98.     return RegisterClassExW(&wcex);
  99. }
  100.  
  101. //
  102. //   FUNCTION: InitInstance(HINSTANCE, int)
  103. //
  104. //   PURPOSE: Saves instance handle and creates main window
  105. //
  106. //   COMMENTS:
  107. //
  108. //        In this function, we save the instance handle in a global variable and
  109. //        create and display the main program window.
  110. //
  111. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  112. {
  113.    hInst = hInstance; // Store instance handle in our global variable
  114.  
  115.    HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  116.       CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
  117.  
  118.    if (!hWnd)
  119.    {
  120.       return FALSE;
  121.    }
  122.  
  123.    ShowWindow(hWnd, nCmdShow);
  124.    UpdateWindow(hWnd);
  125.  
  126.    return TRUE;
  127. }
  128.  
  129. //
  130. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  131. //
  132. //  PURPOSE:  Processes messages for the main window.
  133. //
  134. //  WM_COMMAND  - process the application menu
  135. //  WM_PAINT    - Paint the main window
  136. //  WM_DESTROY  - post a quit message and return
  137. //
  138. //
  139. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  140. {
  141.  
  142.     // deklaracje zmiennych
  143.     BOOL qRetBlit;
  144.     HBITMAP hOldBmp;
  145.     int iReturn;
  146.  
  147.     BITMAP bm;
  148.     BITMAPINFOHEADER bminfoheader;
  149.     int x, y;
  150.     unsigned char* pPixels;
  151.     unsigned char r, g, b;
  152.     switch (message)
  153.     {
  154.     case WM_COMMAND:
  155.         {
  156.             int wmId = LOWORD(wParam);
  157.             // Parse the menu selections:
  158.             switch (wmId)
  159.             {
  160.             case IDM_ABOUT:
  161.                 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
  162.                 break;
  163.             case IDM_EXIT:
  164.                 DestroyWindow(hWnd);
  165.                 break;
  166.             default:
  167.                 return DefWindowProc(hWnd, message, wParam, lParam);
  168.             }
  169.         }
  170.         break;
  171.     case WM_PAINT:
  172.         {
  173.             PAINTSTRUCT ps;
  174.             HDC hdc = BeginPaint(hWnd, &ps);
  175.             // TODO: Add any drawing code that uses hdc here...
  176.             HDC hLocalDC;
  177.             hLocalDC = ::CreateCompatibleDC(hdc);
  178.             // Verify that the device context was created
  179.             if (hLocalDC == NULL) {
  180.                 ::MessageBox(NULL, __T("CreateCompatibleDC err"), __T("Error"), MB_OK);
  181.                     return false;
  182.             }
  183.             // Pobieranie par.bitmapy
  184.                 BITMAP qBitmap;
  185.             iReturn = GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP),
  186.                 reinterpret_cast<LPVOID>(&qBitmap));
  187.             if (!iReturn) {
  188.                 ::MessageBox(NULL, __T("GetObject err."), __T("Error"), MB_OK);
  189.                     return false;
  190.             }
  191.             hOldBmp =
  192.                 (HBITMAP)::SelectObject(hLocalDC, hBitmap);
  193.             if (hOldBmp == NULL) {
  194.                 ::MessageBox(NULL, __T("SelectObject err."), __T("Error"), MB_OK);
  195.                     return false;
  196.             }
  197.             // Rysowanie bitmapy
  198.             qRetBlit = ::BitBlt(hdc, 0, 0, qBitmap.bmWidth, qBitmap.bmHeight, hLocalDC, 0, 0, SRCCOPY);
  199.             if (!qRetBlit) {
  200.                 ::MessageBox(NULL, __T("Blit err."), __T("Error"), MB_OK);
  201.                     return false;
  202.             }
  203.             // Zwolnie zasobow
  204.             ::SelectObject(hLocalDC, hOldBmp);
  205.             ::DeleteDC(hLocalDC);
  206.             EndPaint(hWnd, &ps);
  207.         }
  208.         break;
  209.     case WM_DESTROY:
  210.         PostQuitMessage(0);
  211.         break;
  212.     default:
  213.         return DefWindowProc(hWnd, message, wParam, lParam);
  214.     }
  215.     return 0;
  216. }
  217.  
  218. // Message handler for about box.
  219. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  220. {
  221.     UNREFERENCED_PARAMETER(lParam);
  222.     switch (message)
  223.     {
  224.     case WM_INITDIALOG:
  225.         return (INT_PTR)TRUE;
  226.  
  227.     case WM_COMMAND:
  228.         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
  229.         {
  230.             EndDialog(hDlg, LOWORD(wParam));
  231.             return (INT_PTR)TRUE;
  232.         }
  233.         break;
  234.     }
  235.     return (INT_PTR)FALSE;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement