im new to this c++ thing and windows api thing, and i got most of this code from a tutorial but i modified it alot.
how do i retrieve a handle to a dialog box so i can put my menu inside it?
(when i put the code for the menu in resourcces into the definition of the dialog box in the resources i get a syntax error).
but i want to declare setmenu() in wm_initdialog, but it says i need a handle to the dialog box and a handle to a menu.
how would i get that?

since im learning i dont use visual resource editors.
main cpp:

#include "resource.h"
#include <windows.h>



const char g_szClassName[] = "myWindowClass";
HWND dialogshandle;
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:
     

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_STUFF_GO:
                DialogBox(GetModuleHandle(NULL),
                MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                case ID_NEW_WIN:
         MessageBox(NULL, "fua", "title", MB_OK);
        break;

        case IDOK:
                    DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                break;
                case IDCANCEL:
                    EndDialog(hwnd, IDCANCEL);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}

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

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {


        case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
                break;
                case ID_STUFF_GO:
case IDD_ABOUT:
        {
            int ret = DialogBox(GetModuleHandle(NULL),
                MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
            if(ret == IDOK){
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(ret == IDCANCEL){
                MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            else if(ret == -1){
                MessageBox(hwnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
        }
                break;
                case ID_NEW_WIN:
         MessageBox(NULL, "fua", "title", MB_OK);
        break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:

            PostQuitMessage(0);
        break;
            }

     default:
            return DefWindowProc(hwnd, Message, wParam, lParam);

}
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){

WNDCLASSEX wc;
HWND hwnd;
MSG msg;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon  = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MYMENU);
wc.lpszClassName = g_szClassName;
wc.hIconSm  = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);

if (!RegisterClassEx (&wc))
{
                     MessageBox(NULL, "Window Registration Failed!", "Error!",MB_ICONEXCLAMATION | MB_OK);
                     return 0;
                     }

hwnd = CreateWindowEx (
WS_EX_CLIENTEDGE, g_szClassName, "The title of my window",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);

if(hwnd == NULL)
{
        MessageBox(NULL, "Window creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
        return 0;
        }
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);

        while(GetMessage(&msg, NULL, 0, 0) > 0)
        {
                               TranslateMessage(&msg);
                               DispatchMessage(&msg);
                               }

return msg.wParam;
}

resource.rc

#include "resource.h"
#include "windows.h"
IDR_MYMENU  MENU
BEGIN
    POPUP "File"
    BEGIN
        MENUITEM "E&xit", ID_FILE_EXIT
        MENUITEM "Create New Window", ID_NEW_WIN
    END

    POPUP "&Stuff"
    BEGIN
        MENUITEM "&Go", ID_STUFF_GO
        MENUITEM "G&o somewhere else", 0, GRAYED
    END
END

IDI_MYICON ICON "menu_one.ico"


IDD_ABOUT DIALOG DISCARDABLE  0, 0, 400, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Enter h4x"
FONT 8, "MS Sans Serif"

BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,100,100,50,50
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    GROUPBOX        "D&IALOG",IDC_STATIC,0,0,225,52
    CTEXT           "DI&ALOG",IDC_STATIC,0,0,144,32
END

resource.h

#define IDR_MYMENU 101
#define IDI_MYICON 201
#define IDC_STATIC -1
#define ID_FILE_EXIT 9001
#define ID_STUFF_GO 9002
#define ID_NEW_WIN 9003
#define IDD_ABOUT 9004
#define IDD_ABOUT2 9005

Recommended Answers

All 4 Replies

bump

commented: Bumping is incredibly rude and presumptuous. -5

Like this:

DialogBox(hInst,
          MAKEINTRESOURCE(IDD_DLGINTRESOURCENAME),
          hWnd,
          reinterpret_cast<DLGPROC>(nameOfDlgMessageHandlerProc));

Where would I get the handle to the dialog box, and the handle of the menu?
I'm new at this so you will have to explain to me better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.