home *** CD-ROM | disk | FTP | other *** search
- // WinTools.lib - Functions for setting the state of of Windows. This
- // file may be #included into other Cmm source files, or
- // you can cut and paste in the parts that you need.
- //
- // Note: Most of these routines require either a window
- // handle or a window title. You can use either, but
- // using a Window handle is a little quicker.
- //
- //
- //***** GetWindowHandle(): Get the handle for this window
- // SYNTAX: int GetWindowHandle(int WindowHandle)
- // int GetWindowHandle(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: Returns Window handle for a Windows whose partial title is
- // WindowTitle. Comparison is case-insensitive. If WindowTitle
- // is not found then returns 0 (NULL).
- // NOTE: If WindowHandle is input, then this returns WindowHandle if
- // WindowHandle is valid, else returns 0. WindowTitle is a partial
- // and case-insensitive match and so "write" would match the
- // window titled "Write - THESIS.WRI".
- //
- //
- //***** GetWindowTitle(): Get full Window Title
- // SYNTAX: string GetWindowTitle(int WindowHandle)
- // string GetWindowTitle(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: Returns Full title for this window, or NULL if window not
- // found or title not found
- //
- //
- //***** SetWindowTitle(): Set title for window
- // SYNTAX: bool SetWindowTitle(int WindowHandle,string NewTitle)
- // bool SetWindowTitle(string WindowTitle,string NewTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // NewTitle: New full title for this window
- // RETURN: TRUE if successful, else FALSE if WindowSpec is invalid.
- //
- //
- //***** IsWindow(): Is this a valid window title or handle
- // SYNTAX: bool IsWindow(int WindowHandle)
- // bool IsWindow(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: Returns non-zero if this window exists, else returns zero (FALSE)
- //
- //
- //***** IsMinimized(): Is window minimized (Iconic)
- // SYNTAX: bool IsMinimized(int WindowHandle)
- // bool IsMinimized(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: non-zero if Window is minimized (iconic) else zero (FALSE)
- // if not minimized or if WindowSpec is invalid
- //
- //
- //***** IsMaximized(): Is window maximized
- // SYNTAX: bool IsMinimized(int WindowHandle)
- // bool IsMinimized(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: non-zero if Window is maximized else zero (FALSE) if not
- // maximized or if WindowSpec is invalid
- //
- //
- //***** IsVisible(): Is window visible
- // SYNTAX: bool IsVisible(int WindowHandle)
- // bool IsVisible(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: non-zero if Window is visible else zero (FALSE) if not
- // visible or if WindowSpec is invalid. Visible means that
- // the window exists on the screen even if it is covered by
- // other windows
- //
- //
- //***** IsEnabled(): Is window enabled for input
- // SYNTAX: bool IsEnabled(int WindowHandle)
- // bool IsEnabled(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: non-zero if Window is enabled for mouse and keyboard input,
- // else zero (FALSE) if not enabled or if WindowSpec is invalid
- //
- //
- //***** GetWindowRect(): Get current window coordinates
- // SYNTAX: bool GetWindowRect(int WindowHandle,struct Rectangle)
- // bool GetWindowRect(string WindowTitle,struct Rectangle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // Rectangle: receive structure of current window with following members
- // .left - coordinate for left edge of window
- // .right - coordinate for right edge of window
- // .top - coordinate for top edge of window
- // .bottom - coordinate for bottom edge of window
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- // MODIFY: Modifies Rectangle structure to current coordinates
- //
- //
- //***** SetWindowRect(): Set current window coordinates
- // SYNTAX: bool SetWindowRect(int WindowHandle,struct Rectangle)
- // bool SetWindowRect(string WindowTitle,struct Rectangle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // Rectangle: new structurw of window with the same member elements as
- // defined above in GetWindowRect()
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- //
- //
- //***** GetScreenSize(): Get width and height of the windows screen
- // SYNTAX: void GetScreenSize(int Width,int Height);
- // WHERE: Width: receive screen width
- // Height: receive screen height
- // MODIFY: Sets Width and Height to dimensions of screen
- //
- //
- //***** GetSize(): Get current width and height of window
- // SYNTAX: bool GetSize(int WindowHandle,int Width,int Height)
- // bool GetSize(string WindowTitle,int Width,int Height)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // Width: receive current window width
- // Height: receive current window height
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- // MODIFY: Sets Width and Height to current dimensions of window
- //
- //
- //***** SetSize(): Get current width and height of window
- // SYNTAX: bool GetSize(int WindowHandle,int Width,int Height)
- // bool GetSize(string WindowTitle,int Width,int Height)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // Width: new window width
- // Height: new window height
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- //
- //
- //***** GetPosition(): Get current column and row of window
- // SYNTAX: bool GetPosition(int WindowHandle,int LeftCol,int TopRow)
- // bool GetPosition(string WindowTitle,int LeftCol,int TopRow)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // LeftCol: receive current column coordinate of upper-left corner of window
- // Height: receive current row coordinate of upper-left corner of window
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- // MODIFY: Sets LeftCol and TopRow to current upper-left corner coordinates
- //
- //
- //***** SetPosition(): Get current column and row of window
- // SYNTAX: bool SetPosition(int WindowHandle,int LeftCol,int TopRow)
- // bool SetPosition(string WindowTitle,int LeftCol,int TopRow)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // LeftCol: new column coordinate of upper-left corner of window
- // Height: new row coordinate of upper-left corner of window
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- //
- //
- //***** ShowWindow(): Set the way the window is shown (or not shown)
- // SYNTAX: bool ShowWindow(int WindowHandle,int ShowCommand)
- // bool ShowWindow(string WindowTitle,int ShowCommand)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // ShowCommand: Any of the following values:
- #define SW_HIDE 0 // Hide window; make NOT the active window
- #define SW_MINIMIZE 6 // minimize window; make NOT the active window
- #define SW_RESTORE 9 // activate and display this window; restore from minimized
- // or maximized to original size and position before
- // it was minimized or maximized
- #define SW_RESTORENOACTIVE -9 // Same as restore but active window remains active
- #define SW_SHOW 5 // Activate this window in current size and position
- #define SW_SHOWMAXIMIZED 3 // Activate this window and maximize
- #define SW_SHOWMAXNOACTIVE -3 // Display maximized; active window stays active
- #define SW_SHOWMINIMIZED 2 // Activate this window and display as icon
- #define SW_SHOWMINNOACTIVE 7 // Display as icon; active window stays active
- #define SW_SHOWNA 8 // don't change window state or active window
- #define SW_SHOWNOACTIVATE 4 // display in recent size and place; active window stays active
- #define SW_SHOWNORMAL 1 // same as SW_RESTORE
- //
- //
- //***** GetActiveWindow(): Get the active window
- // SYNTAX: int GetActiveWindow()
- // RETURN: Return window handle for currently active window
- //
- //
- //***** SetActiveWindow(): Set the currently active window
- // SYNTAX: bool SetActiveWindow(int WindowHandle)
- // bool SetActiveWindow(string WindowTitle)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- //
- //
-
- #define _WINTOOLS_LIB 1
-
- /*******************************************************************
- ********* END OF DESCRIPTION FOR WINSET.LIB *********
- *******************************************************************/
-
- GetWindowHandle(WindowSpec)
- {
- // Test if input is string (WindowTitle) or integer (WindowHandle)
- if ( 0 == DataDimension(WindowSpec) ) {
-
- // Input is WindowHandle. Verify that this handle is valid
- if ( DynamicLink("USER","ISWINDOW",SWORD16,PASCAL,WindowSpec) )
- return(WindowSpec);
-
- } else {
-
- // Input is WindowTitle, build list of titles and look for this one
- _TitleLen = strlen(WindowSpec);
-
- // Build list of all root window titles
- if ( NULL != (_winList = WindowList()) ) {
-
- // for each window, compare its title against Window
- BLObSize(_buf,200);
- for ( _i = GetArraySpan(_winList); 0 <= _i; _i-- ) {
- // compare the title for this window, if it has one
- if ( DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL,_winList[_i],_buf,199)
- && !memicmp(WindowSpec,_buf,_TitleLen) )
- return(_winList[_i]);
- }
-
- }
- }
- // if didn't return a handle above, then title was not found
- return(0);
- }
-
-
-
- GetWindowTitle(WindowSpec)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- _ret = NULL;
- else {
- BLObSize(_buf,200);
- if ( !DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL,WindowSpec,_buf,199) )
- _ret = NULL;
- else // copy to short string and return that
- strcpy(_ret,_buf);
- }
- return(_ret);
- }
-
-
- SetWindowTitle(WindowSpec,NewTitle)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- DynamicLink("USER","SETWINDOWTEXT",SWORD16,PASCAL,_handle,NewTitle);
- return(TRUE);
- }
-
-
- IsWindow(WindowSpec)
- {
- return( GetWindowHandle(WindowSpec) );
- }
-
-
- IsMinimized(WindowSpec)
- {
- return( (_handle = GetWindowHandle(WindowSpec))
- ? DynamicLink("USER","ISICONIC",SWORD16,PASCAL,_handle)
- : FALSE );
- }
-
-
- IsMaximized(WindowSpec)
- {
- return( (_handle = GetWindowHandle(WindowSpec))
- ? DynamicLink("USER","ISZOOMED",SWORD16,PASCAL,_handle)
- : FALSE );
- }
-
-
-
- IsVisible(WindowSpec)
- {
- return( (_handle = GetWindowHandle(WindowSpec))
- ? DynamicLink("USER","ISWINDOWVISIBLE",SWORD16,PASCAL,_handle)
- : FALSE );
- }
-
-
- IsEnabled(WindowSpec)
- {
- return( (_handle = GetWindowHandle(WindowSpec))
- ? DynamicLink("USER","ISWINDOWENABLED",SWORD16,PASCAL,_handle)
- : FALSE );
- }
-
-
- GetWindowRect(WindowSpec,Rectangle)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- // set up blob to retrieve four integers
- BLObSize(_rect,4 * 2/*integer size*/);
- DynamicLink("USER","GETWINDOWRECT",SWORD16,PASCAL,_handle,_rect);
- Rectangle.left = BLObGet(_rect,0,SWORD16);
- Rectangle.top = BLObGet(_rect,2,SWORD16);
- Rectangle.right = BLObGet(_rect,4,SWORD16);
- Rectangle.bottom = BLObGet(_rect,6,SWORD16);
- return(TRUE);
- }
-
-
- SetWindowRect(WindowSpec,Rectangle)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- _width = Rectangle.right - Rectangle.left + 1;
- _height = Rectangle.bottom - Rectangle.top + 1;
- DynamicLink("USER","MOVEWINDOW",SWORD16,PASCAL,
- _handle,Rectangle.left,Rectangle.top,_width,_height,TRUE);
- return(TRUE);
- }
-
-
- GetScreenSize(Width,Height)
- {
- #define SM_CXSCREEN 0
- #define SM_CYSCREEN 1
- Width = DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,SM_CXSCREEN);
- Height = DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,SM_CYSCREEN);
- }
-
-
- GetSize(WindowSpec,Width,Height)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- Width = _rect.right - _rect.left + 1;
- Height = _rect.bottom - _rect.top + 1;
- return(TRUE);
- }
-
-
- SetSize(WindowSpec,Width,Height)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- _rect.right = _rect.left + Width - 1;
- _rect.bottom = _rect.top + Height - 1;
- SetWindowRect(WindowSpec,_rect);
- return(TRUE);
- }
-
-
- GetPosition(WindowSpec,LeftCol,TopRow)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- LeftCol = _rect.left;
- TopRow = _rect.top;
- return(TRUE);
- }
-
-
- SetPosition(WindowSpec,LeftCol,TopRow)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- _deltaCol = LeftCol - _rect.left;
- _deltaRow = TopRow - _rect.top;
- _rect.left = LeftCol;
- _rect.right += _deltaCol;
- _rect.top = TopRow;
- _rect.bottom += _deltaRow;
- SetWindowRect(WindowSpec,_rect);
- return(TRUE);
- }
-
-
- ShowWindow(WindowSpec,CmdShow)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- if ( CmdSHow < 0 ) {
- // Windows does not directly provide these commands without activating
- // the window, and so here will find what window is active, maximize
- // the selected window, then restore the active window
- _active = GetActiveWindow();
- ShowWindow(_handle,-CmdShow);
- SetActiveWindow(_active);
- } else {
- DynamicLink("USER","SHOWWINDOW",SWORD16,PASCAL,_handle,CmdShow);
- }
- return(TRUE);
- }
-
-
- GetActiveWindow()
- {
- return DynamicLink("USER","GETACTIVEWINDOW",SWORD16,PASCAL);
- }
-
-
- SetActiveWindow(WindowSpec)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- DynamicLink("USER","SETACTIVEWINDOW",SWORD16,PASCAL,_handle);
- return(TRUE);
- }
-
-