⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.c

📁 linux下的图形界面开发minigui最新源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    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);            SetAutoRepeatMessage ((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);                SetAutoRepeatMessage (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;                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;#ifdef _MOVE_WINDOW_BY_MOUSE    static int oldx, oldy;    static RECT rcWindow;#endif    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;            }#ifdef _MOVE_WINDOW_BY_MOUSE            else if (location == HT_CAPTION) {                GetWindowRect ((HWND)pWin, &rcWindow);                SetPenColor (HDC_SCREEN, PIXEL_lightwhite);                FocusRect (HDC_SCREEN, rcWindow.left, rcWindow.top,                              rcWindow.right, rcWindow.bottom);                oldx = x;                oldy = y;            }#endif            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) {#ifdef _MOVE_WINDOW_BY_MOUSE                    SetPenColor (HDC_SCREEN, PIXEL_lightwhite);                    FocusRect (HDC_SCREEN, rcWindow.left, rcWindow.top,                              rcWindow.right, rcWindow.bottom);                    OffsetRect (&rcWindow, x - oldx, y - oldy);                    FocusRect (HDC_SCREEN, rcWindow.left, rcWindow.top,                              rcWindow.right, rcWindow.bottom);                                        oldx = x;                    oldy = y;#endif                }                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) {#ifdef _MOVE_WINDOW_BY_MOUSE                SetPenColor (HDC_SCREEN, PIXEL_lightwhite);                FocusRect (HDC_SCREEN, rcWindow.left, rcWindow.top,                              rcWindow.right, rcWindow.bottom);                                    MoveWindow ((HWND)pWin, rcWindow.left,                                        rcWindow.top,                                        RECTW (rcWindow),                                        RECTH (rcWindow),                                        FALSE);#endif            }            else if (location == downCode) {                sbUpButton (pWin, downCode);                switch (location) {                    case HT_CLOSEBUTTON:                        SendNotifyMessage ((HWND)pWin, MSG_CLOSE, 0, 0);                    break;                    case HT_MAXBUTTON:                        SendNotifyMessage ((HWND)pWin, MSG_MAXIMIZE, 0, 0);                    break;                    case HT_MINBUTTON:                        SendNotifyMessage ((HWND)pWin, MSG_MINIMIZE, 0, 0);                    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_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_NCRBUTTONDOWN://        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                && !(pWin->dwStyle & WS_DISABLED)) {            SendMessage (pWin->hActiveChild, message, wParam, lParam);        }    }    else if (message == MSG_SYSKEYUP) {       if (pWin->WinType == TYPE_MAINWIN                && !(pWin->dwStyle & WS_DISABLED))           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;    iBorder = wndGetBorder (pWin);    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);#ifdef _FLAT_WINDOW_STYLE        if (iBorder > 0) pWin->cb ++;#endif    }            if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE)) {    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -