Thread: need help in progress bar

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    1

    need help in progress bar

    Hi,
    I new in vc++ programming. I have situation here where my progress bar not show movement at all.
    On the dialog, i add in toolbox progress bar control call IDC_PROGRESS1 and create variable control on it too, call m_pbar1

    Code:
    Bool Form1::OnInitDialog()
    {
    .
    .
    m_pbar1.setpos(20); --> able to see some changing in progress bar
    .
    }


    I add in control button OnProgram where it will create multi threading here which going to access some dll api function.

    Code:
    void Form1::OnProgram()
    {
    .
    .
    create thread here>>
    .
    }
     
    //programming threading, return 1 for success, 0 for error
    DWORD WINAPI ProgramThread(LPVOID para)
    {
    .
    .
    dll api function call >> this function will return back the program progress
    .
    .
    .
    }
     
    //this function below will continue update the status progress program
    int program_progress(value1)
    {
    .
    .
    ## i try to add m_pbar1 here --> error undeclare variable
    ## i try alot method e.g sendDlgItemMessage(hwnd,IDC_PROGRESS1,PBM_SETPOS,value,0); but still no luck at as i don;t know how to get hwnd
    return 1; //return 1 for continue programming
    }

    I have check other ppl solution e.g assign
    HWND hwnd = (HWND)m_hWnd;
    Still not working.
    So,any expert here can give me some guideline or links that i can refer to..
    I using vs2005.

    thanks and regards,
    Simon

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    ok just some general advice: first is check the documentation for the object you are using
    you need to know how you are measuring program progress - eg what is the total number of operations you need to do before completion.
    Then you have to increment the width, value, whatever of your progress bar essentially as a percentage scaled to the total width of the bar with the increment multipler /addition or whatever fits the docs - defined against the total number of operations.
    This is why the docs are so valuable - the default total for the widget might be 1 by default - so progress has to be scaled to that - unless you say otherwise. Also there is always the fact that your application needs time to redraw / check events - so if you are doing intensive work which is probably the case if a progress bar is needed then you have to build in breathing space for updating.

    Also bear in mind if you are resetting the value upon completion and doing something that completes very quickly then you might not even notice it worked.

    you should work it into a very simple program that just counts to a high number, possibly with nested loops and the only other thing that happens is that the bar gets shown working

    here is a link to the msdn description of your control
    Last edited by rogster001; 09-06-2012 at 01:07 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    In CreateThread() you can pass info as the lpParameter.

    Create a struct to hold the required data and/or send the parent window's HWND in with this pointer, catch this in the threads start method and save (for use in the SendMessage)

    Add a user defined msg (and handler) in the parent window that will handle the updates to the progress bar (ie cast the LPARAM or WPARAM back to an int and set the PB postion)

    When the thread needs to update the progress bar you use SendMessage (or PostMessage, even SendMessageTimeout, depending on requirements) with the LPARAM or WPARAM containing the new progressbar values (ie ints for range and position).

    NOTE: Controls are NOT thread safe, so you can not send the progress bars HWND into the thread and have the thread update the position (you must update the progressbar from the main UI thread).
    Last edited by novacain; 09-07-2012 at 10:49 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Progress Bar
    By mikeman118 in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2007, 10:16 PM
  2. Progress Bar
    By Stabbsy in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2007, 10:30 PM
  3. Progress Bar
    By magic.mike in forum Windows Programming
    Replies: 3
    Last Post: 01-26-2005, 04:10 PM
  4. Progress Bar in DLL.
    By UW_COOP in forum Windows Programming
    Replies: 2
    Last Post: 06-12-2003, 02:00 AM
  5. Help - Progress Bar
    By matmil in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2002, 08:48 PM