📄 winuser.c
字号:
}BOOL WINAPIIsWindow(HWND hwnd){ HWND wp; for(wp=listwp; wp; wp=wp->next) if(wp == hwnd) return TRUE; return FALSE;}BOOL WINAPIShowWindow(HWND hwnd, int nCmdShow){ if(!hwnd) return FALSE; /* fix: send show msg*/ switch(nCmdShow) { case SW_HIDE: if (!(hwnd->style & WS_VISIBLE)) return FALSE; MwHideWindow(hwnd, TRUE, TRUE); hwnd->style &= ~WS_VISIBLE; break; default: if (hwnd->style & WS_VISIBLE) return FALSE; hwnd->style |= WS_VISIBLE; MwShowWindow(hwnd, TRUE); } return TRUE;}BOOL WINAPIInvalidateRect(HWND hwnd, CONST RECT *lpRect, BOOL bErase){ /* FIXME: handle bErase*/ if(!hwnd) MwRedrawScreen(); else {#if UPDATEREGIONS RECT rc; /* add to update region*/ if(!lpRect) GetClientRect(hwnd, &rc); else rc = *lpRect; rc.bottom += mwSYSMETRICS_CYCAPTION + mwSYSMETRICS_CYFRAME + 1; rc.right += mwSYSMETRICS_CXFRAME; MwUnionUpdateRegion(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE); /* if update region not empty, mark as needing painting*/ if(hwnd->update->numRects != 0)#endif if(hwnd->gotPaintMsg == PAINT_PAINTED) hwnd->gotPaintMsg = PAINT_NEEDSPAINT; } return TRUE;}#if UPDATEREGIONS/* add region to window update region*/BOOL WINAPIInvalidateRgn(HWND hwnd, HRGN hrgn, BOOL bErase){ /* FIXME: handle bErase*/ if(hwnd) { if(!hrgn) /* add client area to update region*/ return InvalidateRect(hwnd, NULL, bErase); /* passed region is in client coords, convert to screen*/ GdOffsetRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->clirect.left, hwnd->clirect.top); GdUnionRegion(hwnd->update, hwnd->update, ((MWRGNOBJ *)hrgn)->rgn); GdOffsetRegion(((MWRGNOBJ *)hrgn)->rgn, -hwnd->clirect.left, -hwnd->clirect.top); /* if update region not empty, mark as needing painting*/ if(hwnd->update->numRects != 0) if(hwnd->gotPaintMsg == PAINT_PAINTED) hwnd->gotPaintMsg = PAINT_NEEDSPAINT; } return TRUE;}BOOL WINAPIValidateRect(HWND hwnd, CONST RECT *lprc){ RECT rc; if(!hwnd) MwRedrawScreen(); else { /* subtract from update region*/ if(!lprc) GetClientRect(hwnd, &rc); else rc = *lprc; rc.bottom += mwSYSMETRICS_CYCAPTION + mwSYSMETRICS_CYFRAME + 1; rc.right += mwSYSMETRICS_CXFRAME; MwUnionUpdateRegion(hwnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE); /* if update region empty, mark window as painted*/ if(hwnd->update->numRects == 0) if(hwnd->gotPaintMsg == PAINT_NEEDSPAINT) hwnd->gotPaintMsg = PAINT_PAINTED; } return TRUE;}/* remove region from window update region*/BOOL WINAPIValidateRgn(HWND hwnd, HRGN hrgn){ if(hwnd) { if(!hrgn) /* remove client area from update region*/ return ValidateRect(hwnd, NULL); /* passed region is in client coords, convert to screen*/ GdOffsetRegion(((MWRGNOBJ *)hrgn)->rgn, hwnd->clirect.left, hwnd->clirect.top); GdSubtractRegion(hwnd->update, hwnd->update, ((MWRGNOBJ *)hrgn)->rgn); GdOffsetRegion(((MWRGNOBJ *)hrgn)->rgn, -hwnd->clirect.left, -hwnd->clirect.top); /* if update region empty, mark window as painted*/ if(hwnd->update->numRects == 0) if(hwnd->gotPaintMsg == PAINT_NEEDSPAINT) hwnd->gotPaintMsg = PAINT_PAINTED; } return TRUE;}#endif /* UPDATEREGIONS*/BOOL WINAPIUpdateWindow(HWND hwnd){#if PAINTONCE if(hwnd && hwnd->gotPaintMsg == PAINT_NEEDSPAINT) { SendMessage(hwnd, WM_PAINT, 0, 0L); hwnd->gotPaintMsg = PAINT_PAINTED; return TRUE; } return FALSE;#else /* fix: remove other paint messages from queue*/ SendMessage(hwnd, WM_PAINT, 0, 0L); return TRUE;#endif}HWND WINAPIGetFocus(VOID){ return focuswp;}HWND WINAPISetFocus(HWND hwnd){ HWND oldfocus; HWND top, top2; /* if NULL or hidden, set focus to desktop*/ if(!hwnd || hwnd->unmapcount) hwnd = rootwp; if(hwnd == focuswp) return focuswp; oldfocus = focuswp; SendMessage(oldfocus, WM_KILLFOCUS, (WPARAM)hwnd, 0L); focuswp = hwnd; SendMessage(focuswp, WM_SETFOCUS, (WPARAM)oldfocus, 0L); /* FIXME SetActiveWindow() here?*/ top = MwGetTopWindow(oldfocus); top2 = MwGetTopWindow(focuswp); if(top2 != top) { /* send deactivate*/ SendMessage(top, WM_ACTIVATE, (WPARAM)MAKELONG(WA_INACTIVE, 0), (LPARAM)top2); /* repaint captions*/ MwPaintNCArea(top);#if 0 /* Make sure that caption area is fully invalidated, * as repaint will be in active color. * FIXME: this doesn't work; breaks terminal emulator * on focus out/in */ MwUnionUpdateRegion(top2, 0, 0, top2->winrect.right-top2->winrect.left, mwSYSMETRICS_CYCAPTION+4, TRUE);#endif /* send deactivate*/ SendMessage(top, WM_ACTIVATE, (WPARAM)MAKELONG(WA_ACTIVE, 0), (LPARAM)top); MwPaintNCArea(top2); } return oldfocus;}/* the foreground window is the top level window at the top of the z order*//* setting the foreground window sets focus and moves window to top*/BOOL WINAPISetForegroundWindow(HWND hwnd){ /* activate (set focus to) specified window*/ SetFocus(hwnd); /* raise top level parent to top of z order*/ SetWindowPos(MwGetTopWindow(hwnd), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); return TRUE;}/* our SetActiveWindow is the same as SetFocus, no z order change*/HWND WINAPISetActiveWindow(HWND hwnd){ HWND oldActive; oldActive = GetActiveWindow(); SetFocus(hwnd); /* WM_ACTIVATE sent by SetFocus*/ return oldActive;}/* The active window is the first non-child ancestor of focus window*/HWND WINAPIGetActiveWindow(VOID){ return MwGetTopWindow(focuswp);}/* activate the top level window associated with window*/BOOL WINAPIBringWindowToTop(HWND hwnd){ return SetForegroundWindow(hwnd);}HWND WINAPIGetDesktopWindow(VOID){ return rootwp;}HWNDMwGetTopWindow(HWND hwnd){ while(hwnd->style & WS_CHILD) hwnd = hwnd->parent; return hwnd;}HWND WINAPIGetParent(HWND hwnd){ /* top level windows return NULL instead of rootwp*/ if(!hwnd || !(hwnd->style & (WS_POPUP|WS_CHILD))) return NULL; /* toplevel window*/ if(hwnd->style & WS_POPUP) return hwnd->owner; /* popup window*/ return hwnd->parent; /* child window*/}BOOL WINAPIEnableWindow(HWND hwnd, BOOL bEnable){ if(bEnable && (hwnd->style & WS_DISABLED)) { /* enable window*/ hwnd->style &= ~WS_DISABLED; SendMessage(hwnd, WM_ENABLE, TRUE, 0L); return TRUE; } if(!bEnable && !(hwnd->style & WS_DISABLED)) { /* disable window*/ hwnd->style |= WS_DISABLED; /* FIXME: handle lost focus for child window of hwnd*/ /* FIXME: handle lost focus for capture window*/ if(hwnd == focuswp) SetFocus(NULL); SendMessage(hwnd, WM_ENABLE, FALSE, 0L); return FALSE; } return (hwnd->style & WS_DISABLED) != 0;}/* calc window rect from client rect in screen coords*/BOOL WINAPIAdjustWindowRectEx(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle){ int yoffset; if(dwStyle & WS_BORDER) { if((dwStyle & WS_CAPTION) == WS_CAPTION) { InflateRect(lpRect, mwSYSMETRICS_CXFRAME, mwSYSMETRICS_CYFRAME); yoffset = mwSYSMETRICS_CYCAPTION + 1; lpRect->top -= yoffset; lpRect->bottom -= yoffset; } else InflateRect(lpRect, 1, 1); /* make sure upper left is on screen*/ if(lpRect->left < 0) { lpRect->right -= lpRect->left; lpRect->left = 0; } if(lpRect->top < 0) { lpRect->bottom -= lpRect->top; lpRect->top = 0; } } return TRUE;}/* set the client rect for a window from the window position*/voidMwCalcClientRect(HWND hwnd){ NCCALCSIZE_PARAMS nccs; /* set first rectangle to window rect*/ nccs.rgrc[0] = hwnd->winrect; SendMessage(hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)(LPSTR)&nccs); hwnd->clirect = nccs.rgrc[0]; /* adjust client area if scrollbar(s) visible*/ MwAdjustNCScrollbars(hwnd);}BOOL WINAPIGetClientRect(HWND hwnd, LPRECT lpRect){ if(!hwnd || !lpRect) return FALSE; /* convert client area rect from screen coordinates*/ lpRect->left = 0; lpRect->top = 0; lpRect->right = hwnd->clirect.right - hwnd->clirect.left; lpRect->bottom = hwnd->clirect.bottom - hwnd->clirect.top; return TRUE;}BOOL WINAPIGetWindowRect(HWND hwnd, LPRECT lpRect){ if(!hwnd || !lpRect) return FALSE; /* window rect is already in screen coordinates*/ *lpRect = hwnd->winrect; return TRUE;}BOOL WINAPIClientToScreen(HWND hwnd, LPPOINT lpPoint){ if(!hwnd || !lpPoint) return FALSE; MapWindowPoints(hwnd, NULL, lpPoint, 1); return TRUE;}BOOL WINAPIScreenToClient(HWND hwnd, LPPOINT lpPoint){ if(!hwnd || !lpPoint) return FALSE; MapWindowPoints(NULL, hwnd, lpPoint, 1); return TRUE;}int WINAPIMapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints, UINT cPoints){ MWCOORD offx = 0; MWCOORD offy = 0; /* map src window to screen coords*/ if(hwndFrom) { offx = hwndFrom->clirect.left; offy = hwndFrom->clirect.top; } /* map to dst window client coords*/ if(hwndTo) { offx -= hwndTo->clirect.left; offy -= hwndTo->clirect.top; } /* adjust points*/ while(cPoints--) { lpPoints->x += offx; lpPoints->y += offy; ++lpPoints; } return (int)MAKELONG(offx, offy);}BOOL WINAPISetRect(LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom){ lprc->left = xLeft; lprc->top = yTop; lprc->right = xRight; lprc->bottom = yBottom; return TRUE;}BOOL WINAPISetRectEmpty(LPRECT lprc){ lprc->left = lprc->right = lprc->top = lprc->bottom = 0; return TRUE;}BOOL WINAPICopyRect(LPRECT lprcDst, CONST RECT *lprcSrc){ *lprcDst = *lprcSrc; return TRUE;}BOOL WINAPIIsRectEmpty(CONST RECT *lprc){ /* FIXME: should this just be ==, not <= ?*/ /*return lprc->left == lprc->right || lprc->top == lprc->bottom;*/ return lprc->right <= lprc->left || lprc->bottom <= lprc->top;}BOOL WINAPIInflateRect(LPRECT lprc, int dx, int dy){ lprc->left -= dx; lprc->top -= dy; lprc->right += dx; lprc->bottom += dy; return TRUE;}BOOL WINAPIOffsetRect(LPRECT lprc, int dx, int dy){ lprc->left += dx; lprc->right += dx; lprc->top += dy; lprc->bottom += dy; return TRUE;}/* PtInRect is #defined to MwPTINRECT because of bcc struct passing bug*/BOOL WINAPIMwPTINRECT(CONST RECT *lprc, POINT pt){ return (pt.x >= lprc->left && pt.x < lprc->right && pt.y >= lprc->top && pt.y < lprc->bottom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -