Advertisement
desdemona

kopiowanie tekstu i inne fajne rzeczy

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