Page 1 of 1

Strange behavior of TGet

PostPosted: Sat Apr 21, 2012 9:58 am
by Enrico Maria Giordano
In the following sample the GET is rendered with a couple of [ ]. Any ideas about the reason and a possible solution?

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL cVar := PADR( "This is a test", 35 )

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    ACTIVATE DIALOG oDlg;
             ON INIT TEST( oDlg, @cVar );
             CENTER

    RETURN NIL


STATIC FUNCTION TEST( oDlg, cVar )

    @ 1, 1 GET cVar OF oDlg

    @ 3, 1 BUTTON "&Close" OF oDlg;
           ACTION oDlg:End()

    RETURN NIL


EMG

Re: Strange behavior of TGet

PostPosted: Sat Apr 21, 2012 10:03 am
by anserkk
EMG,

I think that the height of the GET object is overlapping the border and hence the []
[] will Vanish if you specify the size for the GET :)

Code: Select all  Expand view
@ 1, 1 GET cVar OF oDlg SIZE 80,20


Anser

Re: Strange behavior of TGet

PostPosted: Sat Apr 21, 2012 10:08 am
by Enrico Maria Giordano
Thank you. One more problem: try to compile the following sample with the manifest file. You will see a strange double border around the GET:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oDlg

    LOCAL cVar := PADR( "This is a test", 35 )

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    ACTIVATE DIALOG oDlg;
             ON INIT TEST( oDlg, @cVar );
             CENTER

    RETURN NIL


STATIC FUNCTION TEST( oDlg, cVar )

    @ 1, 1 GET cVar OF oDlg SIZE 80, 20

    @ 3, 1 BUTTON "&Close" OF oDlg;
           ACTION oDlg:End()

    RETURN NIL


EMG

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 4:51 am
by anserkk
Dear EMG

Yes, I could see the problem which you have mentioned. The problem occurs only when you create the controls (GET and BUTTON) via the ON INIT clause.

I was able to eliminate the problem, when I created the "GET" and "BUTTON" controls from the Main() itself

Code: Select all  Expand view
FUNCTION MAIN()

 LOCAL oDlg

 LOCAL cVar := PADR( "This is a test", 35 )
   
 MsgInfo(If(IsAppThemed(),"Themed","Not Themed"))

 DEFINE DIALOG oDlg;
        SIZE 800, 600 PIXEL
           
 @ 1, 1 GET cVar OF oDlg SIZE 180, 25

 @ 3, 1 BUTTON "&Close" OF oDlg;
           ACTION oDlg:End()

 ACTIVATE DIALOG oDlg
 //          ON INIT TEST( oDlg, @cVar );
//           CENTER

RETURN NIL


Another problem which I noticed is that the size of the controls (GET and BUTTON) are different, when created from the ON INIT clause and from Main(). If I create the controls from the Main(), the controls are bigger in size. :roll:

Regards
Anser

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 6:28 am
by Antonio Linares
Anser,

When the controls are created from inside DEFINE DIALOG ... ACTIVATE DIALOG, Windows API uses dialog units:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms645475(v=vs.85).aspx

When the controls are created from the ON INIT clause, the dialog already exists and Windows uses pixels.

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 6:50 am
by Antonio Linares
Enrico,

It seems as Windows API is not properly applying the themes when the control is created from the ON INIT clause.

You can disable the themes on a specific control calling SetWindowTheme(), i.e.:

Code: Select all  Expand view
STATIC FUNCTION TEST( oDlg, cVar )

    @ 1, 1 GET cVar OF oDlg SIZE 80, 25

    SetWindowTheme( oDlg:aControls[ 1 ]:hWnd, AnsiToWide( "" ), AnsiToWide( "" ) )
   
    @ 3, 1 BUTTON "&Close" OF oDlg ;
           ACTION oDlg:End() SIZE 80, 25

    RETURN NIL


Please notice that we have modified FWH SetWindowTheme() so when just one parameter is used, then we automatically supply L"" to second and third parameters. AnsitoWide( "" ) is equivalent to L"" (in C code). FWH 12.04 automatically supplies L"" when just one parameter is used, so the above code would be equivalent to: SetWindowTheme( oDlg:aControls[ 1 ]:hWnd )

function SetWindowTheme() docs:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb759827(v=vs.85).aspx

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 6:55 am
by anserkk
Antonio Linares wrote:When the controls are created from inside DEFINE DIALOG ... ACTIVATE DIALOG, Windows API uses dialog units:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645475(v=vs.85).aspx
When the controls are created from the ON INIT clause, the dialog already exists and Windows uses pixels.


Thank you for the info.

With SetWindowTheme() it is working fine.

Regards
Anser

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 8:16 am
by Enrico Maria Giordano
Antonio Linares wrote:Enrico,

It seems as Windows API is not properly applying the themes when the control is created from the ON INIT clause.

You can disable the themes on a specific control calling SetWindowTheme(), i.e.:


Ok, but now I don't get the theme on that control and the result is ugly. :-(

EMG

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 11:00 am
by Antonio Linares
Enrico,

Yes, I agree. I have not found a way yet to "reset" the theme or another way to fix that strange theme effect :-(

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 1:00 pm
by Enrico Maria Giordano
Ok, no problem. I will avoid to create controls inside the ON INIT clause.

EMG

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 1:22 pm
by Antonio Linares
Enrico,

Afaik, other controls created from the ON INIT clause are fine.

This is the first time that we get this border painting problem, only when a GET is created and themes are in use.

Re: Strange behavior of TGet

PostPosted: Mon Apr 23, 2012 1:24 pm
by Enrico Maria Giordano
Ok, thank you for the tip.

EMG

Re: Strange behavior of TGet

PostPosted: Mon Apr 15, 2013 9:10 am
by Horizon
Hi,

Has there any solution for this?

Thanks

Re: Strange behavior of TGet

PostPosted: Mon Apr 15, 2013 10:16 am
by Antonio Linares
Hakan,

Not yet. The only solution by now is to create the GETs not from the ON INIT clause of the dialog.

In example, you could create them from:
oDlg:bStart = { || CreateGets() }