Solved

PreCreateWindow does not get called from CDialog

Posted on 2006-06-14
11
1,065 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 250 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Assisted Solution

by:mahesh1402
mahesh1402 earned 100 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 50 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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