How to identify WindowState

Post Reply
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

How to identify WindowState

Post by anserkk »

Hi,

Is there a function available to identify the WindowState ie whether it is Normal OR Minimized OR Maximized.
I would also like to know whether we can set the window state to Normal, Minimized or Maximized programatically.

In VB this can be achieved using the following code

Code: Select all

If Me.WindowState = vbMaximized Then
    Me.WindowState = vbNormal
    Me.Height = "5000"
    Me.Width = "5000"
End If
To bring the window back to normal mode I tried the following code, but the command is removing all the window control buttons from the title bar ie Minimize, Maximize & Close from the window and the same is shown on the MDI Main window

Code: Select all

ShowWindow( oWnd:hWnd, SW_NORMAL  )

My intention is to restore the size and state of the window to its original size even if the user click on the maximize button on a MDICHILD window.
I tried the following code too, but did not work as expected

Code: Select all

#define GWL_STYLE -16

SetWindowLong(oWnd:hWnd, GWL_STYLE, nOr( GetWindowLong(oWnd:hWnd, GWL_STYLE), WS_MAXIMIZEBOX ))
Thanks

Regards
Anser
Last edited by anserkk on Tue Feb 02, 2010 6:38 am, edited 2 times in total.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to identify WindowState

Post by nageswaragunupudi »

IsIconic( oWnd:hWnd )
IsZoomed( oWnd:hWnd )
Regards

G. N. Rao.
Hyderabad, India
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Post by anserkk »

Dear Mr.Rao,

Thank you.

Code: Select all

If IsZoomed( oWnd:hWnd )
    MsgInfo("Yes, the window is in Maximized state")
    ShowWindow( oWnd:hWnd, SW_NORMAL  )  // Now bring back to normal state
Endif
Unfortunately, ShowWindow( oWnd:hWnd, SW_NORMAL ) is removing the Minimize,Maximize and Close buttons from the window and the control buttons are shown on the main MDI window , Otherwise it is working fine

Any idea how to overcome this problem ?

Regards
Anser
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Post by anserkk »

Is ON RESIZE is the right event to be used to control the Maximize button click ?

Code: Select all

ACTIVATE WINDOW oWnd ;
         ON RESIZE Test(oWnd) 

*---------------------------------------------*
FUNCTION Test(oWnd)
*---------------------------------------------*
If IsZoomed( oWnd:hWnd )
//  oWnd:Normal()
    oWnd:Restore()
Endif
 
Regards
Anser
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: How to identify WindowState

Post by Antonio Linares »

Anser,

If you want that the window does not exceed some specific size then you can use the window DATA aMinMaxInfo.

Please review FWH\samples\TestSize.prg
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Post by anserkk »

Dear Mr.Antonio,

DATA aMinMaxInfo is was a very useful information. My requirement was to restrict the window size to a predefined size. Anyway I found the solution for my requirement. I was able to disable the maximize button on a MDICHILD window using the Windows Style.

Regards
Anser
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: How to identify WindowState

Post by nageswaragunupudi »

anserkk wrote:Dear Mr.Antonio,

DATA aMinMaxInfo is was a very useful information. My requirement was to restrict the window size to a predefined size. Anyway I found the solution for my requirement. I was able to disable the maximize button on a MDICHILD window using the Windows Style.

Regards
Anser
It is true that we can disable maximize or minimize buttons by simply using clauses NOMAXIMIZE, NOMINIMIZE, etc. while creating the window. But still the user can resize the window by dragging the right bottom corner of the window.

aMinMaxInfo gives us the full control on resizing. ( We can also control with ON RESIZE clause, but that is not elegant )
Regards

G. N. Rao.
Hyderabad, India
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Post by anserkk »

Dear Mr.Rao,
It is true that we can disable maximize or minimize buttons by simply using clauses NOMAXIMIZE, NOMINIMIZE, etc. while creating the window. But still the user can resize the window by dragging the right bottom corner of the window.

aMinMaxInfo gives us the full control on resizing. ( We can also control with ON RESIZE clause, but that is not elegant )
I found that, using the single line code using the STYLE is serving the expected behavior.

Code: Select all

STYLE  nOr( WS_CAPTION, WS_VISIBLE, WS_SYSMENU, WS_MINIMIZEBOX )
According to me the disadvantage of using aMinMaxInfo is that it requires me to calculate the height and width in pixels. In future, every time I need to alter the window size, I will have to recalculate the height and width again. Whereas using the STYLE, I need not bother about it. I don't use resource editors.

Regards
Anser
Patrizio
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy
Contact:

Re: How to identify WindowState

Post by Patrizio »

anserkk wrote:According to me the disadvantage of using aMinMaxInfo is that it requires me to calculate the height and width in pixels. In future, every time I need to alter the window size, I will have to recalculate the height and width again. Whereas using the STYLE, I need not bother about it. I don't use resource editors.
Anserkk, do you have tried this?

Code: Select all

oDlg:aMinMaxInfo  := {oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight}
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Post by anserkk »

Dear Mr.Patrizio,

Code: Select all

DEFINE WINDOW oWnd MDICHILD OF WndMain() NOMAXIMIZE

oWnd:aMinMaxInfo  := {oWnd:nWidth,oWnd:nHeight,oWnd:nWidth,oWnd:nHeight,oWnd:nWidth,oWnd:nHeight,oWnd:nWidth,oWnd:nHeight}

ACTIVATE WINDOW oWnd
 
The above code ie oWnd:aMinMaxInfo along with NOMAXIMIZE is working as expected. So I understand that this is an alternate to the usage of STYLE while Defining Window

Code: Select all

STYLE  nOr( WS_CAPTION, WS_VISIBLE, WS_SYSMENU, WS_MINIMIZEBOX )
If I don't use NOMAXIMIZE, then clicking on the Maximize button makes the MDI CHILD Window move to a different position and is displayed in the Right hand corner down without the Minimize,Maximaize & Close button it on it. The window control buttons are moved to the MDI Main window.

Regards
Anser
User avatar
Silvio
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Re: How to identify WindowState

Post by Silvio »

try it please


#define NOME_PROGRAMMA_TITLE "MAIN"

FUNCTION Main()

PUBLIC oApp

RddSetDefault( "DBFCDX" )

SetHandleCount( 100 )

SET DATE FORMAT "dd-mm-yyyy"
SET DELETED ON
SET CENTURY ON
SET EPOCH TO year( date() ) - 20
SET MULTIPLE OFF

SetBalloon( .T. )


IF ISEXERUNNING( CFILENAME( HB_ARGV( 0 ) ) )
MsgAlert(NOME_PROGRAMMA_TITLE+" è già in esecuzione !","Attenzione")
SHOWWINDOW( FINDWINDOW( 0, NOME_PROGRAMMA_TITLE ), 9 )
SETFOREGROUNDWINDOW( FINDWINDOW( 0, NOME_PROGRAMMA_TITLE ) )
RETURN NIL
ENDIF

WITH OBJECT oApp := TApplication():New()
:Activate()
END

RETURN nil
Best Regards, Saludos

Falconi Silvio
Post Reply