?
Solved

How to modify the style of a dialog window

Posted on 1999-12-01
16
Medium Priority
?
798 Views
Last Modified: 2013-11-20
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 .
0
Comment
Question by:Brian_HP
  • 5
  • 4
  • 2
  • +5
16 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2246683
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
 

Author Comment

by:Brian_HP
ID: 2246708
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
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2246789
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:migel
ID: 2246980
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
 
LVL 31

Accepted Solution

by:
Zoppo earned 200 total points
ID: 2247057
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
 
LVL 2

Expert Comment

by:Gandalf32
ID: 2247320
If you are creating the dialog with the Create function, just don't include the WS_VISIBLE flag.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2247476
Call ModifyStyle in your overridden OnCreate.
0
 
LVL 2

Expert Comment

by:basant
ID: 2247842
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
 

Author Comment

by:Brian_HP
ID: 2248972
basant,

As I have mentioned, I do not want to change the style in the resources (the RC file)!
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2248982
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
 

Author Comment

by:Brian_HP
ID: 2249005
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
 

Author Comment

by:Brian_HP
ID: 2249048
I have a minor problem more, how can I remove the dialog frame of the window (what style should I remove/include)?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2249071
remove these styles: WS_BORDER|WS_DLGFRAME|DS_MODALFRAME

hope that's it

ZOPPO
0
 

Author Comment

by:Brian_HP
ID: 2249089
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 2249102
You're welcome :)
0
 
LVL 8

Expert Comment

by:milindsm
ID: 25380381
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

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There may be issues when you are trying to access Outlook or send & receive emails or due to Outlook crash which leads to corrupt or damaged PST file. To eliminate the corruption from your PST file, you need to repair the corrupt Outlook PST file. U…
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question