winapi - How to show the progressbar using threading functionality in win32? -
in application have simple module read files process take few seconds..so thought of displaying progress bar(using worker thread) while files in progress.i have created thread (code shown below) , designed dialog window progress control.i used function mythreadfunction below display progressbar shows 1 time , disappears,i not sure how make work.i tried best inspite of fact new threading.please me friends.
reading files void readmyfiles() { for(int = 0; < filecount ; filecount++) { cwinthread* mythread = afxbeginthread((afx_threadproc)mythreadfunction,null); tempstate = *(checkstate + index); if(tempcheckstate == nocheckbox) { //my operations } else//checked or unchecked { //myoperation } mythread->postthreadmessage(wm_quit,null,null); } } thread functions uint mythreadfunction(lparam lparam) { hwnd dialogwnd = createwindowex(0,wc_dialog,l"proccessing...",ws_overlappedwindow|ws_visible, 600,300,280,120,null,null,null,null); hwnd pbarwnd = createwindowex(null,progress_class,null,ws_child|ws_visible|pbs_marquee,40,20,200,20, dialogwnd,(hmenu)idd_progress,null,null); msg msg; postmessage( pbarwnd, pbm_setrange, 0, makelparam( 0, 100 ) ); postmessage(pbarwnd,pbm_setpos,0,0); while(peekmessage(&msg,null,null,null,pm_noremove)) { if(msg.message == wm_quit) { destroywindow(dialogwnd); return 1; } afxgetthread()->pumpmessage(); sleep(40); } return 1; }
turn around , put blocking behavior in worker thread.
its common mistake, not worth creating multiple gui threads in single process.
window messages posted thread queues :- means that, @ point, child, or popup window, going try , communicate blocked window on thread. if user unexpectedly trying resize or move popup window - means both windows again blocked on time consuming process complete.
Comments
Post a Comment