There is a program, a Windows-32 project written in WinAPI + C ++. By clicking on a button, in a window procedure, a function is called that performs some massive amount of computation. It is necessary to ensure that the GUI of the program does not “hang” during the execution of these calculations. How to do it better?
- 2Through the stream - Kyulix
- 2ONLY flows! - Salivan 4:14 pm
- 3Create a separate thread for a function with calculations. - ivan milyutkin
- 2Only through the stream! - Costantino Rupert
- 2Through the stream! - Costantino Rupert
|
1 answer
An example of calling a thread on the Windows API. For a GUI application, you must also do the same by taking a lengthy operation from a GUI stream to a separate stream.
#include <windows.h> #include <tchar.h> #include <strsafe.h> DWORD WINAPI MyThreadFunction(LPVOID lpParam); typedef struct MyData { int value; } MYDATA, * PMYDATA; int _tmain() { PMYDATA pMyData = (PMYDATA) HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MYDATA)); f(pMyData == NULL) { ExitProcess(1); } HANDLE handle = CreateThread( NULL, 0, MyThreadFunction, pMyData, 0, 0); if (handle == NULL) { ExitProcess(2); } WaitForSingleObject(handle, INFINITE); CloseHandle(handle); if (pMyData != NULL) { HeapFree(GetProcessHeap(), 0, pMyData); pMyData = NULL; } return 0; } DWORD WINAPI MyThreadFunction(LPVOID lpParam) { PMYDATA pMyData = (PMYDATA) lpParam; // TODO: Сделать что-либо с данными pMyData return 0; }
- 2Actually, the question was, not how to make the flow. Here should be an example of launching an interactive stream and its interaction with the main stream from the window procedure. - mega
|