Advertisement
Tobiasz931

dafuq

Mar 28th, 2013
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.65 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tchar.h>
  5. #include <string>
  6.  
  7. // Global variables
  8. TCHAR txt[1000];
  9. TCHAR tekst[] = _T(">>");
  10. bool test=true;
  11. int i=0;
  12. char c;
  13. // The main window class name.
  14. static TCHAR szWindowClass[] = _T("win32app");
  15. HWND hwndLabel;
  16. // The string that appears in the application's title bar.
  17. static TCHAR szTitle[] = _T("Windows are Magic");
  18.  
  19. HINSTANCE hInst;
  20.  
  21. // Forward declarations of functions included in this code module:
  22. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  23. std::wstring s2ws(const std::string& s)
  24. {
  25.     int len;
  26.     int slength = (int)s.length() + 1;
  27.     len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
  28.     wchar_t* buf = new wchar_t[len];
  29.     MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
  30.     std::wstring r(buf);
  31.     delete[] buf;
  32.     return r;
  33. }
  34. int WINAPI WinMain(HINSTANCE hInstance,
  35.                    HINSTANCE hPrevInstance,
  36.                    LPSTR lpCmdLine,
  37.                    int nCmdShow)
  38. {
  39.     WNDCLASSEX wcex;
  40.  
  41.     wcex.cbSize = sizeof(WNDCLASSEX);
  42.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  43.     wcex.lpfnWndProc    = WndProc;
  44.     wcex.cbClsExtra     = 0;
  45.     wcex.cbWndExtra     = 0;
  46.     wcex.hInstance      = hInstance;
  47.     wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  48.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  49.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  50.     wcex.lpszMenuName   = NULL;
  51.     wcex.lpszClassName  = szWindowClass;
  52.     wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  53.  
  54.     if (!RegisterClassEx(&wcex))
  55.     {
  56.         MessageBox(NULL,
  57.             _T("Call to RegisterClassEx failed!"),
  58.             _T("Win32 Guided Tour"),
  59.             NULL);
  60.  
  61.         return 1;
  62.     }
  63.  
  64.     hInst = hInstance; // Store instance handle in our global variable
  65.  
  66.     // The parameters to CreateWindow explained:
  67.     // szWindowClass: the name of the application
  68.     // szTitle: the text that appears in the title bar
  69.     // WS_OVERLAPPEDWINDOW: the type of window to create
  70.     // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
  71.     // 500, 100: initial size (width, length)
  72.     // NULL: the parent of this window
  73.     // NULL: this application does not have a menu bar
  74.     // hInstance: the first parameter from WinMain
  75.     // NULL: not used in this application
  76.     HWND hWnd = CreateWindow(
  77.         szWindowClass,
  78.         szTitle,
  79.         WS_OVERLAPPEDWINDOW,
  80.         CW_USEDEFAULT, CW_USEDEFAULT,
  81.         500, 100,
  82.         NULL,
  83.         NULL,
  84.         hInstance,
  85.         NULL
  86.     );
  87.  
  88.     if (!hWnd)
  89.     {
  90.         MessageBox(NULL,
  91.             _T("Call to CreateWindow failed!"),
  92.             _T("Win32 Guided Tour"),
  93.             NULL);
  94.  
  95.         return 1;
  96.     }
  97.     wchar_t szBuff[64];
  98.     swprintf(szBuff, L"STATIC");
  99.     hwndLabel = CreateWindow(szBuff, txt,
  100. WS_VISIBLE | WS_CHILD | SS_RIGHT,
  101. 10,200,75,35,hWnd,NULL,hInstance,NULL);
  102.     // The parameters to ShowWindow explained:
  103.     // hWnd: the value returned from CreateWindow
  104.     // nCmdShow: the fourth parameter from WinMain
  105.     ShowWindow(hWnd,
  106.         nCmdShow);
  107.     UpdateWindow(hWnd);
  108.  
  109.     // Main message loop:
  110.     MSG msg;
  111.     while (GetMessage(&msg, NULL, 0, 0))
  112.     {
  113.         TranslateMessage(&msg);
  114.         DispatchMessage(&msg);
  115.     }
  116.  
  117.     return (int) msg.wParam;
  118. }
  119.  
  120. //
  121. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  122. //
  123. //  PURPOSE:  Processes messages for the main window.
  124. //
  125. //  WM_PAINT    - Paint the main window
  126. //  WM_DESTROY  - post a quit message and return
  127. //
  128. //
  129. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  130. {
  131.     PAINTSTRUCT ps;
  132.     HDC hdc;
  133.     TCHAR greeting[] = _T("Hello, World!");
  134.  
  135.     switch (message)
  136.     {
  137.     case WM_PAINT:
  138.         hdc = BeginPaint(hWnd, &ps);
  139.  
  140.         // Here your application is laid out.
  141.         // For this introduction, we just print out "Hello, World!"
  142.         // in the top left corner.
  143.         /*TextOut(hdc,
  144.             5, 5,
  145.             tekst, _tcslen(tekst));*/
  146.         txt[0]='!';
  147.         TextOut(hdc,
  148.             5, 5,
  149.             txt, _tcslen(txt));
  150.         // End application-specific layout section.
  151.  
  152.         EndPaint(hWnd, &ps);
  153.         break;
  154.     case WM_DESTROY:
  155.         PostQuitMessage(0);
  156.         break;
  157.     case WM_KEYDOWN:
  158.         i++;
  159.         txt[i]=MapVirtualKey(wParam,MAPVK_VK_TO_CHAR);
  160.         test=true;
  161.         break;
  162.         case WM_CHAR:
  163.                 switch(wParam) {
  164.                 default:
  165.                         //int znak = wParam;
  166.                         //txt[i] = znak;
  167.                         SetWindowText(hwndLabel,txt);
  168.                 }
  169.             SetWindowText(hwndLabel,txt);
  170.  
  171.                         HANDLE hData;//For the data to send to the clipboard
  172.                         char *szData = new char[1000];
  173.                         for(int i=0; i<1000;++i) {
  174.                                 szData[i] = txt[i];
  175.                         }
  176.     char *ptrData = NULL;//pointer to allow char copying
  177.     int nStrLen = strlen(szData);//length of phrase
  178.  
  179.     hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
  180.                 1001);//get handle to memory to hold phrase
  181.      
  182.     ptrData = (char*)GlobalLock(hData);//get pointer from handle
  183.  
  184.         memcpy(ptrData,szData,1001);//copy over the phrase
  185.  
  186.     GlobalUnlock(hData);//free the handle
  187.  
  188.     OpenClipboard(NULL);//allow you to work with clipboard
  189.  
  190.     EmptyClipboard();//clear previous contents
  191.  
  192.     SetClipboardData(CF_TEXT,hData);//set our data
  193.  
  194.     CloseClipboard();//finished!!
  195.                 break;
  196.     default:
  197.         return DefWindowProc(hWnd, message, wParam, lParam);
  198.     }
  199.  
  200.     return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement