0
votes

I'm working in a legacy application using MFC.

We have a mechanism to enable/disable controls depending on some business logic.

This mechanism is implemented in the CView-derived class. The way it works is all the views in the application derived from a common CView-derived class (CBaseView) and on the PreTranslateMessage all controls of the view are enabled/disabled.

This worked fine so far because all controls send at least WM_PAINT message when they need to be painted. So the system worked without the user having to move the mouse or anything. I recently added some drawing features and I had to use WS_EX_COMPOSITE to get ride of some flickering. With this flag activated my CView-derived class is not getting any called to PreTranslateMessage when creating the view....so the controls are not disabled until the user moves the mouse over the control.

I understand there is no way to send WM_PAINT using WS_EX_COMPOSITE but is there other message I can use to get the same behaviour???

Edited:

I am currently using the OnIdle approach but it has a big drawback, the windows doesn't become idle until after drawing all the controls...so when you enter the screen al controls are enabled and inmediately they are disabled...this makes a quite ugly effect!

More solutions???

Thanks in advance...

2
Most UI enable/disable in MFC is done during idle processing - perhaps that's an option? You would need to override CWinApp::OnIdle() IIRC. - Roger Rowland
Thanks Roger! I google about that and found some interesting examples...I'll give them a try. I still would like to get other ideas though! - Javier De Pedro
are you manually creating the controls in your CView-derived class, or is your view based on CFormView? Do you need to enable/disable controls depending on the values in your view's document and when they change? - Edward Clements
No, I'm not creating the controls manually they are CFormView-derived classes. I need a mechanism that do not need to create code for any control in the views. - Javier De Pedro
What is that "business logic" looking like that is implemented in PreTranslateMessage? Aren't there some events on which you can enable or disable the controls? PreTranslateMessage is not the optimal place to enable or disable controls. - Werner Henze

2 Answers

1
votes

The logical place to enable/disable controls would be CView::OnUpdate, it is called by the framework after the view's document has been modified and from OnInitialUpdate(); you can also call this function if there is some change that would trigger re-evaluation of your business logic.

EDIT After reading the question a bit more closely, what you could also do is to post a private message at the end of OnInitialUpdate and "catch" it in your PreTranslateMessage:

PostMessage(WM_APP, 0, 0);
0
votes

Calling InvalidateRect followed by UpdateWindow against the window in question will mark the entire client area as dirty and force an immediate repaint. Remember that WM_PAINT is not really a message, in the queue in the usual sense, it is pushed out after all other messages have been processed for that window, which would include any invalidations of the area being drawn. No message is generated at all if there are no invalid segments of the active window display.