Help with Win32 API Menu

Thread Solved

Join Date: Apr 2008
Posts: 30
Reputation: BruenorBH is an unknown quantity at this point 
Solved Threads: 0
BruenorBH's Avatar
BruenorBH BruenorBH is offline Offline
Light Poster

Help with Win32 API Menu

 
0
  #1
Apr 24th, 2009
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
  1. #include <windows.h>
  2. #include <string>
  3. #include "resource.h"
  4.  
  5. LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
  6. {
  7. switch(Msg)
  8. {
  9. case WM_INITDIALOG:
  10. // Initiate what loads when the application starts
  11. return TRUE;
  12.  
  13. case WM_COMMAND:
  14. switch(LOWORD(wParam))
  15. {
  16. case IDC_LATE_BREAK_BTN:
  17. return TRUE;
  18.  
  19. case IDCANCEL:
  20. EndDialog(hWndDlg, 0);
  21. return TRUE;
  22. }
  23. break;
  24. }
  25. return FALSE;
  26.  
  27. }
  28.  
  29. int APIENTRY
  30. WinMain (HINSTANCE hInst, HINSTANCE unused, LPSTR cmdLine, int cmdShow)
  31. {
  32. DialogBox(hInst, MAKEINTRESOURCE(IDD_CONTROLS_DLG), 0, (DLGPROC)(DlgProc));
  33. return 0;
  34. }

GUI.rc
  1. #include "resource.h"
  2. #include <afxres.h>
  3.  
  4. IDD_CONTROLS_DLG DIALOG DISCARDABLE 0, 0, 132, 180
  5. STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
  6. CAPTION "HSBC Break Clock"
  7. FONT 8, "MS Sans Serif"
  8. BEGIN
  9. LTEXT "Current Time is: ",IDC_STATIC,10,10,55,12
  10. LTEXT "Meeting Time: ",IDC_STATIC,10,30,45,12
  11. LTEXT "Start Time: ",IDC_STATIC,10,50,45,12
  12. LTEXT "Break 1 Start: ",IDC_STATIC,10,70,45,12
  13. LTEXT "Lunch Start: ",IDC_STATIC,10,90,45,12
  14. LTEXT "Break 2 Start: ",IDC_STATIC,10,110,45,12
  15. LTEXT "End Time: ",IDC_STATIC,10,130,45,12
  16. EDITTEXT IDC_CURRENT_TIME,80,10,45,12, ES_AUTOHSCROLL
  17. EDITTEXT IDC_MEETING_TIME,80,30,45,12,ES_RIGHT | ES_AUTOHSCROLL
  18. EDITTEXT IDC_START_TIME,80,50,45,12,ES_RIGHT | ES_AUTOHSCROLL
  19. EDITTEXT IDC_BREAK1,80,70,45,12,ES_RIGHT | ES_AUTOHSCROLL
  20. EDITTEXT IDC_LUNCH,80,90,45,12,ES_RIGHT | ES_AUTOHSCROLL
  21. EDITTEXT IDC_BREAK2,80,110,45,12,ES_RIGHT | ES_AUTOHSCROLL
  22. EDITTEXT IDC_LEAVE_TIME,80,130,45,12,ES_RIGHT | ES_AUTOHSCROLL
  23. PUSHBUTTON "Late Break",IDC_LATE_BREAK_BTN,20,150,40,18
  24. PUSHBUTTON "Quit",IDCANCEL,70,150,40,18
  25. END
  26.  
  27. IDR_MAIN_MENU MENU
  28. BEGIN
  29. POPUP "&File"
  30. BEGIN
  31. MENUITEM "Se&lect a Sound", IDM_FILE_SOUND
  32. MENUITEM "E&xit", IDM_FILE_EXIT
  33. END
  34. POPUP "&Help"
  35. BEGIN
  36. MENUITEM "&About...\tF1", IDM_HELP_ABOUT
  37. END
  38. END

resource.h
  1. #define IDD_CONTROLS_DLG 101
  2. #define IDR_MAIN_MENU 102
  3. #define IDR_POPUP 103
  4. #define IDC_CURRENT_TIME 1002
  5. #define IDC_MEETING_TIME 1003
  6. #define IDC_START_TIME 1004
  7. #define IDC_BREAK1 1005
  8. #define IDC_LUNCH 1006
  9. #define IDC_BREAK2 1007
  10. #define IDC_LEAVE_TIME 1008
  11. #define IDC_LATE_BREAK_BTN 1009
  12. #define IDM_FILE_SOUND 2001
  13. #define IDM_FILE_EXIT 2002
  14. #define IDM_HELP_ABOUT 2003
Error: Keyboard not attached. Press F1 to continue.

I do know everything, just not all at once. It's a virtual memory problem.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Help with Win32 API Menu

 
0
  #2
Apr 24th, 2009
You haven't associated the menu with the dialog. Add this line after the FONT line in the dialog definition:
MENU IDR_MAIN_MENU
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: BruenorBH is an unknown quantity at this point 
Solved Threads: 0
BruenorBH's Avatar
BruenorBH BruenorBH is offline Offline
Light Poster

Re: Help with Win32 API Menu

 
0
  #3
Apr 24th, 2009
Where is the FONT line?
Error: Keyboard not attached. Press F1 to continue.

I do know everything, just not all at once. It's a virtual memory problem.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Help with Win32 API Menu

 
0
  #4
Apr 24th, 2009
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).
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 30
Reputation: BruenorBH is an unknown quantity at this point 
Solved Threads: 0
BruenorBH's Avatar
BruenorBH BruenorBH is offline Offline
Light Poster

Re: Help with Win32 API Menu

 
0
  #5
Apr 24th, 2009
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.
Error: Keyboard not attached. Press F1 to continue.

I do know everything, just not all at once. It's a virtual memory problem.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Help with Win32 API Menu

 
0
  #6
Apr 24th, 2009
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>.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC