Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add shadow to a form

338 views
Skip to first unread message

Mario Sernicola

unread,
Jun 9, 2004, 6:36:35 AM6/9/04
to
Hi,

There's a way to add a shadow to a form and decide about its angle and size?

Thanks

Mario Sernicola


Eelke Klein

unread,
Jun 10, 2004, 7:29:40 AM6/10/04
to
Mario Sernicola wrote:

Never have done it myself but here is some information which might be
usefull:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/layerwin.asp

Eelke

Mario Sernicola

unread,
Jun 10, 2004, 10:15:14 AM6/10/04
to
I'm trying with this code:

void __fastcall TForm1::Button6Click(TObject *Sender)
{
const CS_DROPSHADOW = 0x020000;
SetClassLong(Form1->Handle,GCL_STYLE, GetClassLong(Handle, GCL_STYLE) |
CS_DROPSHADOW) ;
SystemParametersInfo(SPI_SETDROPSHADOW, NULL, true, NULL);

// Ask the window and its children to repaint
RedrawWindow(Handle, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME |
RDW_ALLCHILDREN);
}
//--------------------------------------------------------------------------
-

but I've an error:

Undefinited symbol 'SPI_SETDROPSHADOW'

I've included "Windows.h" too

Mario Sernicola

unread,
Jun 10, 2004, 12:42:16 PM6/10/04
to
The right code seems to be

void __fastcall TForm1::Button6Click(TObject *Sender)
{

const CS_DROPSHADOW = 0x002000;
SetClassLong(Form1->Handle, GCL_STYLE, GetClassLong(Form1->Handle,
GCL_STYLE) | CS_DROPSHADOW) ;
SystemParametersInfo(0x1025, true, NULL, 0);
RecreateWnd();
}
//--------------------------------------------------------------------------
-

Now the problem is that I've executed this function:

...
SystemParametersInfo(0x1025, false, NULL, 0);
...

and now the shadow don't appear even if I reboot my computer!

Someone can help me and solve these issues?

Thanks

Mario Sernicola


Remy Lebeau (TeamB)

unread,
Jun 10, 2004, 2:22:27 PM6/10/04
to

"Mario Sernicola" <mariose...@nospam.libero.it> wrote in message
news:40c88f63$1...@newsgroups.borland.com...

> RecreateWnd();

By calling that, you are going to lose your custom settings to the class
info. You should be setting CS_DROPSHADOW in the CreateParams() method
instead so that it is always applied whenever the window is created for any
reason (there are other reasons for a window to be re-created during its
lifetime).

> Now the problem is that I've executed this function:
>
> ...
> SystemParametersInfo(0x1025, false, NULL, 0);
> ...
>
> and now the shadow don't appear even if I reboot my computer!

Well, for one thing, you *disabled* the system's ability to display drop
shadows. Second, which OS are you actually using to begin with?
CS_DROPSHADOW and SPI_SETDROPSHADOW are only available on Win2K and XP.


Gambit


Michel Leunen

unread,
Jun 10, 2004, 3:38:37 PM6/10/04
to
Remy Lebeau (TeamB) wrote:

> CS_DROPSHADOW and SPI_SETDROPSHADOW are only available on Win2K and XP.

According to MSDN, it is only available on XP not on W2k.
"Windows 2000/NT, Windows Me/98/95: This value is not supported."

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------

Mario Sernicola

unread,
Jun 10, 2004, 3:44:34 PM6/10/04
to
Hi Remy,

I'd like to toggle form shadow at runtime, in the OnShow method, reading a
ini file.

How can I do this? Can you help me writing the right code? I think I have to
write in my header file:

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

virtual void __fastcall TForm1::CreateParams(TCreateParams &Params);

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

and in the cpp file:

void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
const CS_DROPSHADOW = 0x00020000;

TForm::CreateParams(Params);

Params.Style = Params.Style | CS_DROPSHADOW; //<---- is it right???
}
//--------------------------------------------------------------------------
-

How can restore in my WinXp system, form shadows?

How can I toggle shadows in my forms by code?

Thanks

Mario Sernicola

"Remy Lebeau (TeamB)" <gambit47...@no.spam.yahoo.com> ha scritto nel
messaggio news:40c8a7f1$1...@newsgroups.borland.com...

Remy Lebeau (TeamB)

unread,
Jun 10, 2004, 4:38:44 PM6/10/04
to

"Mario Sernicola" <mariose...@nospam.libero.it> wrote in message
news:40c8...@newsgroups.borland.com...

> Params.Style = Params.Style | CS_DROPSHADOW; //<---- is it right???

That is not correct. You should be adding the style to the WindowClass
member instead, ie:

Params.WindowClass.style |= CS_DROPSHADOW;

> How can restore in my WinXp system, form shadows?

You already know the answer to that - call SystemParametersInfo() with the
uiAction set to SPI_SETDROPSHADOW and the pvParam set to TRUE.

