progress bars with Win32 API

This is a discussion on progress bars with Win32 API within the C++ Programming forums, part of the General Programming Boards category; im trying to set up a simple progress bar in windows 98 using the win32 API, but im not having ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    progress bars with Win32 API

    im trying to set up a simple progress bar in windows 98 using the win32 API, but im not having much luck. this is a simplified version of my code.

    Code:
    #include <windows.h>
    #include <commctrl.h>
    
    HINSTANCE g_hinst;
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
      HWND hwndPB;
      RECT rcClient;
      int cyVScroll;
      switch(msg)
      {
        case WM_CREATE:
          GetClientRect(hwnd, &rcClient);
          cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
    
          hwndPB = CreateWindowEx(0, PROGRESS_CLASS
                                 (LPSTR)NULL, WS_CHILD | WS_VISIBLE, 
                               rcClient.left, 
    	           rcClient.bottom - cyVScroll, 
    	           rcClient.right, cyVScroll, 
    	           hwnd, (HMENU) 0, g_hinst, NULL);
    
          SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM
                                 (0,100));
          SendMessage(hwndPB, PBM_SETPOS, (WPARAM)33, 0);
          break;
      }
      return 0;
    }
    what is the problem here? according to a reference i downloaded this should all work fine. all i want to do is put a progress bar in a window.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    >>what is the problem here?

    I dont know. What is the problem?

    Seeing as how I dont feel like trying to compile that, nor do I wish to scour it for anything at all that may be wrong, it would be most helpful if you actually told us what the problem was. Does it not compile? What errors? What warnings? If it does compile, what does it do?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    yeah, i didn't really state the problem did i.

    well, the problem is that nothing comes up in the window, no progress bar, nothing. thats all that i can tell.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    The code to create the progress bar should probably go outside the window procedure. You can't put it in the WM_CREATE case, because the parent window hasn't been created yet. There may be another msg you could use instead of WM_CREATE.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>The code to create the progress bar should probably go outside the window procedure. You can't put it in the WM_CREATE case, because the parent window hasn't been created yet.<<

    No. That is (almost) completely wrong. While true that window creation has not been completed, the WM_CREATE message is an excellent place to create any required controls.

    Everything looks ok, typos aside. Are you using InitCommonControlsEx (or the older, obsolete but still functional InitCommonControls)?

    This question should probably have been asked/should be moved on/to the windows board.

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i had tried to use InitCommonControls() before, but it gave me these weird compiling error messages. hold on a sec ill just test it...

    actually, its linker errors:

    api.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
    Debug/win32.exe : fatal error LNK1120: 1 unresolved externals

    in this case, i put InitCommonControls() in WM_CREATE in WndProc just before running CreateWindowEx().

    the same stuff happens if i insert it in WinMain().

    when i put in InitCommonControlsEx() it says i have too few parameters.

    what do i do?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You have not linked with comctl32.lib (msvc6: project->settings->'link tab', project options edit control; just put comctl32.lib in there with the other libs).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Ken,

    I ran the code above with the progress bar creation in the WM_CREATE case, and the progress bar never came up.

    I tried moving the code to the main program after window creation, and it came up fine.

    Do you have any ideas why it won't work in the WM_CREATE case ? Or can you supply some code that will work ?

    I would like to get it to work in the WM_CREATE. Like you said, it makes more sense to put it there.

    Thanks,
    swoopy

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Shouldn't this be posted in the Windows programming board?...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  10. #10
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    KF is right about WM_CREATE. there is no better place to create child windows. Something must be wrong with the way you are doing it int the WM_CREATE case.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  11. #11
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>Or can you supply some code that will work ?<<

    [Warning: shameless plug] Creating Common Controls etc [/shameless plug]

    >>Shouldn't this be posted in the Windows programming board?...<<

    Said it already but I quite agree; if I were a regular c++ boarder I would be alarmed by the insidious creep of the dreaded 'winscum'.
    Last edited by Ken Fitlike; 09-09-2002 at 03:38 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  12. #12
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I put a message box right after this line:
    Code:
          hwndPB = CreateWindowEx(0, PROGRESS_CLASS
                                 (LPSTR)NULL, WS_CHILD | WS_VISIBLE, 
                               rcClient.left, 
    	           rcClient.bottom - cyVScroll, 
    	           rcClient.right, cyVScroll, 
    	           hwnd, (HMENU) 0, g_hinst, NULL);
    to print the value of hwndPB, and it was zero. I guess it never created the progress bar for some reason.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    if I were a regular c++ boarder I would be alarmed by the invidious creep of the dreaded 'winscum'.
    hehe ... have you read any of the newsgroups like comp.lang.cpp? They go ballistic if anything gets platform specific.

  14. #14
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    thanks Ken Fitlike. your site kicks arse
    it would have to be the smallest and simplest site ive been to, but the only one which told me something useful! i finally got the bar to work. next step though, and i know i should start a new thread, but how can i make it go up and down? ie, is there a timing control i can use?

    cheers
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  15. #15
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Originally posted by Hunter2
    Shouldn't this be posted in the Windows programming board?...
    Not on this website. The education level here is not very sophisticated. These people are Microsoft users.

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

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  3. Changing progress bars in win32....
    By jverkoey in forum Windows Programming
    Replies: 6
    Last Post: 04-27-2003, 03:32 AM
  4. Progress Bars
    By knight543 in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2002, 10:45 AM
  5. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM

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