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

📄 beepprop.cpp

📁 英文版的 想要的话可以下载了 为大家服务
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 *  display its contents, using the given parent window and
 *  rectangle.  The window should be initially visible.
 *
 * Parameters:
 *  hWndParent      HWND of the parent window.
 *  prc             LPCRECT of the rectangle to use.
 *  fModal          BOOL indicating whether the frame is modal.
 */

STDMETHODIMP CBeeperPropPage::Activate(HWND hWndParent
    , LPCRECT prc, BOOL fModal)
    {
    if (NULL!=m_hDlg)
        return ResultFromScode(E_UNEXPECTED);

    m_hDlg=CreateDialogParam(m_hInst, MAKEINTRESOURCE(m_uIDTemplate)
        , hWndParent, BeepPropPageProc, (LPARAM)this);

    if (NULL==m_hDlg)
        return ResultFromScode(E_OUTOFMEMORY);

    //Move the page into position and show it.
    SetWindowPos(m_hDlg, NULL, prc->left, prc->top
        , prc->right-prc->left, prc->bottom-prc->top, 0);

	return NOERROR;
    }



/*
 * CBeeperPropPage::Deactivate
 *
 * Purpose:
 *  Instructs the property page to destroy its window that was
 *  created in Activate.
 *
 * Parameters:
 *  None
 */

STDMETHODIMP CBeeperPropPage::Deactivate(void)
    {
    if (NULL==m_hDlg)
        return ResultFromScode(E_UNEXPECTED);

    DestroyWindow(m_hDlg);
    m_hDlg=NULL;
    return NOERROR;
    }



/*
 * CBeeperPropPage::GetPageInfo
 *
 * Purpose:
 *  Fills a PROPPAGEINFO structure describing the page's size,
 *  contents, and help information.
 *
 * Parameters:
 *  pPageInfo       LPPROPPAGEINFO to the structure to fill.
 */

STDMETHODIMP CBeeperPropPage::GetPageInfo(LPPROPPAGEINFO pPageInfo)
    {
    IMalloc     *pIMalloc;

    if (FAILED(CoGetMalloc(MEMCTX_TASK, &pIMalloc)))
        return ResultFromScode(E_FAIL);

    pPageInfo->pszTitle=(LPOLESTR)pIMalloc->Alloc(CCHSTRINGMAX);

    if (NULL!=pPageInfo->pszTitle)
        {
        UINT        ids=IDS_0_PAGETITLE;

        if (PRIMARYLANGID(m_lcid)==LANG_GERMAN)
            ids=IDS_7_PAGETITLE;

       #ifdef WIN32ANSI
        char        szTemp[80];

        LoadString(m_hInst, ids, szTemp, CCHSTRINGMAX);
        MultiByteToWideChar(CP_ACP, 0, szTemp, -1
           , pPageInfo->pszTitle, 80);
       #else
        LoadString(m_hInst, ids, pPageInfo->pszTitle, CCHSTRINGMAX);
       #endif
        }

    pIMalloc->Release();

	pPageInfo->size.cx      = m_cx;
    pPageInfo->size.cy      = m_cy;
	pPageInfo->pszDocString = NULL;
	pPageInfo->pszHelpFile  = NULL;
	pPageInfo->dwHelpContext= 0;
    return NOERROR;
    }



/*
 * CBeeperPropPage::SetObjects
 *
 * Purpose:
 *  Identifies the objects that are being affected by this property
 *  page (and all other pages in the frame).  These are the object
 *  to which to send new property values in the Apply member.
 *
 * Parameters:
 *  cObjects        ULONG number of objects
 *  ppUnk           IUnknown ** to the array of objects being
 *                  passed to the page.
 */

