C# Class ACAT.Lib.Core.Utility.Windows

Contains numerous functions for window manipulation, window sizing, window positioning, etc. Has cross-thread invoke-required functions for most of the commonly used windows functions
Datei anzeigen Open project: brlima94/acat-localization Class Usage Examples

Public Methods

Method Description
Activate ( Form form ) : void

Activates the specified form

ActivateForm ( Form form ) : void

Activates the specified form

ActivateWindow ( IntPtr handle ) : bool

Shows the specified window and brings it to top

ClickOnWindow ( Control control ) : void

Simulates a mouse click on the specified control

CloseAsync ( Form form ) : void

Closes the form asynchronously in a different thread

CloseForm ( Form form ) : void

Closes the specified form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

DockWithScanner ( Form form, Form scanner, WindowPosition scannerPosition ) : void

Docks the form to the scanner form in the relative position specified

FadeIn ( Form form ) : void

Fades in the specified form

FadeOut ( Form form ) : void

Gradually fades out the form

FindControlAtCursor ( Form form ) : Control

Finds the control under the cursor

FindControlAtPoint ( Control container, Point pos ) : Control

Finds which control of a window is at the specified point

GetCaretPosition ( TextBoxBase textBox ) : int

Returns the caret position in a text box. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

GetForegroundWindow ( ) : IntPtr

Returns the currently active fg window

GetOSVersion ( ) : WindowsVersion

Returns the OS version

GetOpacity ( Form form ) : double

Gets the transparency of a form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

GetScannerPosition ( Form form ) : WindowPosition

Gets the position of the specified form. which corner is the scanner at?

GetSelectedText ( TextBoxBase control ) : String

Returns selected text in the text box

GetText ( Control control ) : String

Returns the text value of the control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

GetText ( IntPtr hWnd ) : string

Gets text from the speficied window

GetTrackBarValueInt ( TrackBar trackBar ) : int

Returns trackbar value Takes care of cross-thread invokations that would result in .NET exceptions

GetVisible ( Control control ) : bool

Gets the visibility of a control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

GetWindowTitle ( IntPtr hwnd ) : String

Returns the window title of the specified window

HideTaskbar ( ) : void

Hide windows taskbar

IsDesktopWindow ( IntPtr handle ) : bool

returns if the specified handle is the desktop window

IsMaximized ( IntPtr handle ) : bool

Checks if window is maximized or not

IsMinimized ( IntPtr handle ) : bool

Checks if window is minimzied or not

IsObscuredByNonACATWindows ( IntPtr windowHandle ) : bool

Checks if any part of the specified window is obscured by a window belonging to a process other than ours

IsObscuredWindow ( IntPtr windowHandle ) : bool

Checks if any part of the specified window is obscured by another window. The other window could be one of this application's windows

MaximizeWindow ( IntPtr handle ) : void

Maximizes the window

MinimizeWindow ( IntPtr handle ) : void

Minimizes a window

PostMessage ( IntPtr hWnd, UInt32 Msg, Int32 wParam, UInt32 lParam ) : bool

Windows PostMessage()

RestoreWindow ( IntPtr handle ) : void

Restores the window from the maximized position

SendMessage ( IntPtr hWnd, int Msg, int wparam, int lparam ) : IntPtr

Windows SendMessage()

SetActiveWindow ( IntPtr hwnd ) : void

Sets the window as the active window

SetBackgroundColor ( Control control, Color color ) : void

Sets the background color of the widget. Takes care of cross-thread invokations that would result in .NET exceptions

SetCaretPosition ( TextBoxBase textBox, int position ) : void

Sets the caret position in a text box. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

SetFocus ( Control control ) : bool

Sets focus to the control

SetFocusToDesktop ( ) : void

Sets current focus to the desktop window

SetForegroundColor ( Control control, Color color ) : void

Sets the foreground color of the widget. Takes care of cross-thread invokations that would result in .NET exceptions

SetForegroundWindow ( IntPtr hwnd ) : bool

Sets the fg window to the specified window

SetForegroundWindowSizePercent ( WindowPosition scannerPosition, int percent ) : void

