0

How can I add border to an embedded child window with (WS_CHILD | DS_CONTROL) style hosed by a CFormView?

I have tried to add border in Dialog Editor by selecting Thin border type but it doesn't work.

I also tried SetWindowLong and ModifyStyle. But the result is, WS_BORDER style is added but still no border.

Is it possible to add border to embedded child window by choosing styles? or should I draw it myself?

Thanks, Guan

guan boshen
  • 724
  • 7
  • 15
  • 1
    From [SetWindowLongPtr](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644898.aspx): *"Certain window data is cached, so changes you make using **SetWindowLongPtr** will not take effect until you call the [**SetWindowPos**](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx) function."* Passing `SWP_DRAWFRAME` to [SetWindowPos](https://msdn.microsoft.com/en-us/library/windows/desktop/ms633545.aspx) is required. – IInspectable Aug 22 '16 at 09:56
  • @IInspectable Thank you! I change my code to `ModifyStyle(0, WS_BORDER, SWP_DRAWFRAME)` and it works now. (`SetWindowPos` is internally called by `ModifyStyle`). – guan boshen Aug 23 '16 at 07:32
  • You should write that up as an answer then. See [Can I answer my own question?](http://stackoverflow.com/help/self-answer) in case you are wondering, if this is ok. – IInspectable Aug 23 '16 at 09:13

1 Answers1

0

As @IInspectable points out, passing SWP_DRAWFRAME to SetWindowPos is required after changing the window styles.

I finally choose ModifyStyle to add WS_BORDER to my WS_CHILD window and pass SWP_DRAWFRAME flag to the third parameter: m_wndMainPage.ModifyStyle(0, WS_BORDER, SWP_DRAWFRAME). It internally calls SetWindowPos and update the child window. Window border is drawn as expected.

guan boshen
  • 724
  • 7
  • 15