STDMETHODIMP CBeeperPropPage::SetObjects(ULONG cObjects
    , IUnknown **ppUnk)
    {
    BOOL        fRet=TRUE;

    FreeAllObjects();

    if (0!=cObjects)
        {
        UINT        i;
        HRESULT     hr;

        m_ppIBeeper=new IBeeper * [(UINT)cObjects];

	    for (i=0; i < cObjects; i++)
	        {
            hr=ppUnk[i]->QueryInterface(IID_IBeeper
                , (void **)&m_ppIBeeper[i]);

            if (FAILED(hr))
                fRet=FALSE;
	        }
	    }

    //If we didn't get one of our objects, fail this call.
    if (!fRet)
        return ResultFromScode(E_FAIL);

    m_cObjects=cObjects;
    return NOERROR;
    }



/*
 * CBeeperPropPage::Show
 *
 * Purpose:
 *  Instructs the page to show or hide its window created in
 *  Activate.
 *
 * Parameters:
 *  nCmdShow        UINT to pass to ShowWindow.
 */

STDMETHODIMP CBeeperPropPage::Show(UINT nCmdShow)
    {
    if (NULL==m_hDlg)
        ResultFromScode(E_UNEXPECTED);

    ShowWindow(m_hDlg, nCmdShow);

    //Take the focus
    if (SW_SHOWNORMAL==nCmdShow || SW_SHOW==nCmdShow)
		SetFocus(m_hDlg);

    return NOERROR;
    }



/*
 * CBeeperPropPage::Move
 *
 * Purpose:
 *  Instructs the property page to change its position.
 *
 * Parameters:
 *  prc             LPCRECT containing the new position.
 */

STDMETHODIMP CBeeperPropPage::Move(LPCRECT prc)
    {
    SetWindowPos(m_hDlg, NULL, prc->left, prc->top
        , prc->right-prc->left, prc->bottom-prc->top, 0);

    return NOERROR;
    }



/*
 * CBeeperPropPage::IsPageDirty
 *
 * Purpose:
 *  Asks the page if anything's changed in it, that is, if the
 *  property values in the page are out of sync with the objects
 *  under consideration.
 *
 * Parameters:
 *  None
 *
 * Return Value:
 *  HRESULT         NOERROR if dirty, S_FALSE if not.
 */

STDMETHODIMP CBeeperPropPage::IsPageDirty(void)
    {
    return ResultFromScode(m_fDirty ? S_OK : S_FALSE);
    }




/*
 * CBeeperPropPage::Apply
 *
 * Purpose:
 *  Instructs the page to send changes in its page to whatever
 *  objects it knows about through SetObjects.  This is the only
 *  time the page should change the objects' properties, and not
 *  when the value is changed on the page.
 *
 * Parameters:
 *  None
 */

STDMETHODIMP CBeeperPropPage::Apply(void)
    {
    UINT        i;
    UINT        lSound, lSoundNew;
    BOOL        fChanged;

    if (0==m_cObjects)
        return NOERROR;

    /*
     * The dialog's last known Sound selection is in
     * m_uIDLastSound, so we can just send it via
     * IBeeper::put_Sound.  Since this method has no
     * return value, we have to ask for it again to
     * see if it really changed because the client may
     * be blocking changes through IPropertyNotifySink,
     * in which case we do not clear the dirty flag.
     */

    lSound=(IDC_BEEPDEFAULT==m_uIDLastSound) ? 0L : m_uIDLastSound;
    fChanged=TRUE;

    for (i=0; i < m_cObjects; i++)
        {
        m_ppIBeeper[i]->put_Sound(lSound);
        lSoundNew=m_ppIBeeper[i]->get_Sound();

        fChanged &= (lSound==lSoundNew);
        }

    m_fDirty=!fChanged;
    return NOERROR;
    }



/*
 * CBeeperPropPage::Help
 *
 * Purpose:
 *  Invokes help for this property page when the user presses
 *  the Help button.  If you return NULLs for the help file
 *  in GetPageInfo, the button will be grayed.  Otherwise the
 *  page can perform its own help here.
 *
 * Parameters:
 *  pszHelpDir      LPCOLESTR identifying the default location of
 *                  the help information
 *
 * Return Value:
 *  HRESULT         NOERROR to tell the frame that we've done our
 *                  own help.  Returning an error code or S_FALSE
 *                  causes the frame to use any help information
 *                  in PROPPAGEINFO.
 */

