dllbridge

Untitled

Oct 3rd, 2020 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.55 KB | None | 0 0
  1. #include  <windows.h>
  2. #include <commctrl.h>                                                                //  Этот файл я взял из MSVC 6.0
  3.  
  4.  
  5. HWND         hWnd,
  6.          hProgBar;
  7.          
  8. HINSTANCE   hInst;    
  9.  
  10. HANDLE    hArr[3];    
  11.  
  12. int Timer_CLK = 0;
  13.  
  14. char      sz[123];
  15.  
  16.  
  17.  
  18. /////////////////////////////////////////////////////                                   Рисует строку в окне программы
  19. void xPrint(int x, int y, const char *pChar)       //
  20. {  
  21.        
  22.      HDC hdc = GetDC(hWnd);
  23.      SetTextColor(hdc, RGB(66, 170, 255));
  24.      SetBkColor  (hdc, 0);
  25.      TextOut(hdc, x, y, pChar, strlen(pChar));
  26.      ReleaseDC(hWnd,hdc);
  27. }
  28.  
  29. /////////////////////////////////////////////////////
  30. int TormoZ()                                       //
  31. {
  32.     int c = 0,
  33.         p = 2;
  34.    
  35.     for(int i = -2000000000; i < 2000000000; i++)
  36.     {
  37.         if(c++ > 80000000)
  38.         {  c=0;
  39.            SendMessage(hProgBar, PBM_STEPIT, 0, 0);
  40.            wsprintf(sz, "%d %% ", p += 2);  
  41.            xPrint(250, 205, sz);
  42.         }  
  43.        
  44.     }
  45.     xPrint(40, 170, "                     ");
  46.     xPrint(40, 240, "STOP !  ");
  47. }
  48.  
  49.  
  50. /////////////////////////////////////////////////////
  51. DWORD WINAPI WorkThread0(LPVOID param)             //
  52. {
  53.  
  54.     int c = 0,
  55.         p = 2;
  56.    
  57.     for(int i = -2000000000; i < 2000000000; i++)
  58.     {
  59.         if(c++ > 80000000)
  60.         {  c=0;
  61.            SendMessage(hProgBar, PBM_STEPIT, 0, 0);
  62.            wsprintf(sz, "%d %% ", p += 2);  
  63.            xPrint(250, 205, sz);
  64.         }  
  65.        
  66.     }
  67.     xPrint(40, 170, "                       ");
  68.     xPrint(40, 240, "STOP !  ");
  69.  
  70. ExitThread(0);
  71. }
  72.  
  73. ///////////////////////////////////////////////////////////////////////////////////////////////
  74. LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)              //
  75. {
  76.     switch(Message)
  77.     {  
  78.  
  79.         case  WM_CREATE:   SetTimer(hWnd, 1, 200, 0);        //  Создаём таймер №1, который срабатывает каждые 0.4 сек.          
  80.                            break;                                //  Принимаем однократное сообщение для инициализации
  81.              
  82.         case   WM_TIMER:   switch(Timer_CLK ++)
  83.                            {
  84.  
  85.                                          
  86.                                case  5:  InitCommonControls();
  87.                                          hProgBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
  88.                                                          WS_CHILD | WS_VISIBLE | WS_BORDER,
  89.                                                    25, 203, 200, 20, hWnd, 0, hInst, NULL);  
  90.                                                                        
  91.                                          SendMessage(hProgBar, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0, 50));      
  92.                                          SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);    
  93.                                          
  94.                                          break;
  95.                                          
  96.                                case  7:  
  97.                                          //xPrint(40, 170, "Start TormoZ"); TormoZ();
  98.                 hArr[0] = CreateThread(NULL, 0, WorkThread0, NULL, 0, 0); xPrint(40, 170, "Start thread");
  99.                                          break;                                          
  100.                                                                                  
  101.                            }                                                                           
  102.                            break;
  103.                            
  104.         case WM_COMMAND: break;                            
  105.    
  106.         case WM_DESTROY: PostQuitMessage(0);
  107.                          break;
  108.        
  109.         default: return DefWindowProc(hWnd, Message, wParam, lParam);
  110.            
  111.     }
  112.     return 0;
  113. }
  114.  
  115.  
  116. ///////////////////////////////////////////////////////////////////////////////////////////////
  117. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  118. {
  119.     WNDCLASSEX wc;
  120.    
  121.     MSG Msg;
  122.  
  123.  
  124.         memset(&wc, 0, sizeof(wc));
  125.     wc.cbSize        = sizeof(WNDCLASSEX);
  126.     wc.lpfnWndProc   = WndProc;
  127.     wc.hInstance     = hInst = hInstance;
  128.     wc.hCursor       = LoadCursor(0, IDC_ARROW);
  129.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);                          
  130.     wc.lpszClassName = "WindowClass";
  131.     wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
  132.     wc.hIconSm       = LoadIcon(0, IDI_APPLICATION);
  133.  
  134.     if(!RegisterClassEx(&wc)) {
  135.         MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  136.         return 0;
  137.     }
  138.  
  139.     hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass", "Example for Progress Bar & Thread",
  140.                                                       WS_VISIBLE|WS_OVERLAPPEDWINDOW,
  141.            100,
  142.            100,
  143.            640,
  144.            480,
  145.            0, 0, hInstance, 0);
  146.  
  147.     if(hWnd == NULL) {
  148.         MessageBox(0, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
  149.         return 0;
  150.     }
  151.  
  152.  
  153.     while(GetMessage(&Msg, 0, 0, 0) > 0) {
  154.           TranslateMessage(&Msg);
  155.           DispatchMessage(&Msg);
  156.     }
  157.     return Msg.wParam;
  158. }
  159.  
  160.  
  161.  
Add Comment
Please, Sign In to add comment