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

📄 mainfrm.cpp

📁 图像显示软件源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
    theApp.ModalDialogEvent.ResetEvent();

    COLORREF CustomColours[16] = {0};
    UINT ColourCount = _countof(CustomColours);
    theApp.GetObjectArray(_T("Settings"), _T("Custom Colours"), CustomColours, &ColourCount);
    for (UINT i = ColourCount; i < _countof(CustomColours); ++i)
    {
        CustomColours[i] = GetSysColor(COLOR_WINDOW);
    }

    CHOOSECOLOR cc = {0};
    cc.lStructSize = sizeof(CHOOSECOLOR);
    cc.hwndOwner = m_hWnd;
    cc.rgbResult = BackgroundColour;
    cc.lpCustColors = CustomColours;
    cc.Flags = CC_ANYCOLOR | CC_RGBINIT | CC_SOLIDCOLOR;

    if (ChooseColor(&cc) != 0)
    {
        BackgroundColour = cc.rgbResult;
        theApp.WriteObjectArray(_T("Settings"), _T("Background Colour"), &BackgroundColour);
        theApp.WriteObjectArray(_T("Settings"), _T("Custom Colours"), CustomColours, _countof(CustomColours));
    }

    POSITION pos = theApp.GetFirstDocTemplatePosition();
    CDocTemplate *pDocTemplate = theApp.GetNextDocTemplate(pos);
    pos = pDocTemplate->GetFirstDocPosition();
    while (NULL != pos)
    {
        CDocument *pDoc = pDocTemplate->GetNextDoc(pos);
        pDoc->UpdateAllViews(NULL);
    }

    theApp.ModalDialogEvent.SetEvent();
}

void CMainFrame::OnViewHexadecimalTooltips()
{
    HexTooltip = !HexTooltip;
    ColourTooltip.SetHex(HexTooltip);
}

void CMainFrame::OnUpdateViewHexadecimalTooltips(CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck(HexTooltip ? BST_CHECKED : BST_UNCHECKED);
}

void CMainFrame::OnViewDisplayLock()
{
    DisplayLock = !DisplayLock;
}

void CMainFrame::OnUpdateViewDisplayLock(CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck(DisplayLock ? BST_CHECKED : BST_UNCHECKED);
}

LRESULT CMainFrame::OnGetBGColour(WPARAM, LPARAM)
{
    return static_cast<LRESULT>(BackgroundColour);
}

LRESULT CMainFrame::OnGetDisplayLock(WPARAM, LPARAM)
{
    return static_cast<LRESULT>(DisplayLock);
}

LRESULT CMainFrame::OnSetProperties(WPARAM wp, LPARAM lp)
{
    if (NULL != wp && NULL != lp && IsWindow(PropertiesDialog))
    {
        CMDIChildWnd *pFrame = reinterpret_cast<CMDIChildWnd *>(wp);
        if (MDIGetActive() == pFrame)
        {
            return PropertiesDialog.SendMessage(WMU_SETPROPERTIES, wp, lp);
        }
    }

    return 0;
}

void CMainFrame::OnDestroy()
{
    CMDIFrameWnd::OnDestroy();

    KillTimer(INPUTQUEUEREADERTIMER);

    WINDOWPLACEMENT WindowPlacement = {0};
    WindowPlacement.length = sizeof(WINDOWPLACEMENT);
    GetWindowPlacement(&WindowPlacement);
    theApp.WriteObjectArray(_T("Settings"), _T("Main Window Placement"), &WindowPlacement);
    theApp.WriteProfileInt(_T("Settings"), _T("Hex Tooltips"), HexTooltip);
}

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
    if (CMDIFrameWnd::OnCreateClient(lpcs, pContext))
    {
        // subclass the default MDIClient window with our own class
        MDIClient.SubclassWindow(m_hWndMDIClient);
        return TRUE;
    }

    return FALSE;
}

void CMainFrame::OnViewOnTop()
{
    bool OnTop = WS_EX_TOPMOST == (GetExStyle() & WS_EX_TOPMOST);
    theApp.WriteProfileInt(_T("Settings"), _T("Always on Top"), !OnTop);

    if (OnTop)
    {
        SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
    }
    else
    {
        SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
    }
}

void CMainFrame::OnUpdateViewOnTop(CCmdUI *pCmdUI)
{
    pCmdUI->SetCheck(WS_EX_TOPMOST == (GetExStyle() & WS_EX_TOPMOST) ? BST_CHECKED : BST_UNCHECKED);
}

void CMainFrame::OnImageProperties()
{
    if (this != GetActiveFrame() && IsWindow(PropertiesDialog))
    {
        PropertiesDialog.ShowWindow(PropertiesDialog.IsWindowVisible() ? SW_HIDE : SW_SHOW);
        GetActiveFrame()->GetActiveView()->SetFocus();
    }
}