Sets the width of the foreground window to a certain percentage of the display monitor width.

SetFormStyles ( CreateParams createParams ) : CreateParams

Sets the form style to not activate and also composited for better viewing experience

SetImage ( PictureBox box, Image image ) : void

Sets the image in a picturebox and invalidates the picture box This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

SetOpacity ( Form form, double arg ) : void

Sets the transparency of a form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

SetRegion ( Control control, Region region ) : void

Set region for a control

SetText ( Control control, String text ) : void

Sets the text for the control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

SetTopMost ( Form form, bool topMost = true ) : void

Sets topmost to true

SetTrackBarValue ( TrackBar trackBar, int positionValue ) : void

Sets value of a tackbar as an integer Takes care of cross-thread invokations that would result in .NET exceptions

SetVisible ( Control control, bool visible ) : void

Sets the visibility of the control This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

SetWindowPosition ( Form form, IntPtr insertAfter, WindowPosition position ) : void

Set the window position

SetWindowPosition ( Form form, WindowPosition position ) : void

Set the window position

SetWindowPositionAndNotify ( Form form, IntPtr insertAfter, WindowPosition position ) : void

Set window pos to the specified position and notify when window position has changed

SetWindowPositionAndNotify ( Form form, WindowPosition position ) : void

Set window pos to the specified position and notify when window position has changed

SetWindowSizePercent ( IntPtr handle, WindowPosition scannerPosition, int percent ) : void

Partial maximize. Sets the window width to a percent of the display width.

Show ( Form parent, Form child ) : void

Shows the child window, assigns parent as the owner This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

ShowDialog ( Form parent, Form child ) : void

Shows the child window as a dialog of the parent window This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

ShowForm ( Form form ) : void

Shows the specified form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.

ShowInTaskbar ( Form control, bool show ) : void

Show or hide the specified form in the Windows taskbar

ShowInactiveTopmost ( Form parentForm, Form form ) : void

Show the window as topmost without activating it. Sets the form's parent to parentForm

ShowTaskbar ( ) : void

Show windows taskbar

ShowWindowBorder ( Form form, bool show, String title = "" ) : void

If show is set to true, shows the window borders and title

ShowWindowWithoutActivation ( Form form ) : void

Shows a window without setting focus to it

ShowWithoutActivation ( Form parent, Form child ) : void

Sets the child's owner to parent and shows it without setting focus to it

ToggleFgWindowMaximizeAndPartialMaximize ( WindowPosition scannerPosition, int percent ) : void

Toggles size of the fg window between maximized to partially maximized

TurnOffDPIAwareness ( ) : void

In Win8 and Win10, there are undesirable side-effects where the scanners are scaled imporperly. Turn off DPI awareness to fix this

UnselectText ( TextBoxBase control ) : void

Unselect text in textbox

Private Methods

