Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. AfxbeginThread

AfxbeginThread

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    meirav
    wrote on last edited by
    #1

    In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function . I need that the specific class that was created will get access to another class ( the main Dlg class)???? (i tried to use pointer but no good !) meirav

    C M 2 Replies Last reply
    0
    • M meirav

      In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function . I need that the specific class that was created will get access to another class ( the main Dlg class)???? (i tried to use pointer but no good !) meirav

      C Offline
      C Offline
      Chaos Lawful
      wrote on last edited by
      #2

      You should not pass dialog pointer to the thread because it may be invalid. I think you can use GetSafeHwnd() to get the handle of the main dialog and pass it to the thread. In the thread you can use FromHandle() to get back the main dialog pointer and then you can access the main dialog class. Here is an example: UINT ThreadProc(LPVOID);// the thread proc HWND hWnd; // for handle of main dialog BOOL C???Dlg::OnInitDialog() { ...// some codes hWnd=GetSafeHwnd(); ...// other codes } void C???Dlg::OnButton1() // Button1 is a sample button { AfxBeginThread(ThreadProc,NULL); } UINT ThreadProc(LPVOID lpData) { C???Dlg *pDlg=(C???Dlg*)C???Dlg::FromHandle(hWnd); // get the main dlg pointer ...// do what you want to do } You can also pass the handle through the thread proc's lpData pointer, then you don't have to declare the hWnd as a external variable.:) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.

      1 Reply Last reply
      0
      • M meirav

        In an Mfc programm ( dialog based) i created a thread through the AfxBeginThread function . I need that the specific class that was created will get access to another class ( the main Dlg class)???? (i tried to use pointer but no good !) meirav

        M Offline
        M Offline
        meirav
        wrote on last edited by
        #3

        Thank you for your answer, i tried what you suggest me , but there is one problem: when i pass the LPVOID to the ThreadProc (I did it on ThreadProc::InitInstance) using the debug i saw that he never get at all to this Function . (without the LPVOID it did get there ) it will be a great help if you can help me.

        C 1 Reply Last reply
        0
        • M meirav

          Thank you for your answer, i tried what you suggest me , but there is one problem: when i pass the LPVOID to the ThreadProc (I did it on ThreadProc::InitInstance) using the debug i saw that he never get at all to this Function . (without the LPVOID it did get there ) it will be a great help if you can help me.

          C Offline
          C Offline
          Chaos Lawful
          wrote on last edited by
          #4

          Could you show me your codes? I think that would be a great help.;) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.

          M 1 Reply Last reply
          0
          • C Chaos Lawful

            Could you show me your codes? I think that would be a great help.;) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.

            M Offline
            M Offline
            meirav
            wrote on last edited by
            #5

            Hi,I did exacly the code you suggested in your reply above. I can send the programm i did (it is very short ) if it is needed.

            C 1 Reply Last reply
            0
            • M meirav

              Hi,I did exacly the code you suggested in your reply above. I can send the programm i did (it is very short ) if it is needed.

              C Offline
              C Offline
              Chaos Lawful
              wrote on last edited by
              #6

              OK, you can either paste it or send it to my mailbox.:) Law is meaningless without chaos. Chaos without Law is equal to destruction. Chaos and Law create our rich and colorful world.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups