📄 window.c
字号:
break; } if (movePos == downPos && curPos != downPos) sbUpButton (pWin, downPos); else if (movePos != downPos && curPos == downPos) sbDownButton (pWin, downPos); movePos = curPos; break; } return TRUE;}// this function is CONTROL safe.static int DefaultNCMouseMsgHandler(PMAINWIN pWin, int message, int location, int x, int y){ static PMAINWIN downWin = NULL; static int downCode = HT_UNKNOWN; static int moveCode = HT_UNKNOWN; static int oldx, oldy; static RECT rcWindow; int barItem; if (pWin->WinType == TYPE_MAINWIN && message == MSG_NCMOUSEMOVE) wndTrackMenuBarOnMouseMove(pWin, message, location, x, y); if ((pWin->dwStyle & WS_HSCROLL) && wndHandleHScrollBar (pWin, message, x, y)) return 0; if ((pWin->dwStyle & WS_VSCROLL) && wndHandleVScrollBar (pWin, message, x, y)) return 0; switch( message ) { case MSG_NCLBUTTONDOWN: if (location == HT_MENUBAR) { barItem = MenuBarHitTest ((HWND)pWin, x, y); if (barItem >= 0) TrackMenuBar ((HWND)pWin, barItem); return 0; } else if (location == HT_CAPTION) { GetWindowRect ((HWND)pWin, &rcWindow); FocusRect (0, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom); oldx = x; oldy = y; } downCode = location; moveCode = location; downWin = pWin; sbDownButton (pWin, downCode); break; case MSG_NCMOUSEMOVE: if (pWin->hOldUnderPointer && location == HT_OUT) { PostMessage (pWin->hOldUnderPointer, MSG_MOUSEMOVEIN, FALSE, 0); PostMessage (pWin->hOldUnderPointer, MSG_NCMOUSEMOVE, HT_OUT, MAKELONG (x, y)); pWin->hOldUnderPointer = 0; } if (downCode != HT_UNKNOWN) { if (downCode == HT_CAPTION && downWin == pWin) { FocusRect (0, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom); OffsetRect (&rcWindow, x - oldx, y - oldy); FocusRect (0, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom); oldx = x; oldy = y; } else if (moveCode == downCode && location != downCode) { sbUpButton (pWin, downCode); moveCode = location; } else if (moveCode != downCode && location == downCode) { sbDownButton (pWin, downCode); moveCode = location; } } break; case MSG_NCLBUTTONUP: if (downCode == HT_CAPTION) { FocusRect (0, rcWindow.left, rcWindow.top, rcWindow.right, rcWindow.bottom); MoveWindow ((HWND)pWin, rcWindow.left, rcWindow.top, RECTW (rcWindow), RECTH (rcWindow), FALSE); } else if (location == downCode) { sbUpButton (pWin, downCode); switch (location) { case HT_CLOSEBUTTON: SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0); break; case HT_MAXBUTTON: break; case HT_MINBUTTON: break; case HT_ICON: if (pWin->hSysMenu) TrackPopupMenu (pWin->hSysMenu, TPM_SYSCMD, x, y, (HWND)pWin); break; case HT_CAPTION: break; } } downCode = HT_UNKNOWN; moveCode = HT_UNKNOWN; downWin = NULL; break; case MSG_NCRBUTTONDOWN: break; case MSG_NCRBUTTONUP: if (location == HT_CAPTION && pWin->hSysMenu) TrackPopupMenu (pWin->hSysMenu, TPM_SYSCMD, x, y, (HWND)pWin); break; case MSG_NCLBUTTONDBLCLK: if (location == HT_ICON) SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0);// else if (location == HT_CAPTION)// SendNotifyMessage ((HWND)pWin, MSG_MAXIMIZE, 0, 0); break; case MSG_NCRBUTTONDBLCLK: break; } return 0;}static int DefaultKeyMsgHandler(PMAINWIN pWin, int message, WPARAM wParam, LPARAM lParam){// NOTE:// Currently only handle one message.// Should handle fowllowing messages://// MSG_KEYDOWN,// MSG_KEYUP,// MSG_CHAR,// MSG_SYSKEYDOWN,// MSG_SYSCHAR. if (message == MSG_KEYDOWN || message == MSG_KEYUP || message == MSG_CHAR) { if (pWin->hActiveChild) SendMessage (pWin->hActiveChild, message, wParam, lParam); } else if (message == MSG_SYSKEYUP) { if (pWin->WinType == TYPE_MAINWIN) TrackMenuBar ((HWND)pWin, 0); } return 0;}static int DefaultCreateMsgHandler(PMAINWIN pWin, int message, WPARAM wParam, LPARAM lParam){// NOTE:// Currently does nothing.// Should handle fowllowing messages://// MSG_NCCREATE,// MSG_CREATE,// MSG_INITPANES,// MSG_DESTROYPANES,// MSG_DESTROY,// MSG_NCDESTROY.// return 0;}static void wndScrollBarPos (PMAINWIN pWin, BOOL bIsHBar, RECT* rcBar){ UINT moveRange; PSCROLLBARINFO pSBar; if (bIsHBar) pSBar = &pWin->hscroll; else pSBar = &pWin->vscroll; if (pSBar->minPos == pSBar->maxPos) { pSBar->status |= SBS_HIDE; return; } if (bIsHBar) moveRange = RECTWP (rcBar) - (GetMainWinMetrics (MWM_CXHSCROLL)<<1); else moveRange = RECTHP (rcBar) - (GetMainWinMetrics (MWM_CYVSCROLL)<<1); if (pSBar->pageStep == 0) { pSBar->barLen = GetMainWinMetrics (MWM_DEFBARLEN); if (pSBar->barLen > moveRange) pSBar->barLen = GetMainWinMetrics (MWM_MINBARLEN); } else { pSBar->barLen = (int) (moveRange*pSBar->pageStep * 1.0f/ (pSBar->maxPos - pSBar->minPos + 1) + 0.5); if (pSBar->barLen < GetMainWinMetrics (MWM_MINBARLEN)) pSBar->barLen = GetMainWinMetrics (MWM_MINBARLEN); } pSBar->barStart = (int) (moveRange*(pSBar->curPos - pSBar->minPos) * 1.0f/ (pSBar->maxPos - pSBar->minPos + 1) + 0.5); if (pSBar->barStart + pSBar->barLen > moveRange) pSBar->barStart = moveRange - pSBar->barLen; if (pSBar->barStart < 0) pSBar->barStart = 0;}// This function is CONTROL safe.static void OnChangeSize(PMAINWIN pWin, PRECT pDestRect, PRECT pResultRect){ int iBorder = 0; int iCaptionY = 0; int iIconX = 0; int iIconY = 0; int iMenuY = 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); if( pWin->dwStyle & WS_CAPTION ) { iCaptionY = GetMainWinMetrics(MWM_CAPTIONY); if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon) { iIconX = GetMainWinMetrics(MWM_ICONX); iIconY = GetMainWinMetrics(MWM_ICONY); } } if (pWin->WinType == TYPE_MAINWIN && pWin->hMenu) { iMenuY = GetMainWinMetrics (MWM_MENUBARY); iMenuY += GetMainWinMetrics (MWM_MENUBAROFFY)<<1; } if (pDestRect) { int minWidth = 0, minHeight = 0; memcpy(&pWin->left, pDestRect, sizeof(RECT)); minHeight = iMenuY + (iCaptionY<<1); if (pWin->dwStyle & WS_VSCROLL) { minWidth += GetMainWinMetrics (MWM_CXVSCROLL); minHeight += (GetMainWinMetrics (MWM_CYVSCROLL)<<1) + (GetMainWinMetrics (MWM_MINBARLEN)<<1); } if (pWin->WinType == TYPE_MAINWIN) minWidth += GetMainWinMetrics (MWM_MINWIDTH); if (pWin->dwStyle & WS_HSCROLL) { minHeight += GetMainWinMetrics (MWM_CYHSCROLL); minWidth += (GetMainWinMetrics (MWM_CXHSCROLL)<<1) + (GetMainWinMetrics (MWM_MINBARLEN)<<1); } if(minHeight > (pWin->bottom - pWin->top)) pWin->bottom = pWin->top + minHeight; if(pWin->right < (pWin->left + minWidth)) pWin->right = pWin->left + minWidth; if( pResultRect ) memcpy(pResultRect, &pWin->left, sizeof(RECT)); } memcpy(&pWin->cl, &pWin->left, sizeof(RECT)); pWin->cl += iBorder; pWin->ct += iBorder; pWin->cr -= iBorder; pWin->cb -= iBorder; pWin->ct += iCaptionY; pWin->ct += iMenuY; if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) { RECT rcBar; wndGetHScrollBarRect (pWin, &rcBar); wndScrollBarPos (pWin, TRUE, &rcBar); pWin->cb -= GetMainWinMetrics (MWM_CYHSCROLL); } if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) { RECT rcBar; wndGetVScrollBarRect (pWin, &rcBar); wndScrollBarPos (pWin, FALSE, &rcBar); pWin->cr -= GetMainWinMetrics (MWM_CXVSCROLL); }}static void OnQueryNCRect(PMAINWIN pWin, PRECT pRC){ memcpy(pRC, &pWin->left, sizeof(RECT));}static void OnQueryClientArea(PMAINWIN pWin, PRECT pRC){ memcpy(pRC, &pWin->cl, sizeof(RECT));}int ClientWidthToWindowWidth (DWORD dwStyle, int cw){ int iBorder = 0; int iScroll = 0; if (dwStyle & WS_BORDER) iBorder = GetMainWinMetrics(MWM_BORDER); else if (dwStyle & WS_THICKFRAME) iBorder = GetMainWinMetrics(MWM_THICKFRAME); else if (dwStyle & WS_THINFRAME) iBorder = GetMainWinMetrics (MWM_THINFRAME); if (dwStyle & WS_VSCROLL) iScroll = GetMainWinMetrics (MWM_CXVSCROLL); return cw + (iBorder<<1) + iScroll;}int ClientHeightToWindowHeight (DWORD dwStyle, int ch, BOOL hasMenu){ int iBorder = 0; int iCaption = 0; int iScroll = 0; int iMenu = 0; if (dwStyle & WS_BORDER) iBorder = GetMainWinMetrics(MWM_BORDER); else if (dwStyle & WS_THICKFRAME) iBorder = GetMainWinMetrics(MWM_THICKFRAME); else if (dwStyle & WS_THINFRAME) iBorder = GetMainWinMetrics (MWM_THINFRAME); if (dwStyle & WS_HSCROLL) iScroll = GetMainWinMetrics (MWM_CYHSCROLL); if (dwStyle & WS_CAPTION) iCaption = GetMainWinMetrics(MWM_CAPTIONY); if (hasMenu) { iMenu = GetMainWinMetrics (MWM_MENUBARY); iMenu += GetMainWinMetrics (MWM_MENUBAROFFY)<<1; } return ch + (iBorder<<1) + iCaption + iScroll + iMenu;}// this function is CONTROL safe.static int HittestOnNClient (PMAINWIN pWin, int x, int y){ RECT rcCaption, rcIcon, rcButton, rcMenuBar; 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); if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) { RECT rcBar; wndGetHScrollBarRect (pWin, &rcBar); if (PtInRect (&rcBar, x, y)) return HT_HSCROLL; } if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) { RECT rcBar; wndGetVScrollBarRect (pWin, &rcBar); if (PtInRect (&rcBar, x, y)) return HT_VSCROLL; } if (pWin->dwStyle & WS_CAPTION) { iCaption = GetMainWinMetrics(MWM_CAPTIONY); if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon) { iIconX = GetMainWinMetrics(MWM_ICONX); iIconY = GetMainWinMetrics(MWM_ICONY); } // Caption rect; rcCaption.left = pWin->left + iBorder; rcCaption.top = pWin->top + iBorder; rcCaption.right = pWin->right - iBorder; rcCaption.bottom = rcCaption.top + iCaption; if (pWin->WinType == TYPE_MAINWIN && pWin->hIcon) { rcIcon.left = rcCaption.left; rcIcon.top = rcCaption.top;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -