#1
  1. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0

    Status Bar Problem


    I am trying to implement a status bar in my application, but at this point my knoledge of the windows API is still somewhaty limited. Here is the code microsoft gave as an example of how to make one:

    // DoCreateStatusBar - creates a status bar and divides it into
    // the specified number of parts.
    // Returns the handle to the status bar.
    // hwndParent - parent window for the status bar.
    // nStatusID - child window identifier.
    // hinst - handle to the application instance.
    // nParts - number of parts into which to divide the status bar.
    HWND DoCreateStatusBar(HWND hwndParent, int nStatusID, HINSTANCE
    hinst, int nParts)
    {
    HWND hwndStatus;
    RECT rcClient;
    HLOCAL hloc;
    LPINT lpParts;
    int i, nWidth;

    // Ensure that the common control DLL is loaded.
    InitCommonControls();

    // Create the status bar.
    hwndStatus = CreateWindowEx(
    0, // no extended styles
    STATUSCLASSNAME, // name of status bar class
    (LPCTSTR) NULL, // no text when first created
    SBARS_SIZEGRIP | // includes a sizing grip
    WS_CHILD, // creates a child window
    0, 0, 0, 0, // ignores size and position
    hwndParent, // handle to parent window
    (HMENU) nStatusID, // child window identifier
    hinst, // handle to application instance
    NULL); // no window creation data

    // Get the coordinates of the parent window's client area.
    GetClientRect(hwndParent, &rcClient);

    // Allocate an array for holding the right edge coordinates.
    hloc = LocalAlloc(LHND, sizeof(int) * nParts);
    lpParts = LocalLock(hloc);

    // Calculate the right edge coordinate for each part, and
    // copy the coordinates to the array.
    nWidth = rcClient.right / nParts;
    for (i = 0; i < nParts; i++) {
    lpParts[i] = nWidth;
    nWidth += nWidth;
    }

    // Tell the status bar to create the window parts.
    SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts, (LPARAM)
    lpParts);

    // Free the array, and return.
    LocalUnlock(hloc);
    LocalFree(hloc);
    return hwndStatus;
    }

    I can understand the code for the most part (although I have no idea why they handle the memory like that with the LocalAlloc and LocalLock.) The problem is first, I don't know how to get the handle to the application, and second, why would you need an idetifier for a child window. Isn't the status bar itself a child window? What exactly is the function looking for there? Personally I wish they'd just made the status bar a common control so I could implement it with a recource script. But anyway, if you can help I'd appreciate it.
  2. #2
  3. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0
    Ok, never mind the above, I was able to figure that much out on my own. But now it seems I have a new problem... To create a status bar you must first initialize the class (I assume this is for memory saving purposes.) The function for this is InitCommonControlsEx. You can look up any relevant information on it
    here. The code I wrote to handle this operation is as follows:

    LPINITCOMMONCONTROLSEX ControlSet;

    ControlSet.dwSize = 4 //I assumed 32 bits would be enough for this but honestly I have no clue what it's for :\
    ControlSet.dwICC = ICC_BAR_CLASSES;

    InitCommonControlsEx(ControlSet);

    This produces no less than 7 errors. I have a feeling I'm missing something really obvious here, but I can't figure out where I went wrong. Any advice?
  4. #3
  5. Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Posts
    15
    Rep Power
    0
    Well, nm the whole thing. As it turns out you can't initialize control classes until after you create the diolog (my bad for not including the full code.) Also, I wasn't setting the WS_VISIBLE proporty when creating the status bar. Sheesh, is it just me or is the Windows API way more complicated than it needs to be?
  6. #4
  7. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    27
    Its just you........


    Complex == lots of variations

    You want all apps to look exactly the same?
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo