Stop button doesnt stop a function (using PostMessage)
I'm trying to make a function that will scan through the files that are in a directory of the users choice to search for a certain file. However, the stop button I tried to make doesn't actually work. It's not even possible to do anything while it's searching, including closing the program. I'm using PostMessage() to go through the process one file at a time, hoping that after each file the user could have the option to stop it. Unlike having SendMessage where the user definitely cannot do anything until it's finished. Is there a different route to take so I can stop it in mid search?
Here is what I think is causing the problem.
EDIT: just tried using Sleep(500) and it still has the same problem. I clicked the stop button really fast hoping I'd catch it, but nothing. I also can't regain focus of the window.
//update what the user sees
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Scanning..");
percent = 100*(sofar/total); //get the total percent
itoa(percent,Percent,10); //change the integer percent to string
strcat(Percent,"%"); //add percent sign to percentage
char OverAll[MAX_PATH] = "Progress: "; //reset the overall progress
strcat(OverAll,Percent); //set overall percentage
SendMessage(hStatus, SB_SETTEXT, 1, (LPARAM)OverAll); //display overall percentage
PostMessage(Hwnd,WM_COMMAND,SCAN,0); //repeat the process