Solved

PreCreateWindow does not get called from CDialog

Posted on 2006-06-14
11
966 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

9 Experts available now in Live!

Get 1:1 Help Now