home *** CD-ROM | disk | FTP | other *** search
- // WinTools.lib - Functions for setting the state of of PM windows. This
- // ver.2 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. Many of these
- // utilities require that you include PMdll.lib.
- //
- //
- //***** GetWindowHandle(): Get the handle for this window
- // SYNTAX: int GetWindowHandle(int WindowHandle)
- // int GetWindowHandle(string WindowTitle[,FullLength])
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // FullLength: If specified and true then WindowTitle length must be
- // match fully (still case-insensitive) else only needs to
- // match for length of WindowTitle; default False for partial match
- // 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".
- //
- //
- //***** GetFocusChild(): Get the handle for child that last had focus
- // 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 child of this window that now has
- // focus or most recently had focus before this window was
- // made inactive. NULL if not focus child.
- // 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".
- //
- //
- //***** GetFocus(): Return window handle with current (keyboard) focus
- // SYNTAX: int GetFocus()
- // RETURN: handle of window with focus
- //
- //
- //***** 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 | string WindowTitle,struct Rectangle)
- // bool GetWindowRect(int WindowHandle | string WindowTitle,
- // int Left,int Top,int Right,int Bottom)
- // 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
- // Left, Top, Right, Bottom - Return these four coordinates
- // 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 | string WindowTitle,struct Rectangle)
- // bool SetWindowRect(int WindowHandle | string WindowTitle,
- // int Left,int Top,int Right,int Bottom)
- // 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 BottomRow)
- // bool GetPosition(string WindowTitle,int LeftCol,int BottomRow)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // LeftCol: receive current column coordinate of lower-left corner of window
- // Height: receive current row coordinate of lower-left corner of window
- // RETURN: TRUE if WindowSpec is valid, else FALSE.
- // MODIFY: Sets LeftCol and BottomRow to current lower-left corner coordinates
- //
- //
- //***** SetPosition(): Get current column and row of window
- // SYNTAX: bool SetPosition(int WindowHandle,int LeftCol,int BottomRow)
- // bool SetPosition(string WindowTitle,int LeftCol,int BottomRow)
- // WHERE: WindowHandle: Integer identifier for this window
- // WindowTitle: Partial text title of the window (case-insensitive)
- // LeftCol: new column coordinate of lower-left corner of window
- // Height: new row coordinate of lower-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.
- //
- //
- //***** CloseWindow(): Send a CLOSE message to this window
- // SYNTAX: bool CloseWindow(int WindowHandle)
- // bool CloseWindow(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.
- //
- //
-
- #include <PMdll.lib>
-
- #define HWND_DESKTOP 1
-
- /*******************************************************************
- ********* END OF DESCRIPTION FOR WINSET.LIB *********
- *******************************************************************/
-
-
- GetWindowHandle(pWindowSpec,pFullLength)
- {
- lHwnd = 0; // assume failure
- // Test if input is string (WindowTitle) or integer (WindowHandle)
- if ( 0 == DataDimension(pWindowSpec) ) {
- // Input is WindowHandle. Verify that this handle is valid
- #define ORD_WIN32ISWINDOW 772
- if ( HWND_DESKTOP == pWindowSpec
- || PMDynamicLink("PMWIN",ORD_WIN32ISWINDOW,BIT32,CDECL,PMInfo().hab,pWindowSpec) )
- lHwnd = pWindowSpec;
- } else {
- // Input is WindowTitle, look through top level windows for one with this title
- lTitleLen = strlen(pWindowSpec);
- if ( 1 < va_arg() && pFullLength )
- lTitleLen++;
- lEnum = WinBeginEnumWindows(HWND_DESKTOP);
- while ( lChild = WinGetNextWindow(lEnum) ) {
- if ( (lTitle = GetWindowTitle(lChild)) && !strnicmp(lTitle,pWindowSpec,lTitleLen) ) {
- lHwnd = lChild;
- break;
- }
- }
- WinEndEnumWindows(lEnum);
- }
- return lHwnd;
- }
-
-
- GetWindowTitle(WindowSpec)
- {
- if ( (_handle = GetWindowHandle(WindowSpec)) ) {
- #define ORD_WIN32QUERYWINDOWTEXT 841
- BLObSize(_buf,200);
- if ( PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWTEXT,BIT32,CDECL,_handle,199,_buf) ) {
- strcpy(_ret,_buf);
- return(_ret);
- }
- }
- return(NULL);
- }
-
- SetWindowTitle(WindowSpec,NewTitle)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- #define ORD_WIN32SETWINDOWTEXT 877
- PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWTEXT,BIT32,CDECL,_handle,NewTitle);
- return(TRUE);
- }
-
-
- IsWindow(WindowSpec)
- {
- return( GetWindowHandle(WindowSpec) );
- }
-
-
- #define SWP_SIZE 0x0001
- #define SWP_MOVE 0x0002
- #define SWP_ZORDER 0x0004
- #define SWP_SHOW 0x0008
- #define SWP_HIDE 0x0010
- #define SWP_NOREDRAW 0x0020
- #define SWP_NOADJUST 0x0040
- #define SWP_ACTIVATE 0x0080
- #define SWP_DEACTIVATE 0x0100
- #define SWP_EXTSTATECHANGE 0x0200
- #define SWP_MINIMIZE 0x0400
- #define SWP_MAXIMIZE 0x0800
- #define SWP_RESTORE 0x1000
- #define SWP_FOCUSACTIVATE 0x2000
- #define SWP_FOCUSDEACTIVATE 0x4000
-
- QueryWinFlags(WindowSpec) // return WinPos flags for this window
- { // return 0 if no good
- if ( (_handle = GetWindowHandle(WindowSpec)) ) {
- #define SWP_BLOB_SIZE 9 * 4
- BLObSize(_swp,SWP_BLOB_SIZE);
- #define ORD_WIN32QUERYWINDOWPOS 837
- if ( PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,_handle,_swp) )
- return(BLObGet(_swp,0,UWORD32));
- }
- return(0);
- }
-
- IsMinimized(WindowSpec)
- {
- return( QueryWinFlags(WindowSpec) & SWP_MINIMIZE );
- }
-
-
- IsMaximized(WindowSpec)
- {
- return( QueryWinFlags(WindowSpec) & SWP_MAXIMIZE );
- }
-
-
-
- IsVisible(WindowSpec)
- {
- #define ORD_WIN32ISWINDOWVISIBLE 775
- return( (_handle = GetWindowHandle(WindowSpec))
- ? PMDynamicLink("PMWIN",ORD_WIN32ISWINDOWVISIBLE,BIT32,CDECL,_handle)
- : FALSE );
- }
-
-
- IsEnabled(WindowSpec)
- {
- #define ORD_WIN32ISWINDOWENABLED 773
- return( (_handle = GetWindowHandle(WindowSpec))
- ? PMDynamicLink("PMWIN",ORD_WIN32ISWINDOWENABLED,BIT32,CDECL,_handle)
- : FALSE );
- }
-
-
- SetWindowPos(pHandle,pBehindHandle,pColumn,pRow,pWidth,pHeight,pFlags)
- {
- #define ORD_WIN32SETWINDOWPOS 875
- PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
- pHandle,pBehindHandle,pColumn,pRow,pWidth,pHeight,pFlags);
- }
-
-
- GetWindowRect(pWindowSpec,pRectangleOrLeft,pTop,pRight,pBottom)
- {
- if ( !(lHwnd = GetWindowHandle(pWindowSpec)) )
- return(FALSE);
- #define SWP_BLOB_SIZE 9 * 4
- BLObSize(lSwp,SWP_BLOB_SIZE);
- #define ORD_WIN32QUERYWINDOWPOS 837
- if ( !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,lHwnd,lSwp) )
- return(FALSE);
- lHeight = BLObGet(lSwp,4,SWORD32);
- lWidth = BLObGet(lSwp,8,SWORD32);
- lBottom = BLObGet(lSwp,12,SWORD32);
- lLeft = BLObGet(lSwp,16,SWORD32);
- lTop = lBottom + lHeight - 1;
- lRight = lLeft + lWidth - 1;
- if ( 2 == va_arg() )
- pRectangleOrLeft.left = lLeft, pRectangleOrLeft.right = lRight,
- pRectangleOrLeft.top = lTop, pRectangleOrLeft.bottom = lBottom;
- else
- pRectangleOrLeft = lLeft, pRight = lRight, pTop = lTop, pBottom = lBottom;
- return(TRUE);
- }
-
-
- SetWindowRect(pWindowSpec,pRectangleOrLeft,pTop,pRight,pBottom)
- {
- if ( !(lHwnd = GetWindowHandle(pWindowSpec)) )
- return(FALSE);
- if ( 2 == va_arg() )
- lLeft = pRectangleOrleft.left, lRight = pRectangleOrleft.right,
- lTop = pRectangleOrleft.top, lBottom = pRectangleOrleft.bottom;
- else
- lLeft = pRectangleOrleft, lRight = pRight, lTop = pTop, lBottom = pBottom;
- SetWindowPos(lHwnd,0,lLeft,lBottom,lRight - lLeft + 1,lTop - lBottom + 1,
- SWP_SIZE | SWP_MOVE);
- return(TRUE);
- }
-
-
- GetScreenSize(Width,Height)
- {
- GetSize(HWND_DESKTOP,Width,Height);
- }
-
-
- GetSize(WindowSpec,Width,Height)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- Width = _rect.right - _rect.left + 1;
- Height = _rect.top - _rect.bottom + 1;
- return(TRUE);
- }
-
-
- SetSize(WindowSpec,Width,Height)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- SetWindowPos(_handle,0,0,0,Width,Height,SWP_SIZE);
- return(TRUE);
- }
-
-
- GetPosition(WindowSpec,LeftCol,BottomRow)
- {
- if ( !GetWindowRect(WindowSpec,_rect) )
- return(FALSE);
- LeftCol = _rect.left;
- BottomRow = _rect.bottom;
- return(TRUE);
- }
-
-
- SetPosition(WindowSpec,LeftCol,BottomRow)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- SetWindowPos(_handle,0,LeftCol,BottomRow,0,0,SWP_MOVE | SWP_NOADJUST);
- return(TRUE);
- }
-
-
- ShowWindow(pWindowSpec,pCmdShow)
- {
- if ( !(lHwnd = GetWindowHandle(pWindowSpec)) )
- return(FALSE);
- _active = 0;
- switch( pCmdShow ) {
- case SW_HIDE:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_HIDE);
- break;
- case SW_SHOWNOACTIVATE:
- _active = GetActiveWindow();
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_SHOW);
- break;
- case SW_MINIMIZE:
- case SW_SHOWMINNOACTIVE:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_MINIMIZE);
- break;
- case SW_SHOWMINIMIZED:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_MINIMIZE | SWP_ACTIVATE);
- break;
- case SW_SHOWMAXNOACTIVE:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_MAXIMIZE);
- break;
- case SW_SHOWMAXIMIZED:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_MAXIMIZE | SWP_ACTIVATE);
- break;
- case SW_RESTORENOACTIVE:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_RESTORE);
- break;
- case SW_RESTORE:
- case SW_SHOWNORMAL:
- SetWindowPos(lHwnd,0,0,0,0,0,SWP_RESTORE | SWP_ACTIVATE);
- break;
- case SW_SHOW:
- SetActiveWindow(lHwnd);
- break;
- case SW_SHOWNA:
- break;
- default: return(FALSE);
- }
- if ( _active )
- SetActiveWindow(_active);
- return(TRUE);
- }
-
-
- GetActiveWindow()
- {
- #define ORD_WIN32QUERYACTIVEWINDOW 799
- return PMDynamicLink("PMWIN",ORD_WIN32QUERYACTIVEWINDOW,BIT32,CDECL,HWND_DESKTOP);
- }
-
-
- SetActiveWindow(WindowSpec)
- {
- if ( !(_handle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- SetWindowPos(_handle,0,0,0,0,0,SWP_ACTIVATE);
- return(TRUE);
- }
-
- CloseWindow(WindowSpec)
- {
- if ( !(lHwnd = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- #define ORD_WIN32POSTMSG 919
- #define WM_CLOSE 0x0029
- DynamicLink("PMWIN",ORD_WIN32POSTMSG,BIT32,CDECL,lHwnd,WM_CLOSE,0,0);
- return(TRUE);
- }
-
- GetFocusChild(WindowSpec)
- {
- if ( !(lHandle = GetWindowHandle(WindowSpec)) )
- return(FALSE);
- if ( lHandle == GetActiveWindow() ) {
- // This is currently the active window, so just get the focus window
- return GetFocus();
- } else {
- // This window is not currently active, so get what the active window
- // used to be.
- #define QWL_HWNDFOCUSSAVE 0x0018
- #define ORD_WIN32QUERYWINDOWULONG 843
- return PMDynamicLink("PMWIN",ORD_WIN32QUERYWINDOWULONG,BIT32,CDECL,
- lHandle,QWL_HWNDFOCUSSAVE);
- }
- }
-
- WinBeginEnumWindows(pHwndParent)
- {
- #define ORD_WIN32BEGINENUMWINDOWS 702
- return DynamicLink("PMWIN",ORD_WIN32BEGINENUMWINDOWS,BIT32,CDECL,pHwndParent)
- }
-
- WinGetNextWindow(pHEnum)
- {
- #define ORD_WIN32GETNEXTWINDOW 756
- return DynamicLink("PMWIN",ORD_WIN32GETNEXTWINDOW,BIT32,CDECL,pHEnum)
- }
-
- WinEndEnumWindows(pHEnum)
- {
- #define ORD_WIN32ENDENUMWINDOWS 737
- return DynamicLink("PMWIN",ORD_WIN32ENDENUMWINDOWS,BIT32,CDECL,pHEnum)
- }
-
- GetFocus()
- {
- #define ORD_WIN32QUERYFOCUS 817
- return DynamicLink("PMWIN",ORD_WIN32QUERYFOCUS,BIT32,CDECL,HWND_DESKTOP);
- }
-