I haven't seen any examples of doing this on MSDN. Of course, that doesn't mean it's not there. lol
Printable View
I haven't seen any examples of doing this on MSDN. Of course, that doesn't mean it's not there. lol
Context Menu Strip I believe is what you should be searching for.
I found some context/shortcut menu examples on MSDN, but I can't get anything to actually display a damn menu after loading from the resource.
Post your codes/tell problem?
Custom controls and resources don't play well together unless you know how to do raw resource management.
For an ordinary right-click menu there should be many tutorials.
I haven't seen any in plain C/Win32
I got ........ed and deleted what I had. I did tell the problem. I compiled something nearly identical to the goddamn example and no menu appears. I used WM_RBUTTONUP on a subclassed listview control. I'm also curious if there's any way to force an entire menu to display somewhere like across the top of a tab or listview. I tried just including a menu on the dialog used for a tab, but it didn't appear.
Look at context menus. The platform SDK used to come with some very nice tutorials... Though m$ is really skimping down on what is being shipped with the platform SDKs nowadays. Either way, microsoft has ample code showing both how to make a standard one as well as a nifty office looking one.
Hi,
sometimes (often) the M$ samples don't work, cause there is some stuff deficiency.
And also often the code contains serious errors.
Maybe they drink too much wine or smoke bad pot, I don't know ...:rolleyes:
However ..., here's an example following up on your TabDlg issue ...
main.cpp
resource.hCode:#include "stdafx.h"
#include "resource.h"
HINSTANCE hInst;
TCHAR szAppName[] = TEXT ("MyApp") ;
bool InitTabCtrl (HWND hTabWnd) {
TCITEM tie;
tie.mask = TCIF_TEXT | TCIF_IMAGE;
tie.iImage = -1;
tie.pszText = "1st";
TabCtrl_InsertItem (hTabWnd, TabCtrl_GetItemCount(hTabWnd), &tie);
tie.pszText = "2nd";
TabCtrl_InsertItem (hTabWnd, TabCtrl_GetItemCount(hTabWnd), &tie);
tie.pszText = "3rd";
TabCtrl_InsertItem (hTabWnd, TabCtrl_GetItemCount(hTabWnd), &tie);
tie.pszText = "4th";
TabCtrl_InsertItem (hTabWnd, TabCtrl_GetItemCount(hTabWnd), &tie);
return true;
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndTab;
static HMENU hMenu;
POINT pt;
switch(uMsg)
{
case WM_INITDIALOG:
hwndTab = GetDlgItem (hwndDlg, IDC_TAB1);
InitTabCtrl (hwndTab);
hMenu = LoadMenu (hInst, szAppName) ;
hMenu = GetSubMenu (hMenu, 0) ;
/*
* TODO: Add code to initialize the dialog.
*/
return TRUE;
case WM_RBUTTONUP:
pt.x = LOWORD (lParam);
pt.y = HIWORD (lParam);
ClientToScreen (hwndDlg, &pt);
TrackPopupMenu (hMenu, TPM_RIGHTBUTTON, pt.x, pt.y,
0, hwndDlg, NULL);
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
/*
* TODO: Add more control ID's, when needed.
*/
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_TEST:
MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
return TRUE;
case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
case IDM_FILE_SAVE_AS:
case IDM_EDIT_UNDO:
case IDM_EDIT_CUT:
case IDM_EDIT_COPY:
case IDM_EDIT_PASTE:
case IDM_EDIT_CLEAR:
MessageBeep (0);
return TRUE;
}
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_TAB_CLASSES | ICC_STANDARD_CLASSES;
InitCommonControlsEx (&iccx);
// The user interface is a modal dialog box
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, DialogProc);
}
rcfile.rcCode:#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 101
#define IDC_BTN_TEST 1001
#define IDC_BTN_QUIT 1002
#define IDC_TAB1 1003
#define IDM_FILE_NEW 40001
#define IDM_FILE_OPEN 40002
#define IDM_FILE_SAVE 40003
#define IDM_FILE_SAVE_AS 40004
#define IDM_APP_EXIT 40005
#define IDM_EDIT_UNDO 40006
#define IDM_EDIT_CUT 40007
#define IDM_EDIT_COPY 40008
#define IDM_EDIT_PASTE 40009
#define IDM_EDIT_CLEAR 40010
#define IDM_HELP_HELP 40016
#define IDM_APP_HELP 40016
#define IDM_APP_ABOUT 40017
Code:// Generated by ResEdit 1.4.3
// Copyright (C) 2006-2008
// http://www.resedit.net
#include "resource.h"
#include <windows.h>
//
// Dialog resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
DLG_MAIN DIALOGEX 6, 5, 194, 106
STYLE DS_3DLOOK | DS_CENTER | DS_SETFONT | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_GROUP | WS_THICKFRAME | WS_SYSMENU
CAPTION "Code::Blocks Template Dialog App"
FONT 8, "MS Sans Serif", 0, 0, 1
BEGIN
PUSHBUTTON "&Test", IDC_BTN_TEST, 138, 5, 46, 15
PUSHBUTTON "&Quit", IDC_BTN_QUIT, 138, 29, 46, 15
CONTROL "", IDC_TAB1, WC_TABCONTROL, 0, 4, 4, 125, 97
END
//
// Menu
//
MYAPP MENU DISCARDABLE
BEGIN
POPUP "MyMenu"
BEGIN
POPUP "&Datei"
BEGIN
MENUITEM "&Neu", IDM_FILE_NEW
MENUITEM "&Öffnen", IDM_FILE_OPEN
MENUITEM "&Speichern", IDM_FILE_SAVE
MENUITEM "Speichern &unter", IDM_FILE_SAVE_AS
MENUITEM SEPARATOR
MENUITEM "B&eenden", IDM_APP_EXIT
END
POPUP "&Bearbeiten"
BEGIN
MENUITEM "&Widerrufen", IDM_EDIT_UNDO
MENUITEM SEPARATOR
MENUITEM "A&usschneiden", IDM_EDIT_CUT
MENUITEM "&Kopieren", IDM_EDIT_COPY
MENUITEM "E&infügen", IDM_EDIT_PASTE
MENUITEM "&Löschen", IDM_EDIT_CLEAR
END
POPUP "&Hilfe"
BEGIN
MENUITEM "&Hilfe...", IDM_APP_HELP
MENUITEM "I&nfo über MyApp...", IDM_APP_ABOUT
END
END
END
//
// Manifest resources
//
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 RT_MANIFEST ".\\manifest.xml"
Greetz
Greenhorn
p.s. I can seriously recommend you this book from C. Petzold ...
http://www.charlespetzold.com/pw5/
There is NO cent wasted, believe me.
I can't argue about the M$ code being horrid at times, but the sample source files that they ship with the platform SDK all compile.... granted some with warnings... But they compile. Now the MSDN docs on the other hand. That is always a gamble.
Greenhorn to the rescue again. ;) I think I got it. I'd still be more interested in forcing a whole menu bar to appear where I want it though. I don't want it on the main app, but on a tab itself. There's a dialog resource loaded for each tab. I tried setting the dialog in the resource file to use the menu but I haven't got the menu to appear. I don't know if it needs loaded by itself or if it's because of the dialog being discardable/etc. Last time I used a menu bar with a dialog, it was apparently loaded with the dialog, because I didn't do anything to load it and it worked.
If you make a pseudo-context menu you can make it appear where ever you feel like. I had to do that in a project where I wanted the context menu to have shadows (yep. That sounds like a moronic reason to go through extra work, but I thought it would look spiffy).
Yes, master is right ..., combine a Toolbar/Rebar and the Popup menu to create an User Defiened Menubar ... ;)
Many applications do this.
Greetz
Greenhorn
You are obviously not a rookie, Greenhorn__. You have a misleading name ;) I like it.
Wait. What about loading a menu for the main dialog after it's created? Like destroy the menu that's there and set a different one each time the selected tab changes. I tried slapping context menus on a header control, btw. Is there a way to force a context menu to be a certain width? If it doesn't take up the whole width of the header item, it doesn't look right.
Hmm, I'm not sure what you wanna have as result, I'm a little bit confused, so help me to understand what you wanna do.
You have a main window and several dialog boxes with a Tab control in the dialog box ?
Or do you want to have the Tab controls inside the main window, like normal controls ?
Now you want to have a menubar inside the main window that changes its content for every Tab control ?
Could you post a pic of your current application or attach the source ?
It's easier for us to help you if we know what you wanna get in the end, isn't it !? ;)
Gretz
Greenhorn
p.s. Thanks for the flowers, master, but I believe I am a rookie ;)