Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <windows.h>
- #include <stdio.h>
- #include <commctrl.h>
- #include <tchar.h>
- LRESULT WINAPI WndProc(HWND, UINT, WPARAM, LPARAM);
- long width;
- long height;
- HDC dc;
- HWND w;
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- char Istr[50];
- int global = 5;
- CRITICAL_SECTION sect1, sect2;
- static HWND hList1, hList2, hButton1, hButton2;
- DWORD WINAPI Thread1(LPVOID) {
- EnterCriticalSection(§1);
- for (int i = 0; i < 50; i++){
- wsprintf(Istr, L"%d", global);
- SendMessageA(hList1, LB_ADDSTRING, (WPARAM)0, (LPARAM)Istr);
- global++;
- }
- EnterCriticalSection(§2);
- LeaveCriticalSection(§2);
- LeaveCriticalSection(§1);
- return 0;
- }
- DWORD WINAPI Thread2(LPVOID) {
- EnterCriticalSection(§2);
- EnterCriticalSection(§1);
- for (int i = 0; i < 50; i++){
- wsprintf(Istr, L"%d", global);
- SendMessageA(hList2, LB_ADDSTRING, (WPARAM)0, (LPARAM)Istr);
- global++;
- }
- LeaveCriticalSection(§1);
- LeaveCriticalSection(§2);
- return 0;
- }
- int main(){
- HINSTANCE histance = GetModuleHandleW(NULL);
- WNDCLASSEX wclass = { 0 };
- wclass.cbSize = sizeof(WNDCLASSEX);
- wclass.style = CS_HREDRAW | CS_VREDRAW;
- wclass.lpfnWndProc = WndProc;
- wclass.cbClsExtra = 0;
- wclass.cbWndExtra = 0;
- wclass.hInstance = histance;
- wclass.hIcon = LoadIcon(0, IDI_APPLICATION);
- wclass.hCursor = LoadCursor(0, IDC_ARROW);
- wclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wclass.lpszMenuName = NULL;
- wclass.lpszClassName = "Test";
- RegisterClassEx(&wclass);
- w = CreateWindowExW(
- 0,
- L"Test",
- L"Form",
- WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 300,
- 350,
- 0,
- 0,
- histance,
- 0);
- ShowWindow(w, SW_SHOW);
- UpdateWindow(w);
- MSG msg = { 0 };
- while (GetMessage(&msg, 0, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
- PAINTSTRUCT MyPaint;
- HBRUSH Brush;
- HPEN Pen;
- HANDLE hThread1, hThread2;
- DWORD IDThread1, IDThread2;
- switch (msg) {
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_PAINT:
- break;
- case WM_CLOSE:
- break;
- case WM_CREATE:
- hList1 = CreateWindow(L"LISTBOX", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | LBS_STANDARD, 0, 30, 100, 200, hWnd, HMENU(NULL), NULL, NULL);
- hList2 = CreateWindow(L"LISTBOX", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | LBS_STANDARD, 105, 30, 100, 200, hWnd, HMENU(NULL), NULL, NULL);
- hButton1 = CreateWindow(L"BUTTON", L"Запустить", WS_VISIBLE | WS_CHILD, 0, 250, 110, 20, hWnd, HMENU(NULL), NULL, NULL);
- InitializeCriticalSection(§1);
- InitializeCriticalSection(§2);
- break;
- case WM_COMMAND:
- if (lParam == (LPARAM)hButton1) {
- hThread1 = CreateThread(NULL, 0, Thread1, NULL, 0, &IDThread1);
- hThread2 = CreateThread(NULL, 0, Thread2, NULL, 0, &IDThread2);
- }
- if (lParam == (LPARAM)hButton2) {
- LeaveCriticalSection(§2);
- }
- break;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement