Advertisement
dllbridge

Untitled

Oct 9th, 2020
1,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.06 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3.  
  4. #include   <stdio.h>
  5.  
  6.  
  7. HWND                  hWnd;
  8. int          Timer_CLK = 0;
  9.  
  10.  
  11. CRITICAL_SECTION section = { 0 }; //Критическая секция
  12.  
  13.  
  14. /////////////////////////////////////////////////////                                  Рисует строку в окне программы
  15. void xPrint(int x, int y, const char *pChar)       //
  16. {  
  17.        
  18.      HDC hdc = GetDC(hWnd);
  19.      SetTextColor(hdc, RGB(66, 170, 255));
  20.      SetBkColor  (hdc, 0);
  21.      TextOut(hdc, x, y, pChar, strlen(pChar));
  22.      ReleaseDC(hWnd,hdc);
  23. }
  24.  
  25.  
  26.  
  27. /////////////////////////////////////////////////////
  28. LPCSTR Rus(LPCTSTR pszIn)                          //
  29. {
  30.     static char szBuffer[MAX_PATH];
  31.     CharToOemBuff(pszIn, szBuffer, MAX_PATH);
  32.     return szBuffer;
  33. }
  34.  
  35.  
  36. void ConsolePrint(const char* str, int Colour)
  37. {
  38.    
  39.      EnterCriticalSection(&section);
  40.      DWORD   result;
  41.      COORD    coord;
  42.      HANDLE  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  43.      SetConsoleTextAttribute(hStdout, Colour);                       //  Изменим цвет текста
  44.  
  45.      WriteConsole(hStdout, Rus(str), strlen(str), &result, 0);
  46.      LeaveCriticalSection(&section);
  47. }
  48. /*
  49. //   Y  - это строка, X - это позиция в строке
  50. //  ============================================
  51. void ConsolePrint(int Y, int X, const char* str, int Colour)
  52. {
  53.      DWORD   result;
  54.      COORD    coord;
  55.      HANDLE  hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
  56.      SetConsoleTextAttribute(hStdout, Colour);                    
  57.      coord.X = X;                                                    //  Выбираем позицию
  58.      coord.Y = Y;                                                    //  Выбираем строку
  59.      SetConsoleCursorPosition(hStdout, coord);     
  60.      
  61.      WriteConsole(hStdout, Rus(str), strlen(str), &result, 0);
  62. }
  63. */
  64.  
  65. /*                какой цвет как обозначается:
  66.    (HEX)   
  67. 0   0 = черный
  68. 1   1 = синий
  69. 2   2 = зеленый
  70. 3   3 = голубой
  71. 4   4 = красный
  72. 5   5 = лиловый
  73. 6   6 = желтый
  74. 7   7 = белый
  75. 8   8 = серый
  76. 9   9 = светло-синий
  77. 10  a = светло-зеленый
  78. 11  b = светло-голубой
  79. 12  c = светло-красный
  80. 13  d = светло-лиловый
  81. 14  e = светло-желтый
  82. 15  f = ярко-белый
  83. */
  84.  
  85.  
  86.  
  87.  
  88. HANDLE hArr[3];
  89.  
  90. char sz[150] = "Columbia Pictures Presents",
  91.      sz0[2],
  92.      sz1[2],
  93.      sz2[2],
  94.      sz3[2];
  95.      
  96. /////////////////////////////////////////////////////
  97. DWORD WINAPI WorkThread0(LPVOID param)             //
  98. {
  99.     for(int i = 0; i < 26; ++i)
  100.     {
  101.        
  102.        sz0[0] = sz[i]; 
  103.        sz0[1] = 0; 
  104.        ConsolePrint(sz0, 14);
  105.     }
  106. ExitThread(0);
  107. }
  108.  
  109. DWORD WINAPI WorkThread1(LPVOID param)
  110. {
  111.     for (int i = 0; i < 26; ++i)
  112.     {
  113.        
  114.        sz1[0] = sz[i]; 
  115.        sz1[1] = 0; 
  116.        ConsolePrint(sz1, 12);
  117.     }
  118.  
  119. ExitThread(0);
  120. }
  121.  
  122. DWORD WINAPI WorkThread2(LPVOID param)
  123. {
  124.     for (int i = 0; i < 26; ++i)
  125.     {
  126.        
  127.        sz2[0] = sz[i]; 
  128.        sz2[1] = 0; 
  129.        ConsolePrint(sz2, 10);
  130.     }
  131.  
  132. ExitThread(0);
  133. }
  134.  
  135.  
  136. /////////////////////////////////////////////////////
  137. void spell()
  138. {
  139.     for (int i = 0; i < 26; ++i)
  140.     {
  141.        
  142.        sz3[0] = sz[i]; 
  143.        sz3[1] = 0; 
  144.        ConsolePrint(sz3, 13);
  145.     }
  146.  
  147. }
  148.  
  149.  
  150. LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
  151. {
  152.     switch(Message)
  153.     {  
  154.  
  155.         case  WM_CREATE:   SetTimer(hWnd, 1, 400, 0);        //  Создаём таймер №1, который срабатывает каждые 0.4 сек.          
  156.                            break;                                //  Принимаем однократное сообщение для инициализации
  157.              
  158.         case   WM_TIMER:   switch(Timer_CLK ++)
  159.                            {
  160.                                case  2:  AllocConsole();
  161.                                          xPrint(20, 20, "Hello");
  162.                                          break;  
  163.                                  
  164.                                  
  165.                                case  5:  //printf("DDfkdjsklj");     
  166.                                         // ConsolePrint(3, 12, "Привет !", 6);
  167.                                          //ConsolePrint("Привет !", 6);
  168.                                          
  169.                                          InitializeCriticalSection(&section);
  170.                                          
  171.                                          hArr[0] = CreateThread(NULL, 0, WorkThread0, NULL, 0, 0);
  172.                                         // spell();
  173.                                          hArr[1] = CreateThread(NULL, 0, WorkThread1, NULL, 0, 0);
  174.                                          hArr[2] = CreateThread(NULL, 0, WorkThread2, NULL, 0, 0);
  175.                                         // WaitForMultipleObjects(3, hArr, TRUE, INFINITE);
  176.                                          break;
  177.                                          
  178.                                case 37:  FreeConsole();
  179.                                          xPrint(20, 40, "See you later");  
  180.                                          break;                                          
  181.                            }
  182.                            break;                  
  183.    
  184.         case WM_DESTROY:   PostQuitMessage(0);
  185.                            break;
  186.        
  187.         default: return DefWindowProc(hWnd, Message, wParam, lParam);
  188.            
  189.     }
  190.     return 0;
  191. }
  192.  
  193.  
  194. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  195.     WNDCLASSEX wc;
  196.     //HWND hwnd;
  197.     MSG Msg;
  198.  
  199.  
  200.         memset(&wc, 0, sizeof(wc));
  201.     wc.cbSize        = sizeof(WNDCLASSEX);
  202.     wc.lpfnWndProc   = WndProc;
  203.     wc.hInstance     = hInstance;
  204.     wc.hCursor       = LoadCursor(0, IDC_ARROW);
  205.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);                          
  206.     wc.lpszClassName = "WindowClass";
  207.     wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
  208.     wc.hIconSm       = LoadIcon(0, IDI_APPLICATION);
  209.  
  210.     if(!RegisterClassEx(&wc)) {
  211.         MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  212.         return 0;
  213.     }
  214.  
  215.     hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
  216.            100,
  217.            100,
  218.            640,
  219.            480,
  220.            0, 0, hInstance, 0);
  221.  
  222.     if(hWnd == NULL) {
  223.         MessageBox(0, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  224.         return 0;
  225.     }
  226.  
  227.  
  228.     while(GetMessage(&Msg, 0, 0, 0) > 0) {
  229.         TranslateMessage(&Msg);
  230.         DispatchMessage(&Msg);
  231.     }
  232.     return Msg.wParam;
  233. }
  234.  
  235.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement