How can I redraw the ribbon UI Elements - mfc

I am doing a MFC Ribbon programming based on MDI environments.
I want to change the elements of the MFC Ribbon gallery button on runtime.
So I create a HBITMAP objects on runtime and using SetPallete method in CMFCToolBarImage class.
My code is below.
CMFCRibbonGallery* pGallery = (CMFCRibbonGallery*)pRibbon->FindByID(ID_BUTTON_LABEL_CONTROL_GALLERY);
CMFCToolBarImages test;
test.SetImageSize(t);
test.AddImage(hBitmap, 0);
pGallery->Clear();
pGallery->SetPalette(test);
pGallery->RedrawIcons();
When i run this code, the ribbon gallery button is deleted, but there is no elements in the gallery button.
Strange thing is when I Minimize/Maximize the window, The Icons are visible at the button.
How can Icons are visible without minimize/maximize the window?
Thanks you.

Try and call CMFCRibbonBar::RecalcLayout, this function forces the complete ribbon layout to be recalculated and redrawn.

RecalcLayout() is sometimes not enough. In that case use ForceRecalcLayout(), that will do the trick.

Related

What MFC class should I base free floating views on

I have a dialog based MFC application. Now I want to create a wiew (one or more) with a toolbar, scroll bars and a client window (based on CWnd).
What MFC class should I base this window on?
What is the best way to do it?
Thanks.
Using a scrolling client window is more natural in a Document-View application than a dialog based application -- you can have menu bars and toolbars connected to a dialog, but to a View as far as I know.
A SDI application allows support for multiple docking/floating toolbars and multiple views of the same document, so this would be my advice...
Start with a CFrameWnd. It's job is to give your window a titlebar/close button etc., and position control bars (such as a toolbar) and a menu (if you want one) and a view within itself. The view should be a CScrollView (for painted graphics) or a CFormView (for dialog-like controls).
You will find this to be a lot easier if your just start from scratch and let the app wizard generate an SDI or MDI app to start with.

Put a window behind desktop icons

currently I've this but it doesn't put my window behind the desktop
SetWindowPos(hWnd,HWND_BOTTOM,0,0,SCREEN_WIDTH,SCREEN_HEIGHT,SWP_FRAMECHANGED);
ShowWindow(hWnd,SW_SHOWNOACTIVATE);
i want to put my window behind every window even the taskbar and desktop icons window
please help me how can i do this
thanks in advance
The Desktop is a ListView control, and the desktop icons are its list items. Top-level windows can be made children of that ListView window, but it is impossible to place a child window between the ListView's background and its list items. The only way to make anything appear behind the items is to draw directly on the ListView's background, such as by subclassing it to intercept its WM_ERASEBKGND and WM_PAINT messages.

Insert an UI into another MFC Dialog

I have one MFC application (exe) that contains two panes in its main UI. This application loads another DLL that also contains one dialog. How can I programatically place a Dialog defined into the DLL, and put it into (within) the pane of the MFC application? The question is not how to programatically retrieve the dialog from the DLL but how to put this dialog 'on the top' (within, inside) of one UI pane that belongs to the application?
My goal is to customize the UI of the application with dialog(s) retrieved from a dll and give the user the feeling that these dialogs all belong to one application UI. Thanks for any hint.
I have some applications with this feature, often with a tab control to alternate between windows.
First I set a frame in the container window, invisible to the user. The frame is just a placeholder to where the dialog window will be.
Then I make an instance of the dialog window as a global variable in the container class, I create the dialog window as a modeless window (using Create(), not DoModal()), move the window to the same RECT of the frame control, and call ShowWindow() to show the window.
Am I understanding you correctly that you don't want the dialogs to appear as dialogs, but rather as content of another window, or as a pane?
In other words, you want to get rid of the dialog's title bar and embed the dialog's content into another window, is that right?
That is possible. You would need to create the dialog without the title bar (change the window style) and make sure that you create the dialog's window as a childwindow of the window where you want the content to go. I can explain this further but I first would like to know if I'm understanding you correctly.

Custom dropdown for CComboBox

I'm trying to create a custom dropdown for a derivative of CComboBox. The dropdown will be a calendar control plus some 'hotspots', e.g.
So I figure the best way to achieve this is to have a simple CWnd-derived class which acts as the parent to the calendar control, and have it paint the hotspots itself.
The window needs to be a popup window - I think - rather than a child window so that it isn't clipped. But doing this causes the dialog (on which the combobox control is placed) to stop being the topmost (foreground?) window, leading to its frame being drawn differently:
alt text http://img693.imageshack.us/img693/3474/35148785.png
This spoils the illusion that the dropdown is part of the combobox since its acting more like a modal dialog at this point. Any suggestions on how I make the custom dropdown behave like the regular dropdown?
Are there any other pitfalls I need to watch out for, e.g. focus and mouse capture issues?
When you create your popup window, you need to specify its owner. Owned popup windows will activate their owner when you activate them. Not specifying an owner will cause your window to get activated, which causes the change in the owner you're seeing.
Yeah I had this problem once. A quick google makes me suspect I solved this by using CreateWindowEx() and specifying WS_EX_NOACTIVATE. I have some other code that achieves the same effect by making the window with WS_EX_TOOLWINDOW rather than as a popup window, but I'm not sure of why that was done that way, my intuition would say that making it a popup window would be the way to go.
You can find in the following links two sample project that put in the CComboBox dropdown window a CTreeCtrl or a CListCtrl controls ... similar, you can put whatever you need there. Here is the links:
Tree ComboBox Control
and
List ComboBox Control
I hope this help you.

Can I draw a menu (not popup menu) in any rectangular region of a window with MFC?

I override OnNcPaint() method along with OnNcLButtonDown() and OnNcMouseMove() and OnNcHitTest() method. So the original menu of the window doesn't exist. I want to add a menu with the area of the caption bar. How can I do this?
Thank you very much!
The menu is painted as part of the non-client area. So if you are doing your own non-client painting, you'll also have to draw the window yourself. You may be able to hack something out with TrackPopupMenu to do the actual menu drawing, and you'll just have to handle the menu bar and top-level menu items yourself.
Drawing the non-client area yourself is fraught with peril. Are you sure you don't just want to use an owner drawn menu?
It can be tempting to tweak your UI dialogs to fit your exact needs, but also keep in mind that it is jarring to users who are accustomed to the look-and-feel of windows already.