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. Process

Process

Scheduled Pinned Locked Moved C / C++ / MFC
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.
  • S Offline
    S Offline
    sarfaraznawaz
    wrote on last edited by
    #1

    hi i am calling the video player exe in my application that will show preview for the user. now the problems is that i want to disable the child window or window untill this exe run.after completion of preview the window should enable .

    Here is my code :
    void CPreview::OnpreviewBtnClk()
    {
    ::MessageBox(m_hWnd,_T("here is the preview "),_T("INFORMATION"),MB_ICONINFORMATION);

    TCHAR szCmdline\[MAX\_PATH\];
    CString szWindowTitle = \_T("rs-mplayer");
    VERIFY(::GetModuleFileName(AfxGetApp()->m\_hInstance, szCmdline, \_MAX\_PATH));			
    szCmdline \[StrRChr (szCmdline, NULL, \_T('\\\\')) - szCmdline\] = \_T('\\0');
    \_tcscat\_s(szCmdline, \_T("\\\\rs-mplayer.exe /"));
    
    ShellExecute(NULL,\_T("open"),szCmdline,NULL,sourceFileName,SW\_SHOWNORMAL);
    

    // ProcessID = GetProcessId(szWindowTitle);

    Sleep(500);
    
    CWnd \*pOtherWnd = CWnd::FindWindow(NULL, szWindowTitle);
    h\_Rs\_playerProcessId  =pOtherWnd;
    
    if (pOtherWnd)
    {
    	//ProcessID = GetProcessId(pOtherWnd);
    	
    	MYDATA      m\_mydata;
    	wcscpy(m\_mydata.m\_pName,sourceFileName);
    	m\_mydata.m\_bNameLength = (BYTE)sourceFileName.GetLength();
    	m\_mydata.m\_ullNodeSize =   m\_li64FileSize.QuadPart;
    
    	COPYDATASTRUCT cpd;
    	cpd.dwData = 1;
    	cpd.cbData = sizeof(MYDATA);
    	cpd.lpData = (void\*)&m\_mydata;
    	//GetProcessTimes(h\_Rs\_playerProcessId,);
    
    	copyDataResult = pOtherWnd->SendMessage(WM\_COPYDATA,
    		(WPARAM)AfxGetApp()->m\_pMainWnd->GetSafeHwnd(),
    		(LPARAM)&cpd);
    
    } 
    ProcessID;
    
    
    // PreviewFile(szCmdline, sourceFileName, szWindowTitle,  m\_li64FileSize.QuadPart);
    

    }

    Please reply me soon got struct from past two days Best Regards sarfaraz

    C 1 Reply Last reply
    0
    • S sarfaraznawaz

      hi i am calling the video player exe in my application that will show preview for the user. now the problems is that i want to disable the child window or window untill this exe run.after completion of preview the window should enable .

      Here is my code :
      void CPreview::OnpreviewBtnClk()
      {
      ::MessageBox(m_hWnd,_T("here is the preview "),_T("INFORMATION"),MB_ICONINFORMATION);

      TCHAR szCmdline\[MAX\_PATH\];
      CString szWindowTitle = \_T("rs-mplayer");
      VERIFY(::GetModuleFileName(AfxGetApp()->m\_hInstance, szCmdline, \_MAX\_PATH));			
      szCmdline \[StrRChr (szCmdline, NULL, \_T('\\\\')) - szCmdline\] = \_T('\\0');
      \_tcscat\_s(szCmdline, \_T("\\\\rs-mplayer.exe /"));
      
      ShellExecute(NULL,\_T("open"),szCmdline,NULL,sourceFileName,SW\_SHOWNORMAL);
      

      // ProcessID = GetProcessId(szWindowTitle);

      Sleep(500);
      
      CWnd \*pOtherWnd = CWnd::FindWindow(NULL, szWindowTitle);
      h\_Rs\_playerProcessId  =pOtherWnd;
      
      if (pOtherWnd)
      {
      	//ProcessID = GetProcessId(pOtherWnd);
      	
      	MYDATA      m\_mydata;
      	wcscpy(m\_mydata.m\_pName,sourceFileName);
      	m\_mydata.m\_bNameLength = (BYTE)sourceFileName.GetLength();
      	m\_mydata.m\_ullNodeSize =   m\_li64FileSize.QuadPart;
      
      	COPYDATASTRUCT cpd;
      	cpd.dwData = 1;
      	cpd.cbData = sizeof(MYDATA);
      	cpd.lpData = (void\*)&m\_mydata;
      	//GetProcessTimes(h\_Rs\_playerProcessId,);
      
      	copyDataResult = pOtherWnd->SendMessage(WM\_COPYDATA,
      		(WPARAM)AfxGetApp()->m\_pMainWnd->GetSafeHwnd(),
      		(LPARAM)&cpd);
      
      } 
      ProcessID;
      
      
      // PreviewFile(szCmdline, sourceFileName, szWindowTitle,  m\_li64FileSize.QuadPart);
      

      }

      Please reply me soon got struct from past two days Best Regards sarfaraz

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      1. Instead of ShellExecute, use CreateProcess[^]. This will give you a handle to the process in the struct specified for lpProcessInformation. 2. Use EnableWindow[^] to disable whatever you wish to disable. 3. Run a timer with SetTimer[^], e.g. let it run every 5 seconds. 4. In the timer function, use WaitForSingleObject[^] with the handle of the process and a timeout of zero. When this gives you WAIT_OBJECT_0, it means that the process has exited. If it did not, do nothing special. 5. If the process DID exit (you got the event signalled in step 4), then kill the timer with KillTimer[^], use EnableWindow to re-enable what you need and don't forget to close the handles you got in that structure in step 1. Wouldn't this work for you?

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

      S 1 Reply Last reply
      0
      • C Code o mat

        1. Instead of ShellExecute, use CreateProcess[^]. This will give you a handle to the process in the struct specified for lpProcessInformation. 2. Use EnableWindow[^] to disable whatever you wish to disable. 3. Run a timer with SetTimer[^], e.g. let it run every 5 seconds. 4. In the timer function, use WaitForSingleObject[^] with the handle of the process and a timeout of zero. When this gives you WAIT_OBJECT_0, it means that the process has exited. If it did not, do nothing special. 5. If the process DID exit (you got the event signalled in step 4), then kill the timer with KillTimer[^], use EnableWindow to re-enable what you need and don't forget to close the handles you got in that structure in step 1. Wouldn't this work for you?

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

        S Offline
        S Offline
        sarfaraznawaz
        wrote on last edited by
        #3

        while(pOtherWnd!=0)
        {
        pOtherWnd = CWnd::FindWindow(NULL, szWindowTitle);
        //WaitForSingleObject(h_Rs_playerProcessId,INFINITE)
        CPreview::EnableWindow(FALSE);
        if(pOtherWnd == NULL)
        {
        CPreview::EnableWindow(TRUE);

                break;
            }
            sleepmode=5000;
            Sleep(sleepmode);
        

        } lang="c++"></

        i got the pOtherWnd is handle i set the timer sleepmode in sleep(sleepmode) its working fine after some time the window will strat not responding .. i have added the code with respect to the earlier code which i had posted . i tried with waitsingleobject by getting the handle og main window even though its not working help me out this Best Regards sarfaraz

        C 1 Reply Last reply
        0
        • S sarfaraznawaz

          while(pOtherWnd!=0)
          {
          pOtherWnd = CWnd::FindWindow(NULL, szWindowTitle);
          //WaitForSingleObject(h_Rs_playerProcessId,INFINITE)
          CPreview::EnableWindow(FALSE);
          if(pOtherWnd == NULL)
          {
          CPreview::EnableWindow(TRUE);

                  break;
              }
              sleepmode=5000;
              Sleep(sleepmode);
          

          } lang="c++"></

          i got the pOtherWnd is handle i set the timer sleepmode in sleep(sleepmode) its working fine after some time the window will strat not responding .. i have added the code with respect to the earlier code which i had posted . i tried with waitsingleobject by getting the handle og main window even though its not working help me out this Best Regards sarfaraz

          C Offline
          C Offline
          Code o mat
          wrote on last edited by
          #4

          Noone said you should use WaitForSingleObject with the window handle, of coure that doesn't work. And your aproach is wrong because while you are running this while loop -i assume you do this in the main GUI thread- your application is not processing any incoming messages, thus it will not respond.

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

          S 1 Reply Last reply
          0
          • C Code o mat

            Noone said you should use WaitForSingleObject with the window handle, of coure that doesn't work. And your aproach is wrong because while you are running this while loop -i assume you do this in the main GUI thread- your application is not processing any incoming messages, thus it will not respond.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

            S Offline
            S Offline
            sarfaraznawaz
            wrote on last edited by
            #5

            hey bro i got it .. i added ontimer msg to GUI thread. thanks to you for sharing your knowledge

            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