Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: CreateParams failed in XE8 builder


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Sep 15, 2015 10:57 AM Last Post By: Remy Lebeau (Te...
Ari Mannonen

Posts: 3
Registered: 6/25/15
CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 3:06 AM
I need to set special window settings such as CS_OWDC, WS_CHILD and WS_CLIPSIBLINGS in my 32 bit VCL forms application. This should be accomplished using virtual CreateParams function

virtual void __fastcall CreateParams(TCreateParams& Params);

declared in form's header file. However, this doesn't work. To illustrate this, create a new project and test CreateParams function by setting the width of a form.

Normally we do this using Object Inspector and now too, let's put Width=500. Then we want to override the setting in Object Inspector using CreateParams function. Let's write the declaration above to the public part in the header file of the form and the implementation

void __fastcall TForm1::CreateParams(TCreateParams& Params)
{
TForm::CreateParams(Params);
Params.Width=1000;
}

to Unit1.cpp file. Now, if CreateParams work, the width of form is 1000, not 500, but it won't.

What am I doing wrong?

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 10:45 AM   in response to: Ari Mannonen in response to: Ari Mannonen
Ari wrote:

I need to set special window settings such as CS_OWDC, WS_CHILD and
WS_CLIPSIBLINGS in my 32 bit VCL forms application.

WS_CHILD is handled by setting the Parent property. TWinControl enables
WS_CHILD by default, and then TCustomForm disables WS_CHILD if there is no
parent window specified, either via the Parent or PopupParent property.

TWinControl enables WS_CLIPSIBLINGS by default, and TCustomForm does not
disable it.

However, this doesn't work.

Define "doesn't work" exactly.

--
Remy Lebeau (TeamB)
Ari Mannonen

Posts: 3
Registered: 6/25/15
Re: CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 11:20 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Ari wrote:

I need to set special window settings such as CS_OWDC, WS_CHILD and
WS_CLIPSIBLINGS in my 32 bit VCL forms application.

WS_CHILD is handled by setting the Parent property. TWinControl enables
WS_CHILD by default, and then TCustomForm disables WS_CHILD if there is no
parent window specified, either via the Parent or PopupParent property.

TWinControl enables WS_CLIPSIBLINGS by default, and TCustomForm does not
disable it.

However, this doesn't work.

Define "doesn't work" exactly.

--
Remy Lebeau (TeamB)

I got createparams working with WSCHILD, WSCLIPSIBLINGS and CSOWNDC.
Params.x and Params.y are also working, but no Params.Width and Params.Height.
I think there is some restriction. Do you know do we have more restrictions?

Sorry about text, Im using SSamsungGalaxy.

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 11:35 AM   in response to: Ari Mannonen in response to: Ari Mannonen
Ari wrote:

I got createparams working with WSCHILD, WSCLIPSIBLINGS and CSOWNDC.
Params.x and Params.y are also working, but no Params.Width and
Params.Height. I think there is some restriction. Do you know do we
have more restrictions?

Do you have any values assigned to the Form's Constraints property? It has
MinWidth, MinHeight, MaxWidth, and MaxHeight sub-properties.

Have you tried stepping into the VCL source code with the debugger to find
out what is actually happening during your Form's window creation?

Have you tried overriding the virtual CreateWindowHandle() method to see
the final TCreateParams that is actually being passed to the Win32 API CreateWindowEx()
function?

Have you tried overriding the virtual SetBounds() method to see if the Form
is being resized with different values after its HWND has been created?

--
Remy Lebeau (TeamB)

Ari Mannonen

Posts: 3
Registered: 6/25/15
Re: CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 15, 2015 12:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Do you have any values assigned to the Form's Constraints property? It has
MinWidth, MinHeight, MaxWidth, and MaxHeight sub-properties.

I tried setting Constraints. Seems that they have no effect.

Have you tried stepping into the VCL source code with the debugger to find
out what is actually happening during your Form's window creation?

I could't get debugger step deep enough the code to see what's happening.

Have you tried overriding the virtual CreateWindowHandle() method to see
the final TCreateParams that is actually being passed to the Win32 API CreateWindowEx()
function?

CreateWindowHandle does not spoil the values of width and height according to my testing. It works as it should.

Have you tried overriding the virtual SetBounds() method to see if the Form
is being resized with different values after its HWND has been created?

SetBounds reveals that something is spoiling widht and height values. SetBounds is called several times before and after GreateParams and CreateWindowHandle, and the right values go through it, but after that also the wrong values.

The only way to get the right sized window by coding seems to be to define those values in form's constructor. Below is my testing code:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
// Width=100;
// Height=100;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::CreateParams(TCreateParams& Params)
{
TForm::CreateParams(Params);
Params.WindowClass.style=Params.WindowClass.style | CS_OWNDC;
Params.Style = WS_CHILD | WS_CLIPSIBLINGS;
Params.WndParent = Form1->Handle;
Params.X=100;
Params.Y=100;
Params.Width=100;
Params.Height=100;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::CreateWindowHandle(const TCreateParams& Params)
{
int test1=Params.Width;
int test2=Params.Height;
TForm::CreateWindowHandle(Params);
int test3=Width;
int test4=Height;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::SetBounds(int ALeft, int ATop, int AWidth, int AHeight)
{
TForm::SetBounds(ALeft, ATop, AWidth, AHeight);
}
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: CreateParams failed in XE8 builder  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 15, 2015 10:57 AM   in response to: Ari Mannonen in response to: Ari Mannonen
Ari wrote:

I could't get debugger step deep enough the code to see what's
happening.

In order to step into the VCL's source code, you have to enable the "Project
| Options | Delphi compiler | Compiling | Use debug .dcus" option (yes, this
works in C++, too).

CreateWindowHandle does not spoil the values of width and height
according to my testing. It works as it should.

Then the window dimensions have to be getting modified after the window is
created. Something is calling SetWindowPos(), or processing the WM_SIZING
or WM_WINDOWPOSCHANGING message to modify the dimensions before they are
applied to the window.

SetBounds reveals that something is spoiling widht and height values.

Now that you can see that, you can set a breakpoint in your SetBounds() method
and walk up the call stack to see where itis being resized from and with
which source values.

The only way to get the right sized window by coding seems to be to
define those values in form's constructor.

You can also modify the values that you pass to the base class SetBounds():

void __fastcall TForm2::SetBounds(int ALeft, int ATop, int AWidth, int AHeight)
{
    TForm::SetBounds(ALeft, ATop, 100, 100);
}


However, it would be better to find out who is resizing the Form to the wrong
dimensions any why, and then fix that instead.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02