FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to identify WindowState
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
How to identify WindowState
Posted: Tue Feb 02, 2010 05:55 AM
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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 (fw): Select all Collapse
#define GWL_STYLE -16

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


Thanks

Regards
Anser
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 06:11 AM

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

Regards



G. N. Rao.

Hyderabad, India
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 06:21 AM
Dear Mr.Rao,

Thank you.

Code (fw): Select all Collapse
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
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 06:49 AM
Is ON RESIZE is the right event to be used to control the Maximize button click ?

Code (fw): Select all Collapse
ACTIVATE WINDOW oWnd ;
         ON RESIZE Test(oWnd) 

*---------------------------------------------*
FUNCTION Test(oWnd)
*---------------------------------------------*
If IsZoomed( oWnd:hWnd )
//  oWnd:Normal()
    oWnd:Restore()
Endif


Regards
Anser
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 11:21 AM

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
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 12:18 PM

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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 01:39 PM
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
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 05:15 AM
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 (fw): Select all Collapse
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
Posts: 90
Joined: Wed Nov 07, 2007 08:56 AM
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 08:16 AM
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 (fw): Select all Collapse
oDlg:aMinMaxInfo  := {oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight}
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 11:36 AM
Dear Mr.Patrizio,

Code (fw): Select all Collapse
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 (fw): Select all Collapse
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
Posts: 3107
Joined: Fri Oct 07, 2005 06:28 PM
Re: How to identify WindowState
Posted: Sat Feb 06, 2010 08:58 AM

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

Continue the discussion