Results 1 to 9 of 9

Thread: Menus with API

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Angry Menus with API

    I would like to use the API to create my menus, instead of a resource file. Could anyone please tell me how to, or where i could find a tutorial? thank you very much!
    Amon Ra
    The Power of Learning.

  2. #2

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Talking Finally...

    Ahhh, thanks so much no more hassle from MS VC++ resources. Btw, how do i produce an event for when the menu is clicked?(know which menu is clicked, and then have an event?)
    Thanks in advance
    Amon Ra
    The Power of Learning.

  3. #3

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy Weird...

    How come my MSVC++ always gives me this error?
    Fatal Error:
    "The compiler is out of heap space..."
    Here is all the code:

    #include <windows.h>

    static char g_szClassName[] = "My Window Class";
    static HINSTANCE g_hInst = NULL;

    HMENU MyMenu;
    HMENU SubMenu;
    HWND hButton;

    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam,
    LPARAM lParam)
    {
    switch(Message) {
    case WM_CREATE:
    {

    MENUITEMINFO MenuInfo ;
    MenuInfo.cbSize=sizeof(MenuInfo);
    MenuInfo.fMask=MIIM_DATA|MIIM_ID|MIIM_TYPE|MIIM_STATE ;
    MenuInfo.fType= MFT_STRING|MFT_MENUBREAK ;
    MenuInfo.fState=MFS_DISABLED ;
    MenuInfo.wID=152;
    MenuInfo.hSubMenu=NULL;
    MenuInfo.hbmpChecked=NULL;
    MenuInfo.hbmpUnchecked=NULL;
    MenuInfo.dwItemData=153;
    MenuInfo.dwTypeData="My Menu Item";
    MenuInfo.cch=sizeof("My Menu Item");

    SubMenu=CreateMenu();
    InsertMenuItem(SubMenu,2,true,&MenuInfo);

    MenuInfo.cbSize=sizeof(MenuInfo);
    MenuInfo.fMask=MIIM_DATA|MIIM_ID|MIIM_TYPE|MIIM_STATE|MIIM_SUBMENU ;
    MenuInfo.fType= MFT_STRING ;
    MenuInfo.fState=MFS_ENABLED ;
    MenuInfo.wID=150;
    MenuInfo.hSubMenu=SubMenu;
    MenuInfo.hbmpChecked=NULL;
    MenuInfo.hbmpUnchecked=NULL;
    MenuInfo.dwItemData=151;
    MenuInfo.dwTypeData="My Menu";
    MenuInfo.cch=sizeof("My Menu");
    MyMenu=CreateMenu();
    InsertMenuItem(MyMenu,1,true,&MenuInfo);

    SetMenu(hwnd,MyMenu);
    }
    break;
    case WM_LBUTTONDOWN: //handles the message when clicked
    {
    char szFileName[MAX_PATH];
    HINSTANCE hInstance = GetModuleHandle(NULL);

    GetModuleFileName(hInstance, szFileName, MAX_PATH);
    MessageBox(hwnd, szFileName, "Left Button Clicked: Program Name and Path: ",
    MB_ICONINFORMATION | MB_OK);
    SetWindowText(hwnd, "hello cruel world!");
    }
    break;
    case WM_RBUTTONDOWN:
    PostMessage(hwnd, WM_CLOSE,0,0); //Post a message in the message queue
    break;
    case WM_CLOSE: //destroy the window
    DestroyMenu(SubMenu);
    DestroyMenu(MyMenu);
    DestroyWindow(hwnd);
    break;
    case WM_DESTROY: //terminates the program
    PostQuitMessage(0);
    break;
    default:
    return DefWindowProc(hwnd,Message,wParam,lParam);
    }

    return 0;
    }

    //main function of the program(like main() in console)
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nShowCmd)
    {
    WNDCLASSEX WndClass;
    HWND hwnd;
    MSG msg;

    //set class characteristics
    g_hInst = hInstance;
    WndClass.cbSize = sizeof(WNDCLASSEX);
    WndClass.style = NULL;
    WndClass.lpfnWndProc = WndProc;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = g_hInst;
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    WndClass.lpszMenuName = NULL;
    WndClass.lpszClassName = g_szClassName;
    WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    //check for window creation: success?
    if(!RegisterClassEx(&WndClass)) {
    MessageBox(0, "Window Registration Failed!","Error",
    MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
    return 0;
    }

    //finally create the window
    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,
    g_szClassName,
    "This is my first window in C++!!",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, 300, 300,
    NULL, NULL, g_hInst, NULL);

    //created successfully?
    if(hwnd == NULL) {
    MessageBox(0, "Window Creation Failed", "Error",
    MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
    return 0;
    }

    //show it
    ShowWindow(hwnd, nShowCmd);
    UpdateWindow(hwnd);

    hButton = CreateWindowEx(NULL,"Button1","C++ Button",
    WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, NULL,
    g_hInst);

    //message loop: message --> WindowProc
    while(GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }

    return msg.wParam;
    }

    Thanks for helping If you dont mind, you can also help on the previous post Thanks
    Alex
    Amon Ra
    The Power of Learning.

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Guys, just one note: Please put the code in the [code./code] tags.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    I dont know why you are running out of heap space, but I did find a problem with your program. You need to fix your CreateWindowEX, your button class has to be called "Button", plus you need a lParm, at the end of your call.

    So it would look like this:

    PHP Code:
    hButton CreateWindowEx(NULL,"Button","C++ Button"
    WS_CHILD WS_VISIBLE005050hwndNULL
    g_hInst,0); 
    Other than that your program worked fine for me.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  6. #6
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    I think MenuInfo.wID is the item number you should intercept in th WM_COMMAND but i'm not shure so try out all the different item number's and see which one the the menu item ID.
    VB-World addict!

    All spelling errors are undocumented words!
    http://www.bells.f2s.com

  7. #7

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Question Menus...

    How do I get the message when a menu item is clicked? Meaning, how do i respond to a menu click the way i respond to a button click?
    Amon Ra
    The Power of Learning.

  8. #8
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Just change the case to your wID #ers:
    PHP Code:
    case WM_COMMAND:
            {
                switch(
    wparam)
                {
                case 
    ID_QUIT:
                    {
                        
    MessageBox(NULL"The application is now quiting!"
                                   
    "Quiting application"MB_OK MB_ICONINFORMATION);
                        
    PostQuitMessage(0);
                        return 
    0;
                    } break;
                }
            } break; 
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  9. #9

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Talking Cool...

    Thanks a lot
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width