Click here to Skip to main content
12,754,745 members (35,360 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.4K views
5 bookmarked
Posted 5 Oct 2012

A Tale of Two Flags: DS_CONTROL and WS_EX_CONTROLPARENT

, 5 Oct 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
A tale of two flags: DS_CONTROL and WS_EX_CONTROLPARENT

I recently ran into problems with an MFC application that was hosting some Windows Form user control in a modal dialog; the application hanged after it lost focus. The problem was the window received WM_GETDLGCODE message in an infinite loop making it impossible to handle anything else. After a lot of digging, I found that the cause was the missing WS_EX_CONTROLPARENT style of the window that hosted the WinForms control. What I want to do is summarize the information about this Window style. The most information I’ve been able to pull came from Raymond Chen’s blog The Old New Thing.

First of all, there are two styles: DS_CONTROL and WS_EX_CONTROLPARENT.

WS_EX_CONTROLPARENT

The window itself contains child windows that should take part in dialog box navigation. If this style is specified, the dialog manager resources into children of this window when performing navigation operations such as handling the TAB key, an arrow key, or a keyboard mnemonic.

WS_EX_CONTROLPARENT is an extended window style. It tells the dialog manager that it should treat the children of the window with this flag as direct children of the window’s parent (got that?). Raymond has a simple figure in this blog post. When embedding a dialog inside another, make sure you don’t accidentally create duplicate control IDs.

DS_CONTROL

Creates a dialog box that works well as a child window of another dialog box, much like a page in a property sheet. This style allows the user to tab among the control windows of a child dialog box, use its accelerator keys, and so on.

DS_CONTROL is a style for dialog templates. The dialog manager translates this style into window styles and extended window styles. It removes WS_CAPTION and WS_SYSMENU (if existing) and adds WS_EX_CONTROLPARENT.

Bottom line is, the WS_EX_CONTROLPARENT style tells function that do control searches (such as GetNextDlgTabItem) that they should treat the dialog marked with the flag as a container of other controls (and iterate them) and not a single, big, control.

More Readings

References to Similar Problems As My Own

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Marius Bancila
Architect Visma Software
Romania Romania
Marius Bancila is a Microsoft MVP for VC++. He works as a system architect for Visma, a Norwegian-based company. He is mainly focused on building desktop applications with VC++ and VC#. He keeps a blog at http://www.mariusbancila.ro/blog, focused on Windows programming. He is the co-founder of codexpert.ro, a community for Romanian C++ programmers.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 Oct 2012
Article Copyright 2012 by Marius Bancila
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid