Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to stop a process using a "Stop Button"
    primarykey
    data
    text
    <p>I created a simple window with two buttons, the first one calls a function that lasts a long time, the second one sets the value of a variable "stop" to TRUE, that was initially set to FALSE.</p> <p>My intention is that, by pressing the first button it runs a long process, that controls if the stop variable is set to TRUE or FALSE for every loop, if the value is TRUE the function should return, so the process is stopped.</p> <pre><code>... static BOOL stop = FALSE; // My variable defined somewhere ... int longProcess () // My function { while(stop == FALSE) { // do something } return 0; } ... switch (msg) { case WM_CREATE: { ... Button1 = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Start"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100, 100, 20, hWnd, (HMENU)BUTTON_START, NULL, NULL); Button2 = CreateWindowEx(0, TEXT("BUTTON"), TEXT("Stop"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 200, 200, 100, 20, hWnd, (HMENU)BUTTON_STOP, NULL, NULL); ... } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case BUTTON_START: longProcess(); // Starts the process break; case BUTTON_STOP: stop = TRUE; // Should stop the process break; } } break; ... } </code></pre> <p>}</p> <p>The problem is that when I press the first button the process starts normally, but when I press the second button in order to stop the process nothing happens, I noticed that the stop variable is set to TRUE only after the end of the process. I thought that probably in a problem related to the message queue...</p> <p>What could be the best solution??? It is correct to call longProcess() there and in that way? (I'am a newbie :) )</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload