Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PreCreateWindow does not get called from CDialog

Posted on 2006-06-14
11
Medium Priority
?
1,128 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 45

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 45

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

609 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