📄 window.c
字号:
rcIcon.right = rcIcon.left + iIconX; rcIcon.bottom = rcIcon.top + iIconY; if (PtInRect (&rcIcon, x, y)) return HT_ICON; } rcButton.left = rcCaption.right - GetMainWinMetrics (MWM_SB_WIDTH); rcButton.top = rcCaption.top; rcButton.right = rcCaption.right; rcButton.bottom = rcCaption.top + GetMainWinMetrics (MWM_SB_HEIGHT); if (!(pWin->dwExStyle & WS_EX_NOCLOSEBOX)) { if (PtInRect (&rcButton, x, y)) return HT_CLOSEBUTTON; rcButton.left -= GetMainWinMetrics (MWM_SB_WIDTH); rcButton.left -= GetMainWinMetrics (MWM_SB_INTERX)<<1; } if (pWin->dwStyle & WS_MAXIMIZEBOX) { rcButton.right = rcButton.left + GetMainWinMetrics (MWM_SB_WIDTH); if (PtInRect (&rcButton, x, y)) return HT_MAXBUTTON; rcButton.left -= GetMainWinMetrics (MWM_SB_WIDTH); rcButton.left -= GetMainWinMetrics (MWM_SB_INTERX); } if (pWin->dwStyle & WS_MINIMIZEBOX) { rcButton.right = rcButton.left + GetMainWinMetrics (MWM_SB_WIDTH); if (PtInRect (&rcButton, x, y)) return HT_MINBUTTON; } if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) { rcMenuBar.left = rcCaption.left; rcMenuBar.top = rcCaption.bottom + 1; rcMenuBar.right = rcCaption.right; rcMenuBar.bottom = rcMenuBar.top + GetMainWinMetrics (MWM_MENUBARY); rcMenuBar.bottom += GetMainWinMetrics (MWM_MENUBAROFFY)<<1; if (PtInRect (&rcMenuBar, x, y)) return HT_MENUBAR; } if (PtInRect (&rcCaption, x, y)) return HT_CAPTION; } else { // Caption rect; rcCaption.left = pWin->left + iBorder; rcCaption.top = pWin->top + iBorder; rcCaption.right = pWin->right - iBorder; rcCaption.bottom = rcCaption.top; if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) { rcMenuBar.left = rcCaption.left; rcMenuBar.top = rcCaption.bottom + 1; rcMenuBar.right = rcCaption.right; rcMenuBar.bottom = rcMenuBar.top + GetMainWinMetrics (MWM_MENUBARY); rcMenuBar.bottom += GetMainWinMetrics (MWM_MENUBAROFFY)<<1; if (PtInRect (&rcMenuBar, x, y)) return HT_MENUBAR; } } return HT_BORDER;}static int DefaultPostMsgHandler(PMAINWIN pWin, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_SETCURSOR://// NOTE:// this message is only implemented for main window.// for CONTROL, must handle this message and should NOT // call default window procedure// when handle MSG_SETCURSOR.// if (wndMouseInWhichControl (pWin, LOWORD(lParam), HIWORD(lParam), NULL)) break; if (pWin->hCursor) SetCursor(pWin->hCursor); break; case MSG_NCSETCURSOR://// NOTE:// this message is only implemented for main window.// for CONTROL, must handle this message and should NOT // call default window procedure// when handle MSG_SETCURSOR.// SetCursor (GetSystemCursor (IDC_ARROW)); break; case MSG_HITTEST: if( PtInRect((PRECT)(&(pWin->cl)), (int)wParam, (int)lParam) ) return HT_CLIENT; else return HittestOnNClient (pWin, (int)wParam, (int)lParam); break; case MSG_CHANGESIZE: OnChangeSize(pWin, (PRECT)wParam, (PRECT)lParam); break; case MSG_SIZECHANGING: memcpy ((PRECT)lParam, (PRECT)wParam, sizeof (RECT)); break; case MSG_QUERYNCRECT: OnQueryNCRect(pWin, (PRECT)lParam); break; case MSG_QUERYCLIENTAREA: OnQueryClientArea(pWin, (PRECT)lParam); break; case MSG_SETFOCUS: case MSG_KILLFOCUS: if (pWin->hActiveChild) SendMessage (pWin->hActiveChild, message, 0, 0); break; case MSG_MOUSEACTIVE: if (pWin->WinType == TYPE_CONTROL && !(pWin->dwStyle & WS_DISABLED)) { PCONTROL pCtrl = (PCONTROL)pWin; if (pCtrl->pParent->active != (PCONTROL)pWin) { if (pCtrl->pParent->active) { SendMessage ((HWND)pCtrl->pParent->active, MSG_ACTIVE, FALSE, 0); SendMessage ((HWND)pCtrl->pParent->active, MSG_KILLFOCUS, 0, 0); } pCtrl->pParent->active = (PCONTROL)pWin; SendMessage ((HWND)pWin, MSG_ACTIVE, TRUE, 0); SendMessage ((HWND)pWin, MSG_SETFOCUS, 0, 0); } } break; case MSG_ACTIVEMENU: break; case MSG_VSCROLL: case MSG_HSCROLL: break; } return 0;}// this function is CONTROL safe.static void wndDrawNCArea(const MAINWIN* pWin, HDC hdc){ // Draw window frame if (pWin->dwStyle & WS_BORDER) { if (pWin->dwStyle & WS_CHILD) Draw3DDownFrame(hdc, 0, 0, pWin->right - pWin->left - 1, pWin->bottom - pWin->top - 1, PIXEL_invalid); else Draw3DUpFrame(hdc, 0, 0, pWin->right - pWin->left, pWin->bottom - pWin->top, PIXEL_invalid); } else if ((pWin->dwStyle & WS_THICKFRAME) || (pWin->dwStyle & WS_THINFRAME)) { SetPenColor(hdc, PIXEL_black); Rectangle(hdc, 0, 0, pWin->right - pWin->left - 1, pWin->bottom - pWin->top - 1); }}// this function is CONTROL safe.static void wndDrawScrollBar (MAINWIN* pWin, HDC hdc){ int iBorder = 0, start = 0; RECT rcHBar, rcVBar; PBITMAP bmp; 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); wndGetVScrollBarRect (pWin, &rcVBar); rcVBar.left -= pWin->left; rcVBar.top -= pWin->top; rcVBar.right -= pWin->left; rcVBar.bottom -= pWin->top; wndGetHScrollBarRect (pWin, &rcHBar); rcHBar.left -= pWin->left; rcHBar.top -= pWin->top; rcHBar.right -= pWin->left; rcHBar.bottom -= pWin->top; SetBrushColor (hdc, PIXEL_lightgray); if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) { FillBox (hdc, rcHBar.left, rcHBar.top, RECTW (rcHBar) + GetMainWinMetrics (MWM_CXVSCROLL), RECTH (rcHBar)); // draw left and right buttons. if (pWin->hscroll.status & SBS_DISABLED) bmp = GetSystemBitmap (SYSBMP_ARROWLEFTD); else bmp = GetSystemBitmap (SYSBMP_ARROWLEFT); FillBoxWithBitmap (hdc, rcHBar.left, rcHBar.top, GetMainWinMetrics (MWM_CXHSCROLL), GetMainWinMetrics (MWM_CYHSCROLL), bmp); if (pWin->hscroll.status & SBS_DISABLED) bmp = GetSystemBitmap (SYSBMP_ARROWRIGHTD); else bmp = GetSystemBitmap (SYSBMP_ARROWRIGHT); FillBoxWithBitmap (hdc, rcHBar.right - GetMainWinMetrics (MWM_CXHSCROLL), rcHBar.top, GetMainWinMetrics (MWM_CXHSCROLL), GetMainWinMetrics (MWM_CYHSCROLL), bmp); // draw moving bar. start = rcHBar.left + GetMainWinMetrics (MWM_CXHSCROLL) + pWin->hscroll.barStart; if (start + pWin->hscroll.barLen > rcHBar.right) start = rcHBar.right - pWin->hscroll.barLen; Draw3DUpFrame (hdc, start, rcHBar.top, start + pWin->hscroll.barLen, rcHBar.bottom, PIXEL_invalid); } if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) { FillBox (hdc, rcVBar.left, rcVBar.top, RECTW (rcVBar), RECTH (rcVBar)); // draw top and bottom buttons. if (pWin->vscroll.status & SBS_DISABLED) bmp = GetSystemBitmap (SYSBMP_ARROWUPD); else bmp = GetSystemBitmap (SYSBMP_ARROWUP); FillBoxWithBitmap (hdc, rcVBar.left, rcVBar.top, GetMainWinMetrics (MWM_CXVSCROLL), GetMainWinMetrics (MWM_CYVSCROLL), bmp); if (pWin->vscroll.status & SBS_DISABLED) bmp = GetSystemBitmap (SYSBMP_ARROWDOWND); else bmp = GetSystemBitmap (SYSBMP_ARROWDOWN); FillBoxWithBitmap (hdc, rcVBar.left, rcVBar.bottom - GetMainWinMetrics (MWM_CYVSCROLL), GetMainWinMetrics (MWM_CXVSCROLL), GetMainWinMetrics (MWM_CYVSCROLL), bmp); // draw moving bar start = rcVBar.top + GetMainWinMetrics (MWM_CYVSCROLL) + pWin->vscroll.barStart; if (start + pWin->vscroll.barLen > rcVBar.bottom) start = rcVBar.bottom - pWin->vscroll.barLen; Draw3DUpFrame (hdc, rcVBar.left, start, rcVBar.right, start + pWin->vscroll.barLen, PIXEL_invalid); }}// this function is CONTROL safe.static void wndDrawCaption(const MAINWIN* pWin, HDC hdc, BOOL bFocus){ int i; RECT rc; int iBorder = 0; int iCaption = 0; int iIconX = 0; int iIconY = 0; int x, y, w, h; PBITMAP bmp; if (pWin->dwStyle & WS_BORDER) iBorder = GetMainWinMetrics(MWM_BORDER); else if( pWin->dwStyle & WS_THICKFRAME ) { iBorder = GetMainWinMetrics(MWM_THICKFRAME); SetPenColor (hdc, bFocus?PIXEL_blue:PIXEL_black); for (i=1; i<iBorder; i++) Rectangle(hdc, i, i, pWin->right - pWin->left - i - 1, pWin->bottom - pWin->top - i - 1); } else if (pWin->dwStyle & WS_THINFRAME) iBorder = GetMainWinMetrics (MWM_THINFRAME); if (!(pWin->dwStyle & WS_CAPTION)) return; if (pWin->hIcon ) { iIconX = GetMainWinMetrics(MWM_ICONX); iIconY = GetMainWinMetrics(MWM_ICONY); } iCaption = GetMainWinMetrics(MWM_CAPTIONY); // draw Caption rc.left = iBorder; rc.top = iBorder; rc.right = pWin->right - pWin->left - iBorder; rc.bottom = iBorder + iCaption; ClipRectIntersect (hdc, &rc); SetBrushColor(hdc, bFocus ? PIXEL_darkblue : PIXEL_darkgray); FillBox(hdc, iBorder, iBorder, pWin->right - pWin->left - iBorder, iCaption); if (pWin->hIcon) DrawIcon(hdc, iBorder, iBorder, iIconX, iIconY, pWin->hIcon); SetTextColor(hdc, bFocus ? PIXEL_lightwhite : PIXEL_lightgray); SetBkColor(hdc, bFocus ? PIXEL_darkblue : PIXEL_darkgray); TextOut(hdc, iBorder + iIconX + 2, iBorder*2, pWin->spCaption); // draw system button w = GetMainWinMetrics (MWM_SB_WIDTH); x = rc.right - w; y = GetMainWinMetrics (MWM_SB_HEIGHT); if (y < iCaption) { y = iBorder + ((iCaption - y)>>1); h = GetMainWinMetrics (MWM_SB_HEIGHT); } else { y = iBorder; h = iIconY; } if (!(pWin->dwExStyle & WS_EX_NOCLOSEBOX)) { // close bitmap bmp = GetSystemBitmap (SYSBMP_CLOSE); FillBoxWithBitmap (hdc, x, y, w, h, bmp); x -= GetMainWinMetrics (MWM_SB_WIDTH); x -= GetMainWinMetrics (MWM_SB_INTERX)<<1; } if (pWin->dwStyle & WS_MAXIMIZEBOX) { // restore/maximize bitmap if (pWin->dwStyle & WS_MAXIMIZE) bmp = GetSystemBitmap (SYSBMP_RESTORE); else bmp = GetSystemBitmap (SYSBMP_MAXIMIZE); FillBoxWithBitmap (hdc, x, y, w, h, bmp); x -= GetMainWinMetrics (MWM_SB_WIDTH); x -= GetMainWinMetrics (MWM_SB_INTERX); } if (pWin->dwStyle & WS_MINIMIZEBOX) { // minimize bitmap bmp = GetSystemBitmap (SYSBMP_MINIMIZE); FillBoxWithBitmap (hdc, x, y, w, h, bmp); }}static void wndEraseBackground(const MAINWIN* pWin, HDC hdc, const RECT* pClipRect){ RECT rcTemp; BOOL fGetDC = FALSE; if (hdc == 0) { hdc = GetClientDC ((HWND)pWin); fGetDC = TRUE; } if (pClipRect) { rcTemp = *pClipRect; if (pWin->WinType == TYPE_MAINWIN) { ScreenToClient ((HWND)pWin, &rcTemp.left, &rcTemp.top); ScreenToClient ((HWND)pWin, &rcTemp.right, &rcTemp.bottom); } } else { rcTemp.left = rcTemp.top = 0; rcTemp.right = pWin->cr - pWin->cl; rcTemp.bottom = pWin->cb - pWin->ct; } SetBrushColor(hdc, pWin->iBkColor); FillBox(hdc, rcTemp.left, rcTemp.top, RECTW (rcTemp), RECTH (rcTemp));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -