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

📄 window.c

📁 linux下的图形界面开发minigui最新源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        RECT rcBar;        wndGetVScrollBarRect (pWin, &rcBar);        wndScrollBarPos (pWin, FALSE, &rcBar);        pWin->cr -= GetMainWinMetrics (MWM_CXVSCROLL);#ifdef _FLAT_WINDOW_STYLE        if (iBorder > 0) pWin->cr ++;#endif    }}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 = wndGetBorder (pWin);    int iCaption = 0;    int iIconX = 0;    int iIconY = 0;    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;            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;}extern HWND __mg_ime_wnd;static void open_ime_window (PMAINWIN pWin, int message, HWND rev_hwnd){#ifndef _LITE_VERSION    if (__mg_ime_wnd && pWin) {        BOOL is_edit = SendAsyncMessage ((HWND)pWin, MSG_DOESNEEDIME, 0, 0L);        if (pWin->pMainWin && ((pWin->pMainWin->dwExStyle & WS_EX_TOOLWINDOW)                           || ((HWND)(pWin->pMainWin) == __mg_ime_wnd)))            return;        if (message == MSG_SETFOCUS) {            if (is_edit)                SendNotifyMessage (__mg_ime_wnd, MSG_IME_OPEN, 0, 0);            else                SendNotifyMessage (__mg_ime_wnd, MSG_IME_CLOSE, 0, 0);        }        else if (message == MSG_KILLFOCUS && is_edit) {            BOOL other_is_edit                 = rev_hwnd && SendAsyncMessage (rev_hwnd, MSG_DOESNEEDIME, 0, 0L);            if (!other_is_edit)                SendNotifyMessage (__mg_ime_wnd, MSG_IME_CLOSE, 0, 0);        }    }#elif !defined(_STAND_ALONE)    if (!mgIsServer && pWin) {        BOOL is_edit = SendAsyncMessage ((HWND)pWin, MSG_DOESNEEDIME, 0, 0L);        REQUEST req;        BOOL open = FALSE;        if (pWin->pMainWin && (pWin->pMainWin->dwExStyle & WS_EX_TOOLWINDOW))            return;        req.id = REQID_OPENIMEWND;        req.data = &open;        req.len_data = sizeof (BOOL);        if (message == MSG_SETFOCUS) {            if (is_edit)                open = TRUE;            cli_request (&req, NULL, 0);        }        else if (message == MSG_KILLFOCUS && is_edit) {            BOOL other_is_edit                 = rev_hwnd && SendAsyncMessage (rev_hwnd, MSG_DOESNEEDIME, 0, 0L);            if (!other_is_edit) {                cli_request (&req, NULL, 0);            }        }    }#endif}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, LOSWORD(lParam), HISWORD(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)                SendNotifyMessage (pWin->hActiveChild, message, 0, 0);            open_ime_window (pWin, message, (HWND)wParam);        break;                case MSG_MOUSEACTIVE:            if (pWin->WinType == TYPE_CONTROL                 && !(pWin->dwStyle & WS_DISABLED)) {                PCONTROL pCtrl = (PCONTROL)pWin;                PCONTROL old_active = pCtrl->pParent->active;                               if (old_active != (PCONTROL)pWin) {                    if (old_active) {                        SendNotifyMessage ((HWND)old_active, MSG_ACTIVE, FALSE, 0);                        SendNotifyMessage ((HWND)old_active, MSG_KILLFOCUS, (WPARAM)pWin, 0);                    }                    pCtrl->pParent->active = (PCONTROL)pWin;                    SendNotifyMessage ((HWND)pWin, MSG_ACTIVE, TRUE, 0);                    SendNotifyMessage ((HWND)pWin, MSG_SETFOCUS, (WPARAM)old_active, 0);                }            }        break;    }    return 0;}// this function is CONTROL safe.static void wndDrawNCArea (const MAINWIN* pWin, HDC hdc){#ifdef _FLAT_WINDOW_STYLE    int i, iBorder;#endif    // Draw window frame    if (pWin->dwStyle & WS_BORDER) {#ifdef _FLAT_WINDOW_STYLE        iBorder = GetMainWinMetrics (MWM_BORDER);        SetPenColor (hdc, GetWindowElementColor (WEC_FLAT_BORDER));        for (i = 0; i < iBorder; i++)            Rectangle (hdc, i, i,                       pWin->right - pWin->left - i - 1,                       pWin->bottom - pWin->top - i - 1);#else        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);#endif    }    else if ((pWin->dwStyle & WS_THICKFRAME) ||            (pWin->dwStyle & WS_THINFRAME))    {       SetPenColor(hdc, GetWindowElementColor (WEC_FRAME_NORMAL));       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, start = 0;    RECT rcHBar, rcVBar;    PBITMAP bmp;    int xo, yo, bw, bh;        iBorder = wndGetBorder (pWin);       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;    bmp = GetSystemBitmap (SYSBMP_ARROWS);    bw = bmp->bmWidth >> 2;    bh = bmp->bmHeight >> 1;    if (pWin->dwStyle & WS_HSCROLL && !(pWin->hscroll.status & SBS_HIDE)) {        int w = RECTW (rcHBar);        if (pWin->dwStyle & WS_VSCROLL && !(pWin->vscroll.status & SBS_HIDE))            w += GetMainWinMetrics (MWM_CXVSCROLL);        SetBrushColor (hdc, GetWindowElementColor (BKC_CONTROL_DEF));#ifdef _FLAT_WINDOW_STYLE        FillBox (hdc, rcHBar.left, rcHBar.top, w, RECTH (rcHBar) - 1);#else        FillBox (hdc, rcHBar.left, rcHBar.top, w, RECTH (rcHBar));#endif        // draw left and right buttons.        if (pWin->hscroll.status & SBS_DISABLED) {            xo = bw << 1; yo = bh;        }        else {            xo = bw << 1; yo = 0;        }                FillBoxWithBitmapPart (hdc, rcHBar.left, rcHBar.top,                                 bw, bh, 0, 0, bmp, xo, yo);        if (pWin->hscroll.status & SBS_DISABLED) {            xo = (bw << 1) + bw; yo = bh;        }        else {            xo = (bw << 1) + bw; yo = 0;        }                FillBoxWithBitmapPart (hdc,                         rcHBar.right - GetMainWinMetrics (MWM_CXHSCROLL), rcHBar.top,                        bw, bh, 0, 0, bmp, xo, yo);#ifdef _FLAT_WINDOW_STYLE

⌨️ 快捷键说明

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