Results 1 to 3 of 3

Thread: creating a menu or dialog

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Unhappy creating a menu or dialog

    I've been trying for a long time as well as all day today to get a menu or dialog box to work, with no luck. THe windows Programming book has led me to many problems I can't figure out. Does someone have a simple menu or dialog box step by step instructions? I just want something so i can get something to work so I get the concept down. THanks alot!!
    Matt
    Matt

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Assuming you're using VC++

    1) Create an empty Win32 Application project (NOT console).

    2) Choose Project->Add to Project->New... and add a code file (.cpp)

    3) Choose Project->Add to Project->New... and add a resource script

    4) Choose Insert->Resource... and add a menu resource. Use the resource editor to add menu items. Give the menu a meaningful ID (like IDM_MAINMENU, in the menu properties dialog).

    5) Choose Project->Add to Project->Files... and select the file "resource.h" that was automatically created.

    6) Now write the following code in your main module.

    Code:
    // extracts from the code, the complete file is attached
    #include <windows.h>
    #include "resource.h"	// resource ID aliases
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int iShowCmd)
    {
    	MSG msg;
    	WNDCLASS wc;
    	// ...
    	wc.lpszClassName = "MenuDemo";
    	wc.lpszMenuName = MAKEINTRESOURCE(IDM_MAINMENU);  // this is the most important line!
    	RegisterClass(&wc);
    
    	HWND hwnd = CreateWindow("MenuDemo", /* ... */);
    	ShowWindow(hwnd, iShowCmd);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    Attached Files Attached Files
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Thumbs up

    Thanks you very much!! It works!
    Matt

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