Page 1 of 1
How to identify WindowState
Posted: Tue Feb 02, 2010 5:55 am
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
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 6:11 am
by nageswaragunupudi
IsIconic( oWnd:hWnd )
IsZoomed( oWnd:hWnd )
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 6:21 am
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
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 6:49 am
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
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 7:55 am
by Enrico Maria Giordano
Yes, as far as I know.
EMG
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 11:21 am
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
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 12:18 pm
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
Re: How to identify WindowState
Posted: Tue Feb 02, 2010 1:39 pm
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 )
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 5:15 am
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
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 8:16 am
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}
Re: How to identify WindowState
Posted: Wed Feb 03, 2010 11:36 am
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
Re: How to identify WindowState
Posted: Sat Feb 06, 2010 8:58 am
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