> How can I toggle shadows in my forms by code?

Simple store a flag somewhere that indicates whether the shadow should be
applied or not, and then have CreateParams() access that flag when deciding
whether to apply or remove the CS_DROPSHADOW style. Then just call the
form's RecreateWnd() method whenever you change the value of the flag after
it has been set the first time.


Gambit


Mario Sernicola

unread,
Jun 11, 2004, 7:38:45 AM6/11/04
to
Nothing to do!

The first time I've launched my exe, the shadow appears, after I've executed

SystemParametersInfo(0x1025, FALSE, NULL, 0);

and the shadow doesn't appear anymore

Now I'm trying this code, according to your previous message:

bool shadow = false //global variable

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


void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
const CS_DROPSHADOW = 0x00020000;

TForm::CreateParams(Params);

if (shadow)
Params.WindowClass.style |= CS_DROPSHADOW;
else
Params.WindowClass.style &= ~CS_DROPSHADOW;

SystemParametersInfo(0x1025, TRUE, NULL, 0);
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button8Click(TObject *Sender)
{
shadow=true;
RecreateWnd();
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::Button7Click(TObject *Sender)
{
shadow=false;
RecreateWnd();
}
//--------------------------------------------------------------------------
-

But it seems not working. Where have I wrong?

There's a way to not use RecreateWnd function?

My really scope is to obtain a shadow like Photoshop splash screen, that
shadow is bigger and better than the shadow I can obtain with previous code
.

Thanks

Mario Sernicola


Remy Lebeau (TeamB)

unread,
Jun 11, 2004, 1:55:07 PM6/11/04
to

"Mario Sernicola" <mariose...@nospam.libero.it> wrote in message
news:40c999be$1...@newsgroups.borland.com...

> SystemParametersInfo(0x1025, FALSE, NULL, 0);

You have the parameters backwards. The FALSE should be passed via the
pvParam parameter, but you are passing it via the uiParam parameter instead.

> SystemParametersInfo(0x1025, TRUE, NULL, 0);

Again, you have the parameters backwards

> There's a way to not use RecreateWnd function?

As I said earlier, the form's window can be recreated for a number of other
reasons beyond your own code. Using CreateParams() is the most reliable way
to ensure that your custom settings are always applied whenever the window
is recreated for any reason.

> My really scope is to obtain a shadow like Photoshop splash
> screen, that shadow is bigger and better than the shadow I
> can obtain with previous code

I have not seen Photoshop's splash screen in several years, so I cannot
comment on that. Can you please provide a screen shot?


Gambit


Mario Sernicola

unread,
Jun 11, 2004, 4:09:07 PM6/11/04
to
The pvParams is the third parameter in

BOOL SystemParametersInfo(
UINT uiAction, // system parameter to query or set
UINT uiParam, // depends on action to be taken
PVOID pvParam, // depends on action to be taken
UINT fWinIni // user profile update flag
);

When I compile

SystemParametersInfo(0x1025, NULL, TRUE, 0);

Builder give me an error:

E2034 Cannot convert 'int' to 'void *'
E2342 Type mismatch in parameter 'pvParam' (wanted 'void *', got 'int')

Can you write the right code please?

> I have not seen Photoshop's splash screen in several years, so I cannot
> comment on that. Can you please provide a screen shot?

I'll try to attach a screenshot of Photoshop autorun splash screen on
borland.public.attachments , I hope it will be visible.

Mario Sernicola


Remy Lebeau (TeamB)

unread,
Jun 11, 2004, 4:10:59 PM6/11/04
to

"Mario Sernicola" <mariose...@nospam.libero.it> wrote in message
news:40ca1165$1...@newsgroups.borland.com...

> The pvParams is the third parameter in

Yes, and that is the parameter you are supposed to be passing your
TRUE/FALSE values with. MSDN's documentation even says as much.

> Builder give me an error:
>
> E2034 Cannot convert 'int' to 'void *'

You have to cast:

SystemParametersInfo(0x1025, 0, (void*)TRUE, 0);
SystemParametersInfo(0x1025, 0, (void*)FALSE, 0);

Or possibly use an actual pointer:

BOOL bEnabled = TRUE;
SystemParametersInfo(0x1025, 0, &bEnabled, 0);

bEnabled = FALSE;
SystemParametersInfo(0x1025, 0, &bEnabled , 0);

> I'll try to attach a screenshot of Photoshop autorun
> splash screen on borland.public.attachments

That is not a standard drop shadow. Adobe draws its own shadows onto the
screen manually.


Gambit


Mario Sernicola

unread,
Jun 12, 2004, 2:39:37 AM6/12/04
to
> That is not a standard drop shadow. Adobe draws its own shadows onto the
> screen manually.

Can I do something of that by code?

Mario Sernicola


0 new messages