void CMainFrame::OnUpdateImageProperties(CCmdUI *pCmdUI)
{
    if (this == GetActiveFrame() || !IsWindow(PropertiesDialog))
    {
        pCmdUI->Enable(FALSE);
        pCmdUI->SetCheck(BST_UNCHECKED);

        if (IsWindow(PropertiesDialog) && PropertiesDialog.IsWindowVisible())
        {
            PropertiesDialog.ShowWindow(SW_HIDE);
        }
    }
    else
    {
        pCmdUI->Enable(TRUE);
        pCmdUI->SetCheck(PropertiesDialog.IsWindowVisible() ? BST_CHECKED : BST_UNCHECKED);
    }
}

void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
    CMDIFrameWnd::OnActivate(nState, pWndOther, bMinimized);

    if (IsWindow(ColourTooltip))
    {
        // the tooltip is active only when this app has the input focus
        ColourTooltip.Activate(nState != WA_INACTIVE);
    }
}

void CMainFrame::OnUpdateIndicatorMem(CCmdUI *pCmdUI)
{
    // Update the memory usage indicator on the status bar.
    // See CMainStatusBar::DrawItem()
    size_t mem = CImageData::GetMemUsage() / 1024;
    pCmdUI->SetText(reinterpret_cast<LPCTSTR>(&mem));
}

LRESULT CMainFrame::OnUpdateTooltip(WPARAM, LPARAM)
{
    ColourTooltip.Update();

    return 0;
}

// Single Instance message handlers.
//
// When the Image Viewer app starts it uses a mutex to ensure only one
// instance can run (see CImageViewerApp::OnInitInstance()). If another
// instance is running it sequentially sends out a RWM_ARE_YOU_ME message
// to all the top level windows on the system looking for the other
// instance. The first one that returns with RWM_ARE_YOU_ME is assumed
// to be the existing instance. The existing instance can then activate itself.
// If the new instance was suppose to open a file, it will send a
// WM_COPYDATA message to the existing instance with the file name so
// that the existing instance can open it instead.

LRESULT CMainFrame::OnAreYouMe(WPARAM, LPARAM)
{
    if (IsIconic())
    {
        ShowWindow(SW_RESTORE);
    }

    SetForegroundWindow();

    return RWM_ARE_YOU_ME;
}

BOOL CMainFrame::OnCopyData(CWnd* /*pWnd*/, COPYDATASTRUCT* pCopyDataStruct)
{
    BOOL ret = FALSE;

    if (pCopyDataStruct->dwData == 0x1FEB1965 &&
        pCopyDataStruct->lpData != NULL)
    {
        // only open the file if a file operation is not already in progress
        if (WAIT_OBJECT_0 == WaitForSingleObject(theApp.ModalDialogEvent, 0))
        {
            CString File = (LPCTSTR)pCopyDataStruct->lpData;

            theApp.ModalDialogEvent.ResetEvent();
            if (NULL != AfxGetApp()->OpenDocumentFile(File))
            {
                ret = TRUE;
            }
            theApp.ModalDialogEvent.SetEvent();
        }
    }

    return ret;
}

LRESULT CMainFrame::OnSetMessageString(WPARAM wp, LPARAM lp)
{
    if (wp == AFX_IDS_IDLEMESSAGE || wp == IDS_PAUSEDMESSAGE)
    {
        if (WAIT_OBJECT_0 != WaitForSingleObject(theApp.MemoryEvent, 0))
        {
            wp = IDS_OUTOFMEMORY;
        }
        else if (WAIT_OBJECT_0 != WaitForSingleObject(theApp.PausedEvent, 0))
        {
            wp = IDS_PAUSEDMESSAGE;
        }
    }

    return CMDIFrameWnd::OnSetMessageString(wp, lp);
}

BOOL CALLBACK CloseChildFrames(HWND hWnd, LPARAM lp)
{
    CWnd *pWnd = CWnd::FromHandle(hWnd);
    CWnd *pActive = reinterpret_cast<CWnd*>(lp);

    if (pWnd->IsKindOf(RUNTIME_CLASS(CMDIChildWnd)) && pWnd != pActive)
    {
        pWnd->PostMessage(WM_CLOSE, 0, 0);
    }

    return TRUE;
}

void CMainFrame::OnFileCloseAll()
{
    EnumChildWindows(*this, &CloseChildFrames, NULL);
}

void CMainFrame::OnFileCloseAllExceptActive()
{
    EnumChildWindows(*this, &CloseChildFrames, reinterpret_cast<LPARAM>(MDIGetActive()));
}

void CMainFrame::OnFileCloseActive()
{
    MDIGetActive()->PostMessage(WM_CLOSE, 0, 0);
}

⌨️ 快捷键说明

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