Solved

PreCreateWindow in CDialog

Posted on 2002-07-21
9
1,315 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 34
FizzBuzz challenge 9 81
Use of condition with 'serial' in ansible 2 60
Fibonacci challenge 11 122
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

772 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