Solved

PreCreateWindow in CDialog

Posted on 2002-07-21
9
1,294 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 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.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now