STDMETHODIMP CBeeperPropPage::Help(LPCOLESTR pszHelpDir)
    {
    /*
     * We can either provide help ourselves, or rely on the
     * information in PROPPAGEINFO.
     */
    return ResultFromScode(S_FALSE);
    }




/*
 * CBeeperPropPage::TranslateAccelerator
 *
 * Purpose:
 *  Provides the page with the messages that occur in the frame.
 *  This gives the page to do whatever it wants with the message,
 *  such as handle keyboard mnemonics.
 *
 * Parameters:
 *  pMsg            LPMSG containing the keyboard message.
 */

STDMETHODIMP CBeeperPropPage::TranslateAccelerator(LPMSG lpMsg)
    {
    //No keyboard interface supported here
    return ResultFromScode(E_NOTIMPL);
    }



/*
 * BeepPropPageProc
 *
 * Purpose:
 *  Dialog procedure for the Beeper Property Page.
 */

BOOL APIENTRY BeepPropPageProc(HWND hDlg, UINT iMsg
    , WPARAM wParam, LPARAM lParam)
    {
    PCBeeperPropPage    pObj;
    WORD                wID;

   #ifdef WIN32
    pObj=(PCBeeperPropPage)(ULONG)GetProp(hDlg, g_szObj);
   #else
    pObj=(PCBeeperPropPage)MAKELONG((WORD)GetProp(hDlg, g_szObjLo)
       , (WORD)GetProp(hDlg, g_szObjHi));
   #endif

    switch (iMsg)
        {
        case WM_INITDIALOG:
            pObj=(PCBeeperPropPage)(ULONG)lParam;
           #ifdef WIN32
            SetProp(hDlg, g_szObj, (HANDLE)lParam);
           #else
            SetProp(hDlg, g_szObjHi, (HANDLE)HIWORD(lParam));
            SetProp(hDlg, g_szObjLo, (HANDLE)LOWORD(lParam));
           #endif

            if (NULL==pObj)
                return TRUE;

            SetFocus(GetDlgItem(hDlg, IDOK));

            /*
             * If we have one object then we can try to set the
             * right field in the dialog box.  Otherwise we could
             * ask for the value from all of the objects and see
             * if they all match.
             */
            if (1==pObj->m_cObjects)
                {
                UINT        iButton;

                iButton=(UINT)pObj->m_ppIBeeper[0]->get_Sound();

                if (0==iButton)
                    iButton=IDC_BEEPDEFAULT;

                CheckRadioButton(hDlg, IDC_BEEPDEFAULT
                    , IDC_BEEPASTERISK, iButton);

                pObj->m_uIDLastSound=iButton;
                }

            return FALSE;

        case WM_DESTROY:
           #ifdef WIN32
            RemoveProp(hDlg, g_szObj);
           #else
            RemoveProp(hDlg, g_szObjHi);
            RemoveProp(hDlg, g_szObjLo);
           #endif
            return FALSE;

        case WM_COMMAND:
            wID=LOWORD(wParam);

            switch (wID)
                {
                case IDC_BEEPDEFAULT:
                case IDC_BEEPHAND:
                case IDC_BEEPQUESTION:
                case IDC_BEEPEXCLAMATION:
                case IDC_BEEPASTERISK:
                    if (NULL==pObj)
                        break;

                    //Selecting the same one doesn't dirty
                    if (pObj->m_uIDLastSound==wID)
                        break;

                    //Save the most recently selected
                    pObj->m_uIDLastSound=LOWORD(wParam);
                    pObj->m_fDirty=TRUE;

                    if (NULL!=pObj->m_pIPropertyPageSite)
                        {
                        pObj->m_pIPropertyPageSite
                            ->OnStatusChange(PROPPAGESTATUS_DIRTY);
                        }

                    break;


                case IDOK:
                    /*
                     * We could call the object's Beep, but
                     * as it's property page, we know what
                     * it will do so we can just do it.
                     */
                    if (NULL!=pObj)
                        MessageBeep(pObj->m_uIDLastSound);

                    break;
                }
            break;
        }
    return FALSE;
    }

⌨️ 快捷键说明

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