Solved

PreCreateWindow does not get called from CDialog

Posted on 2006-06-14
11
1,027 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 106
how to monitor remote shell execution on linux 9 104
notReplace  challenge 53 142
Modbus - whats the maximum I can store in one register? 4 80
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…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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