00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <windows.h>
00020 #include <windowsx.h>
00021 #include <commctrl.h>
00022
00023 #include "windowTools.h"
00024
00025
00026 BOOL GetWindowSize(HWND hWnd,int *dx,int *dy)
00027 {
00028 RECT rect;
00029 if (!GetClientRect(hWnd,&rect)) return FALSE;
00030 *dx = rect.right-rect.left;
00031 *dy = rect.bottom-rect.top;
00032 return TRUE;
00033 }
00034
00035
00036 BOOL SetWindowSize(HWND hWndControl,int dx,int dy)
00037 {
00038 return SetWindowPos(hWndControl,NULL,0,0,dx,dy,SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOSENDCHANGING);
00039 }
00040
00041
00042 BOOL GetWindowPos(HWND hWnd,int *x,int *y)
00043 {
00044 RECT rect;
00045 GetWindowRect(hWnd,&rect);
00046 POINT pt;
00047 pt.x = rect.left;
00048 pt.y = rect.top;
00049 ScreenToClient(GetParent(hWnd),&pt);
00050 *x=pt.x;
00051 *y=pt.y;
00052 return TRUE;
00053 }
00054
00055
00056 LONG SetWindowStyle(HWND hWnd,int set,LONG dwStyle)
00057 {
00058 LONG result = GetWindowLong(hWnd,GWL_STYLE);
00059 result |=dwStyle;
00060 if (!set) result-=dwStyle;
00061 return SetWindowLong(hWnd,GWL_STYLE,result);
00062 }
00063
00064
00065 void SetFullScreen(HWND hWnd,BOOL isFull,BOOL isTopMost)
00066 {
00067 HWND hWndConfig = isTopMost? HWND_TOPMOST : NULL;
00068
00069 static int dxOld,dyOld,xOld,yOld;
00070 static BOOL oldIsFull=FALSE;
00071 if (isFull)
00072 {
00073 if (!oldIsFull)
00074 {
00075 GetWindowSize(hWnd,&dxOld,&dyOld);
00076 GetWindowPos(hWnd,&xOld,&yOld);
00077 }
00078 oldIsFull=TRUE;
00079 int dx = GetSystemMetrics(SM_CXSCREEN);
00080 int dy = GetSystemMetrics(SM_CYSCREEN);
00081 SetWindowStyle(hWnd,FALSE,WS_BORDER|WS_CAPTION|WS_DLGFRAME|WS_SIZEBOX );
00082 SetWindowPos(hWnd,NULL,0,0,dx,dy,SWP_SHOWWINDOW);
00083 SetWindowPos(hWnd,hWndConfig,0,0,dx,dy,SWP_SHOWWINDOW);
00084 SetActiveWindow(hWnd);
00085 }
00086 else
00087 {
00088 oldIsFull=FALSE;
00089 SetWindowStyle(hWnd,TRUE,WS_BORDER|WS_CAPTION|WS_DLGFRAME|WS_SIZEBOX);
00090 SetWindowPos(hWnd,hWndConfig, xOld, yOld, dxOld, dyOld, 0);
00091 SetActiveWindow(hWnd);
00092 }
00093 }
00094
00095
00096 void SetWindowTitle(HWND hWnd,char *title,BOOL enableTitle)
00097 {
00098 SetWindowStyle(hWnd,enableTitle,WS_TILEDWINDOW);
00099 SetWindowText(hWnd,title);
00100 }
00101
00102
00103 void PushButton(HWND hWnd,int idControl)
00104 {
00105 SendMessage(hWnd,WM_COMMAND,idControl,0);
00106 }
00107
00108
00109 BOOL ToggleCheck(HWND hWnd,int idControl)
00110 {
00111 HWND hWndCtrl = GetDlgItem(hWnd,idControl);
00112 BOOL state = !Button_GetCheck(hWndCtrl);
00113 Button_SetCheck(hWndCtrl,state);
00114 PushButton(hWnd,idControl);
00115 return state;
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00130 void ShowMouse(BOOL active)
00131 {
00132 if (active) while (ShowCursor(TRUE)<0);
00133 else while (ShowCursor(FALSE)>=0);
00134 }
00135
00136
00137 BOOL GetDeltaWindow(HWND hWndParent,RECT *oldRect,int *deltaX,int *deltaY)
00138 {
00139 RECT newRect;
00140
00141 GetWindowRect(hWndParent,&newRect);
00142 *deltaX = (newRect.right-newRect.left)-(oldRect->right-oldRect->left);
00143 *deltaY = (newRect.bottom-newRect.top)-(oldRect->bottom-oldRect->top);
00144
00145 CopyMemory(oldRect,&newRect,sizeof(RECT));
00146 return TRUE;
00147 }
00148
00149
00150 BOOL SetDeltaWindowSize(HWND hWndControl,int deltaX,int deltaY)
00151 {
00152 RECT rect;
00153
00154 GetWindowRect(hWndControl,&rect);
00155 int dX = rect.right-rect.left;
00156 int dY= rect.bottom-rect.top;
00157
00158 SetWindowPos(hWndControl,NULL,0,0,dX+deltaX,dY+deltaY,SWP_NOMOVE|SWP_NOZORDER|SWP_NOREDRAW|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOSENDCHANGING);
00159 return TRUE;
00160 }
00161
00162
00163 BOOL SetDeltaWindowPos(HWND hWndControl,int deltaX,int deltaY)
00164 {
00165 POINT point;
00166 RECT rect;
00167 GetWindowRect(hWndControl,&rect);
00168 point.x=rect.left;
00169 point.y=rect.top;
00170 HWND hWndParent = GetParent(hWndControl);
00171 ScreenToClient(hWndParent,&point);
00172 SetWindowPos(hWndControl,NULL,point.x+deltaX,point.y+deltaY,0,0,SWP_NOSIZE);
00173 return TRUE;
00174 }
00175
00176
00177 void TreeView_ExpandAll (HWND hTree,BOOL expand,HTREEITEM rootTree)
00178 {
00179 if (!rootTree) rootTree = TreeView_GetRoot(hTree);
00180
00181 while (rootTree)
00182 {
00183 TreeView_Expand(hTree,rootTree,expand? TVE_EXPAND : TVE_COLLAPSE);
00184 HTREEITEM childTree = TreeView_GetNextItem(hTree,rootTree,TVGN_CHILD);
00185 if (childTree) TreeView_ExpandAll(hTree,expand,childTree);
00186 rootTree = TreeView_GetNextSibling(hTree,rootTree);
00187 }
00188 }
00189
00190
00191 void TreeView_ExpandAll_Level (HWND hTree,BOOL expand,int levelMax,HTREEITEM rootTree)
00192 {
00193 static int level=0;
00194 if (!rootTree) rootTree = TreeView_GetRoot(hTree);
00195
00196 level++;
00197 if (level<levelMax)
00198 {
00199 while (rootTree)
00200 {
00201 TreeView_Expand(hTree,rootTree,expand? TVE_EXPAND : TVE_COLLAPSE);
00202 HTREEITEM childTree = TreeView_GetNextItem(hTree,rootTree,TVGN_CHILD);
00203 if (childTree) TreeView_ExpandAll_Level (hTree,expand,levelMax,childTree);
00204 rootTree = TreeView_GetNextSibling(hTree,rootTree);
00205 }
00206 }
00207 level--;
00208 }
00209
00210
00211
00212
00213
00214
00215 void MoveToBorderTask (HWND hUpdatingWnd)
00216 {
00217 if (!hUpdatingWnd) return ;
00218
00219 APPBARDATA Data ;
00220 memset (&Data, 0, sizeof(Data)) ;
00221 Data.hWnd = hUpdatingWnd ;
00222 SHAppBarMessage( ABM_GETTASKBARPOS , &Data) ;
00223 RECT r ;
00224 GetWindowRect (hUpdatingWnd , &r) ;
00225
00226 int cx = GetSystemMetrics(SM_CXSCREEN);
00227 int cy = GetSystemMetrics(SM_CYSCREEN);
00228
00229 if (Data.rc.top < 0 && Data.rc.left < 0 && Data.rc.right > cx)
00230 {
00231 MoveWindow (hUpdatingWnd,
00232 cx - (r.right - r.left),
00233 Data.rc.bottom - Data.rc.top,
00234 r.right - r.left,
00235 r.bottom - r.top,
00236 FALSE);
00237 }
00238 else if (Data.rc.bottom > cy && Data.rc.left < 0 && Data.rc.right > cx)
00239 {
00240 MoveWindow (hUpdatingWnd,
00241 cx - (r.right - r.left),
00242 cy - (Data.rc.bottom-Data.rc.top)-(r.bottom - r.top),
00243 r.right - r.left,
00244 r.bottom - r.top,
00245 FALSE);
00246 }
00247 else if (Data.rc.top < 0 && Data.rc.left < 0 && Data.rc.bottom > cy)
00248 {
00249 MoveWindow (hUpdatingWnd,
00250 (Data.rc.right-Data.rc.left),
00251 cy - (r.bottom - r.top),
00252 r.right - r.left,
00253 r.bottom - r.top,
00254 FALSE);
00255 }
00256 else if (Data.rc.top < 0 && Data.rc.bottom > cy && Data.rc.right > cx)
00257 {
00258 MoveWindow (hUpdatingWnd,
00259 cx - (Data.rc.right-Data.rc.left)- (r.right - r.left),
00260 cy -(r.bottom - r.top),
00261 r.right - r.left,
00262 r.bottom - r.top,
00263 FALSE);
00264 }
00265 else
00266 MoveWindow (hUpdatingWnd,
00267 cx - (r.right - r.left),
00268 cy - (Data.rc.bottom-Data.rc.top)-(r.bottom - r.top),
00269 r.right - r.left,
00270 r.bottom - r.top,
00271 FALSE);
00272 }