?
Solved

PreCreateWindow does not get called from CDialog

Posted on 2006-06-14
11
Medium Priority
?
1,101 Views
Last Modified: 2013-11-20
Hi all,
  I have a dialog that I want to dynamically change the size of based on the size of a bitmap. I tried overriding PreCreateWindow, but that does not seem to get called for dialogs. So my question is: how will I do it if I can't use PreCreateWindow?

J
0
Comment
Question by:Joe_Banks_217
[X]
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
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16908832
>> how will I do it if I can't use PreCreateWindow

Simply Put your 'PreCreateWindow' code in your dialog's InitDialog() function. OR better option you  put that code in your dialog's OnCreate() function.

So you may use CDialog::OnCreate() or CDialog::InitDialog().

-MAHESH
0
 
LVL 1

Accepted Solution

by:
ramesh_hyd_ap earned 1000 total points
ID: 16911568
Hi joe,
         
          You can use setwindowpos()  in the InitDialog() function of your dialog.

          SetWindowPos ( NULL , 0 , 0 , bitmap_width , bitmap_height , SWP_NOZORDER);

Thanks,
Ramesh.
0
 

Author Comment

by:Joe_Banks_217
ID: 16913276
Mahesh,
  How do I access the "CREATESTRUCT" that gets automatically passed to PreCreateWindow from InitDialog()??
0
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
LVL 22

Assisted Solution

by:mahesh1402
mahesh1402 earned 400 total points
ID: 16917820
>>How do I access the "CREATESTRUCT" that gets automatically passed to PreCreateWindow from InitDialog()??

You can retrieve all the parameters of CREATESTRUCT by individual functions.. for Window Size you may retrieve that by GetWindowRect(), to get parent window you may call GetParent()..etc So you dont need CREATESTRUCT at all just call this function to get needed parameters.

As I suggested you may better use OnCreate() from which you can access CREATESTRUCT.
http://msdn2.microsoft.com/en-us/library/384x0633.aspx <==

-MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16917832
NOTE You may also use CWnd::OnNcCreate() The framework calls this member function prior to the WM_CREATE message when the CWnd object is first created in which you may also access CREATESTRUCT.
afx_msg BOOL OnNcCreate( LPCREATESTRUCT lpCreateStruct );
http://msdn2.microsoft.com/en-us/library/ytd5cczf.aspx <==

-MAHESH

0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 200 total points
ID: 16918279
As mahesh says use the OnInitDialog.

BOOL CMyDlg::OnInitDialog()
{
      CDialog::OnInitDialog();

        CRect rc(0, 0, 850, 400);  //bitmap width 850 and height 400
      CalcWindowRect(&rc);
      SetWindowPos(NULL, 0, 0, rc.Width(), rc.Height(), SWP_NOMOVE | SWP_NOZORDER);
      //CenterWindow();   //If you want to center the dialog


CalcWindowRect:
Call this member function to compute the required size of the window rectangle based on the desired client-rectangle size.

0
 
LVL 1

Expert Comment

by:ramesh_hyd_ap
ID: 16918551
Hi Andy,

I think i have suggested to use SetWindowPos,  but you are descrbing as  "As mahesh says"  ?

Thanks,
Ramesh.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 16918734
apologies - I meant the OnInitDialog which mahesh had said first.

Note, however, you need to adjust the total size to cope with borders.  Just using the bitmap width and height will not give a satisfactory result (unless the dialog is without border / caption).
0
 
LVL 1

Expert Comment

by:ramesh_hyd_ap
ID: 16918766
Hi Andy,

Off course you are right, but i did not get any feedback/concern from joe for this solution, otherwise i would have given work around for this.

Joe any comments on this?

Thanks,
Ramesh.
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16921285
Dont know which params joe want to access from CREATESTRUCT but as said you may put CalcWindowRect() GetWindowRect() on InitDialog if deal with positions or if want to access CREATESTRUCT then may use OnCreate() or OnNcCreate().

-MAHESH
0
 

Author Comment

by:Joe_Banks_217
ID: 16921894
hey guys, i appreciate the comments. thank you. andy, yes, the dialog has no border.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

762 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