Featured post
windows - No matter what, I can't get this progress bar to update from a thread -
i have windows app written in c (using gcc/mingw) works pretty except few ui problems. one, cannot progress bar update thread. in fact, can't ui stuff update.
basically, have spawned thread processing, , thread attempt update progress bar in main thread. tried using postmessage() main hwnd, no luck though can other things open message boxes. however, it's unclear whether message box getting called within thread or on main thread.
here's code:
// in header/globally accessible hwnd wnd; // main application window hwnd progress_bar; //progress bar typedef struct { //to pass thread dword mainthreadid; hwnd mainhwnd; char *filename; } threadstuff; //callback function lresult callback wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam){ switch (msg){ case wm_create:{ // create progress bar progress_bar = createwindowex( 0, progress_class, (lpctstr) null, ws_child | ws_visible, 79,164,455,15, hwnd, (hmenu)20, null, null); sendmessage(progress_bar, pbm_setstep, 1, 0 ); sendmessage(progress_bar, pbm_setpos, 0, 0 ); //test make sure works sendmessage(progress_bar, pbm_stepit, 0, 0 ); //works fine sendmessage(progress_bar, pbm_stepit, 0, 0 ); //works fine sendmessage(progress_bar, pbm_stepit, 0, 0 ); //works fine sendmessage(progress_bar, pbm_stepit, 0, 0 ); //works fine break; } case wm_command: { if(loword(wparam)==2){ //do processing in thread //struct of stuff need pass thread threadstuff *threadstuff; threadstuff = (threadstuff*)malloc(sizeof(*threadstuff)); threadstuff->mainthreadid = getcurrentthreadid(); threadstuff->mainhwnd = hwnd; threadstuff->filename = (void*)&filename; hthread1 = createthread(null,0,convertfile (lpvoid)threadstuff,0,null); }else if(loword(wparam)==5){ //update progress bar messagebox(hwnd,"i got message!", "message", mb_ok | mb_iconinformation); postmessage(progress_bar,pbm_stepit,0,0); } break; } } }
this seems work okay. problem in thread:
dword winapi convertfile(lpvoid params){ //get passed params, works fine threadstuff *tdata = (threadstuff*)params; messagebox(tdata->mainhwnd,tdata->filename,"file name",mb_ok | mb_iconinformation); //yep postmessage(tdata->mainhwnd,wm_command,5,0); //only shows message postthreadmessage(tdata->mainthreadid,wm_command,5,0); //does nothing }
when say, "only shows message," means messagebox() function in callback works, not postmessage() update position of progress bar.
if use postthreadmessage() send message main thread's message loop, can intercept , launch messageboxes it's working. however, if try update progress bar way. still won't update.
what missing?
from msdn documentation pbm_stepit:
wparam must zero. lparam must zero.
clr_default defined 0xff000000l. happens if change code to:
postmessage(progress_bar, pbm_stepit, 0, 0);
- Get link
- X
- Other Apps
Comments
Post a Comment