How to convert member function to a thread

Hi,

I would like to know how to convert a member function in a class to a thread.My application is made in "Win32 Application" and here is my program format:


#include <stdafx.h>
#include <afxcmn.h>
#include <process.h>
#include "resource.h"
#include "stdio.h"
#include "stdlib.h"



// 'ABOUT' DIALOG BOX

class aboutdialog : public CDialog
{
public:

      aboutdialog(int n) : CDialog(n)
      {
      }

      void OnOK()
      {
            CDialog :: OnOK();
      }
};




class myframe : public CFrameWnd
{
private:

      CString mainwindow;
      CMenu menu;
      CListCtrl tablist;
      HBRUSH bckcolorbrush;


public:
      
      myframe()
      {
            bckcolorbrush = (HBRUSH)::GetStockObject(LTGRAY_BRUSH);

            mainwindow = AfxRegisterWndClass (CS_HREDRAW|CS_VREDRAW,0,bckcolorbrush,0);

            Create (mainwindow, "Packet Sniffer");
      }




// MESSAGE HANDLERS

      int OnCreate (LPCREATESTRUCT l)
      {
            CFrameWnd :: OnCreate (l);


//here i write code for message handler for MENUS and  LIST CONTROLS


            return 0;
      }




// MENU FUNCTIONS

      void open()
      {
            MessageBox ("Code for Open Frame", "Open Frame");
      }

      void save()
      {
            MessageBox ("Code for Save Frame", "Save Frame");
      }

      void exit()
      {
            _exit(0);
      }

                void display()
                {
           
                             MessageBox ("Code for Display", "Display");

                }


      void about()
      {
            aboutdialog d (IDD_DIALOGBAR1);
            d.DoModal();
      }

      DECLARE_MESSAGE_MAP()
};



BEGIN_MESSAGE_MAP (myframe, CFrameWnd)

ON_WM_CREATE()

ON_COMMAND (101, open)
ON_COMMAND (102, save)      //here i write all the message maps
ON_COMMAND (103, exit)                //for menus and sub menus
ON_COMMAND (501, about)


END_MESSAGE_MAP()




class myapp : public CWinApp
{
public:
      int InitInstance()
      {
            myframe *p;
            p=new myframe;
            p->ShowWindow(3);
            m_pMainWnd = p;

            return 1;
      }
};

myapp a;


//END OF PROGRAM



Now I would to convert the function display into a thread.Can any one tell me what code i should add to convert this member function to thread preferably a workers thread.


Thanks

Jejo
jejob007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mahesh1402IT ProfessionalCommented:
refer this sample :

http://www.codeproject.com/threads/memberthread.asp <====

MAHESH
mahesh1402IT ProfessionalCommented:
//declare display function like following in header :
static UINT display(LPVOID param);

typedef struct THREADSTRUCT
{
    myframe*    _this;
        //you can add here other parameters you might be interested on
} THREADSTRUCT;


// function imple.
UINT display(LPVOID param)
                {
                           THREADSTRUCT*    ts = (THREADSTRUCT*)param;
                             MessageBox ("Code for Display", "Display");

                }


//Now call the thread on a button action or menu
    THREADSTRUCT *_param = new THREADSTRUCT;
    _param->_this = this;
    AfxBeginThread (display, _param);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jejob007Author Commented:
Hi,

Thanks mahesh1402 for ur valuable post.My thread is working properly.I have another problem I hope u can solve that too.

How do I split the main frame into two parts - top and bottom with the above code format.I tried to use the CSplitterWnd class but it is not working.Iam a newbie in this topic of MFC.

Hope u could help me.

Thanks

Jejo
mahesh1402IT ProfessionalCommented:
jejob007
Is this relavent question with your original query ? anyways You can use CSplitterWnd::CreateView() function for this.

MAHESH
jejob007Author Commented:
Hi

Yes it is a relevat question with the original query.I would like to know what code to add to split the window or changes I need to make for the existing one.Should I change the entire frame class.

Please help.

Thanks

Jejo

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.