Re: Distorted dialog title bar after SetWindowPos in OnInitDialog

Tech-Archive recommends: Fix windows errors by optimizing your registry



That ;is exactly one of the problems I've seen; and Default() really does pass the
WM_SETTEXT to the base class, which gets the drawing wrong. It also can produce annoying
flicker as the wrong text is displayed, the area is invalidated, and the right text is
displayed.

There's a cheat I do, when I'm feeling lazy. I place a CStatic down and use it as a
frame. Then I

c_Frame.GetWindowRect(&r);
ScreenToClient(&r);
c_MyControl.Create(...., r, c_Frame.GetDlgCtrlID(), this);
c_Frame.DestroyWindow();

it adds just a few lines to the OnInitDialog, lets me place the control easily, and just
replaces it at runtime by a control of the same size and ID, but derived from my desired
class. Much easier than having to define new window classes so I can name them and then
figure out the hex values for the style bits.
joe

On Mon, 4 Dec 2006 17:17:00 -0800, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:crf9n21oh9a8elitp9n8ivkhcr1ql5ek1h@xxxxxxxxxx
I've seen this bug appear in a number of situations when CStatic was
chosen. I have
typically fixed it by changing it from a CStatic to a CWnd derivation. I
only see the
problem when SetWindowText is involved. It has been a couple years since
I last saw it,
but I have a vague memory that WM_SETTEXT was actually being handled and
it still came out
wrong, but I've forgotten the details.

I've not hit it myself because I tend to derive from CStatic only for
non-text displays.

Actually, my OnSetText() calls Default(), then InvalidateWindow() so maybe
the Default() causes the original STATIC wndproc to do GetDC() and draw on
it rather than invalidating the window still. But then I follow that up
with a call to InvalidateWindow() so the control should be painted for good.

I like to derive from CStatic because it makes it easy for my control to be
used in a dialog. Just drag a static control from the Toolbox into the
dialog, and use the Add Class wizard to set it to my CStatic-derived class.
This isn't possible with a CWnd derived class. I don't think it's even
possible to add a control of your class using the dialog editor.

-- David
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Distorted dialog title bar after SetWindowPos in OnInitDialog
    ... typically fixed it by changing it from a CStatic to a CWnd derivation. ... Actually, my OnSetTextcalls Default, then InvalidateWindowso maybe the Defaultcauses the original STATIC wndproc to do GetDCand draw on it rather than invalidating the window still. ... But then I follow that up with a call to InvalidateWindow() so the control should be painted for good. ...
    (microsoft.public.vc.mfc)
  • Re: Child Window Creation
    ... I have a CWnd derived class, which gets created using Create method and in some places gets subclassed using DDX_Control. ... If I do it in PreSubclassWindow, it will only work correctly when the control is subclassed using DDX_Control, and will break when it is created with Create, since the window is not created yet, and there is no HWND. ... If it just this particular control that has this split personality, then when using it on the dialog template I would use treat the template control as a placeholder and then in OnInitDialoggrab its rectangle, destroy it, and recreate my control in its place with the same ID. ... Visual C++ MVP ...
    (microsoft.public.vc.mfc)
  • Unexpected WM_MOUSEMOVE after double click in list control
    ... I have a view with two child windows. ... and the other is a CWnd derived class (my own control). ... All this happens inside WM_NOTIFY event handler. ...
    (microsoft.public.vc.mfc)