Advertisement
Tobiasz931

kitranie w schowek

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