Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h> // Этот файл я взял из MSVC 6.0
- HWND hWnd,
- hProgBar;
- HINSTANCE hInst;
- HANDLE hArr[3];
- int Timer_CLK = 0;
- char sz[123];
- ///////////////////////////////////////////////////// Рисует строку в окне программы
- void xPrint(int x, int y, const char *pChar) //
- {
- HDC hdc = GetDC(hWnd);
- SetTextColor(hdc, RGB(66, 170, 255));
- SetBkColor (hdc, 0);
- TextOut(hdc, x, y, pChar, strlen(pChar));
- ReleaseDC(hWnd,hdc);
- }
- /////////////////////////////////////////////////////
- int TormoZ() //
- {
- int c = 0,
- p = 2;
- for(int i = -2000000000; i < 2000000000; i++)
- {
- if(c++ > 80000000)
- { c=0;
- SendMessage(hProgBar, PBM_STEPIT, 0, 0);
- wsprintf(sz, "%d %% ", p += 2);
- xPrint(250, 205, sz);
- }
- }
- xPrint(40, 170, " ");
- xPrint(40, 240, "STOP ! ");
- }
- /////////////////////////////////////////////////////
- DWORD WINAPI WorkThread0(LPVOID param) //
- {
- int c = 0,
- p = 2;
- for(int i = -2000000000; i < 2000000000; i++)
- {
- if(c++ > 80000000)
- { c=0;
- SendMessage(hProgBar, PBM_STEPIT, 0, 0);
- wsprintf(sz, "%d %% ", p += 2);
- xPrint(250, 205, sz);
- }
- }
- xPrint(40, 170, " ");
- xPrint(40, 240, "STOP ! ");
- ExitThread(0);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) //
- {
- switch(Message)
- {
- case WM_CREATE: SetTimer(hWnd, 1, 200, 0); // Создаём таймер №1, который срабатывает каждые 0.4 сек.
- break; // Принимаем однократное сообщение для инициализации
- case WM_TIMER: switch(Timer_CLK ++)
- {
- case 5: InitCommonControls();
- hProgBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
- WS_CHILD | WS_VISIBLE | WS_BORDER,
- 25, 203, 200, 20, hWnd, 0, hInst, NULL);
- SendMessage(hProgBar, PBM_SETRANGE, 0, (LPARAM)MAKELONG(0, 50));
- SendMessage(hProgBar, PBM_SETSTEP, (WPARAM)1, 0);
- break;
- case 7:
- //xPrint(40, 170, "Start TormoZ"); TormoZ();
- hArr[0] = CreateThread(NULL, 0, WorkThread0, NULL, 0, 0); xPrint(40, 170, "Start thread");
- break;
- }
- break;
- case WM_COMMAND: break;
- case WM_DESTROY: PostQuitMessage(0);
- break;
- default: return DefWindowProc(hWnd, Message, wParam, lParam);
- }
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- MSG Msg;
- memset(&wc, 0, sizeof(wc));
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInst = hInstance;
- wc.hCursor = LoadCursor(0, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
- wc.lpszClassName = "WindowClass";
- wc.hIcon = LoadIcon(0, IDI_APPLICATION);
- wc.hIconSm = LoadIcon(0, IDI_APPLICATION);
- if(!RegisterClassEx(&wc)) {
- MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
- return 0;
- }
- hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass", "Example for Progress Bar & Thread",
- WS_VISIBLE|WS_OVERLAPPEDWINDOW,
- 100,
- 100,
- 640,
- 480,
- 0, 0, hInstance, 0);
- if(hWnd == NULL) {
- MessageBox(0, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
- return 0;
- }
- while(GetMessage(&Msg, 0, 0, 0) > 0) {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Add Comment
Please, Sign In to add comment