Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h>
- //#include "commctrl.h" // Этот файл я взял из MSVC 6.0
- HWND hTreeView;
- 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);
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- HTREEITEM InsTreeItem(HTREEITEM hParent, LPSTR szText,
- HTREEITEM hAfter, int iImage, int iSelectedImage)
- {
- TV_INSERTSTRUCT tvins;
- HTREEITEM hItem;
- memset(&tvins, 0, sizeof(tvins));
- tvins.item.mask = TVIF_TEXT | TVIF_IMAGE |
- TVIF_SELECTEDIMAGE | TVIF_PARAM;
- tvins.item.pszText = szText;
- tvins.item.cchTextMax = lstrlen(szText);
- tvins.item.iImage = iImage;
- tvins.item.iSelectedImage = iSelectedImage;
- tvins.hInsertAfter = hAfter;
- tvins.hParent = hParent;
- // hItem = TreeView_InsertItem(hwndTree, &tvins); // hTreeView
- hItem = TreeView_InsertItem(hTreeView, &tvins); // hTreeView
- return hItem;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) //
- {
- // static HWND hTreeView;
- switch(Message)
- {
- case WM_CREATE: SetTimer(hWnd, 1, 200, 0); // Создаём таймер №1, который срабатывает каждые 0.4 сек.
- HWND hPanel = CreateWindowEx(0, "STATIC", 0, // Создаем панель слева
- WS_CHILD | WS_VISIBLE | SS_BLACKFRAME,
- 0, 0, 200, 500, hWnd, NULL, NULL, NULL);
- hTreeView = CreateWindowEx(0, WC_TREEVIEW, NULL, // Создаем дерево
- WS_CHILD | WS_VISIBLE | TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS,
- 10, 10, 180, 480, hPanel, NULL, NULL, NULL);
- break; // Принимаем однократное сообщение для инициализации
- case WM_TIMER: switch(Timer_CLK ++)
- {
- case 5:
- hProgBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
- WS_CHILD | WS_VISIBLE | WS_BORDER,
- 325, 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;
- // INITCOMMONCONTROLSEX icc; // Инициализация Common Controls
- // icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
- 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); // (GRAY_BRUSH);
- 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,
- 800,
- 600,
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement