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

📄 desktop-comm.c

📁 使用miniGUI模拟器的简单开发例子(值得参考)
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (__mgs_captured_main_win != (void*)HWND_INVALID && __mgs_captured_main_win != NULL) {        CapHitCode = SendAsyncMessage((HWND)__mgs_captured_main_win, MSG_HITTEST,                                        (WPARAM)x, (LPARAM)y);    }        pCtrlPtrIn = GetMainWindowPtrUnderPoint (x, y);    if (dskHandleMouseHooks ((HWND)pCtrlPtrIn,                             message, flags, MAKELONG (x, y)) == HOOK_STOP)        return 0;        if (pCtrlPtrIn && pCtrlPtrIn->WinType == TYPE_CONTROL) {        pUnderPointer = pCtrlPtrIn->pMainWin;        UndHitCode = HT_CLIENT;        cx = x - pUnderPointer->cl;        cy = y - pUnderPointer->ct;    }    else {        pUnderPointer = pCtrlPtrIn;        pCtrlPtrIn = NULL;        if (pUnderPointer) {            UndHitCode = SendAsyncMessage((HWND)pUnderPointer, MSG_HITTEST,                                         (WPARAM)x, (LPARAM)y);            cx = x - pUnderPointer->cl;            cy = y - pUnderPointer->ct;        }    }    switch (message) {        case MSG_MOUSEMOVE:            if (__mgs_captured_main_win != (void *)HWND_INVALID) {                if (__mgs_captured_main_win)                    PostMessage((HWND)__mgs_captured_main_win, MSG_NCMOUSEMOVE,                                 CapHitCode, MAKELONG (x, y));                else                    PostMessage(HWND_DESKTOP, MSG_DT_MOUSEMOVE,                                pUnderPointer == NULL, MAKELONG (x, y));                break;            }            if (pUnderPointer == NULL) {                if (__mgs_old_under_pointer) {                    PostMessage ((HWND)__mgs_old_under_pointer,                        MSG_MOUSEMOVEIN, FALSE, 0);                    PostMessage ((HWND)__mgs_old_under_pointer,                        MSG_NCMOUSEMOVE, HT_OUT, MAKELONG (x, y));                }#if defined(_LITE_VERSION) && !defined(_STAND_ALONE)                if (!mgIsServer)#endif                    SetCursor (GetSystemCursor (IDC_ARROW));                __mgs_old_under_pointer = NULL;            }            else {                HCURSOR def_cursor = GetDefaultCursor ();                if (__mgs_old_under_pointer != pUnderPointer) {                    if (__mgs_old_under_pointer) {                        PostMessage ((HWND)__mgs_old_under_pointer,                            MSG_MOUSEMOVEIN, FALSE, (LPARAM)pUnderPointer);                        PostMessage ((HWND)__mgs_old_under_pointer,                            MSG_NCMOUSEMOVE, HT_OUT, MAKELONG (x, y));                    }                    PostMessage ((HWND)pUnderPointer,                        MSG_MOUSEMOVEIN, TRUE, (LPARAM)__mgs_old_under_pointer);                    __mgs_old_under_pointer = pUnderPointer;                }                if (pUnderPointer->dwStyle & WS_DISABLED) {                    if (def_cursor)                        SetCursor (def_cursor);                    break;                }                if (UndHitCode == HT_CLIENT) {                    if (def_cursor)                        SetCursor (def_cursor);                    PostMessage ((HWND)pUnderPointer, MSG_SETCURSOR,                             UndHitCode, MAKELONG (cx, cy));                    PostMessage((HWND)pUnderPointer, MSG_NCMOUSEMOVE,                             UndHitCode, MAKELONG (x, y));                    PostMessage((HWND)pUnderPointer, MSG_MOUSEMOVE,                             flags, MAKELONG (cx, cy));                }                else {                    if (def_cursor)                        SetCursor (def_cursor);                    PostMessage ((HWND)pUnderPointer, MSG_NCSETCURSOR,                             UndHitCode, MAKELONG (x, y));                    PostMessage((HWND)pUnderPointer, MSG_NCMOUSEMOVE,                             UndHitCode, MAKELONG (x, y));                }            }        break;        case MSG_LBUTTONDOWN:        case MSG_RBUTTONDOWN:            if (pUnderPointer) {                if (__mg_ptmi)                    dskForceCloseMenu ();                if (pUnderPointer->dwStyle & WS_DISABLED) {                    Ping ();                    break;                }                if (pCtrlPtrIn == NULL) {                    if (!dskIsTopMost (pUnderPointer)) {                        dskMoveToTopMost (pUnderPointer, RCTM_CLICK, MAKELONG (x, y));                    }                                    if (pUnderPointer != dskChangActiveWindow (pUnderPointer))                        PostMessage ((HWND) pUnderPointer,                                MSG_MOUSEACTIVE, UndHitCode, 0);                }                                if (UndHitCode != HT_CLIENT) {                    if (UndHitCode & HT_NEEDCAPTURE)                        __mgs_captured_main_win = pUnderPointer;                    else                        __mgs_captured_main_win = (void*)HWND_INVALID;                    PostMessage ((HWND)pUnderPointer, message + MSG_NCMOUSEOFF,                            UndHitCode, MAKELONG (x, y));                }                else {                    PostMessage((HWND)pUnderPointer, message,                         flags, MAKELONG(cx, cy));                    __mgs_captured_main_win = (void*)HWND_INVALID;                }            }            else {                dskChangActiveWindow (NULL);                __mgs_captured_main_win = NULL;                PostMessage (HWND_DESKTOP, message + MSG_DT_MOUSEOFF,                            flags, MAKELONG (x, y));            }        break;        case MSG_LBUTTONUP:        case MSG_RBUTTONUP:            if (__mgs_captured_main_win != (void*)HWND_INVALID) {                if (__mgs_captured_main_win)                    PostMessage ((HWND)__mgs_captured_main_win, message + MSG_NCMOUSEOFF,                        CapHitCode, MAKELONG (x, y));                else if (!pUnderPointer)                    PostMessage (HWND_DESKTOP, message + MSG_DT_MOUSEOFF,                        flags, MAKELONG (x, y));                                __mgs_captured_main_win = (void*)HWND_INVALID;                break;            }            else {                if (pUnderPointer) {                    if (pUnderPointer->dwStyle & WS_DISABLED) {                        break;                    }                                        if (UndHitCode == HT_CLIENT) {                        PostMessage((HWND)pUnderPointer, message,                             flags, MAKELONG (cx, cy));                    }                    else {                        PostMessage((HWND)pUnderPointer,                             message + MSG_NCMOUSEOFF,                             UndHitCode, MAKELONG (x, y));                    }                }                else                    PostMessage (HWND_DESKTOP, message + MSG_DT_MOUSEOFF,                        flags, MAKELONG (x, y));            }        break;                case MSG_LBUTTONDBLCLK:        case MSG_RBUTTONDBLCLK:            if (pUnderPointer)            {                if (pUnderPointer->dwStyle & WS_DISABLED) {                    Ping ();                    break;                }                if(UndHitCode == HT_CLIENT)                    PostMessage((HWND)pUnderPointer, message,                         flags, MAKELONG(cx, cy));                else                    PostMessage((HWND)pUnderPointer, message + MSG_NCMOUSEOFF,                         UndHitCode, MAKELONG (x, y));            }            else {                PostMessage(HWND_DESKTOP, message + MSG_DT_MOUSEOFF,                         flags, MAKELONG (x, y));            }        break;    }    return 0;}static int WindowMessageHandler(int message, PMAINWIN pWin, LPARAM lParam){    PMAINWIN pTemp;    int iRet = 0;    switch (message)    {        case MSG_ADDNEWMAINWIN:            if (__mg_ptmi)                dskForceCloseMenu ();            pWin->pGCRInfo = &pWin->GCRInfo;            iRet = (int)dskAddNewMainWindow(pWin, (PZORDERNODE)lParam);        break;        case MSG_REMOVEMAINWIN:            if (__mg_ptmi)                dskForceCloseMenu ();            iRet = (int)dskRemoveMainWindow(pWin);            __mg_reset_desktop_capture_info (pWin);        break;        case MSG_MOVETOTOPMOST:            if (__mg_ptmi)                dskForceCloseMenu ();            pTemp = dskMoveToTopMost(pWin, RCTM_MESSAGE, 0);        break;        case MSG_SHOWMAINWIN:            if (__mg_ptmi)                dskForceCloseMenu ();            iRet = (int)dskShowMainWindow(pWin, TRUE);            if ((HWND)pWin == __mg_ime_wnd)                return iRet;        break;        case MSG_HIDEMAINWIN:            if (__mg_ptmi)                dskForceCloseMenu ();            iRet = (int)dskHideMainWindow(pWin);            __mg_reset_desktop_capture_info (pWin);            if ((HWND)pWin == __mg_ime_wnd)                return iRet;        break;        case MSG_MOVEMAINWIN:            dskMoveToTopMost (pWin, RCTM_MESSAGE, 0);            dskMoveMainWindow (pWin, (const RECT*)lParam);            return 0;        case MSG_GETACTIVEMAIN:            return (int)__mg_active_mainwnd;                case MSG_SETACTIVEMAIN:            iRet = (int)dskChangActiveWindow (pWin);            return iRet;        case MSG_GETCAPTURE:            return (int)__mg_capture_wnd;                case MSG_SETCAPTURE:            return (int)DesktopSetCapture ((HWND)pWin);                case MSG_TRACKPOPUPMENU:            return dskTrackPopupMenu((PTRACKMENUINFO)lParam);        case MSG_ENDTRACKMENU:            return dskEndTrackMenu((PTRACKMENUINFO)lParam);        case MSG_CLOSEMENU:            if (!dskForceCloseMenu ())                return 0;            if (!lParam)                return 0;        break;        case MSG_SCROLLMAINWIN:            iRet = dskScrollMainWindow (pWin, (PSCROLLWINDOWINFO)lParam);            return iRet;        case MSG_CARET_CREATE:            sg_hCaretWnd = (HWND)pWin;            sg_uCaretBTime = pWin->pCaretInfo->uTime;            return 0;        case MSG_CARET_DESTROY:            sg_hCaretWnd = HWND_DESKTOP;            return 0;        case MSG_ENABLEMAINWIN:            iRet = !(pWin->dwStyle & WS_DISABLED);            if ( (!(pWin->dwStyle & WS_DISABLED) && !lParam)                    || ((pWin->dwStyle & WS_DISABLED) && lParam) ) {                if (lParam)                    pWin->dwStyle &= ~WS_DISABLED;                else                    pWin->dwStyle |=  WS_DISABLED;                if (pWin->dwStyle & WS_DISABLED) {                                    if (__mg_capture_wnd && GetMainWindowPtrOfControl (__mg_capture_wnd) == pWin)                         __mg_capture_wnd = HWND_DESKTOP;                    if (__mg_active_mainwnd == pWin) {                        dskChangActiveWindow (NULL);                        break;                    }                }                SendAsyncMessage ((HWND)pWin, MSG_NCPAINT, 0, 0);            }            break;                case MSG_ISENABLED:            return !(pWin->dwStyle & WS_DISABLED);                case MSG_SETWINCURSOR:        {            HCURSOR old = pWin->hCursor;            pWin->hCursor = (HCURSOR)lParam;            return old;        }        case MSG_GETNEXTMAINWIN:        {            PZORDERNODE pNode;            HWND hWnd = HWND_DESKTOP;            while (1) {                if (pWin) {                    pNode = pWin->pZOrderNode->pNext;                    if (pNode)                        hWnd = pNode->hWnd;                    else if (pWin->dwExStyle & WS_EX_TOPMOST)                        hWnd = sg_MainWinZOrder.pTopMost->hWnd;                }                else {                    if (sg_TopMostWinZOrder.pTopMost->hWnd)                        hWnd = sg_TopMostWinZOrder.pTopMost->hWnd;                    else                        hWnd = sg_MainWinZOrder.pTopMost->hWnd;                }                pWin = CheckAndGetMainWindowPtr (hWnd);                if (pWin && (pWin->dwExStyle & WS_EX_CTRLASMAINWIN))                    continue;                return hWnd;            }            break;        }        case MSG_SHOWGLOBALCTRL:            if (__mg_ptmi)                dskForceCloseMenu ();            dskMoveToTopMost (pWin, RCTM_SHOWCTRL, 0);            dskSetPrimitiveChildren (pWin, TRUE);            break;        case MSG_HIDEGLOBALCTRL:            if (__mg_ptmi)                dskForceCloseMenu ();            dskHideMainWindow (pWin);            dskSetPrimitiveChildren (pWin, FALSE);            break;   }   return iRet;}#define IDM_REDRAWBG    MINID_RESERVED#define IDM_CLOSEALLWIN (MINID_RESERVED + 1)#define IDM_ENDSESSION  (MINID_RESERVED + 2)#define IDM_FIRSTWINDOW (MINID_RESERVED + 101)#ifndef _LITE_VERSION/* * When the user clicks right mouse button on desktop,  * MiniGUI will display a menu for user. You can use this  * function to customize the desktop menu. e.g. add a new  * menu item. * Please use an integer larger than IDM_DTI_FIRST as the  * command ID. */#define IDC_DTI_ABOUT   (IDM_DTI_FIRST)void CustomizeDesktopMenuDefault (HMENU hmnu, int iPos){#ifdef _MISC_ABOUTDLG    MENUITEMINFO mii;    memset (&mii, 0, sizeof(MENUITEMINFO));    mii.type        = MFT_STRING;    mii.id          = IDC_DTI_ABOUT;    mii.typedata    = (DWORD)GetSysText(SysText [19]);    mii.hsubmenu    = 0;    InsertMenuItem (hmnu, iPos, TRUE, &mii);#endif}/* * When user choose a custom menu item on desktop menu, * MiniGUI will call this function, and pass the command ID * of selected menu item. */int CustomDesktopCommandDefault (int id){#ifdef _MISC_ABOUTDLG#ifndef _LITE_VERSION    if (id == IDC_DTI_ABOUT)        OpenAboutDialog ();#endif#endif    return 0;}CustomizeDesktopMenuFunc CustomizeDesktopMenu = CustomizeDesktopMenuDefault;CustomDesktopCommandFunc CustomDesktopCommand = CustomDesktopCommandDefault;#endifconst char* SysText [] ={    "Windows...",               // 0    "Start...",                 // 1    "Refresh Background",       // 2    "Close All Windows",        // 3    "End Session",              // 4    "Operations...",            // 5    "Minimize",                 // 6    "Maximize",                 // 7    "Restore",                  // 8    "Close",                    // 9    "OK",                       // 10    "Next",                     // 11    "Cancel",                   // 12    "Previous",                 // 13    "Yes",                      // 14    "No",                       // 15    "Abort",                    // 16    "Retry",                    // 17    "Ignore",                   // 18    "About MiniGUI...",         // 19    "Open File",                // 20    "Save File",                // 21    "Color Selection",          // 22    NULL};#if defined(_GB_SUPPORT) | defined (_GBK_SUPPORT) | defined (_GB18030_SUPPORT)static const char* SysText_GB [] ={    "窗口...",              // 0    "开始...",              // 1    "刷新背景",             // 2    "关闭所有窗口",         // 3    "结束会话",             // 4    "窗口操作...",          // 5    "最小化",               // 6    "最大化",               // 7    "恢复",                 // 8 

⌨️ 快捷键说明

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