Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 26th, 2005, 3:21 AM   #1
aquanius
Newbie
 
Join Date: Feb 2005
Posts: 8
Rep Power: 0 aquanius is on a distinguished road
menus

I'm new to c++ and i'm using this code:
#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           800,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

How can I make a menu bar like File | Edit | View like that, and how can I make the rest of the area while, so it'd look like a program with out anything in the content area.
aquanius is offline   Reply With Quote
Old Feb 26th, 2005, 9:06 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
To make menus, you generally have to fiddle with resource files and stuff like that. Bookmark http://www.functionx.com/, then take yourself to http://www.functionx.com/win32/howto/menus.htm and learn. I also suggest picking up a book on Windows programming.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 18th, 2005, 10:48 AM   #3
Trivium
Newbie
 
Join Date: May 2005
Location: Arkansas, USA
Posts: 5
Rep Power: 0 Trivium is on a distinguished road
I usually use the ShellExecute() API.
Trivium is offline   Reply With Quote
Old May 18th, 2005, 11:33 AM   #4
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
You have to have 2 new files to do this, a resource.h header file that you make yourself, it will contain all the id's of the menu items, and you will have a .rc file which contains the menu's "design". You have to also change

wincl.lpszMenuName = NULL;

to

wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MENUNAME);

in the main file.

Heres an example of the rsrc.rc file (This is what the .rc file is named by default in dev-c++, you can access it by clicking the edit resource file button in dev-c++.

IDR_MENUNAME MENU DISCARDABLE 
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New",                        ID_FILE_NEW
        MENUITEM "&Open",                       ID_FILE_OPEN
        MENUITEM "&Save",                       0, GRAYED
        MENUITEM "Save As",                     0, GRAYED
        MENUITEM "E&xit",                       ID_FILE_EXIT
        MENUITEM "&About",                      ID_FILE_ABOUT
    END
    POPUP "&Format"
    BEGIN
        MENUITEM "&Font",                       ID_FORMAT_FONT
        MENUITEM "&Highlighting",               ID_FORMAT_HIGHLIGHTING
        MENUITEM "&Tabbing",                    ID_FORMAT_TABBING
        MENUITEM "Template",                    ID_FORMAT_TEMPLATE
    END
END

The &'s before any letter specify that its a shortcut key to it, so if you hit Alt+F, the file menu expands.

After that you have to make and include the resource.h file, its included in both the main project file, and the .rc file.

Heres what the resource.h file might look like:

#define IDR_MENUNAME                      101
#define ID_FILE_OPEN                    9003
#define ID_FILE_SAVE                    9004
#define ID_FILE_SAVEAS                  9005
#define ID_FILE_NEW                     9006
#define ID_FILE_EXIT                    9001
#define ID_FILE_ABOUT                   9002
#define ID_FORMAT_FONT                  9007
#define ID_FORMAT_HIGHLIGHTING          9008
#define ID_FORMAT_TABBING               9009
#define ID_FORMAT_TEMPLATE              9010

Each item in the menu is given a uniquie id in the resource.h file. Then you use save resource.h, put #include "resource.h" in the main project file right below #include "windows.h" and you put it at the top or rsrc.rc file. Then rebuild the .rc file, and then compile the project, and if you followed the steps correctly, you should have a menu... I would recommend going to winprog.org for more help, they have full source code, and examples that will help a lot more... this is just something I typed up off the top of my head.
brokenhope is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:08 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC