I have been trying to put a CMFCMenuBar and CMFCToolBar together. The OnCreate of CFrameWndEx has following code for the purpose
if ( !m_wndMenuBar.Create(this) ) {
TRACE0("Failed to create menubar\n");
return -1; // fail to create
}
m_wndMenuBar.SetPaneStyle( m_wndMenuBar.GetPaneStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY );
CMFCPopupMenu::SetForceMenuFocus(FALSE);
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail (ID_FILE_NEW);
lstBasicCommands.AddTail (ID_FILE_OPEN);
lstBasicCommands.AddTail (ID_FILE_SAVE);
lstBasicCommands.AddTail (ID_APP_EXIT);
lstBasicCommands.AddTail (ID_APP_ABOUT);
CMFCToolBar::SetBasicCommands (lstBasicCommands);
CMFCToolBarInfo toolBarStruct;
SecureZeroMemory( &toolBarStruct, sizeof(CMFCToolBarInfo) );
toolBarStruct.m_uiMenuResID = IDR_TOOLBAR;
m_wndToolBar.SetMenuSizes( CSize(21,22), CSize(15,16) );
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC ) ||//, CRect(1,1,1,1), theApp.m_bHiColorIcons ? IDR_TOOLBAR_MAIN_256 : IDR_TOOLBAR_MAIN ) ||
!m_wndToolBar.LoadToolBarEx(IDR_TOOLBAR, toolBarStruct) ) {
TRACE0("Failed to create toolbar\n");
return -1;
}
m_wndMenuBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockPane(&m_wndMenuBar, CBRS_ALIGN_TOP);
DockPane(&m_wndToolBar);
The resultant UI that shows is something like
My question is two fold.
1. Why isnt the toolbar showing any icons?
2. Why isnt the menubar taking up the whole avaiable space horizontally?
Related
I tried to draw the menu background in MFC Dlg App.
But I found if I declare CMenu subMenu in OnInitDialog(), the background color works well.
If I declare CMenu subMenu in Head file or like CMenu* subMenu=new CMenu; in OnInitDialog(), the Item's background will not be changed.This is weird and seems to be related to the CMenu lifetime.
Variable:
CMenu m_accountMenu;
CMenu subMenu;
CMFCApplication3Dlg::OnInitDialog()
......some code
// TODO: Add extra initialization here
m_accountMenu.CreateMenu();
subMenu.CreatePopupMenu();
m_accountMenu.AppendMenuW(MF_BYPOSITION | MF_POPUP | MF_STRING , (UINT)subMenu.m_hMenu, _T("Sub Info"));
subMenu.AppendMenuW(/*MF_MENUBREAK|*/ MF_STRING | MF_ENABLED , 1001, _T("sub Info1")); // note: MF_MENUBREAK can make it work
subMenu.AppendMenuW(MF_STRING | MF_ENABLED , 1002, _T("sub Info2"));
CBrush cBrush;
cBrush.CreateSolidBrush(RGB(255, 0, 0));
MENUINFO mi = { 0 };
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_BACKGROUND;
mi.hbrBack = cBrush;
SetMenuInfo(m_accountMenu.GetSubMenu(0)->GetSafeHmenu(), &mi);
cBrush.Detach();
SetMenu(&m_accountMenu);
Can someone help me unravel the mystery? Any useful information will be appreciated.
I'm using TrackPopupMenuEx inside a UI CWinThread,
CMonitor is derived from CWinThread
monitor_ = (CMonitor *)AfxBeginThread(RUNTIME_CLASS(CMonitor));
CMonitor::InitInstance containes
m_pMainWnd = new CWnd();
m_pMainWnd->CreateEx(WS_EX_TOOLWINDOW | WS_EX_CONTROLPARENT | WS_EX_WINDOWEDGE | WS_EX_TOPMOST, AfxRegisterWndClass(CS_DBLCLKS),
NULL, WS_POPUP | WS_CLIPSIBLINGS | WS_VISIBLE, 50, 50, 50, 50, NULL, NULL);
Then later I do
SetForegroundWindow(AfxGetMainWnd()->m_hWnd);
auto popup_menu_flags = TPM_RETURNCMD | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON | TPM_VERTICAL;
auto menu_item = TrackPopupMenuEx(menu, popup_menu_flags, point.x, point.y, AfxGetMainWnd()->m_hWnd, NULL);
DestroyMenu(menu);
The PopupMenu display correctly and I can use the mouse to select a menu item. However the arrow keys do not work.
I have used Spy++ and m_pMainWnd get messages for WM_KEYUP, VK_DOWN but nothing happens. WM_KEYDOWN is not seen.
What am I missing?
Is it possible to get the offset of the page/window in the main Firefox window from inside an extension? To make things clear: It's not a DOM related question, I think it's an XPCOM question. I'll try to give an idea of what I need:
[Firefox]------------------------------------------------[ - # X ]
| Tab1 Title | Tab2 Title | |
------------------------------------------------------------------
| http://address.com/ | > |
------------------------------------------------------------------
* <- (X, Y) Offset of the page inside the main Firefox window |
| |
| |
| Page contents... |
| |
. .
. .
. .
Examples of basic bootstrap:
https://gist.github.com/Noitidart/9025999
This one has some extra stuff like the Services module imported, you need to import this module to use Services.wm; But to import Services you need the component Cu. see the top of the gist here:
https://gist.github.com/Noitidart/9026493
Now Services.wm.getMostRecentWindow('navigator:browser') gets only one window. If you want to iterate through all browser windows copy paste this. I include how to iterate over each each HTML window in the tabs in each browser as well.
const {interfaces: Ci, utils: Cu} = Components;
Cu.import('resource://gre/modules/Services.jsm');
//on this line can do Services.wm.getMostRecentBrowser('navigator:browser').gBrowser.contentDocument to get the currently focused tab document of the most recent browser window OR or continue to the loop below and it will do all windows and all tabs.
let XULWindows = Services.wm.getXULWindowEnumerator(null);
while (XULWindows.hasMoreElements()) {
let aXULWindow = XULWindows.getNext();
let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
//aDOMWindow.gBrowser can be accesed here
//to go through all tabs in the gBrowser do this:
if (aDOMWindow.gBrowser && aDOMWindow.gBrowser.tabContainer) {
var tabs = aDOMWindow.gBrowser.tabContainer.childNodes;
for (var i = 0; i < tabs.length; i++) {
Cu.reportError('DOING tab: ' + i);
var tabBrowser = tabs[i].linkedBrowser;
var aHTMLWindow = tabBrowser.contentWindow;
var aHTMLDocument = aHTMLWindow.document;
}
}
}
yes run this code to get the offset, you mean page offset right?
gBrowser.contentDocument.getBoundingClientRect().left
you just access the dom of the main page and you can do anything there
In WM_CREATE message of my main window procedure I create a listview with the next code:
hMyList = CreateWindowA( WC_LISTVIEW,TEXT(""), WS_CHILD | WS_VISIBLE |
LVS_LIST | LVS_TYPEMASK , XPOS(450), YPOS(20), NWIDTH(200),
NHEIGHT(200),hWnd,(HMENU) 9876, hInst, NULL);
Then I insert code to add a column to that listview:
LVCOLUMN column;
column.mask = LVCF_TEXT;
column.pszText = "Name";
SendMessage(hMyList, LVM_INSERTCOLUMN, NULL, (LPARAM)&column );
//returns 0; so everything is fine
But column doesn't appear in the listview.
What can be the source of the problem?
Columns are visible only in report/details view of the listview. To switch it in that mode you should post LVM_SETVIEW message to it, or use LVS_REPORT style instead of LVS_LIST in the CreateWindowA.
I am trying to add Image before the text in CTreeList control but it is not coming up, But what i observed is the the node name is started after some space , like it is leaving the space for bitmap , but image is not showing up.. here is the code snap:-
CImageList m_ImageList;
CBitmap m_Bitmap1;
m_ImageList.Create(16,16,ILC_COLOR32,1,1);
m_Bitmap1.LoadBitmap(IDB_BITMAP1);
m_ImageList.Add(&m_Bitmap1, RGB(0,0,0));
TreeSoft->Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP |
TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT |
TVS_SINGLEEXPAND | TVS_SHOWSELALWAYS |
TVS_TRACKSELECT,
CRect(10, 10, 200, 240), this, 0x1221);
TreeSoft->SetImageList(&m_ImageList, TVSIL_NORMAL);
hTree = TreeSoft->InsertItem( L"Software Production",0,0, TVI_ROOT);
hCompany = TreeSoft->InsertItem(L"Microsoft",0,0, hTree);
Pls tell me what i am missing here...
Now you just need to set the image for the newly created branch:
TreeSoft->SetItemImage(hTree , 0, 0); // I think it starts from 0 (if it does not show try 1)
Just for testing purposes.
Create an icon with 16-bit color palette.
Instead of ILC_COLOR32 use ILC_COLOR.
And instead of RGB(0,0,0) use (COLORREF)0xFFFFFF
I have exact the same code except the smaller color palette and it works.
If this works you can try with the bigger palette.