|
From: Arvind on 19 Feb 2005 02:16 Hello, Im creating the following Progress bar at initinstance() and created a seperate thread for executing. like this void Progressdown() { SetForegroundWindow(hwnd1); TerminateThread(DecryptThread,NULL); DecryptThread = CreateThread(NULL,NULL,Threaddecry,NULL,NULL,&ThreadID); } DWORD WINAPI Threaddecry(LPVOID lpParameter) // function executes the thread { ShowWindow(hwnd1, SW_SHOW); SetForegroundWindow(hwnd1); SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); for(int t = 0; t<=10;t++ ) { for(int a = 0;a<=100;a++) { SendMessage(hwnd1, PBM_SETPOS, (WPARAM) a, 0); } } ShowWindow(hwnd1, SW_HIDE); SendMessage(hwnd1, PBM_SETPOS, (WPARAM) 0, 0); TerminateThread(DecryptThread,NULL); return 0; } planning to use it while downloading the files/or some where required but when i call Progressdown() with in some other function the progress bar just displays and nothin happens.(it just shows the Progressbar with no activity) hwnd1 = CreateWindowEx(0, PROGRESS_CLASS, TEXT("test"), WS_CHILD | WS_VISIBLE | PBS_SMOOTH, 15, 200, 215, 35, hWnd, NULL, hInst, NULL); so in thought instead of progress bar can i create soe messagebox lile windows using CreateWindowEx() and hide it with the particular function operation is over. (i want either progress bar working or showing a static screen) how to do it? any ideas? Thanks, Arvind
From: Marius Prisecaru on 19 Feb 2005 10:36 Hi, >DWORD WINAPI Threaddecry(LPVOID lpParameter) // function executes the thread >{ >ShowWindow(hwnd1, SW_SHOW); >SetForegroundWindow(hwnd1); >SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); You have done almost everything wrong in your thread implementation. First of all, don't use 'SendMessage' ; SendMessage does not return until the message sent is processed by the destination, but if the destination is busy waiting on something else, [such as some notification from the thread that initiated the sendmessage] then you have a deadlock [both your threads will hang.] At this point, your application will be unresponsive. What you want to do, is use a "PostMessage" instead. Furthermore, the whole way of thinking about it is wrong. What you should do is let the UI thread do the actual show/hide/update of the progress bar and let the worker thread notify it about progress by means of PostMessage. Also, don't ever use "TerminateThread" unless it's REALLY your last choice and you are willing to potentially leak resources... this would be when you are just trying to save your application and provide some last way of escaping from a fatal system failure. That is because "TerminateThread" tells the thread... exit.. NOW!, so the thread won't have any chance of cleaning certain resources [for e.g., by having certain destructors called, and so on.] Instead, you should provide a mechanism for your thread to quit gracefully; i.e., it could wait on an event and when that event would be set, it would just break from its main WaitForMultipleObjects loop and thus it would quit gracefully. So, have a worker thread in which you start the long operation needed [such as loading files/computing/etc..] and at various points, post a message to the UI thread informing it that you completed whatever percentage of your task, and let the UI thread display that percentage [by means of updating a progress bar/etc] in its handler for the message you post. This message can be a user-defined message that needs to be based on WM_APP rather than WM_USER. Not that you asked, but WM_USER+ messages may conflict w/ some messages that Windows uses internally. Marius
From: Arvind on 20 Feb 2005 23:28 Thanks a lot for your detailed messege. il implement that way. and 1 more thing is how to user createwindowex() to create a messagebox sort of window.? -- ---------------------------------------------------------------------------- ------------------------------------ "eRiva Systems" - Where Technology Meets Life, Every Minute. e-Mail : arvindr(a)erivasystems.com Web Site: www.erivasystems.com Yahoo Messenger : arvish27 "Marius Prisecaru" <prisasm(a)h0tmail.remove-this-n-make-zero-o.com> wrote in message news:eMzWJfpFFHA.1924(a)TK2MSFTNGP14.phx.gbl... > Hi, > > >DWORD WINAPI Threaddecry(LPVOID lpParameter) // function executes the > thread > >{ > >ShowWindow(hwnd1, SW_SHOW); > >SetForegroundWindow(hwnd1); > >SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); > > You have done almost everything wrong in your thread implementation. First > of all, don't use 'SendMessage' ; SendMessage does not return until the > message sent is processed by the destination, but if the destination is busy > waiting on something else, [such as some notification from the thread that > initiated the sendmessage] then you have a deadlock [both your threads will > hang.] At this point, your application will be unresponsive. What you want > to do, is use a "PostMessage" instead. Furthermore, the whole way of > thinking about it is wrong. What you should do is let the UI thread do the > actual show/hide/update of the progress bar and let the worker thread notify > it about progress by means of PostMessage. Also, don't ever use > "TerminateThread" unless it's REALLY your last choice and you are willing to > potentially leak resources... this would be when you are just trying to save > your application and provide some last way of escaping from a fatal system > failure. That is because "TerminateThread" tells the thread... exit.. NOW!, > so the thread won't have any chance of cleaning certain resources [for e.g., > by having certain destructors called, and so on.] Instead, you should > provide a mechanism for your thread to quit gracefully; i.e., it could wait > on an event and when that event would be set, it would just break from its > main WaitForMultipleObjects loop and thus it would quit gracefully. > > So, have a worker thread in which you start the long operation needed [such > as loading files/computing/etc..] and at various points, post a message to > the UI thread informing it that you completed whatever percentage of your > task, and let the UI thread display that percentage [by means of updating a > progress bar/etc] in its handler for the message you post. This message can > be a user-defined message that needs to be based on WM_APP rather than > WM_USER. Not that you asked, but WM_USER+ messages may conflict w/ some > messages that Windows uses internally. > > Marius > > >
From: Michael J. Salamone on 21 Feb 2005 08:19 Create a dialog and call DialogBox(). -- Michael Salamone [eMVP] Entrek Software, Inc. www.entrek.com "Arvind" <arvinds(a)erivasystems.com> wrote in message news:ey5pg08FFHA.1476(a)TK2MSFTNGP09.phx.gbl... > Thanks a lot for your detailed messege. > > il implement that way. > > > and 1 more thing is how to user createwindowex() > > to create a messagebox sort of window.? > > -- > ---------------------------------------------------------------------------- > ------------------------------------ > "eRiva Systems" - Where Technology Meets Life, Every Minute. > > e-Mail : arvindr(a)erivasystems.com > > Web Site: www.erivasystems.com > > Yahoo Messenger : arvish27 > "Marius Prisecaru" <prisasm(a)h0tmail.remove-this-n-make-zero-o.com> wrote > in > message news:eMzWJfpFFHA.1924(a)TK2MSFTNGP14.phx.gbl... >> Hi, >> >> >DWORD WINAPI Threaddecry(LPVOID lpParameter) // function executes the >> thread >> >{ >> >ShowWindow(hwnd1, SW_SHOW); >> >SetForegroundWindow(hwnd1); >> >SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); >> >> You have done almost everything wrong in your thread implementation. >> First >> of all, don't use 'SendMessage' ; SendMessage does not return until the >> message sent is processed by the destination, but if the destination is > busy >> waiting on something else, [such as some notification from the thread >> that >> initiated the sendmessage] then you have a deadlock [both your threads > will >> hang.] At this point, your application will be unresponsive. What you >> want >> to do, is use a "PostMessage" instead. Furthermore, the whole way of >> thinking about it is wrong. What you should do is let the UI thread do >> the >> actual show/hide/update of the progress bar and let the worker thread > notify >> it about progress by means of PostMessage. Also, don't ever use >> "TerminateThread" unless it's REALLY your last choice and you are willing > to >> potentially leak resources... this would be when you are just trying to > save >> your application and provide some last way of escaping from a fatal >> system >> failure. That is because "TerminateThread" tells the thread... exit.. > NOW!, >> so the thread won't have any chance of cleaning certain resources [for > e.g., >> by having certain destructors called, and so on.] Instead, you should >> provide a mechanism for your thread to quit gracefully; i.e., it could > wait >> on an event and when that event would be set, it would just break from >> its >> main WaitForMultipleObjects loop and thus it would quit gracefully. >> >> So, have a worker thread in which you start the long operation needed > [such >> as loading files/computing/etc..] and at various points, post a message >> to >> the UI thread informing it that you completed whatever percentage of your >> task, and let the UI thread display that percentage [by means of updating > a >> progress bar/etc] in its handler for the message you post. This message > can >> be a user-defined message that needs to be based on WM_APP rather than >> WM_USER. Not that you asked, but WM_USER+ messages may conflict w/ some >> messages that Windows uses internally. >> >> Marius >> >> >> > >
From: Arvind on 21 Feb 2005 09:41 createwindow()? or createwindowex()? any sample code for it..i want to use it like a messagebox -- ---------------------------------------------------------------------------- ------------------------------------ "eRiva Systems" - Where Technology Meets Life, Every Minute. e-Mail : arvindr(a)erivasystems.com Web Site: www.erivasystems.com Yahoo Messenger : arvish27 "Michael J. Salamone" <mikesa#at#entrek#dot#com> wrote in message news:ePMEnfBGFHA.228(a)TK2MSFTNGP15.phx.gbl... > Create a dialog and call DialogBox(). > > -- > Michael Salamone [eMVP] > Entrek Software, Inc. > www.entrek.com > > > "Arvind" <arvinds(a)erivasystems.com> wrote in message > news:ey5pg08FFHA.1476(a)TK2MSFTNGP09.phx.gbl... > > Thanks a lot for your detailed messege. > > > > il implement that way. > > > > > > and 1 more thing is how to user createwindowex() > > > > to create a messagebox sort of window.? > > > > -- > > -------------------------------------------------------------------------- -- > > ------------------------------------ > > "eRiva Systems" - Where Technology Meets Life, Every Minute. > > > > e-Mail : arvindr(a)erivasystems.com > > > > Web Site: www.erivasystems.com > > > > Yahoo Messenger : arvish27 > > "Marius Prisecaru" <prisasm(a)h0tmail.remove-this-n-make-zero-o.com> wrote > > in > > message news:eMzWJfpFFHA.1924(a)TK2MSFTNGP14.phx.gbl... > >> Hi, > >> > >> >DWORD WINAPI Threaddecry(LPVOID lpParameter) // function executes the > >> thread > >> >{ > >> >ShowWindow(hwnd1, SW_SHOW); > >> >SetForegroundWindow(hwnd1); > >> >SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM (0, 100)); > >> > >> You have done almost everything wrong in your thread implementation. > >> First > >> of all, don't use 'SendMessage' ; SendMessage does not return until the > >> message sent is processed by the destination, but if the destination is > > busy > >> waiting on something else, [such as some notification from the thread > >> that > >> initiated the sendmessage] then you have a deadlock [both your threads > > will > >> hang.] At this point, your application will be unresponsive. What you > >> want > >> to do, is use a "PostMessage" instead. Furthermore, the whole way of > >> thinking about it is wrong. What you should do is let the UI thread do > >> the > >> actual show/hide/update of the progress bar and let the worker thread > > notify > >> it about progress by means of PostMessage. Also, don't ever use > >> "TerminateThread" unless it's REALLY your last choice and you are willing > > to > >> potentially leak resources... this would be when you are just trying to > > save > >> your application and provide some last way of escaping from a fatal > >> system > >> failure. That is because "TerminateThread" tells the thread... exit.. > > NOW!, > >> so the thread won't have any chance of cleaning certain resources [for > > e.g., > >> by having certain destructors called, and so on.] Instead, you should > >> provide a mechanism for your thread to quit gracefully; i.e., it could > > wait > >> on an event and when that event would be set, it would just break from > >> its > >> main WaitForMultipleObjects loop and thus it would quit gracefully. > >> > >> So, have a worker thread in which you start the long operation needed > > [such > >> as loading files/computing/etc..] and at various points, post a message > >> to > >> the UI thread informing it that you completed whatever percentage of your > >> task, and let the UI thread display that percentage [by means of updating > > a > >> progress bar/etc] in its handler for the message you post. This message > > can > >> be a user-defined message that needs to be based on WM_APP rather than > >> WM_USER. Not that you asked, but WM_USER+ messages may conflict w/ some > >> messages that Windows uses internally. > >> > >> Marius > >> > >> > >> > > > > > >
|
Next
|
Last
Pages: 1 2 Prev: Programatically Provisioning PocketPC for 802.11 Next: How can I get evc manual or tutorial? |