Updating Progress Bar

This is a discussion on Updating Progress Bar within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by binks So I only have to change these fields to reflect my project? You need to change ...

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by binks View Post
    So I only have to change these fields to reflect my project?
    You need to change the x86 to amd64 in two places... but yes that's essentially correct.


    And to include it, do I just add
    Code:
    #include "style.manifest"
    Or do I have to include it with the project options, similarly to adding linker commands or including a resource (.rc) file.?

    And is there anything I need to enable the style, or is it automatically done once included w/ the project?
    It goes in your .rc file. Then when you compiler the project it's placed in the resources area of the executable. When you call inticommoncontrols(), usually the first thing you do on startup, the DLL will read the resources and find the manifest.

    You can also have the manifest as a freestanding file provided you name it according to their rules...
    If your exe is MyProgram.exe ... you name the manifest MyProgram.exe.manifest This is ok mainly for testing. When you release the code, if they get separated the program will no longer display visual styles so the smart money is to get it into your .rc file right from the start.

    You should also keep a copy of it someplace safe, since you're going to need it over and over again... pretty much in every project.

  2. #17
    Registered User
    Join Date
    Mar 2011
    Posts
    211
    How do you put the manifest in the resource file, do you just copy-paste it in? (because I get a syntax error with that) Or it's a separate file, that is included via the .rc file, and embedded into the res file.
    Last edited by binks; 12-13-2011 at 02:16 PM.

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by binks View Post
    How do you put the manifest in the resource file, do you just copy-paste it in? (because I get a syntax error with that) Or it's a separate file, that is included via the .rc file, and embedded into the res file.
    What resource editor are you using?

    It's an external file that is included...

    Code:
    1 MANIFEST "Manifest.xml"
    ... like that.

  4. #19
    Registered User
    Join Date
    Mar 2011
    Posts
    211
    Dev-C++ I know it's ancient, but I've yet to find another good editor similar to Devs style and look.

    Here is the XML file
    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
      <assemblyIdentity type="win32" 
                        name="Progress Bar" 
                        version="1.0.0.0" 
                        processorArchitecture="X86" /> 
      <description> 
        My Program Description  
      </description> 
      <dependency> 
        <dependentAssembly> 
          <assemblyIdentity type="win32" 
                            name="Microsoft.Windows.Common-Controls" 
                            version="6.0.0.0" 
                            processorArchitecture="X86" 
                            publicKeyToken="6595b64144ccf1df" 
                            language="*" /> 
        </dependentAssembly> 
      </dependency> 
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
        <security> 
          <requestedPrivileges> 
            <requestedExecutionLevel  level="AsInvoker"  
                                      uiAccess="False" />  
          </requestedPrivileges> 
        </security> 
      </trustInfo> 
    </assembly>
    And here is the .rc file
    Code:
    #include "progress_bar.h"
    #include <afxres.h>
    
    1 MANIFEST "style.xml"
    
    IDD_CONTROLS_DLG DIALOG 260, 200, 200, 120
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Progress Bar"
    FONT 8, "MS Shell Dlg"
    BEGIN
        DEFPUSHBUTTON   "Load", IDLOAD, 30, 100, 50, 14
        DEFPUSHBUTTON   "Close", IDCANCEL, 120, 100, 50, 14
    END
    It compiles fine, but the style does not show up.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Check out Pelles C ... it's C99, up to date, and comes with a wonderful IDE and full documentation of the entire library (including hundreds of extension calls), does Console and GUI mode... Best helpfile I've ever seen : read the section on POIDE to get familiar before you start. It also has a full set of built in resource editors (including images, animations, icons and dialogs) and comes with a complete set of Windows headers and libs... all for free.

    Trust me... DEV C will be very quickly set aside.

    In POIDE all you have to do is right click on your resource file, select Import and then select your manifest from the dialog, and it's in there!

    Ok... now for your manifest...

    Line 4... Where you have ... name = "progress bar" ... you need to change it to the name of your Executable Program File... if it's called smoo.exe ... name = "smoo" ... believe it or not, getting this wrong can actually stop a program from running!

    Line 8 ... Description should be changed to something like "Settings updater" or something that describes your program's function... It's what you see in tooltips in explorer and in properties dialogs.

    The rest looks ok.
    Last edited by CommonTater; 12-13-2011 at 05:14 PM.

  6. #21
    Registered User
    Join Date
    Mar 2011
    Posts
    211
    Is that what you use?

    Any idea on why the style does not show for the progress bar?
    Here is the cpp file also
    Code:
    #include <windows.h>
    #include <commctrl.h>
    #include "progress_bar.h"
    
    #define length 100000
    
    //---------------------------------------------------------------------------
    HWND hWnd;
    HINSTANCE hInst;
    LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    HWND hwndpb;
    //---------------------------------------------------------------------------
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine, int nCmdShow)
    {
    	hInst = hInstance;
    	
    	INITCOMMONCONTROLSEX InitCtrlEx;
    
    	InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	InitCtrlEx.dwICC  = ICC_PROGRESS_CLASS;
    	InitCommonControlsEx(&InitCtrlEx);
    
    	DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG),
    	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));
    
    	return FALSE;
    }
    //---------------------------------------------------------------------------
    LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg,
    		       WPARAM wParam, LPARAM lParam)
    {
    
    	switch(Msg)
    	{
    	case WM_INITDIALOG:
    		hwndpb = CreateWindowEx(0, PROGRESS_CLASS, NULL,
    		               WS_CHILD | WS_VISIBLE | PBS_SMOOTH ,
    			      20, 20, 260, 17,
    			      hWndDlg, (HMENU)IDC_PROGBAR, hInst, NULL);
    			      
    		return TRUE;
    
    	case WM_COMMAND:
    		switch(wParam)
    		{
    		 case IDLOAD: 
             {
                int pb_pos;
                SendMessage(hwndpb, PBM_SETRANGE, 0, MAKELPARAM(0, length ));
    			while(pb_pos <= length)
                {           
                            pb_pos = SendMessage(hwndpb, PBM_GETPOS, 0, 0);
                            pb_pos++;
                            SendMessage(hwndpb, PBM_SETPOS, pb_pos, 0);
                }
    			return TRUE;
             }
             break;
    		 case IDCANCEL:
             {
                DestroyWindow(hwndpb);
    			EndDialog(hWndDlg, 0);
    			return TRUE;
             }
             break;
    		}
    	}
    
    	return FALSE;
    }

  7. #22
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    If you're still not getting the visual style... it's almost certain to be a problem with the manifest...

    If you open your EXE in a hex editor can you see the manifest in the resources at the end of the file?
    Perhaps it's not being included correctly.

    I use Pelles C, which is C99 ... no C++, so we're on a slightly different page here.
    Last edited by CommonTater; 12-13-2011 at 05:41 PM.

  8. #23
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    I would remove the SendMessage() call to get the PB position each loop (as it is not required).

    SendMessage() is slow, you already have the current PB position and, if the last set position called failed, you want to step the PB multiple times (to catch up).

    Quote Originally Posted by CommonTater View Post
    Mind you these are multi-tasking applications where the UI runs independent of the other processes, and WM_TIMER is not blocked by the function call.
    This is only possible with a multi threaded app, as you say, I assumed that we were talking about single threaded apps.

    I think you should also mention how you made the PB postition variable thread safe ('Lines' in your example) [stopped the UI thread accessing the variable 'Lines' while the worker thread changes its value].
    "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

  9. #24
    Registered User
    Join Date
    Mar 2011
    Posts
    211
    Name:  pic.jpg
