How to modify the style of a dialog window

Hi,

I have a dialog window which is predefined to be e.g. visible, but when I create it I want it to be invisible. Therefore, I tried to change the styles with ModifyStyle, but this member funciton only works after Create, and this causes the window to be shown and then hidden again (when there are 4-5 windows of this kind, there is a lot of flickering).
  How can I change any* of the styles before I create the dialog window (ie. it is not enough to uncheck 'Visible' in the resource editor.
  * I have to change other styles too, eg. popup to child and .
Brian_HPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

U are using create means, they are modeless dialogs.
Why can't U use m_pDialog->ShowWindow(SW_HIDE); to display it as hidden, and then change the other properties by modifystyle() function.

Try it out.
0
Brian_HPAuthor Commented:
Yes, it is modeless dialogs
No, ShowWindow(SW_HIDE) did not help (it did the same), and it will not solve that I have other styles I need to change before create.
0
Vinayak KumbarSr Program ManagerCommented:
Hi,

What if we can do the following...
For that dialog class, in the OnInitDialog function try to use ModifyStyle(), to change the style!?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

migelCommented:
Hi!
as VinExper said you can use OnInitDialog since it called before dialog brings to the window.
also you can use CDialogTemplate class (it defined in the <afxpriv.h>) to achieve this
0
ZoppoCommented:
Hi Brian_HP,

you can implement a function to create the modeless dialog hidden like this:

/*****************************/
// call this function in the same way as you call CMyDlg::Create(...)
BOOL
CMyDlg::CreateHidden( UINT id, CWnd* pParent )
{
 HINSTANCE hInst = AfxGetResourceHandle();
 if ( !hInst )
 {
  ASSERT( NULL );
  return FALSE;
 }
 HRSRC hResource = FindResourceEx( hInst, RT_DIALOG, MAKEINTRESOURCE( id ), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) );
 if ( !hResource )
 {
  ASSERT( NULL );
  return FALSE;
 }
 HGLOBAL hTemplate = LoadResource( hInst, hResource );
 if ( !hTemplate )
 {
  ASSERT( NULL );
  return FALSE;
 }
 DLGTEMPLATE* pTemplate = (DLGTEMPLATE*)hTemplate;
 pTemplate->style &= ~WS_VISIBLE;
 return CreateIndirect( pTemplate, pParent );
}
/*****************************/

hope that helps,

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gandalf32Commented:
If you are creating the dialog with the Create function, just don't include the WS_VISIBLE flag.
0
chensuCommented:
Call ModifyStyle in your overridden OnCreate.
0
basantCommented:
Open the RC File , Remove the
WS_VISIBLE tag

Default :

STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU


You can remove the WS_VISIBLE tag.

STYLE DS_MODALFRAME | WS_POPUP |  WS_CAPTION | WS_SYSMENU
0
Brian_HPAuthor Commented:
basant,

As I have mentioned, I do not want to change the style in the resources (the RC file)!
0
ZoppoCommented:
Have you tried my suggestion ? I've tried chensu's suggestion but can't get it work :(

Gandalf32: CDialog::Create() has no style argument ...
0
Brian_HPAuthor Commented:
Gandalf32,
I'm not using the Create member function that way :(

Chensu,
Calling ModifyStyle in OnCreate doesn't work in my application - maybe I'm doing something wrong?

VinExpert,
Calling ModifyStyle from OnInitDialog doesn't seem to work either - again, maybe I'm doing something wrong elsewhere in my application?
0
Brian_HPAuthor Commented:
I have a minor problem more, how can I remove the dialog frame of the window (what style should I remove/include)?
0
ZoppoCommented:
remove these styles: WS_BORDER|WS_DLGFRAME|DS_MODALFRAME

hope that's it

ZOPPO
0
Brian_HPAuthor Commented:
Hi Zoppo,
Thanks a lot, it really helped, my dialogs do not flicker when 'loaded' into the tab control.
To your last comment, I forgot DS_MODALFRAME.
0
ZoppoCommented:
You're welcome :)
0
milindsmCommented:
hello Zoppo,

I have a modeless dialog with property sheet on it as a child and unfortunately it flickers in this case. :( If I remove property sheet then it works fine. Is property sheet causing this flicker?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.