Solved

PreCreateWindow in CDialog

Posted on 2002-07-21
9
1,267 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now