Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

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.
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

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 summarizing 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 a 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:
What is the DS_CONTROL style for?
The dialog manager, part 2: Creating the frame window
Why doesn’t the TAB key work on controls I’ve marked as WS_TABSTOP?
Why do we need IsDialogMessage at all?

And references to similar problems as my own:
endless messages WM_GETDLGCODE when focus is lost
WS_EX_CONTROLPARENT

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
Software Developer (Senior) Visma Software
Romania Romania
Marius Bancila is a Microsoft MVP for VC++. He works as a software developer 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.
Follow on   Twitter

Comments and Discussions

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