Advertisement
desdemona

anna w

Mar 28th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1.  
  2. #ifndef UNICODE
  3. #define UNICODE
  4. #endif
  5.  
  6. #include <windows.h>
  7. #include <stdio.h>
  8. #include <string>
  9.  
  10. using namespace std;
  11.  
  12. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  13. char literka = '0';
  14. HWND hwnd;
  15. string bogdan = "dziobak ";
  16.  
  17. wstring s2ws(const string& s)
  18. {
  19.     int len;
  20.     int slength = (int)s.length() + 1;
  21.     len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
  22.     wchar_t* buf = new wchar_t[len];
  23.     MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
  24.     std::wstring r(buf);
  25.     delete[] buf;
  26.     return r;
  27. }
  28.  
  29.  
  30. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
  31. {
  32.     // Register the window class.
  33.     const wchar_t CLASS_NAME[]  = L"Sample Window Class";
  34.    
  35.     WNDCLASS wc = { };
  36.  
  37.     wc.lpfnWndProc   = WindowProc;
  38.     wc.hInstance     = hInstance;
  39.     wc.lpszClassName = CLASS_NAME;
  40.  
  41.     wstring stemp = s2ws(bogdan);
  42.     LPCWSTR result = stemp.c_str();
  43.  
  44.     RegisterClass(&wc);
  45.  
  46.     // Create the window.
  47.  
  48.     hwnd = CreateWindowEx(
  49.         0,                              // Optional window styles.
  50.         CLASS_NAME,                     // Window class
  51.         result,    // Window text
  52.         WS_OVERLAPPEDWINDOW,            // Window style
  53.  
  54.         // Size and position
  55.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  56.  
  57.         NULL,       // Parent window    
  58.         NULL,       // Menu
  59.         hInstance,  // Instance handle
  60.         NULL        // Additional application data
  61.         );
  62.  
  63.     if (hwnd == NULL)
  64.     {
  65.         return 0;
  66.     }
  67.  
  68.     ShowWindow(hwnd, nCmdShow);
  69.  
  70.     // Run the message loop.
  71.  
  72.     MSG msg = { };
  73.     while (GetMessage(&msg, NULL, 0, 0))
  74.     {
  75.         TranslateMessage(&msg);
  76.         DispatchMessage(&msg);
  77.     }
  78.  
  79.     return 0;
  80. }
  81.  
  82. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  83. {
  84.     switch (uMsg)
  85.     {
  86.     case WM_DESTROY:
  87.         PostQuitMessage(0);
  88.         return 0;
  89.  
  90.     case WM_PAINT:
  91.         {
  92.             PAINTSTRUCT ps;
  93.             HDC hdc = BeginPaint(hwnd, &ps);
  94.  
  95.             FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
  96.  
  97.             EndPaint(hwnd, &ps);
  98.             return 0;
  99.         }
  100.  
  101.     case WM_KEYDOWN:
  102.         {
  103.                 TCHAR inc;
  104.         inc = MapVirtualKey(wParam, MAPVK_VK_TO_CHAR);
  105.          unsigned char* x;
  106.         for(short i = 0; i < sizeof(TCHAR); i++)
  107.         {
  108.            x = reinterpret_cast<unsigned char*>(&inc);
  109.         }
  110.                 literka = x[0];
  111.                 bogdan+=literka;
  112.                 wstring stemp = s2ws(bogdan);
  113.                 LPCWSTR result = stemp.c_str();
  114.                 SetWindowText(hwnd, result);
  115.            
  116.             return 0;
  117.         }
  118.        
  119.  
  120.  
  121.     }
  122.     return DefWindowProc(hwnd, uMsg, wParam, lParam);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement