For the control progress bar:
Create a global structure threadinfo to store the information of the progress bar object.
Typedef struct threadinfo
{
Cprogressctrl * progress; // progress bar object
Int speed; // progress bar speed
Int Pos; // progress bar position
}
This is convenient to use.
Start the process,
(1) create a Process Handle
Handle hthread; // thread handle
(2) define the global thread entry function, which is a callback function.
DWORD winapi threadfun (lpvoid pthread)
{
Lpthread temp = (lpthread) pthread; // progress bar structure
Temp-> progress-> setpos (temp-> POS );
While (temp-> POS <20)
{
Sleep (temp-> speed); // you can specify the speed.
Temp-> POS ++; // increase the progress
Temp-> progress-> setpos (temp-> POS); // you can specify a new position for the progress bar.
If (temp-> Pos = 20)
{
Temp-> Pos = 0; // 0 if the progress bar is full
}
}
Return true;
}
(3) Use the API function createthread to create a thread, use the API function terminatethread to terminate the thread, and destroy the thread handle.
If (! Getexitcodethread (hthread1, & code) | (code! = Still_active ))
{
Hthread1 = createthread (null, 0, threadfun, & thread1, 0, & threadid );
// Create and start a thread
}
At this time, the thread has been created and the thread function is running.
If (getexitcodethread (hthread1, & Code) // if the current thread is active
{
If (code = still_active)
{
Terminatethread (hthread1, 0 );
// Terminate the thread
Closehandle (hthread1); // destroy the thread handle
M_progress.setpos (0 );
}
}
Key Points
Createthread: Create a new process and return the existing process handle.
Suspendthread: Used to suspend a specified thread and terminate the thread execution.
Resumethread: reduces the number of pending processes by 1.
Exitthread: The operation that the thread itself terminates.
Terminatethread: the operation of forcibly terminating a process.
Getthreadpriority: gets the priority of a process.
Setthreadpriority: Set the relative priority of a process.
Postthreadmessage: used to publish a message to the thread, which puts the message in the specified message queue and returns it immediately.