Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PreCreateWindow in CDialog

Posted on 2002-07-21
9
1,332 Views
Last Modified: 2013-11-20
Hi,
I created a class which derive from CDialog, in which I want to remove some styles before the dialog creation. I tried to catch PreCreateWindow, but I dont stop there.
1. Why ???
2. how can I remove/add styles On dialog creation (without changing it in the resources !)

igal.
0
Comment
Question by:igalb
  • 5
  • 3
9 Comments
 
LVL 1

Expert Comment

by:prakashsl
ID: 7168881
Hi,

Why not change in the rc file itself, open ur rc file in text mode and keep whatever styles you want and then run it, thatz it,


or else u can tackle it in initdialog also.

prakash


0
 

Author Comment

by:igalb
ID: 7169113
my question was why dont I stop in PreCreateWindow.
0
 
LVL 1

Expert Comment

by:prakashsl
ID: 7169177
Hi,

Sometimes the code just doesn't go to the precreatwindow  function, if you are using create functions like
Create(IDD_DIALOG_GTK);

It sometimes skips of this function or is overridden by initdialog.

prakash
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
LVL 1

Expert Comment

by:prakashsl
ID: 7169189
Hi,

PreCreateWindow function is actually called by the framework, which usally exits in MDI and SDI, but this will not be present in dialog based application, May be u can create a dialog inside another dialog and then use it.

Just check this msdn help... This is a snippet of help found in msdn...

To change the default window attributes used by a framework application created with AppWizard, override the window’sPreCreateWindow virtual member function. PreCreateWindow allows an application to access the creation process normally managed internally by theCDocTemplate class. The framework calls PreCreateWindow just prior to creating the window. By modifying theCREATESTRUCT parameter to PreCreateWindow, your application can change the attributes used to create the window.


regards
prakash
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7170051
You can do it in OnInitDialog:

LONG lStyle = ::GetWindowLong( m_hWnd, GWL_STYLE );
lStyle |= ( STYLES | TO | BE | ADDED );
lStyle &= ~( STYLES | TO | BE | REMOVED );
::SetWindowLong( m_hWnd, GWL_STYLE, lStyle );

To change extended style use GWL_EXSTYLE in place of GWL_STYLE.
0
 
LVL 1

Accepted Solution

by:
prakashsl earned 30 total points
ID: 7170936
Hi floyd,
But this call is in initdialog. offcourse you can add and delete styles in the way you have said, but his question was why not in precreatewindow() function in a dialog based application.
The problem is precreatewindow function is called from the framework which exits with mdi and sdi application and not with dialog based.
So he has got to pull his code out of precreatewindow and put in in initdialog() function, and then do the way you have said or may be by directly setting the new styles, or may be even by editing the rc file if it is having fixed styles which is predetermined.

regards
prakash


0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7171299
Yes?? This is in OnInitDialog since PreCreateWindow isn't called for dialogs/dialog-based applications. I don't really see why you think there is that much trouble with taking code from one function and placing it in another one. I'm sure you have heard of copy-paste, haven't you?

p.s.: the question also included "(without changing it in the resources !)"
0
 
LVL 1

Expert Comment

by:prakashsl
ID: 7171419
Hi floyd,

Sorry,
i didn't see this line "(without changing it in the resources !)" in the question

::)

prakash
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7171515
igal, still listening? I found an easier way since you are using MFC. Just use

ModifyStyle( dwRemove, dwAdd ); // or
ModifyStyleEx( dwRemove, dwAdd );

in OnInitDialog or better yet in OnCreate. Don't worry about the nFlags-argument in both of those function calls -- if you don't specify a value they will only change the window style without calling ::SetWindowPos.

int CMyDialog::OnCreate( LPCREATESTRUCT lpCreateStruct ) {

    if( -1 == CDialog::OnCreate( lpCreateStruct ) )
        return -1;

    DWORD dwRemove = styles_to_be_removed;
    DWORD dwAdd = styles_to_be_set;
    ModifyStyle( dwRemove, dwAdd );

    return 0;
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 96
viewing source code from eclipse 13 110
isEverywhere  challenge 19 82
Bartender label printing - switch on and off graphics 3 54
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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