// WinUtil.lib - Cmm code wrapper for various useful Windows functions. // This is by no means an exhaustive collection, but simply // examples. You may #include this file in your CMM source // or you may simply copy the routines you like into your // code. The routines in this file are: // GetSystemMetrics() - Width and height of various display elements // GetWindowRect() - return structure containing window coordinates // MoveWindow() - Move a window to specified coordinates on the screen // GetWindowHandle() - get handle for a window based on it's matching title // GetWindowText() - Get title of a window #define _WINUTIL_LIB 1 GetSystemMetrics(Index) // return this system metric { #define SM_CXSCREEN 0 // screen width #define SM_CYSCREEN 1 // screen height #define SM_CXVSCROLL 2 #define SM_CYHSCROLL 3 #define SM_CYCAPTION 4 #define SM_CXBORDER 5 #define SM_CYBORDER 6 #define SM_CXDLGFRAME 7 #define SM_CYDLGFRAME 8 #define SM_CYVTHUMB 9 #define SM_CXHTHUMB 10 #define SM_CXICON 11 #define SM_CYICON 12 #define SM_CXCURSOR 13 #define SM_CYCURSOR 14 #define SM_CYMENU 15 #define SM_CXFULLSCREEN 16 #define SM_CYFULLSCREEN 17 #define SM_CYKANJIWINDOW 18 #define SM_MOUSEPRESENT 19 #define SM_CYVSCROLL 20 #define SM_CXHSCROLL 21 #define SM_DEBUG 22 #define SM_SWAPBUTTON 23 #define SM_RESERVED1 24 #define SM_RESERVED2 25 #define SM_RESERVED3 26 #define SM_RESERVED4 27 #define SM_CXMIN 28 #define SM_CYMIN 29 #define SM_CXSIZE 30 #define SM_CYSIZE 31 #define SM_CXFRAME 32 #define SM_CYFRAME 33 #define SM_CXMINTRACK 34 #define SM_CYMINTRACK 35 #define SM_CMETRICS 36 return( DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,Index) ); } GetWindowRect(WindowHandle) // return window coordinates in a structure with the following members // .left // .top // .right // .bottom { // set up blob to retrieve four integers BLObSize(_rect,4 * 2/*integer size*/); DynamicLink("USER","GETWINDOWRECT",SWORD16,PASCAL,WindowHandle,_rect); _ret.left = BLObGet(_rect,0,SWORD16); _ret.top = BLObGet(_rect,2,SWORD16); _ret.right = BLObGet(_rect,4,SWORD16); _ret.bottom = BLObGet(_rect,6,SWORD16); return(_ret); } GetClientRect(WindowHandle) // return window client-area coordinates in a structure with the following members // .left // .top // .right // .bottom { // set up blob to retrieve four integers BLObSize(_rect,4 * 2/*integer size*/); DynamicLink("USER","GETCLIENTRECT",SWORD16,PASCAL,WindowHandle,_rect); _ret.left = BLObGet(_rect,0,SWORD16); _ret.top = BLObGet(_rect,2,SWORD16); _ret.right = BLObGet(_rect,4,SWORD16); _ret.bottom = BLObGet(_rect,6,SWORD16); return(_ret); } MoveWindow(WindowHandle,x,y,width,height,Repaint) // move the window to coordinates x,y on the screen, with size width,height. // if Repaint is not-False then will repaint window { DynamicLink("USER","MOVEWINDOW",SWORD16,PASCAL, WindowHandle,x,y,width,height,Repaint); } GetWindowText(WindowHandle) // return string containing text of this Window handle, or NULL if this window // has no text { BLObSize(_buf,200); if ( 0 == DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL, WindowHandle,_buf,BLObSize(_buf)-1) ) { return(NULL); } // copy to shorter string and return that strcpy(_ret,_buf); return(_ret); } GetWindowHandle(Title) // Search for a window to match the string: Title or match title for at // least the length of the string. Return the handle of the window as an // integer, or return 0 if the window was not found. { _len = strlen(Title); if ( NULL == (_winList = WindowList()) ) return 0; _count = 1 + GetArraySpan(_winList); for ( i = 0; i < _count; i++ ) { // compare the title for this window, if it has one if ( NULL != (_title = GetWindowText(_winList[i])) && 0 == strnicmp(Title,_title,_len) ) return(_winList[i]); } return(0); }