Have Dialog dissapear when minimizing application
Moderators: Dorian (MJT support), JRL
Have Dialog dissapear when minimizing application
I have made a dialog for a specific application. I wish to have it dissapear when the application is minimized or closed and vice versa. Can someone point me in the right direction or supply a sample. Thanks.
You can probably use the size of the application window to determine if it is maximized or minimized. This example uses Notepad as the application. If I was doing this for real I'd probably acquire the application window handle and use it rather than the name as I've done in the sample.
Hope this is helpful.
Hope this is helpful.
Code: Select all
Let>ShowFlag=0
Dialog>Dialog1
object Dialog1: TForm
Left = 100
Top = 10
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Window is showing'
ClientHeight = 200
ClientWidth = 300
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
end
EndDialog>Dialog1
Label>Loop
IfWindowOpen>Notepad*
GetWindowSize>NotePad*,wide,tall
EndIf
If>Tall>50
GoSub>ShowDialog
EndIf
If>ShowFlag>0
Add>ShowFlag,1
If>ShowFlag>10
Let>ShowFlag=0
CloseDialog>Dialog1
EndIf
EndIf
Wait>0.01
Goto>Loop
SRT>ShowDialog
If>ShowFlag=0
Show>dialog1
EndIf
Let>ShowFlag=1
END>ShowDialog
I don't have MS version 12 yet with the new dialog stuff, or the GetWindowSize> command so I created a similar script which works with my version 10.1.21
[code]
Dialog>Dialog1
Caption=
Width=445
Height=250
Top=222
Left=522
Label=Notepad window is showing,48,56,true
EndDialog>Dialog1
Let>WIN_USEHANDLE=1
Let>ShowFlag=0
Let>HideFlag=0
Label>Loop
GetWindowHandle>Notepad*,notepad_hwnd
Assigned>notepad_hwnd,notepad_hwnd_defined
If>notepad_hwnd_defined=TRUE
If>notepad_hwnd>0
GetWindowPos>notepad_hwnd,npX,npY
If>npY>0
Gosub>ShowDialog
Else
Gosub>HideDialog
Endif
Endif
Else
Gosub>HideDialog
Endif
Wait>1
Goto>Loop
SRT>ShowDialog
If>ShowFlag=0
Show>dialog1
Let>ShowFlag=1
Let>HideFlag=0
Endif
END>ShowDialog
SRT>HideDialog
If>HideFlag=0
CloseDialog>Dialog1
Let>HideFlag=1
Let>ShowFlag=0
Endif
END>HideDialog
[/code]
[code]
Dialog>Dialog1
Caption=
Width=445
Height=250
Top=222
Left=522
Label=Notepad window is showing,48,56,true
EndDialog>Dialog1
Let>WIN_USEHANDLE=1
Let>ShowFlag=0
Let>HideFlag=0
Label>Loop
GetWindowHandle>Notepad*,notepad_hwnd
Assigned>notepad_hwnd,notepad_hwnd_defined
If>notepad_hwnd_defined=TRUE
If>notepad_hwnd>0
GetWindowPos>notepad_hwnd,npX,npY
If>npY>0
Gosub>ShowDialog
Else
Gosub>HideDialog
Endif
Endif
Else
Gosub>HideDialog
Endif
Wait>1
Goto>Loop
SRT>ShowDialog
If>ShowFlag=0
Show>dialog1
Let>ShowFlag=1
Let>HideFlag=0
Endif
END>ShowDialog
SRT>HideDialog
If>HideFlag=0
CloseDialog>Dialog1
Let>HideFlag=1
Let>ShowFlag=0
Endif
END>HideDialog
[/code]
A window handle is absolutely unique to the window. You could have several Notepad windows open all with identical names. Programmatically it could be difficult or impossible to work with the exact window that you desire to work with using a window name. Using the handle you are able to work with a precise match every time.
Looking at adroege's solution; I think it is probably a more reliable concept to check for the position of a minimized window rather than checking the size which was the concept I proposed. I did a little experimenting this afternoon and discovered that on both my XP machine and a friend's Windows 7 machine, a minimized window's location is -32000,-32000. Armed with that information, I'd guess that it might be safe to assume that if a Window's position is -32000 on the x and -32000 on the y... it is minimized.
Also, I'm not sure about the reliability of adroege's test for a minimized window. Checking to be sure the y position is greater than 0 is possibly not good because its conceivable that a user could move a window to a negative y position on any normal computer. And a multi-monitor setup could have a monitor or two in a negative y position. That said I'm sure there is some reasonable number that could be used. Maybe If>npY>-10000... then show dialog.
Just a thought,
Dick
Also, I'm not sure about the reliability of adroege's test for a minimized window. Checking to be sure the y position is greater than 0 is possibly not good because its conceivable that a user could move a window to a negative y position on any normal computer. And a multi-monitor setup could have a monitor or two in a negative y position. That said I'm sure there is some reasonable number that could be used. Maybe If>npY>-10000... then show dialog.
Just a thought,
Dick
IsZoomed and IsIconic
Here is another approach to check whether a window is minimized:
http://www.mjtnet.com/usergroup/viewtop ... 8407#18407
If IsIconic returns TRUE the window is minimized. That would be when rZ=1 near the end of the code example.
Gale
http://www.mjtnet.com/usergroup/viewtop ... 8407#18407
If IsIconic returns TRUE the window is minimized. That would be when rZ=1 near the end of the code example.
Gale