Handling dynamic text editing in an MFC CView - mfc

I have a class that implements OnDraw to draw text and images to a CView. At certain times (ie onClick) I would like this text to be editable in place. What would be the best way to implement this?
Have the class have a CEdit object that I hide and show and draw over
the top of my text.
Handle key presses in the class and implement my
own editing
Have something external to the class control whether to show the edit box or my class
Something else?

Go with your first idea, create a CEdit box when you need some text editing. If you look at how a ListCtrl handles rename functionality it does exactly that.

Related

Refreshing display objects after resizing

I have an app that contains a CControlBar and in that sits a few CStatic Objects which each display an icon with some text.
I have a bug where if I keep resizing the control bar a bit using the mouse, all the text and icons on the control bat as well as other icons and menu item texts across my whole app go invisible / break.
Is there a specific type of redraw function of a specific class that i should be using from the onSize method? or is there something else i need to be doing?
Thanks

How to write a scrollable MFC custom control?

I want to write my own chart control which requires scrolling.
I found that there is a CScrollView but nothing like this for a control.
Other toolkits like Cocoa, QT or GTK offer me a base class where i can set a content view which is displayed in a viewport and saves me from writting all of the scrolling code.
The code for custom scrolling isn't that much. Create the scrollbars, write the message handlers and remember one rectangle for the current visible part.
I would just try it. If you have problems, we are here to help :-)

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.

QTabBar icon position

Is there a way to change the alignment of the icon or text of a tab in Qt? Specifically, I would like the text to appear below the icon. By default the icon sits to the left of the text, but that's not appropriate for all situations (especially when you start styling your tabs with stylesheets) It would seem very odd to me that this aspect would be so restricted when I can completely alter the look and feel of the rest of the tab.
Thanks for any suggestions!
The only way I can see is to create a subclass of QTabBar that implements your own painting algorithm. Then you'd need to subclass QTabWidget to set your own version of the tab bar. It doesn't look like a lot of fun to me.

MFC Panel and window handle

Is there something like a panel that I can use in a MFC application. This is to overlay the default window in MFC (a dialog application). Then to paint the panel black and paint some random stuff on top of it. Something like a view port.
is there a better option than this to achieve the same effect ?
Sure. It's called a window! Create a class that derives from CWnd and overrides OnPaint().
In your dialog's OnInitInstance(), instantiate a CMyWnd object and call it's Create() member. Of course, make sure the lifetime of your CMyWnd object is the same as the dialog's object lifetime window. iow, make it a member of you CMyDialog class.
Not very complicated but obviously an area where MFC shows why it doesn't fall in the RAD tools category.
Another solution would be to derive from CDialog. This way you can use the resource editor to edit the panel visually and you don't need to paint anything yourselve. Also the Panel class is rather thin and just needs to propagate the Create() and Show() calls to support subpanels and multiple panels within a single form.