eHow launches Android app: Get the best of eHow on the go.

How To

How to Write a Multi Threaded Application in MFC

Contributor
By eHow Contributing Writer
(0 Ratings)

The smallest unit of code in an application is a thread. There may be several threads in a process within an application. This allows a user to multitask. The threads are done in an organizational manner that's operated by windows. Although the threads don't actually work simultaneously, they appear to as they are only 20 milliseconds apart.

Difficulty: Challenging
Instructions
  1. Step 1

    Log on to codesource.net and download the MFC application "Multithreaded_Animation.zip." Save it to the desktop and unzip it. Open the "Animate.dsw" file.

  2. Step 2

    Create a thread for the application in MFC. Associate a message handler for the menu and toolbar.

  3. Step 3

    Use the AFxBeginThread. This is located in the command handler.

  4. Step 4

    Pass the address of the thread function. This is the function where the unit of code that will be executed is written.

  5. Step 5

    Surpass the HWND of the parent application window through the GetSafeHwnd(). From here pass the priority of the thread as "THREAD_PRIORITY_NORMAL. Control shifts in meeting this statement to the portion of code within this function.

  6. Step 6

    Type the following code: CWINthread *pthread1; pthread1=AfxBeginThread(Thread1,GetSafeHwnd(),THREAD_PRIORITY_NORMAL); UINT Thread1(LPVOID Ip) { Meassagebox(?Thread In Execution?); }. This represents Steps 2 through 5 consolidated into the actual code.

  7. Step 7

    Animate the functions using the MFC application. Here you can program the threads to work simultaneously.

Tips & Warnings
  • The MFC application may stop responding when the application is initialized as a multi threaded apartment.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics