Status bar

This is a discussion on Status bar within the C Programming forums, part of the General Programming Boards category; Hello. I need to create a C application and i have to use a status bar. I think i can ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    1

    Status bar

    Hello. I need to create a C application and i have to use a status bar. I think i can use MFC, but i don't know how to start. Can anyone help me?
    Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If I were going to do it, I'd first, go d/l the ascii table, if you don't have one. Look in the table, and ID the parts for drawing a rectangle - lines (horizontal and vertical char's), and the 4 corners.

    Then practice with that until I could draw a rectangle, just fine. Then use ascii 185, 186 or 187, to mark the progress of your application, with some color - maybe blue, in the center of your rectangle. Ideally, it would have a size suitable for showing the increments you want, in the char's of the progress bar.

    You only draw the box and (perhaps),the 186 char's, once, and you don't re-print the earlier progress char's, either. You just add another char in the next place, when it reaches the next 5%, 10%, whatever, and keep that up until it's at 100%.

    Give it a try.
    Last edited by Adak; 06-08-2008 at 01:05 AM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    I think i can use MFC, but i don't know how to start.
    I'm assuming that you want to do this in a GUI environment since you're referring to MFC. It's probably a lot easier to do with MFC. But I didn't want to post an MFC example containing a lot of lines of code. So, I'll post a very basic Win32 example containing minimal lines of code .

    Code:
    #pragma comment( lib, "user32.lib" )
    #pragma comment( lib, "comctl32.lib" )
    
    #include <windows.h>
    #include <commctrl.h>
    
    const char ClassName[] = "MainWindowClass";
    
    LRESULT CALLBACK MainWndProc( HWND    hWnd,
        UINT    Msg,
        WPARAM  wParam,          
        LPARAM  lParam )
    {
        HWND hStatus = NULL;
        switch (Msg)
        {
            case WM_CREATE:
                {
                    int iStatBarWidths[] = {200, -1};       
                    hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
                        WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
                        hWnd, (HMENU)NULL, GetModuleHandle(NULL), NULL);
                    if(!hStatus)
                    {
                        MessageBox(NULL, "Failed To Create The Status Bar", "Error", MB_OK | MB_ICONERROR);
                        return 0;
                    }
                    SendMessage(hStatus, SB_SETPARTS, sizeof(iStatBarWidths)/sizeof(int), (LPARAM)iStatBarWidths);
                    SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Fabricio's first status bar");
                }
                break;
            case WM_CLOSE:
                DestroyWindow(hWnd);
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                return (DefWindowProc(hWnd, Msg, wParam, lParam));
        }
        return 0;
    }
    
    INT WINAPI WinMain( HINSTANCE  hInstance,
        HINSTANCE  hPrevInstance,
        LPSTR      lpCmdLine,
        INT        nCmdShow )
    {
        INITCOMMONCONTROLSEX iccex; 
        iccex.dwSize = sizeof(iccex); 
        iccex.dwICC = ICC_WIN95_CLASSES; 
    
        WNDCLASSEX wc;
        HWND hWnd;
        MSG Msg;
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = MainWndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = ClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        InitCommonControlsEx(&iccex);
        if (!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Failed To Register The Window Class.", "Error", MB_OK | MB_ICONERROR);
            return 0;
        }
        hWnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            ClassName,
            "Fabricio's Status Bar",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            340,
            120,
            NULL,
            NULL,
            hInstance,
            NULL);
        if (!hWnd)
        {
            MessageBox(NULL, "Window Creation Failed.", "Error", MB_OK | MB_ICONERROR);
            return 0;
        }
        ShowWindow(hWnd, SW_SHOW);
        UpdateWindow(hWnd);
        while (GetMessage(&Msg, NULL, 0, 0))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    But I didn't want to post an MFC example containing a lot of lines of code.
    What's this?
    It would be much fewer lines than Win32.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    I'm referring to the complete working MFC example to display a status bar. Not just the code to display the status bar. I could post just sample MFC code. But that would'nt prove to the OP that it works. I always try to post minimal complete examples to prove that I'm not talking thru one of my orifaces.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Umm, if we exclude the dialog class itself, that would leave a message handler and a member function for handling the status bar which wouldn't be so big in itself.
    Of course, it might vary if it's SDI or MDI, but if it's a dialog, it would be easy. At least I think.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    The MFC code for status bar is about a 100 lines shorter than the Win32 sample. Create a new dialog app and then add a status bar control. Set its ID and then name it. All that is left is to view the MFC docs about CStatusBar and call the right function to get it to update.

    In order to do this from a thread you will have to look at the CThread information. Worker threads should NEVER touch the GUI in MFC.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    The MFC code for status bar is about a 100 lines shorter than the Win32 sample.
    I'm not so sure about this. The fully functional Win32 example above has a 101 lines of code. Compile this example and you can run it from the command line.

    On the flip side, Adding a status bar to a MFC dialog Codeproject example has a total of 287 lines for the CPP files alone. That's not counting the header files.

    The complete project code can be found in the Release Mode executable link from the above referenced page.

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Funny, because I see only 28 lines of code in the article.
    A lot of the code is auto-generated and thus doesn't count.
    Plus you are unfairly counting the comments.
    And it includes more code not necessary to just create a status bar. Sorry, but the comparison is just too unjust.
    Last edited by Elysia; 06-10-2008 at 05:20 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Elysia View Post
    Funny, because I see only 28 lines of code in the article.
    A lot of the code is auto-generated and thus doesn't count.
    If we remove the "doesn't count" part from the Win32 example, we are left with:
    Code:
    HWND hStatus=CreateWindowEx(0,STATUSCLASSNAME,NULL,WS_CHILD|WS_VISIBLE,0,0,0,0,hWnd,(HMENU)NULL,GetModuleHandle(NULL),NULL);
    SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Fabricio's first status bar");
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. status bar flickering
    By rakan in forum Windows Programming
    Replies: 5
    Last Post: 01-07-2008, 09:11 PM
  2. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 12:32 PM
  3. Status bar
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2005, 10:45 AM
  4. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 05:31 AM
  5. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 07:51 PM

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