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. Maintaining program control while in a loop...

Maintaining program control while in a loop...

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
5 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.
  • A Offline
    A Offline
    aquawicket
    wrote on last edited by
    #1

    Hi I'm currently trying to code a REAL-TIME midi remapper program in Visual C++ using MFC.. I need the program to constantly look for a input midi signal... The only way I have figured out how to do this is to run a constant loop that contains the midipoll(); I've had to set it to only recieve a certain number of signals so it will eventually end. I works great and recieves all of the messages.. but while in this loop I loose control of the rest of the program... The loop takes over. Is their a way I can do this without loosing control of the program?

    B 1 Reply Last reply
    0
    • A aquawicket

      Hi I'm currently trying to code a REAL-TIME midi remapper program in Visual C++ using MFC.. I need the program to constantly look for a input midi signal... The only way I have figured out how to do this is to run a constant loop that contains the midipoll(); I've had to set it to only recieve a certain number of signals so it will eventually end. I works great and recieves all of the messages.. but while in this loop I loose control of the rest of the program... The loop takes over. Is their a way I can do this without loosing control of the program?

      B Offline
      B Offline
      Blake Miller
      wrote on last edited by
      #2

      Put that processing into a secondary thread. People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

      A 1 Reply Last reply
      0
      • B Blake Miller

        Put that processing into a secondary thread. People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

        A Offline
        A Offline
        aquawicket
        wrote on last edited by
        #3

        Thanks.. that worked out great using a work thread... Now i'm having a problem accessing the UI from within the thread.. ie. a listbox I need to send info to the listbox from within the thread.. Any Ideas this is what I got... UINT MyThread( LPVOID pParam ); //prototye UINT MyThread( LPVOID pParam ) { while(RunThread) { If (inputdetected){ m_ListBox1.Additem("input detected"); // <-- I don't have access to ListBox 1 from withing this thread. } } return 0; // thread completed successfully } I call the thread to start with.. AfxBeginThread(MyThread, NULL); -- modified at 15:50 Thursday 6th April, 2006

        B 1 Reply Last reply
        0
        • A aquawicket

          Thanks.. that worked out great using a work thread... Now i'm having a problem accessing the UI from within the thread.. ie. a listbox I need to send info to the listbox from within the thread.. Any Ideas this is what I got... UINT MyThread( LPVOID pParam ); //prototye UINT MyThread( LPVOID pParam ) { while(RunThread) { If (inputdetected){ m_ListBox1.Additem("input detected"); // <-- I don't have access to ListBox 1 from withing this thread. } } return 0; // thread completed successfully } I call the thread to start with.. AfxBeginThread(MyThread, NULL); -- modified at 15:50 Thursday 6th April, 2006

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          You can not use the MFC control placeholders from the thread. Instead, it is better to use the listbox control's window handle directly to add elements to the listbox. The LPVOID pParam passed to thread could be a data structure, in that data structure, one of the fields could be the window handle for the list box control. So you call typedef struct { HWND hListBox; } MYSTRUCT ; MYSTRUCT MyThreadInfo; MyThreadInfo.hListbox = m_ListBox1.m_hWnd; then AfxBeginThread(MyThread, &MyThreadInfo); UINT MyThread( LPVOID pParam ) { MYSTRUCT* pMyThreadInfo = (MYSTRUCT*)pParam; while( RunThread ){ if( inputdetected ){ SendMessage(pMyThreadInfo->hListbox, LB_ADDSTRING, 0, (LPARAM)"input detected"); } } return 0; // thread completed successfully } People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

          A 1 Reply Last reply
          0
          • B Blake Miller

            You can not use the MFC control placeholders from the thread. Instead, it is better to use the listbox control's window handle directly to add elements to the listbox. The LPVOID pParam passed to thread could be a data structure, in that data structure, one of the fields could be the window handle for the list box control. So you call typedef struct { HWND hListBox; } MYSTRUCT ; MYSTRUCT MyThreadInfo; MyThreadInfo.hListbox = m_ListBox1.m_hWnd; then AfxBeginThread(MyThread, &MyThreadInfo); UINT MyThread( LPVOID pParam ) { MYSTRUCT* pMyThreadInfo = (MYSTRUCT*)pParam; while( RunThread ){ if( inputdetected ){ SendMessage(pMyThreadInfo->hListbox, LB_ADDSTRING, 0, (LPARAM)"input detected"); } } return 0; // thread completed successfully } People that start writing code immediately are programmers (or hackers), people that ask questions first are Software Engineers - Graham Shanks

            A Offline
            A Offline
            aquawicket
            wrote on last edited by
            #5

            AWSOME!!!!! everything works perfectly using this method... Thanks Blake ;)

            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