📄 window.c
字号:
else wndGetVScrollBarRect (pWin, &rcBar); *w = GetMainWinMetrics (MWM_CXHSCROLL); *h = GetMainWinMetrics (MWM_CYHSCROLL); switch (location) { case SBPOS_LEFTARROW: *x = rcBar.left; *y = rcBar.top; break; case SBPOS_RIGHTARROW: *x = rcBar.right - GetMainWinMetrics (MWM_CXHSCROLL) ; *y = rcBar.top; break; case SBPOS_UPARROW: *x = rcBar.left; *y = rcBar.top; break; case SBPOS_DOWNARROW: *x = rcBar.left; *y = rcBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL); break; default: return FALSE; } *x -= pWin->left; *y -= pWin->top; return TRUE;}static BOOL sbGetButtonPos (PMAINWIN pWin, int location, int* x, int* y, int* w, int* h){ RECT rc; int iBorder = 0; int iCaption = 0; int iIconX = 0; int iIconY = 0; if (pWin->dwStyle & WS_BORDER) iBorder = GetMainWinMetrics(MWM_BORDER); else if (pWin->dwStyle & WS_THICKFRAME) iBorder = GetMainWinMetrics(MWM_THICKFRAME); else if (pWin->dwStyle & WS_THINFRAME) iBorder = GetMainWinMetrics(MWM_THINFRAME); // scroll bar position if (location & SBPOS_MASK) return sbGetSBarArrowPos (pWin, location, x, y, w, h); if (!(pWin->dwStyle & WS_CAPTION)) return FALSE; if (pWin->hIcon) { iIconX = GetMainWinMetrics(MWM_ICONX); iIconY = GetMainWinMetrics(MWM_ICONY); } iCaption = GetMainWinMetrics(MWM_CAPTIONY); rc.left = iBorder; rc.top = iBorder; rc.right = pWin->right - pWin->left - iBorder; rc.bottom = iBorder + iCaption; // close button *x = rc.right - GetMainWinMetrics (MWM_SB_WIDTH); *y = GetMainWinMetrics (MWM_SB_HEIGHT); *w = GetMainWinMetrics (MWM_SB_WIDTH); if (*y < iCaption) { *y = iBorder + ((iCaption - *y)>>1); *h = GetMainWinMetrics (MWM_SB_HEIGHT); } else { *y = iBorder; *h = iIconY; } if (!(pWin->dwExStyle & WS_EX_NOCLOSEBOX)) { if (location == HT_CLOSEBUTTON) return TRUE; *x -= GetMainWinMetrics (MWM_SB_WIDTH); *x -= GetMainWinMetrics (MWM_SB_INTERX)<<1; } if (pWin->dwStyle & WS_MAXIMIZEBOX) { // restore/maximize button if (location == HT_MAXBUTTON) return TRUE; *x -= GetMainWinMetrics (MWM_SB_WIDTH); *x -= GetMainWinMetrics (MWM_SB_INTERX); } if (pWin->dwStyle & WS_MINIMIZEBOX) { // minimize button. if (location == HT_MINBUTTON) return TRUE; } return FALSE;}static BOOL sbDownButton (PMAINWIN pWin, int downCode){ HDC hdc; int x, y, w, h; if (!sbGetButtonPos (pWin, downCode, &x, &y, &w, &h)) return FALSE; w += x - 1; h += y - 1; hdc = GetDC ((HWND)pWin); Draw3DDownFrame(hdc, x, y, w, h, PIXEL_invalid); ReleaseDC (hdc); return TRUE;}static BOOL sbUpButton (PMAINWIN pWin, int downCode){ HDC hdc; int x, y, w, h; PBITMAP bmp = NULL; if (!sbGetButtonPos (pWin, downCode, &x, &y, &w, &h)) return FALSE; hdc = GetDC ((HWND)pWin); switch (downCode) { case HT_MAXBUTTON: bmp = GetSystemBitmap (SYSBMP_MAXIMIZE); break; case HT_MINBUTTON: bmp = GetSystemBitmap (SYSBMP_MINIMIZE); break; case HT_CLOSEBUTTON: bmp = GetSystemBitmap (SYSBMP_CLOSE); break; case SBPOS_UPARROW: bmp = GetSystemBitmap (SYSBMP_ARROWUP); break; case SBPOS_DOWNARROW: bmp = GetSystemBitmap (SYSBMP_ARROWDOWN); break; case SBPOS_LEFTARROW: bmp = GetSystemBitmap (SYSBMP_ARROWLEFT); break; case SBPOS_RIGHTARROW: bmp = GetSystemBitmap (SYSBMP_ARROWRIGHT); break; } if (bmp) FillBoxWithBitmap (hdc, x, y, w, h, bmp); ReleaseDC (hdc); return TRUE;}int MenuBarHitTest (HWND hwnd, int x, int y);static void wndTrackMenuBarOnMouseMove(PMAINWIN pWin, int message, int location, int x, int y){ PMENUBAR pMenuBar; int oldBarItem; int barItem; pMenuBar = (PMENUBAR)(pWin->hMenu); if (!pMenuBar) return; oldBarItem = pMenuBar->hilitedItem; if (location == HT_OUT) { if (oldBarItem >= 0) HiliteMenuBarItem ((HWND)pWin, oldBarItem, HMF_DEFAULT); return; } barItem = MenuBarHitTest ((HWND)pWin, x, y); if (barItem != oldBarItem) { if (oldBarItem >= 0) HiliteMenuBarItem ((HWND)pWin, oldBarItem, HMF_DEFAULT); if (barItem >= 0) { HiliteMenuBarItem ((HWND)pWin, barItem, HMF_UPITEM); pMenuBar->hilitedItem = barItem; pMenuBar->hiliteFlag = HMF_UPITEM; } else pMenuBar->hilitedItem = -1; }}static BOOL wndHandleHScrollBar (PMAINWIN pWin, int message, int x, int y){ static int downPos = SBPOS_UNKNOWN; static int movePos = SBPOS_UNKNOWN; static int sbCode; static int oldBarStart; static int oldThumbPos; static int oldx; int curPos; RECT rcBar; wndGetHScrollBarRect (pWin, &rcBar); rcBar.left += GetMainWinMetrics (MWM_CXHSCROLL); rcBar.right -= GetMainWinMetrics (MWM_CXHSCROLL); curPos = wndGetHScrollBarPos (pWin, x, y); if (curPos == SBPOS_UNKNOWN && downPos == SBPOS_UNKNOWN) return FALSE; switch( message ) { case MSG_NCLBUTTONDOWN: oldBarStart = pWin->hscroll.barStart; oldThumbPos = pWin->hscroll.curPos; oldx = x; downPos = curPos; movePos = curPos; if (curPos == SBPOS_LEFTARROW) { sbDownButton (pWin, curPos); if (pWin->hscroll.curPos == pWin->hscroll.minPos) break; sbCode = SB_LINELEFT; } else if (curPos == SBPOS_RIGHTARROW) { sbDownButton (pWin, curPos); if (pWin->hscroll.curPos == pWin->hscroll.maxPos) break; sbCode = SB_LINERIGHT; } else if (curPos == SBPOS_LEFTSPACE) { if (pWin->hscroll.curPos == pWin->hscroll.minPos) break; sbCode = SB_PAGELEFT; } else if (curPos == SBPOS_RIGHTSPACE) { if (pWin->hscroll.curPos == pWin->hscroll.maxPos) break; sbCode = SB_PAGERIGHT; } else if (curPos == SBPOS_THUMB) { sbCode = SB_THUMBTRACK; break; } SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, sbCode, 0); SetRepeatMessage ((HWND)pWin, MSG_HSCROLL, sbCode, 0); break; case MSG_NCLBUTTONUP: if (sbCode == SB_THUMBTRACK && downPos == SBPOS_THUMB) { int newBarStart = oldBarStart + x - oldx; int newThumbPos = newBarStart * (pWin->hscroll.maxPos - pWin->hscroll.minPos + 1) / (rcBar.right - rcBar.left) + pWin->hscroll.minPos; if (newThumbPos != oldThumbPos && newThumbPos >= pWin->hscroll.minPos && newThumbPos <= pWin->hscroll.maxPos) SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, SB_THUMBPOSITION, newThumbPos); downPos = SBPOS_UNKNOWN; movePos = SBPOS_UNKNOWN; break; } if (downPos != SBPOS_UNKNOWN) { sbUpButton (pWin, curPos); SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, SB_ENDSCROLL, 0); SetRepeatMessage (HWND_DESKTOP, 0, 0, 0); } downPos = SBPOS_UNKNOWN; movePos = SBPOS_UNKNOWN; break; case MSG_NCMOUSEMOVE: if (sbCode == SB_THUMBTRACK && downPos == SBPOS_THUMB) { int newBarStart = oldBarStart + x - oldx; int newThumbPos = newBarStart * (pWin->hscroll.maxPos - pWin->hscroll.minPos + 1) / (rcBar.right - rcBar.left) + pWin->hscroll.minPos; if (newThumbPos != oldThumbPos && newThumbPos >= pWin->hscroll.minPos && newThumbPos <= pWin->hscroll.maxPos) { SendNotifyMessage ((HWND)pWin, MSG_HSCROLL, SB_THUMBTRACK, newThumbPos); oldThumbPos = newThumbPos; } movePos = curPos; break; } if (movePos == downPos && curPos != downPos) sbUpButton (pWin, downPos); else if (movePos != downPos && curPos == downPos) sbDownButton (pWin, downPos); movePos = curPos; break; } return TRUE;}static BOOL wndHandleVScrollBar (PMAINWIN pWin, int message, int x, int y){ static int downPos = SBPOS_UNKNOWN; static int movePos = SBPOS_UNKNOWN; static int sbCode; static int oldBarStart; static int oldThumbPos; static int oldy; int curPos; RECT rcBar; int newBarStart; int newThumbPos; wndGetVScrollBarRect (pWin, &rcBar); rcBar.top += GetMainWinMetrics (MWM_CYVSCROLL); rcBar.bottom -= GetMainWinMetrics (MWM_CYVSCROLL); curPos = wndGetVScrollBarPos (pWin, x, y); if (curPos == SBPOS_UNKNOWN && downPos == SBPOS_UNKNOWN) return FALSE; switch (message) { case MSG_NCLBUTTONDOWN: oldBarStart = pWin->vscroll.barStart; oldThumbPos = pWin->vscroll.curPos; oldy = y; downPos = curPos; movePos = curPos; if (curPos == SBPOS_UPARROW) { sbDownButton (pWin, curPos); if (pWin->vscroll.curPos == pWin->vscroll.minPos) break; sbCode = SB_LINEUP; } else if (curPos == SBPOS_DOWNARROW) { sbDownButton (pWin, curPos); if (pWin->vscroll.curPos == pWin->vscroll.maxPos) break; sbCode = SB_LINEDOWN; } else if (curPos == SBPOS_UPSPACE) { if (pWin->vscroll.curPos == pWin->vscroll.minPos) break; sbCode = SB_PAGEUP; } else if (curPos == SBPOS_DOWNSPACE) { if (pWin->vscroll.curPos == pWin->vscroll.maxPos) break; sbCode = SB_PAGEDOWN; } else if (curPos == SBPOS_THUMB) { sbCode = SB_THUMBTRACK; break; } SendNotifyMessage ((HWND)pWin, MSG_VSCROLL, sbCode, 0); SetRepeatMessage ((HWND)pWin, MSG_VSCROLL, sbCode, 0); break; case MSG_NCLBUTTONUP: if (sbCode == SB_THUMBTRACK && downPos == SBPOS_THUMB) { newBarStart = oldBarStart + y - oldy; newThumbPos = newBarStart * (pWin->vscroll.maxPos - pWin->vscroll.minPos + 1) / (rcBar.bottom - rcBar.top) + pWin->vscroll.minPos; if (newThumbPos != oldThumbPos && newThumbPos >= pWin->vscroll.minPos && newThumbPos <= pWin->vscroll.maxPos) SendNotifyMessage ((HWND)pWin, MSG_VSCROLL, SB_THUMBPOSITION, newThumbPos); downPos = SBPOS_UNKNOWN; movePos = SBPOS_UNKNOWN; break; } if (downPos != SBPOS_UNKNOWN) { sbUpButton (pWin, curPos); SendNotifyMessage ((HWND)pWin, MSG_VSCROLL, SB_ENDSCROLL, 0); SetRepeatMessage (HWND_DESKTOP, 0, 0, 0); } downPos = SBPOS_UNKNOWN; movePos = SBPOS_UNKNOWN; break; case MSG_NCMOUSEMOVE: if (sbCode == SB_THUMBTRACK && downPos == SBPOS_THUMB) { newBarStart = oldBarStart + y - oldy; newThumbPos = newBarStart * (pWin->vscroll.maxPos - pWin->vscroll.minPos + 1) / (rcBar.bottom - rcBar.top) + pWin->vscroll.minPos; if (newThumbPos != oldThumbPos && newThumbPos >= pWin->vscroll.minPos && newThumbPos <= pWin->vscroll.maxPos) { SendNotifyMessage ((HWND)pWin, MSG_VSCROLL, SB_THUMBTRACK, newThumbPos); oldThumbPos = newThumbPos; } movePos = curPos;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -