I am new to Win32 API and am having trouble setting up the menu. Here is what I have at the moment (my new way of doing the main.cpp code is from another member) but I cannot understand where to put in the function call for the menu..

main.cpp

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

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
 switch(Msg)
 {
  case WM_INITDIALOG:
       // Initiate what loads when the application starts
  return TRUE;
  
  case WM_COMMAND:
       switch(LOWORD(wParam))
       {
        case IDC_LATE_BREAK_BTN:
        return TRUE;
        
        case IDCANCEL:
             EndDialog(hWndDlg, 0);
        return TRUE;
       }
       break;
 }
 return FALSE;
 
}

int APIENTRY
WinMain (HINSTANCE hInst, HINSTANCE unused, LPSTR cmdLine, int cmdShow)
{
 DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG), 0, (DLGPROC)(DlgProc));
 return 0;
}

GUI.rc

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

IDD_CONTROLS_DLG DIALOG DISCARDABLE  0, 0, 132, 180
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "HSBC Break Clock"
FONT 8, "MS Sans Serif"
BEGIN
    LTEXT           "Current Time is: ",IDC_STATIC,10,10,55,12
    LTEXT           "Meeting Time: ",IDC_STATIC,10,30,45,12
    LTEXT           "Start Time: ",IDC_STATIC,10,50,45,12
    LTEXT           "Break 1 Start: ",IDC_STATIC,10,70,45,12
    LTEXT           "Lunch Start: ",IDC_STATIC,10,90,45,12
    LTEXT           "Break 2 Start: ",IDC_STATIC,10,110,45,12
    LTEXT           "End Time: ",IDC_STATIC,10,130,45,12
    EDITTEXT        IDC_CURRENT_TIME,80,10,45,12, ES_AUTOHSCROLL
    EDITTEXT        IDC_MEETING_TIME,80,30,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_START_TIME,80,50,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_BREAK1,80,70,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_LUNCH,80,90,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_BREAK2,80,110,45,12,ES_RIGHT | ES_AUTOHSCROLL
    EDITTEXT        IDC_LEAVE_TIME,80,130,45,12,ES_RIGHT | ES_AUTOHSCROLL
    PUSHBUTTON      "Late Break",IDC_LATE_BREAK_BTN,20,150,40,18
    PUSHBUTTON      "Quit",IDCANCEL,70,150,40,18
END

IDR_MAIN_MENU MENU 
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "Se&lect a Sound",             IDM_FILE_SOUND
        MENUITEM "E&xit",                       IDM_FILE_EXIT
    END
    POPUP "&Help"
    BEGIN
        MENUITEM "&About...\tF1",               IDM_HELP_ABOUT
    END
END

resource.h

#define IDD_CONTROLS_DLG                101
#define IDR_MAIN_MENU                   102
#define IDR_POPUP                       103
#define IDC_CURRENT_TIME                1002
#define IDC_MEETING_TIME                1003
#define IDC_START_TIME                  1004
#define IDC_BREAK1                      1005
#define IDC_LUNCH                       1006
#define IDC_BREAK2                      1007
#define IDC_LEAVE_TIME                  1008
#define IDC_LATE_BREAK_BTN              1009
#define IDM_FILE_SOUND                  2001
#define IDM_FILE_EXIT                   2002
#define IDM_HELP_ABOUT                  2003

You haven't associated the menu with the dialog. Add this line after the FONT line in the dialog definition: MENU IDR_MAIN_MENU

Where is the FONT line?

The FONT line is about the 7th line in gui.rc. Put the MENU line after that.

In that same file you can get rid of <afxres.h> if you replace IDC_STATIC with its value, -1. I believe most people do this.

In main.c, <string> should be <string.h>. If you didn't get an error, then you're compiling in C++ mode (probably with a .cpp filename). This is not necessarily a problem, but if you mean to be using C, you should compile in C mode (with a .c filename).

I am way out of date with c.. I am using Dev-C++.. And I have the settings tweaked for compiling with c++ and enabling C.

It works now.. Thanks.. After I finish this project in C I will start using C++. I am just learning Win32 API and the best tutorial i found was in C.. I just dont understand most of it yet.. I am very proficient in Java and VB and C.. Thanks again.

Sounds good. :)

I forgot to mention above that if you do remove <afxres.h> (and use -1 instead of IDC_STATIC) you probably have to replace it with <windows.h>.

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.