Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef UNICODE
- #define UNICODE
- #endif
- #include <windows.h>
- #include <stdio.h>
- #include <string>
- using namespace std;
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- char znak = '0';
- HWND hwnd;
- HDC hDc;
- string tresc = "";
- int My_Little_Number=0;
- wstring s2ws(const string& s)
- {
- int len;
- int slength = (int)s.length() + 1;
- len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
- wchar_t* buf = new wchar_t[len];
- MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
- std::wstring r(buf);
- delete[] buf;
- return r;
- }
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
- {
- // Register the window class.
- const wchar_t CLASS_NAME[] = L"Sample Window Class";
- WNDCLASS wc = { };
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = CLASS_NAME;
- wstring stemp = s2ws(tresc);
- LPCWSTR result = stemp.c_str();
- RegisterClass(&wc);
- // Create the window.
- hwnd = CreateWindowEx(
- 0, // Optional window styles.
- CLASS_NAME, // Window class
- result, // Window text
- WS_OVERLAPPEDWINDOW, // Window style
- // Size and position
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, // Parent window
- NULL, // Menu
- hInstance, // Instance handle
- NULL // Additional application data
- );
- if (hwnd == NULL)
- {
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- // Run the message loop.
- MSG msg = { };
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hwnd, &ps);
- FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
- EndPaint(hwnd, &ps);
- wstring stemp = s2ws("Dear Princess Celestia");
- LPCWSTR result = stemp.c_str();
- SetWindowText(hwnd, result);
- return 0;
- }
- case WM_KEYDOWN:
- {
- TCHAR inc;
- inc = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR);
- unsigned char* x;
- for(short i = 0; i < sizeof(TCHAR); i++)
- {
- x = reinterpret_cast<unsigned char*>(&inc);
- }
- znak = x[0];
- if((znak>='a' && znak <='z') || (znak>='A' && znak <='Z') || znak==' ' || (znak>='0' && znak<='9') || znak==',' || znak=='.'){
- tresc+=znak;
- My_Little_Number++;
- const char* output = tresc.data();
- const size_t len = strlen(output) + 1;
- HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
- memcpy(GlobalLock(hMem), output, len);
- GlobalUnlock(hMem);
- OpenClipboard(0);
- EmptyClipboard();
- SetClipboardData(CF_TEXT, hMem);
- CloseClipboard();
- wstring stemp2 = s2ws(tresc);
- LPCWSTR result2 = stemp2.c_str();
- hDc = GetDC(hwnd);
- TextOut(hDc,50,50,result2,My_Little_Number);
- ReleaseDC(hwnd,hDc);
- }
- return 0;
- }
- }
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement