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. 2 Process at a time in Win 32 App

2 Process at a time in Win 32 App

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestiontutorial
9 Posts 3 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.
  • S Offline
    S Offline
    Suresh H
    wrote on last edited by
    #1

    Hello All, I have a timer in my dialog which starts in the function and some process is done and I have called the stop timer as below. working code:- int OnStart(HWND hwnd) { // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return 0; } Now the problem is timer clock is not displayed on the dialog, once the process is over the timer is displayed. Can one please tell me how to do 2 process at a time ??? displaying the timer clock on the dialog and doing the process ?? I tried with thread as below its not working what is the error ?? what changes I have to make to thread ?? int OnStart(HWND hwnd) { HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,0,0,0); return 0; } // Declaration UINT WorkerThreadProc(LPVOID Param); UINT WorkerThreadProc(LPVOID Param) { HWND hwnd; IMyA *pA; // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return true; } Thanking you, Suresh HC.

    N 1 Reply Last reply
    0
    • S Suresh H

      Hello All, I have a timer in my dialog which starts in the function and some process is done and I have called the stop timer as below. working code:- int OnStart(HWND hwnd) { // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return 0; } Now the problem is timer clock is not displayed on the dialog, once the process is over the timer is displayed. Can one please tell me how to do 2 process at a time ??? displaying the timer clock on the dialog and doing the process ?? I tried with thread as below its not working what is the error ?? what changes I have to make to thread ?? int OnStart(HWND hwnd) { HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,0,0,0); return 0; } // Declaration UINT WorkerThreadProc(LPVOID Param); UINT WorkerThreadProc(LPVOID Param) { HWND hwnd; IMyA *pA; // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return true; } Thanking you, Suresh HC.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Suresh H wrote:

      SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);

      how did u get the handle hwnd in the thread function? As per your code its not valid handle. You need to pass this handle to the WorkerThreadProc from the OnStart function. Modify it as below int OnStart(HWND hwnd) { HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,(LPVOID)hwnd,0,0); return 0; } UINT WorkerThreadProc(LPVOID Param) { HWND hwnd = (HWND)Param; IMyA *pA; // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return true; }

      nave

      S 2 Replies Last reply
      0
      • N Naveen

        Suresh H wrote:

        SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);

        how did u get the handle hwnd in the thread function? As per your code its not valid handle. You need to pass this handle to the WorkerThreadProc from the OnStart function. Modify it as below int OnStart(HWND hwnd) { HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,(LPVOID)hwnd,0,0); return 0; } UINT WorkerThreadProc(LPVOID Param) { HWND hwnd = (HWND)Param; IMyA *pA; // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return true; }

        nave

        S Offline
        S Offline
        Suresh H
        wrote on last edited by
        #3

        Hi Naveen, Thank you very much now the thread function is working & the timer is also displayed along with process. I forgot to pass the HWND from onStart function. Thank you very much,:) Suresh HC.

        1 Reply Last reply
        0
        • N Naveen

          Suresh H wrote:

          SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL);

          how did u get the handle hwnd in the thread function? As per your code its not valid handle. You need to pass this handle to the WorkerThreadProc from the OnStart function. Modify it as below int OnStart(HWND hwnd) { HANDLE hr; hr = CreateThread(NULL,0,(unsigned long (__stdcall *)(void *))WorkerThreadProc,(LPVOID)hwnd,0,0); return 0; } UINT WorkerThreadProc(LPVOID Param) { HWND hwnd = (HWND)Param; IMyA *pA; // Start the timer dwLastTickCount = GetTickCount(); SetTimer(hwnd, ID_ELASPED_TIMER, 25, NULL); pA->start(); KillTimer(hwnd, ID_ELASPED_TIMER); return true; }

          nave

          S Offline
          S Offline
          Suresh H
          wrote on last edited by
          #4

          hi Naveen, I am getting some problem with the handle HWND & hwnd. in thread i am trying to extract the Edit box contents but i am getting the junk values, why i am getting the junk values ?? what is wrong in the code ??? same code was working in the OnStart function, when I moved it to thread is not working what is cause ??? UINT WorkerThreadProc(LPVOID Param) { HWND hwnd = (HWND)Param; char *FName = new char[20]; HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME); SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName); } output :- ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ

          N 1 Reply Last reply
          0
          • S Suresh H

            hi Naveen, I am getting some problem with the handle HWND & hwnd. in thread i am trying to extract the Edit box contents but i am getting the junk values, why i am getting the junk values ?? what is wrong in the code ??? same code was working in the OnStart function, when I moved it to thread is not working what is cause ??? UINT WorkerThreadProc(LPVOID Param) { HWND hwnd = (HWND)Param; char *FName = new char[20]; HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME); SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName); } output :- ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            Suresh H wrote:

            SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);

            MSDN says lParam: Pointer to the buffer that receives a copy of the line. Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line. so u should set the first 2 byte of buffer as size of the array. char *FName = new char[20]; WORD* pWord = (WORD*)FName; *pWord = 20; HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME); SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);] if the edit control is a single line edit I suggest you to use GetWindowText() function.

            nave

            S 1 Reply Last reply
            0
            • N Naveen

              Suresh H wrote:

              SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);

              MSDN says lParam: Pointer to the buffer that receives a copy of the line. Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer. For ANSI text, this is the number of bytes; for Unicode text, this is the number of characters. The size in the first word is overwritten by the copied line. so u should set the first 2 byte of buffer as size of the array. char *FName = new char[20]; WORD* pWord = (WORD*)FName; *pWord = 20; HWND HEFName = GetDlgItem(hwnd, IDC_FILE_NAME); SendMessage(HEFName , EM_GETLINE, 0 ,(LPARAM)FName);] if the edit control is a single line edit I suggest you to use GetWindowText() function.

              nave

              S Offline
              S Offline
              Suresh H
              wrote on last edited by
              #6

              Hi Naveen, Once again thank you very much for the response. Now i am getting the values properly. Thank you very much for explanation its very use full. I had used the same code in the OnStart() and it was working properly ,but how ??

              N 1 Reply Last reply
              0
              • S Suresh H

                Hi Naveen, Once again thank you very much for the response. Now i am getting the values properly. Thank you very much for explanation its very use full. I had used the same code in the OnStart() and it was working properly ,but how ??

                N Offline
                N Offline
                Naveen
                wrote on last edited by
                #7

                Suresh H wrote:

                and it was working properly ,but how ??

                may be because the following reason. When you new some data, the memory allocated contains some junk values. when you call the function from OnStart(), the first two byte might had some valid positive values. Then there is a chance for that function to work properly. Just a guess :)

                nave

                S 1 Reply Last reply
                0
                • N Naveen

                  Suresh H wrote:

                  and it was working properly ,but how ??

                  may be because the following reason. When you new some data, the memory allocated contains some junk values. when you call the function from OnStart(), the first two byte might had some valid positive values. Then there is a chance for that function to work properly. Just a guess :)

                  nave

                  S Offline
                  S Offline
                  Suresh H
                  wrote on last edited by
                  #8

                  Thanks Naveen for the response.:)

                  S 1 Reply Last reply
                  0
                  • S Suresh H

                    Thanks Naveen for the response.:)

                    S Offline
                    S Offline
                    S Douglas
                    wrote on last edited by
                    #9

                    In addition to what Naveen said, read this article on creating and dealing with worker threads ->Using Worker Threads[^] There is a sub topic "Worker threads and the GUI II: Don't touch the GUI" that specifically spells out to not to let other threads touch the UI and why its bad. Best of luck.


                    I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:

                    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