Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- using namespace std;
- namespace D3DTest1
- {
- HWND hMainWindow;
- int MessageBox(LPCWSTR text, LPCWSTR caption = L"Alert", long type = MB_OK, HWND hWnd = hMainWindow)
- {
- return MessageBox(hWnd, text, caption, type);
- }
- void OnKeyDown(WPARAM virtualKeyCode)
- {
- wstring caption = L"You pressed the following key: \n";
- int charCode = MapVirtualKey(virtualKeyCode, MAPVK_VK_TO_CHAR);
- wchar_t key = (wchar_t)charCode;
- wstring text = caption + L"Character: \"" + key + L"\"\nCharcode: " + to_wstring(charCode);
- MessageBox(text.c_str());
- }
- LRESULT CALLBACK OnWindowMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- break;
- case WM_KEYDOWN:
- OnKeyDown(wParam);
- break;
- }
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(wc));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = OnWindowMessage;
- wc.hInstance = hInstance;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszClassName = L"WC_Default";
- RegisterClassEx(&wc);
- int width = 800;
- int height = 600;
- RECT wr = { 0, 0, width, height };
- AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
- hMainWindow = CreateWindowEx
- (
- NULL,
- L"WC_Default",
- L"D3DTest1 Main Window",
- WS_OVERLAPPEDWINDOW,
- 300,
- 300,
- wr.right - wr.left,
- wr.bottom - wr.top,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- ShowWindow(hMainWindow, nShowCmd);
- MSG message;
- while (GetMessage(&message, NULL, 0, 0))
- {
- TranslateMessage(&message);
- DispatchMessage(&message);
- }
- return 0;
- }
- }
- int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- D3DTest1::WinMain(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement