Some questions about Status Bars/Menus...

This is a discussion on Some questions about Status Bars/Menus... within the Windows Programming forums, part of the Platform Specific Boards category; Greetings everybody. I am attempting to create my very own complicated window program with a status bar, a complicated menu, ...

  1. #1
    AoA
    AoA is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    8

    Some questions about Status Bars/Menus...

    Greetings everybody. I am attempting to create my very own complicated window program with a status bar, a complicated menu, and more. So far I have the window and a simple version of the menu complete. However, with my limited knowledge of C++, I have a few questions on how to do some more complicated things (at least they're complicated to me).

    1. How do I make it so when somebody clicks on a menu item it loads a certain URL in their default browser?

    2. I am trying to make a status bar, but everything I've tried hasn't worked. I've used the search on this forum and google, but I haven't found any code that works for me... All I am asking for is a simple status bar (it doesn't have to have anything on it for all I care), but I need to know what site/book I can look at to know how to add features to it (such as a progress bar for loading things, a method of displaying the current x,y position of the cursor within certain sections of the program and more). But as long as it works, I'm happy.

    I've tried codes from a multitude of web sites such as:

    http://winprog.org/tutorial/app_three.html
    http://msdn.microsoft.com/msdnmag/issues/03/01/CQA/
    Status bar

    ...but none of them work...

    3. How do I create a popup window type thing (such as if you open Dev C++ and select Help --> About Dev C++...) where I can type in information about my program?

    4. Last question...how do I add links to my messages displayed in popup windows? (See #3)

    If any of these questions are obvious or easily found, I apologize. Thanks for any help I recieve and I'll probably have more questions in the future.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    1) ShellExecute() (Found this in <60sec of googling.) Example:
    Code:
    #include <windows.h>
    
    int main()
    {
    	ShellExecute(HWND_DESKTOP, "open", "http://google.com", "", "", SW_SHOW);
    	return 0;
    }
    Just call ShellExecute() when you get a WM_COMMAND for that menu item. (The above, when run, opens google for me.)

    2) I like CreateStatusWindow() - it's easier than CreateWindow() or CreateWindowEx(). (All three can achive the same purpose.) What have you tried? Did you link to the common controls library, and did you call InitCommonControls() ?

    3) (This one worries me) Create... a... dialog. Easiest way: Design an "about" dialog as a resource, and use DialogBox() to load/display that resource. (Keep reading winprog!)

    4) I don't think there's a standard window available to display a link. You'll have to create one yourself, or subclass the STATIC class (which is used for labels).

    What have you tried so far? It's easier to help when we can see your code and use it to see where you might've gone astray.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    AoA
    AoA is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    For number one, there seems to be a problem with my code. I have my menu designed pretty much to what it will be when the project is complete, but I'm keeping them GRAYED for now. However, whenever I ungray something and then click on it, it automatically closes the entire program, even if I didn't code it to do that. I believe the problem is somewhere in here, but I am just a newbie...

    Code:
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_DESTROY:
                PostQuitMessage (0);
                break;
            case WM_COMMAND:
            {
              case MENU_FILE_EXIT:
              {PostQuitMessage (0);}
              break;
              case MENU_HELP_FORUMS:
              {ShellExecute(HWND_DESKTOP, "open", "http://www.honzikhorava.com/forum/", "", "", SW_SHOW);
    	       return 0;
              }break;
            }
            default:
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    Any ideas?

    For number two, I've tried the codes specified by those three links. I've put them everywhere in my code (because I don't think any of them specify where you have to put them) and I always get an error. The method that gives me the least amount of errors is when I put (for example) the code (in the section about Status Bars) from http://winprog.org/tutorial/app_three.html to the end of my code, I get this error:

    Code:
    expected constructor, deconstructor, or type conversion before '=' token
    expected ',' or ';' before '=' token
    [Build Error][main.o]Error 1
    For number three, I guess I forgot about that winprog page... I'll get right on that.

    And for number four, I don't understand your response, but it isn't that big of a priority.

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    903
    You forgot to add a break statement at the end of the WM_COMMAND processing. As suggested, you may want to subclass the static control or simply make your very own control. It's not that hard, it's the same as creating your main window. You fill in a WNDCLASSEX structure and pass it to RegisterClassEx(). You will need a procedure (like WndProc) and it will simply check if the user clicked the text inside, if he did, open up the browser.

  5. #5
    AoA
    AoA is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    Quote Originally Posted by Desolation
    You forgot to add a break statement at the end of the WM_COMMAND processing. As suggested, you may want to subclass the static control or simply make your very own control. It's not that hard, it's the same as creating your main window. You fill in a WNDCLASSEX structure and pass it to RegisterClassEx(). You will need a procedure (like WndProc) and it will simply check if the user clicked the text inside, if he did, open up the browser.
    I tried adding a break statement to the end of the WM_COMMAND processing as you said, but nothing works. Even if the menu item is supposed to do nothing, it still closes the program. Could you help me out by specifying where exactly I should put the break statement?
    [EDIT]Never mind! Problem Solved! However, I still don't understand what you said...[/EDIT]

    As for the other stuff you said, my limited knowledge of C++ means I have no idea what your talking about...
    Last edited by AoA; 07-30-2006 at 01:34 AM.

  6. #6
    AoA
    AoA is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    I've been experimenting with various status bar/dialogs (I already supplied the status bar code links in some previous posts, and I'm using the winprog tutorial for the dialogs), but none of them work. I've made sure I followed all the steps exactly, but there is always some sort of error.

    For example, with the winprog dialog tutorial, I tried to copy all the code to my project, but there is one small erorr:
    Code:
    [Resource Error] Syntax Error
    And the error occurs in the bold line:
    Code:
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END

  7. #7
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    For the resource error, are you including windows.h?

    For the code: inside the WM_COMMAND, you need another switch() statement, switch(LOWORD(wParam)). Since you'll be two switch()s deep, you might consider stuffing all of WM_COMMAND inside a function, something like:
    Code:
    void MyWin_OnCommand(HWND hwnd, WORD notifycode, WORD id, HWND control);
    or of your own definition, and call it from your window proc.

    Controls (edit boxes, buttons, etc) are simply windows, exactly like the window you create. They just have more complicated window procedures, and handle their own painting. Creating controls is just like creating a window, you just need to account for painting, and leave off normal "window" flags (WS_CAPTION, for example, wouldn't be proper for a control).

    Subclassing, however, is where you take an already made control (let's use STATIC for example), and "tweak" it. The static control is used for labels, icons, etchings, and some other things. To subclass, you replace the window's procedure with your own, but at the same time, you remember where the original procedure is. For some messages you do your own processing, but for most, you pass them on to the original procedure. Google "window subclassing".
    Last edited by Cactus_Hugger; 07-30-2006 at 05:58 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  8. #8
    AoA
    AoA is offline
    Registered User
    Join Date
    Oct 2005
    Posts
    8
    Quote Originally Posted by Cactus_Hugger
    For the resource error, are you including windows.h?

    For the code: inside the WM_COMMAND, you need another switch() statement, switch(LOWORD(wParam)). Since you'll be two switch()s deep, you might consider stuffing all of WM_COMMAND inside a function, something like:
    Code:
    void MyWin_OnCommand(HWND hwnd, WORD notifycode, WORD id, HWND control);
    or of your own definition, and call it from your window proc.
    I guess I didn't realize I had to include <windows.h> in my .rc file. Adding <windows.h> solves the original problem, but a new one pops up. It's the same error, but on a new line:
    Code:
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END
    As for the WM_COMMAND related problem, I already solved that, but thanks for your help.

  9. #9
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Is IDC_STATIC #define'd somewhere? Generally for resources, you create another file ("rsrc.h" or something) that looks like:
    Code:
    #ifndef RSRC_H
    #define RSRC_H
    
    #define IDD_ABOUT 100
    #define IDC_MYCONTROL 101
    #define IDC_ANOTHER 102
    ... etc ...
    #endif
    And then #include that in both the resource file and any .c files that need it. (For GetDlgItem() or other such functions.) Resource compilers won't flag IDD_ABOUT not being defined: resources themselves can have text names. (But it's more efficient to use #defines.) IDOK and IDCANCEL are defined in windows.h and friends.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 06:36 AM
  2. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 06:31 AM
  3. BMP Loading Questions, More OpenGL!!! :D
    By Shamino in forum Game Programming
    Replies: 13
    Last Post: 05-08-2005, 03:31 PM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM

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