Views: 279
Size:  159.6 KB
    The code is there, that's for sure. Though it's not at the end, it's around the middle.

    @novacain

    I removed that from the while loop, and placed it right before. That fixes the not responding problem. Thanks so much for that!

  10. #25
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by novacain View Post
    I would remove the SendMessage() call to get the PB position each loop (as it is not required).

    SendMessage() is slow, you already have the current PB position and, if the last set position called failed, you want to step the PB multiple times (to catch up).



    This is only possible with a multi threaded app, as you say, I assumed that we were talking about single threaded apps.

    I think you should also mention how you made the PB postition variable thread safe ('Lines' in your example) [stopped the UI thread accessing the variable 'Lines' while the worker thread changes its value].
    Correct again... Yes, it's in a critical section, so the PB code waits in the event of a collision.

  11. #26
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by binks View Post
    The code is there, that's for sure. Though it's not at the end, it's around the middle.
    Ok... did you make the changes from my message #20?
    You have to get this stuff right or it simply ignores the entire manifest....

    Ok... now for your manifest...

    Line 4... Where you have ... name = "progress bar" ... you need to change it to the name of your Executable Program File... if it's called smoo.exe ... name = "smoo" ... believe it or not, getting this wrong can actually stop a program from running!

    Line 8 ... Description should be changed to something like "Settings updater" or something that describes your program's function... It's what you see in tooltips in explorer and in properties dialogs.

    The rest looks ok.
    Make these changes and recompile the resources...

    And FWIW.... windows programs cannot have spaces in their filenames...
    progressbar.exe is ok ... progress bar.exe is not.
    Last edited by CommonTater; 12-13-2011 at 07:28 PM.

  12. #27
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by CommonTater View Post
    And FWIW.... windows programs cannot have spaces in their filenames...
    progressbar.exe is ok ... progress bar.exe is not.
    Man, this must be a record for most disinformation in a thread.

    One wonders why you use Windows if it's so rubbish that it can't handle 5 line loops, open files with spaces in their names, or run programs if the name in the manifest is different than the actual name. You might want to change the caret blink rate, I hear setting it to maximum fixes all these problems.

    OP, the problem you're having is:
    Code:
    1 MANIFEST "Manifest.xml"
    should be:
    Code:
    1 RT_MANIFEST "Manifest.xml"
    or if you want to be completely foolproof:
    Code:
    CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "Manifest.xml"
    Although considering how outdated Dev-cpp is you'll probably have to go with
    Code:
    1 24 "Manifest.xml"
    Last edited by adeyblue; 12-13-2011 at 08:45 PM.

  13. #28
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by adeyblue View Post
    Man, this must be a record for most disinformation in a thread.


    One wonders why you use Windows if it's so rubbish that it can't handle 5 line loops, open files with spaces in their names, or run programs if the name in the manifest is different than the actual name. You might want to change the caret blink rate, I hear setting it to maximum fixes all these problems.

    Don't be an ass.

    I said windows programs are not supposed to have spaces in their names... because of the way they're interpreted...

    It's about how the command interpreter parses the filename from the command line...

    "notepad" is taken correctly as "notepad.exe"

    "note pad" can be taken as program = note , flag = pad resulting in "note.exe pad" which isn't correct.


    Although considering how outdated Dev-cpp is you'll probably have to go with
    Code:
    1 24 "Manifest.xml"
    This is worth a try.



    For the rest of your crap... do these good people a favour and go crawl back under your rock.
    Last edited by CommonTater; 12-13-2011 at 09:58 PM.

  14. #29
    Registered User
    Join Date
    Mar 2011
    Posts
    211
    I tried this
    Code:
    1 24 "style.xml"
    but it didn't work. However, this does work and gives this output.
    Code:
    1 RT_MANIFEST "style.xml"
    Name:  result.jpg
Views: 343
Size:  16.0 KB

    Though there is a bit of 'lag' when the progress bar finishes, and you click cancel. I also notice that this progress bar is faster than the one without a style. Is that just a side effect?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Progress bar
    By JFonseka in forum C Programming
    Replies: 9
    Last Post: 02-26-2008, 02:49 PM
  2. Progress Bar
    By mikeman118 in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2007, 09:16 PM
  3. Updating a progress bar
    By NewGuy100 in forum C++ Programming
    Replies: 2
    Last Post: 03-13-2006, 12:00 PM
  4. Progress Bar
    By magic.mike in forum Windows Programming
    Replies: 3
    Last Post: 01-26-2005, 03:10 PM
  5. Progress Bar in DLL.
    By UW_COOP in forum Windows Programming
    Replies: 2
    Last Post: 06-12-2003, 02:00 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21