Win32 API Process Creation Control

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.