Method Description
DeleteObject ( [ hObject ) : bool
SetProcessDpiAwareness ( _Process_DPI_Awareness value ) : int
closeFormThreadProc ( Form form ) : void

Thread proc for CloseAsync()

fadeInProc ( Form form ) : void

Threadproc for fade-in

fadeOutProc ( Form form ) : void

Thread proc for fading out

Method Details

Activate() public static method

Activates the specified form
public static Activate ( Form form ) : void
form System.Windows.Forms.Form form to activate
return void

ActivateForm() public static method

Activates the specified form
public static ActivateForm ( Form form ) : void
form System.Windows.Forms.Form form to activate
return void

ActivateWindow() public static method

Shows the specified window and brings it to top
public static ActivateWindow ( IntPtr handle ) : bool
handle System.IntPtr window handle
return bool

ClickOnWindow() public static method

Simulates a mouse click on the specified control
public static ClickOnWindow ( Control control ) : void
control System.Windows.Forms.Control the control
return void

CloseAsync() public static method

Closes the form asynchronously in a different thread
public static CloseAsync ( Form form ) : void
form System.Windows.Forms.Form form to close
return void

CloseForm() public static method

Closes the specified form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static CloseForm ( Form form ) : void
form System.Windows.Forms.Form Form to close
return void

DockWithScanner() public static method

Docks the form to the scanner form in the relative position specified
public static DockWithScanner ( Form form, Form scanner, WindowPosition scannerPosition ) : void
form System.Windows.Forms.Form form to dock
scanner System.Windows.Forms.Form scanner form to dock to
scannerPosition WindowPosition relative position
return void

FadeIn() public static method

Fades in the specified form
public static FadeIn ( Form form ) : void
form System.Windows.Forms.Form form to fade in
return void

FadeOut() public static method

Gradually fades out the form
public static FadeOut ( Form form ) : void
form System.Windows.Forms.Form form to fade out
return void

FindControlAtCursor() public static method

Finds the control under the cursor
public static FindControlAtCursor ( Form form ) : Control
form System.Windows.Forms.Form form under the cursor
return System.Windows.Forms.Control

FindControlAtPoint() public static method

Finds which control of a window is at the specified point
public static FindControlAtPoint ( Control container, Point pos ) : Control
container System.Windows.Forms.Control the container window
pos Point point to examine
return System.Windows.Forms.Control

GetCaretPosition() public static method

Returns the caret position in a text box. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static GetCaretPosition ( TextBoxBase textBox ) : int
textBox System.Windows.Forms.TextBoxBase
return int

GetForegroundWindow() public static method

Returns the currently active fg window
public static GetForegroundWindow ( ) : IntPtr
return System.IntPtr

GetOSVersion() public static method

Returns the OS version
public static GetOSVersion ( ) : WindowsVersion
return WindowsVersion

GetOpacity() public static method

Gets the transparency of a form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static GetOpacity ( Form form ) : double
form System.Windows.Forms.Form Form object
return double

GetScannerPosition() public static method

Gets the position of the specified form. which corner is the scanner at?
public static GetScannerPosition ( Form form ) : WindowPosition
form System.Windows.Forms.Form the scanner form
return WindowPosition

GetSelectedText() public static method

Returns selected text in the text box
public static GetSelectedText ( TextBoxBase control ) : String
control System.Windows.Forms.TextBoxBase text box
return String

GetText() public static method

Returns the text value of the control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static GetText ( Control control ) : String
control System.Windows.Forms.Control
return String

GetText() public static method

Gets text from the speficied window
public static GetText ( IntPtr hWnd ) : string
hWnd System.IntPtr window handle
return string

GetTrackBarValueInt() public static method

Returns trackbar value Takes care of cross-thread invokations that would result in .NET exceptions
public static GetTrackBarValueInt ( TrackBar trackBar ) : int
trackBar System.Windows.Forms.TrackBar the trackbar object
return int

GetVisible() public static method

Gets the visibility of a control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static GetVisible ( Control control ) : bool
control System.Windows.Forms.Control
return bool

GetWindowTitle() public static method

Returns the window title of the specified window
public static GetWindowTitle ( IntPtr hwnd ) : String
hwnd System.IntPtr handle to the window
return String

HideTaskbar() public static method

Hide windows taskbar
public static HideTaskbar ( ) : void
return void

IsDesktopWindow() public static method

returns if the specified handle is the desktop window
public static IsDesktopWindow ( IntPtr handle ) : bool
handle System.IntPtr
return bool

IsMaximized() public static method

Checks if window is maximized or not
public static IsMaximized ( IntPtr handle ) : bool
handle System.IntPtr window handle
return bool

IsMinimized() public static method

Checks if window is minimzied or not
public static IsMinimized ( IntPtr handle ) : bool
handle System.IntPtr window handle
return bool

IsObscuredByNonACATWindows() public static method

Checks if any part of the specified window is obscured by a window belonging to a process other than ours
public static IsObscuredByNonACATWindows ( IntPtr windowHandle ) : bool
windowHandle System.IntPtr Window to check for
return bool

IsObscuredWindow() public static method

Checks if any part of the specified window is obscured by another window. The other window could be one of this application's windows
public static IsObscuredWindow ( IntPtr windowHandle ) : bool
windowHandle System.IntPtr Window to check for
return bool

MaximizeWindow() public static method

Maximizes the window
public static MaximizeWindow ( IntPtr handle ) : void
handle System.IntPtr window handle
return void

MinimizeWindow() public static method

Minimizes a window
public static MinimizeWindow ( IntPtr handle ) : void
handle System.IntPtr window handle
return void

PostMessage() public static method

Windows PostMessage()
public static PostMessage ( IntPtr hWnd, UInt32 Msg, Int32 wParam, UInt32 lParam ) : bool
hWnd System.IntPtr
Msg System.UInt32
wParam System.Int32
lParam System.UInt32
return bool

RestoreWindow() public static method

Restores the window from the maximized position
public static RestoreWindow ( IntPtr handle ) : void
handle System.IntPtr window handle
return void

SendMessage() public static method

Windows SendMessage()
public static SendMessage ( IntPtr hWnd, int Msg, int wparam, int lparam ) : IntPtr
hWnd System.IntPtr
Msg int
wparam int
lparam int
return System.IntPtr

SetActiveWindow() public static method

Sets the window as the active window
public static SetActiveWindow ( IntPtr hwnd ) : void
hwnd System.IntPtr window handle
return void

SetBackgroundColor() public static method

Sets the background color of the widget. Takes care of cross-thread invokations that would result in .NET exceptions
public static SetBackgroundColor ( Control control, Color color ) : void
control System.Windows.Forms.Control
color Color Color to set
return void

SetCaretPosition() public static method

Sets the caret position in a text box. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static SetCaretPosition ( TextBoxBase textBox, int position ) : void
textBox System.Windows.Forms.TextBoxBase
position int
return void

SetFocus() public static method

Sets focus to the control
public static SetFocus ( Control control ) : bool
control System.Windows.Forms.Control control to set focus to
return bool

SetFocusToDesktop() public static method

Sets current focus to the desktop window
public static SetFocusToDesktop ( ) : void
return void

SetForegroundColor() public static method

Sets the foreground color of the widget. Takes care of cross-thread invokations that would result in .NET exceptions
public static SetForegroundColor ( Control control, Color color ) : void
control System.Windows.Forms.Control
color Color Color to set
return void

SetForegroundWindow() public static method

Sets the fg window to the specified window
public static SetForegroundWindow ( IntPtr hwnd ) : bool
hwnd System.IntPtr window handle
return bool

SetForegroundWindowSizePercent() public static method

Sets the width of the foreground window to a certain percentage of the display monitor width.
public static SetForegroundWindowSizePercent ( WindowPosition scannerPosition, int percent ) : void
scannerPosition WindowPosition where to position the window?
percent int the percent width
return void

SetFormStyles() public static method

Sets the form style to not activate and also composited for better viewing experience
public static SetFormStyles ( CreateParams createParams ) : CreateParams
createParams System.Windows.Forms.CreateParams Windows create params
return System.Windows.Forms.CreateParams

SetImage() public static method

Sets the image in a picturebox and invalidates the picture box This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static SetImage ( PictureBox box, Image image ) : void
box System.Windows.Forms.PictureBox
image Image
return void

SetOpacity() public static method

Sets the transparency of a form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static SetOpacity ( Form form, double arg ) : void
form System.Windows.Forms.Form Form object
arg double opacity value
return void

SetRegion() public static method

Set region for a control
public static SetRegion ( Control control, Region region ) : void
control System.Windows.Forms.Control control to set region for
region System.Drawing.Region region to set
return void

SetText() public static method

Sets the text for the control. This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static SetText ( Control control, String text ) : void
control System.Windows.Forms.Control
text String text to set
return void

SetTopMost() public static method

Sets topmost to true
public static SetTopMost ( Form form, bool topMost = true ) : void
form System.Windows.Forms.Form which form?
topMost bool set to true for topmost, false otherwise
return void

SetTrackBarValue() public static method

Sets value of a tackbar as an integer Takes care of cross-thread invokations that would result in .NET exceptions
public static SetTrackBarValue ( TrackBar trackBar, int positionValue ) : void
trackBar System.Windows.Forms.TrackBar
positionValue int
return void

SetVisible() public static method

Sets the visibility of the control This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static SetVisible ( Control control, bool visible ) : void
control System.Windows.Forms.Control
visible bool
return void

SetWindowPosition() public static method

Set the window position
public static SetWindowPosition ( Form form, IntPtr insertAfter, WindowPosition position ) : void
form System.Windows.Forms.Form form to reposition
insertAfter System.IntPtr insert after this window
position WindowPosition new position
return void

SetWindowPosition() public static method

Set the window position
public static SetWindowPosition ( Form form, WindowPosition position ) : void
form System.Windows.Forms.Form form to reposition
position WindowPosition the new position
return void

SetWindowPositionAndNotify() public static method

Set window pos to the specified position and notify when window position has changed
public static SetWindowPositionAndNotify ( Form form, IntPtr insertAfter, WindowPosition position ) : void
form System.Windows.Forms.Form The form
insertAfter System.IntPtr
position WindowPosition Where to set the position
return void

SetWindowPositionAndNotify() public static method

Set window pos to the specified position and notify when window position has changed
public static SetWindowPositionAndNotify ( Form form, WindowPosition position ) : void
form System.Windows.Forms.Form The form
position WindowPosition Where to set the position
return void

SetWindowSizePercent() public static method

Partial maximize. Sets the window width to a percent of the display width.
public static SetWindowSizePercent ( IntPtr handle, WindowPosition scannerPosition, int percent ) : void
handle System.IntPtr handle of the window
scannerPosition WindowPosition which corner should the window be positioned at?
percent int percentage of display monitor width
return void

Show() public static method

Shows the child window, assigns parent as the owner This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static Show ( Form parent, Form child ) : void
parent System.Windows.Forms.Form
child System.Windows.Forms.Form
return void

ShowDialog() public static method

Shows the child window as a dialog of the parent window This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static ShowDialog ( Form parent, Form child ) : void
parent System.Windows.Forms.Form
child System.Windows.Forms.Form
return void

ShowForm() public static method

Shows the specified form This is just a helper function that takes care of cross-thread invokations that would result in .NET exceptions.
public static ShowForm ( Form form ) : void
form System.Windows.Forms.Form
return void

ShowInTaskbar() public static method

Show or hide the specified form in the Windows taskbar
public static ShowInTaskbar ( Form control, bool show ) : void
control System.Windows.Forms.Form form
show bool set to true to show
return void

ShowInactiveTopmost() public static method

Show the window as topmost without activating it. Sets the form's parent to parentForm
public static ShowInactiveTopmost ( Form parentForm, Form form ) : void
parentForm System.Windows.Forms.Form the parent of the form
form System.Windows.Forms.Form the form
return void

ShowTaskbar() public static method

Show windows taskbar
public static ShowTaskbar ( ) : void
return void

ShowWindowBorder() public static method

If show is set to true, shows the window borders and title
public static ShowWindowBorder ( Form form, bool show, String title = "" ) : void
form System.Windows.Forms.Form the target form
show bool true to show border/title
title String title to set
return void

ShowWindowWithoutActivation() public static method

Shows a window without setting focus to it
public static ShowWindowWithoutActivation ( Form form ) : void
form System.Windows.Forms.Form the window form
return void

ShowWithoutActivation() public static method

Sets the child's owner to parent and shows it without setting focus to it
public static ShowWithoutActivation ( Form parent, Form child ) : void
parent System.Windows.Forms.Form parent form
child System.Windows.Forms.Form child form
return void

ToggleFgWindowMaximizeAndPartialMaximize() public static method

Toggles size of the fg window between maximized to partially maximized
public static ToggleFgWindowMaximizeAndPartialMaximize ( WindowPosition scannerPosition, int percent ) : void
scannerPosition WindowPosition where to position the window
percent int the partial maximize percentage
return void

TurnOffDPIAwareness() public static method

In Win8 and Win10, there are undesirable side-effects where the scanners are scaled imporperly. Turn off DPI awareness to fix this
public static TurnOffDPIAwareness ( ) : void
return void

UnselectText() public static method

Unselect text in textbox
public static UnselectText ( TextBoxBase control ) : void
control System.Windows.Forms.TextBoxBase the text box control
return void