Advertisement
vovan333

I LPCWSTRed Bill Gates' mother yesterday

Dec 30th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <string>
  3. using namespace std;
  4.  
  5. namespace D3DTest1
  6. {
  7.     HWND hMainWindow;
  8.  
  9.     int MessageBox(LPCWSTR text, LPCWSTR caption = L"Alert", long type = MB_OK, HWND hWnd = hMainWindow)
  10.     {
  11.         return MessageBox(hWnd, text, caption, type);
  12.     }
  13.  
  14.     void OnKeyDown(WPARAM virtualKeyCode)
  15.     {
  16.         wstring caption = L"You pressed the following key: \n";
  17.         int charCode = MapVirtualKey(virtualKeyCode, MAPVK_VK_TO_CHAR);
  18.         wchar_t key = (wchar_t)charCode;
  19.         wstring text = caption + L"Character: \"" + key + L"\"\nCharcode: " + to_wstring(charCode);
  20.         MessageBox(text.c_str());
  21.     }
  22.  
  23.     LRESULT CALLBACK OnWindowMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  24.     {
  25.         switch (message)
  26.         {
  27.             case WM_DESTROY:
  28.                 PostQuitMessage(0);
  29.                 return 0;
  30.                 break;
  31.             case WM_KEYDOWN:
  32.                 OnKeyDown(wParam);
  33.                 break;
  34.         }
  35.         return DefWindowProc(hWnd, message, wParam, lParam);
  36.     }
  37.  
  38.     int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  39.     {
  40.         WNDCLASSEX wc;
  41.         ZeroMemory(&wc, sizeof(wc));
  42.  
  43.         wc.cbSize = sizeof(WNDCLASSEX);
  44.         wc.style = CS_HREDRAW | CS_VREDRAW;
  45.         wc.lpfnWndProc = OnWindowMessage;
  46.         wc.hInstance = hInstance;
  47.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  48.         wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
  49.         wc.lpszClassName = L"WC_Default";
  50.  
  51.         RegisterClassEx(&wc);
  52.  
  53.         int width = 800;
  54.         int height = 600;
  55.         RECT wr = { 0, 0, width, height };
  56.  
  57.         AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
  58.  
  59.         hMainWindow = CreateWindowEx
  60.         (
  61.             NULL,
  62.             L"WC_Default",
  63.             L"D3DTest1 Main Window",
  64.             WS_OVERLAPPEDWINDOW,
  65.             300,
  66.             300,
  67.             wr.right - wr.left,
  68.             wr.bottom - wr.top,
  69.             NULL,
  70.             NULL,
  71.             hInstance,
  72.             NULL
  73.         );
  74.  
  75.         ShowWindow(hMainWindow, nShowCmd);
  76.  
  77.         MSG message;
  78.         while (GetMessage(&message, NULL, 0, 0))
  79.         {
  80.             TranslateMessage(&message);
  81.             DispatchMessage(&message);
  82.         }
  83.  
  84.         return 0;
  85.     }
  86. }
  87.  
  88. int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
  89. {
  90.     D3DTest1::WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
  91. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement