How to identify WindowState

How to identify WindowState

Postby anserkk » Tue Feb 02, 2010 5: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: Select all  Expand view
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  Expand view
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  Expand view
#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
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Postby nageswaragunupudi » Tue Feb 02, 2010 6:11 am

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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to identify WindowState

Postby anserkk » Tue Feb 02, 2010 6:21 am

Dear Mr.Rao,

Thank you.

Code: Select all  Expand view
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: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Postby anserkk » Tue Feb 02, 2010 6:49 am

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

Code: Select all  Expand view
ACTIVATE WINDOW oWnd ;
         ON RESIZE Test(oWnd)

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


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


Re: How to identify WindowState

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: How to identify WindowState

Postby anserkk » 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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Postby nageswaragunupudi » Tue Feb 02, 2010 1: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
User avatar
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to identify WindowState

Postby anserkk » Wed Feb 03, 2010 5: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: Select all  Expand view
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
User avatar
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Postby Patrizio » Wed Feb 03, 2010 8: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: Select all  Expand view
oDlg:aMinMaxInfo  := {oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight,oDlg:nWidth,oDlg:nHeight}
Patrizio
 
Posts: 90
Joined: Wed Nov 07, 2007 8:56 am
Location: Italy

Re: How to identify WindowState

Postby anserkk » Wed Feb 03, 2010 11:36 am

Dear Mr.Patrizio,

Code: Select all  Expand view
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  Expand view
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
anserkk
 
Posts: 1332
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: How to identify WindowState

Postby Silvio » Sat Feb 06, 2010 8: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
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 88 guests