avi file on Status bar
-
I am trying to play a AVI file on status bar indicating the progress for the lengthy operation. I am doing this in a button click event. it is working fine if no statements are there below the call and, if there are statements below the avi start.. the avi is not playing on status bar. I tryed with thread, but of no use. void TestPb::OnButton1() { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); pFrame->StartAnimation( IDR_AVITEST ,1); whie(1)//Say length process.... If i comment while(1) .. avi is playing on mainfram status bar {} }
-
I am trying to play a AVI file on status bar indicating the progress for the lengthy operation. I am doing this in a button click event. it is working fine if no statements are there below the call and, if there are statements below the avi start.. the avi is not playing on status bar. I tryed with thread, but of no use. void TestPb::OnButton1() { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); pFrame->StartAnimation( IDR_AVITEST ,1); whie(1)//Say length process.... If i comment while(1) .. avi is playing on mainfram status bar {} }
you should move the portion of code playing the AVI in its own thread... and start the thread on the trigger of your choice.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
I am trying to play a AVI file on status bar indicating the progress for the lengthy operation. I am doing this in a button click event. it is working fine if no statements are there below the call and, if there are statements below the avi start.. the avi is not playing on status bar. I tryed with thread, but of no use. void TestPb::OnButton1() { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); pFrame->StartAnimation( IDR_AVITEST ,1); whie(1)//Say length process.... If i comment while(1) .. avi is playing on mainfram status bar {} }
while (1); not only stops avi to play, but the complete UI on the GUI thread will stop working.
-
while (1); not only stops avi to play, but the complete UI on the GUI thread will stop working.
well, Yes true just i mentioned to as a length process Thanks u I want to paly the avi on the mainfram status bar and start some lenthly process, while still the avi is playing... pls advice
-
you should move the portion of code playing the AVI in its own thread... and start the thread on the trigger of your choice.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
I tried placing in threaed but failed
-
well, Yes true just i mentioned to as a length process Thanks u I want to paly the avi on the mainfram status bar and start some lenthly process, while still the avi is playing... pls advice
ptr_Electron wrote:
well, Yes true just i mentioned to as a length process Thanks u I want to paly the avi on the mainfram status bar and start some lenthly process, while still the avi is playing... pls advice
I would run the lengthy operation in a background thread. Nathan
-
I tried placing in threaed but failed
-
you should move the portion of code playing the AVI in its own thread... and start the thread on the trigger of your choice.
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Hi, Its hard to give you advice without seeing what type of 'processing' you are doing. You should avoid drawing on a window from a separate thread if at all possible. You may be able to simply pump the message que and move the AVI-frame painting into OnPaint. In the while loop you can probably add:
while(somecondition) { MSG oMSG; while(::PeekMessage(&oMSG, NULL, 0, 0, PM_NOREMOVE)) { if(::GetMessage(&oMSG, NULL, 0, 0)) { ::TranslateMessage(&oMSG); ::DispatchMessage(&oMSG); } else { break; } } //Your processing code goes here //Hopefully the work is done in chunks and continues to the top of the loop. } pre>
This will allow the dialog to process WM_PAINT messages normally. -
Hi, Its hard to give you advice without seeing what type of 'processing' you are doing. You should avoid drawing on a window from a separate thread if at all possible. You may be able to simply pump the message que and move the AVI-frame painting into OnPaint. In the while loop you can probably add:
while(somecondition) { MSG oMSG; while(::PeekMessage(&oMSG, NULL, 0, 0, PM_NOREMOVE)) { if(::GetMessage(&oMSG, NULL, 0, 0)) { ::TranslateMessage(&oMSG); ::DispatchMessage(&oMSG); } else { break; } } //Your processing code goes here //Hopefully the work is done in chunks and continues to the top of the loop. } pre>
This will allow the dialog to process WM_PAINT messages normally. -
Hi, Its hard to give you advice without seeing what type of 'processing' you are doing. You should avoid drawing on a window from a separate thread if at all possible. You may be able to simply pump the message que and move the AVI-frame painting into OnPaint. In the while loop you can probably add:
while(somecondition) { MSG oMSG; while(::PeekMessage(&oMSG, NULL, 0, 0, PM_NOREMOVE)) { if(::GetMessage(&oMSG, NULL, 0, 0)) { ::TranslateMessage(&oMSG); ::DispatchMessage(&oMSG); } else { break; } } //Your processing code goes here //Hopefully the work is done in chunks and continues to the top of the loop. } pre>
This will allow the dialog to process WM_PAINT messages normally.Thanks you very much, for your help, what I am trying to do is extrading 1000's of records from database. since it takes quite some time I want play the avi file on the status bar of main frame, but the call will be made from the dialg. say on button click event we are extracting records form DB and need progress on the status bar, but does not work... void TestPb::OnButton1() { thpbar=AfxBeginThread(thPrgbar,THREAD_PRIORITY_NORMAL,0,0,NULL); //Get 1000's records from DB ..verytime consumming process... } UINT TestPb::thPrgbar( LPVOID pParam ) { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); pFrame->StartAnimation( IDR_AVITEST ,1); return (1); } void CMainFrame::StartAnimation( UINT id, int nPane /*=1*/ ) { StopAnimation(); m_pAnimate = new CStatusbarAnimate; m_pAnimate->Create(id, nPane); } void CMainFrame::StopAnimation() { delete m_pAnimate; m_pAnimate = NULL; } bool CMainFrame::IsAnimationActive() { return (m_pAnimate != NULL); } // needed to ensure original text not visible void CMainFrame::OnUpdateAnimate(CCmdUI* pCmdUI) { pCmdUI->SetText(_T("")); }
-
Thanks you very much, for your help, what I am trying to do is extrading 1000's of records from database. since it takes quite some time I want play the avi file on the status bar of main frame, but the call will be made from the dialg. say on button click event we are extracting records form DB and need progress on the status bar, but does not work... void TestPb::OnButton1() { thpbar=AfxBeginThread(thPrgbar,THREAD_PRIORITY_NORMAL,0,0,NULL); //Get 1000's records from DB ..verytime consumming process... } UINT TestPb::thPrgbar( LPVOID pParam ) { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); pFrame->StartAnimation( IDR_AVITEST ,1); return (1); } void CMainFrame::StartAnimation( UINT id, int nPane /*=1*/ ) { StopAnimation(); m_pAnimate = new CStatusbarAnimate; m_pAnimate->Create(id, nPane); } void CMainFrame::StopAnimation() { delete m_pAnimate; m_pAnimate = NULL; } bool CMainFrame::IsAnimationActive() { return (m_pAnimate != NULL); } // needed to ensure original text not visible void CMainFrame::OnUpdateAnimate(CCmdUI* pCmdUI) { pCmdUI->SetText(_T("")); }
Perhaps you should move to a message based inter-thread communication. You can even pass the percentage of completion. Try something like this:
#define WM_START_ANIMATION WM_USER + 0x8 #define WM_INC_PROGRESS WM_USER + 0x10 void TestPb::OnButton1() { thpbar=AfxBeginThread(thPrgbar,THREAD_PRIORITY_NORMAL,0,0,NULL); } UINT TestPb::thPrgbar( LPVOID pParam ) { CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd(); ::PostMessage(pFrame->GetSafeHwnd(),WM_START_ANIMATION,IDR_AVITEST,1); int iCount; int iPosition =0; //Get count(*) from SQL DB and save into iCount; // for each record in DB while(reading DB) { // get 1 record int iPercent = iCount * (iPosition / 100.0); ::PostMessage(pFrame->GetSafeHwnd(),WM_INC_PROGRESS,(WPARAM)iPercent,0); ++iPosition; } //end if return (1); } void CMainFrame::OnStartAnimation( WPARAM id, WPARAM nPane /*=1*/ ) { StopAnimation(); m_pAnimate = new CStatusbarAnimate; m_pAnimate->Create(id, nPane); } void CMainFrame::StopAnimation() { if(IsAnimationActive()) { delete m_pAnimate; m_pAnimate = NULL; } } bool CMainFrame::IsAnimationActive() { return (m_pAnimate != NULL); } // needed to ensure original text not visible void CMainFrame::OnUpdateAnimate(CCmdUI* pCmdUI) { pCmdUI->SetText(_T("")); } Add the following to your CMainFrame /////// // ADD INTO YOUR CMainFrame HEADER FILE: /////// afx_msg LRESULT OnMyProgress(WPARAM wParam, LPARAM lParam); ////////// // ADD INTO YOUR CMainFrame MESSAGE MAP ///////// ON_MESSAGE(WM_INC_PROGRESS,OnMyProgress) ON_MESSAGE(WM_START_ANIMATION,OnStartAnimation) ////////// // ADD INTO YOUR CMainFrame CPP file ///////// LRESULT void CMainFrame::OnMyProgress(WPARAM wParam, LPARAM lParam) { int iPercent = (int)wParam; if(100 == iPercent && IsAnimationActive()) { StopAnimation(); } else { // Update visuals here perhaps to reflect percentage of completion }