📄 winuser.c
字号:
}LONG WINAPIGetWindowLong(HWND hwnd, int nIndex){ switch(nIndex) { case GWL_WNDPROC: return (LONG)hwnd->pClass->lpfnWndProc; case GWL_HINSTANCE: /* nyi*/ break; case GWL_HWNDPARENT: return (LONG)hwnd->parent; case GWL_ID: return hwnd->id; case GWL_STYLE: return hwnd->style; case GWL_EXSTYLE: return hwnd->exstyle; case GWL_USERDATA: return hwnd->userdata; default: if(nIndex+3 < hwnd->nextrabytes) return *(LONG *)&hwnd->extrabytes[nIndex]; } return 0;}LONG WINAPISetWindowLong(HWND hwnd, int nIndex, LONG lNewLong){ LONG oldval = 0; switch(nIndex) { case GWL_USERDATA: oldval = hwnd->userdata; hwnd->userdata = lNewLong; break; case GWL_WNDPROC: oldval = (LONG)hwnd->pClass->lpfnWndProc; hwnd->pClass->lpfnWndProc = (WNDPROC)lNewLong; break; case GWL_HINSTANCE: case GWL_HWNDPARENT: case GWL_ID: case GWL_STYLE: case GWL_EXSTYLE: /* nyi*/ break; default: if(nIndex+3 < hwnd->nextrabytes) { oldval = GetWindowLong(hwnd, nIndex); *(LONG *)&hwnd->extrabytes[nIndex] = lNewLong; } break; } return oldval;}WORD WINAPIGetWindowWord(HWND hwnd, int nIndex){ if(nIndex+1 < hwnd->nextrabytes) return *(WORD *)&hwnd->extrabytes[nIndex]; return 0;}WORD WINAPISetWindowWord(HWND hwnd, int nIndex, WORD wNewWord){ WORD oldval = 0; if(nIndex+1 < hwnd->nextrabytes) { oldval = GetWindowWord(hwnd, nIndex); *(WORD *)&hwnd->extrabytes[nIndex] = wNewWord; } return oldval;}DWORD WINAPIGetClassLong(HWND hwnd, int nIndex){ switch(nIndex) { case GCL_HBRBACKGROUND: return (DWORD)hwnd->pClass->hbrBackground; case GCL_CBWNDEXTRA: return (DWORD)hwnd->pClass->cbWndExtra; } return 0;}int WINAPIGetWindowTextLength(HWND hwnd){ return SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0L);}int WINAPIGetWindowText(HWND hwnd, LPSTR lpString, int nMaxCount){ return SendMessage(hwnd, WM_GETTEXT, nMaxCount,(LPARAM)(LPSTR)lpString);}BOOL WINAPISetWindowText(HWND hwnd, LPCSTR lpString){ return SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)(LPCSTR)lpString);}/* Recursively offset all children of passed window*/static voidMwOffsetChildren(HWND hwnd, int offx, int offy){ HWND cp; /* offset all child windows for move*/ for(cp=hwnd->children; cp; cp=cp->siblings) { /* offset window and client area rects*/ OffsetRect(&cp->winrect, offx, offy); OffsetRect(&cp->clirect, offx, offy); /* offset scrollbar NC hittest rects*/ if(!IsRectEmpty(&cp->vscroll.rc)) OffsetRect(&cp->vscroll.rc, offx, offy); if(!IsRectEmpty(&cp->hscroll.rc)) OffsetRect(&cp->hscroll.rc, offx, offy); MwOffsetChildren(cp, offx, offy); }}BOOLSetWindowPos(HWND hwnd, HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags){ int hidden; BOOL bMove, bSize, bZorder; MWCOORD offx = 0, offy = 0; /* = 0 for bad gcc warning*/ WINDOWPOS winpos; if(!hwnd || hwnd == rootwp || cx < 0 || cy < 0) return FALSE; /* FIXME SWP_NOACTIVATE*/ if((fuFlags & SWP_SHOWWINDOW)) return ShowWindow(hwnd, SW_SHOW); if((fuFlags & SWP_HIDEWINDOW)) return ShowWindow(hwnd, SW_HIDE); /* move is relative to parent's client rect for child windows*/ if(hwnd->style & WS_CHILD) { x += hwnd->parent->clirect.left; y += hwnd->parent->clirect.top; } else { x += hwnd->parent->winrect.left; y += hwnd->parent->winrect.top; } bMove = !(fuFlags & SWP_NOMOVE) && (hwnd->winrect.left != x || hwnd->winrect.top != y); bSize = !(fuFlags & SWP_NOSIZE) && ((hwnd->winrect.right - hwnd->winrect.left) != cx || (hwnd->winrect.bottom - hwnd->winrect.top) != cy); bZorder = !(fuFlags & SWP_NOZORDER); if(!bMove && !bSize && !bZorder) return TRUE; /* could optimize to not require redraw when possible*/ hidden = hwnd->unmapcount || (fuFlags & SWP_NOREDRAW); if(bZorder) { switch((int)hwndInsertAfter) { case (int)HWND_TOP: MwRaiseWindow(hwnd); break; case (int)HWND_BOTTOM: MwLowerWindow(hwnd); break; default: /* FIXME for non top/bottom zorder*/ break; } } else { if(!hidden) MwHideWindow(hwnd, FALSE, FALSE); } if(bMove) { offx = x - hwnd->winrect.left; offy = y - hwnd->winrect.top; } if(bMove || bSize) { hwnd->winrect.left = x; hwnd->winrect.top = y; hwnd->winrect.right = x + cx; hwnd->winrect.bottom = y + cy; } if(bMove) MwOffsetChildren(hwnd, offx, offy); if(bMove || bSize) { MwCalcClientRect(hwnd); /* send windowposchanged message*/ /* FIXME: move WM_MOVE, WM_SIZE to defwndproc*/ winpos.hwnd = hwnd; winpos.hwndInsertAfter = hwndInsertAfter; winpos.x = x; winpos.y = y; winpos.cx = cx; winpos.cy = cy; winpos.flags = fuFlags; SendMessage(hwnd, WM_WINDOWPOSCHANGED, 0, (LPARAM)&winpos); MwSendSizeMove(hwnd, bSize, bMove); } ++mwpaintSerial; /* increment paint serial # for alphablending*/ ++mwpaintNC; /* increment paint serial # for NC painting*/ if(!bZorder && !hidden) MwShowWindow(hwnd, FALSE); return TRUE;}BOOL WINAPIMoveWindow(HWND hwnd, int x, int y, int nWidth, int nHeight, BOOL bRepaint){ UINT flags = SWP_NOZORDER | SWP_NOACTIVATE; if(!bRepaint) flags |= SWP_NOREDRAW; return SetWindowPos(hwnd, 0, x, y, nWidth, nHeight, flags);}voidMwSendSizeMove(HWND hwnd, BOOL bSize, BOOL bMove){ DWORD dwStyle; RECT rc; if(bSize) { GetClientRect(hwnd, &rc); SendMessage(hwnd, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.right, rc.bottom)); } if(bMove) { dwStyle = GetWindowLong(hwnd, GWL_STYLE); GetWindowRect(hwnd, &rc); /* return parent coords for child windows*/ if(dwStyle & WS_CHILD) ScreenToClient(hwnd->parent, (LPPOINT)&rc.left); SendMessage(hwnd, WM_MOVE, 0, MAKELONG(rc.left, rc.top)); }}/* * Specify a cursor for a window. * This cursor will only be used within that window, and by default * for its new children. If the cursor is currently within this * window, it will be changed to the new one immediately. */voidMwSetCursor(HWND wp, PMWCURSOR pcursor){ HCURSOR cp; int bytes; if(!wp || !pcursor) return; bytes = MWIMAGE_SIZE(pcursor->width,pcursor->height) * sizeof(MWIMAGEBITS); /* * See if the window is using a shared cursor definition. * If so, then allocate a new private one, otherwise reuse it. */ cp = wp->cursor; if (!cp || cp->usecount-- > 1) { cp = GdItemNew(struct hcursor); if(!cp) return; } cp->usecount = 1; cp->cursor.width = pcursor->width; cp->cursor.height = pcursor->height; cp->cursor.hotx = pcursor->hotx; cp->cursor.hoty = pcursor->hoty; cp->cursor.fgcolor = pcursor->fgcolor; cp->cursor.bgcolor = pcursor->bgcolor; memcpy(cp->cursor.image, pcursor->image, bytes); memcpy(cp->cursor.mask, pcursor->mask, bytes); wp->cursor = cp; /* * If this was the current cursor, then draw the new one. */ if (cp == curcursor || curcursor == NULL) { GdMoveCursor(cursorx - cp->cursor.hotx, cursory - cp->cursor.hoty); GdSetCursor(&cp->cursor); }}BOOL WINAPIGetCursorPos(LPPOINT lpPoint){ MWCOORD x, y; if(lpPoint) { GdGetCursorPos(&x, &y); lpPoint->x = x; lpPoint->y = y; return TRUE; } return FALSE;}HWND WINAPIGetCapture(VOID){ return capturewp;}HWND WINAPISetCapture(HWND hwnd){ HWND oldCapture = capturewp; capturewp = hwnd; MwCheckMouseWindow(); return oldCapture;}BOOL WINAPIReleaseCapture(VOID){ capturewp = NULL; MwCheckMouseWindow(); return TRUE;}struct timer { /* private timer structure*/ HWND hwnd; /* window associated with timer, NULL if none*/ UINT idTimer; /* id for timer*/ UINT uTimeout; /* timeout value, in msecs*/ DWORD dwClockExpires; /* GetTickCount timer expiration value*/ TIMERPROC lpTimerFunc; /* callback function*/};static struct timer timer; /* single global timer FIXME*/UINT WINAPISetTimer(HWND hwnd, UINT idTimer, UINT uTimeout, TIMERPROC lpTimerFunc){ static UINT nextID = 0; /* next ID when hwnd is NULL*/ /* assign timer id based on valid window handle*/ timer.hwnd = hwnd; timer.idTimer = hwnd? idTimer: ++nextID; timer.uTimeout = uTimeout; timer.dwClockExpires = GetTickCount() + uTimeout; timer.lpTimerFunc = lpTimerFunc; return timer.idTimer;}BOOL WINAPIKillTimer(HWND hwnd, UINT idTimer){ if(timer.hwnd == hwnd && timer.idTimer == idTimer) { timer.uTimeout = 0; return TRUE; } return FALSE;}/* * Return the next timeout value in msecs */UINTMwGetNextTimeoutValue(void){ int timeout; if(timer.uTimeout) { timeout = timer.dwClockExpires - GetTickCount(); if(timeout > 0) return timeout; } return 0;}/* * Check if any timers have expired by looking at current system ticks */voidMwHandleTimers(void){ int timeout; DWORD dwTime; /* check if timer running*/ if(timer.uTimeout == 0) return; /* determine if timer expired*/ dwTime = GetTickCount(); timeout = timer.dwClockExpires - dwTime; if(timeout > 0) return; /* call timer function or post timer message*/ if(timer.lpTimerFunc) timer.lpTimerFunc(timer.hwnd, WM_TIMER, timer.idTimer, dwTime); else PostMessage(timer.hwnd, WM_TIMER, timer.idTimer, 0); /* reset timer*/ timer.dwClockExpires = dwTime + timer.uTimeout;}int WINAPIGetSystemMetrics(int nIndex){ switch(nIndex) { case SM_CXSCREEN: return scrdev.xvirtres; case SM_CYSCREEN: return scrdev.yvirtres; case SM_CXVSCROLL: return mwSYSMETRICS_CXVSCROLL; case SM_CYHSCROLL: return mwSYSMETRICS_CYHSCROLL; case SM_CYCAPTION: /* + 1 for line under caption*/ return mwSYSMETRICS_CYCAPTION + 1; case SM_CXBORDER: return mwSYSMETRICS_CXBORDER; case SM_CYBORDER: return mwSYSMETRICS_CYBORDER; case SM_CYMENU: break; /* FIXME: 19 when menubars work*/ case SM_CYVSCROLL: return mwSYSMETRICS_CYVSCROLL; case SM_CXHSCROLL: return mwSYSMETRICS_CXHSCROLL; case SM_CXFRAME: case SM_CXDLGFRAME: return mwSYSMETRICS_CXFRAME; case SM_CYFRAME: case SM_CYDLGFRAME: return mwSYSMETRICS_CYFRAME; } return 0;}HWND WINAPIGetDlgItem(HWND hDlg, int nIDDlgItem){ HWND wp; if(hDlg) { for(wp=hDlg->children; wp; wp=wp->siblings) if(wp->id == nIDDlgItem) return wp; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -