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

📄 ftpprop.cpp

📁 很好用的ftp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

    return fResult;
}
#endif // FEATURE_CHANGE_PERMISSIONS


/*****************************************************************************\
 *    DlgProc
\*****************************************************************************/
INT_PTR CFtpProp::DlgProc(HWND hDlg, UINT wm, WPARAM wParam, LPARAM lParam)
{
    INT_PTR fResult = 0;   // not Handled
    CFtpProp * pfp = (CFtpProp *)GetWindowLongPtr(hDlg, GWLP_USERDATA);

    switch (wm)
    {
    case WM_INITDIALOG:
    {
        LPPROPSHEETPAGE ppsp = (LPPROPSHEETPAGE) lParam;
        pfp =  (CFtpProp *)ppsp->lParam;
        SetWindowLongPtr(hDlg, GWLP_USERDATA, (LPARAM)pfp);

        ASSERT(pfp);
        fResult = pfp->OnInitDialog(hDlg);
    }
    break;

    case WM_NOTIFY:
        if (lParam)
        {
            switch (((NMHDR *)lParam)->code) 
            {
                case PSN_APPLY:
                    if (pfp->OnClose(hDlg))
                    {
                        fResult = FALSE;    // Tell comctl32 I'm happy
                    }
                    else
                    {
                        SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID);
                        fResult = TRUE;    // Tell comctl32 to look at the error code and don't close.
                    }
                break;
                
                case PSN_TRANSLATEACCELERATOR:
                    if (pfp->m_ftpDialogTemplate.HasNameChanged(hDlg, pfp->m_pff, pfp->m_pflHfpl))
                        PropSheet_Changed(GetParent(hDlg), hDlg);
                    break;
            }
        }
        break;
#ifdef FEATURE_CHANGE_PERMISSIONS
    case WM_CTLCOLORSTATIC:
    case WM_CTLCOLOREDIT:
        fResult = pfp->_SetWhiteBGCtlColor(hDlg, (HDC)wParam, (HWND)lParam);
        break;
#endif // FEATURE_CHANGE_PERMISSIONS
    }

    return fResult;
}


/*****************************************************************************\
 *    DoProp_OnThread
 *
 *    Display a property sheet on the current thread.
 *
 *    WARNING!  VIOLATION OF OLE REFERENCE STUFF!
 *
 *    The PFP that comes in must be Release()d when we're done.
 *
 *    The reason is that the caller has "given us" the reference;
 *    we now own it and are responsible for releasing it.
\*****************************************************************************/
DWORD CFtpProp::_PropertySheetThread(void)
{
    HRESULT hrOleInit;
    PROPSHEETHEADER psh;
    PROPSHEETPAGE psp;
    TCHAR szTitle[MAX_PATH];

    FTPDebugMemLeak(DML_TYPE_THREAD | DML_BEGIN);
    hrOleInit = SHOleInitialize(0);
    ASSERT(SUCCEEDED(hrOleInit));

    // This will allow the dialog to work with items outside of the font.
    // So Date, Name, and URL can be in the correct font even through
    // it's not supported by the DLL's font.
    InitComctlForNaviteFonts();
    LoadString(HINST_THISDLL, IDS_PROP_SHEET_TITLE, szTitle, ARRAYSIZE(szTitle));

    // psh.hwndParent being NULL or valid will determine if the property
    // sheet appears in the taskbar.  We do want it there to be consistent
    // with the shell.
    //
    // BUGBUG: Comctl32's property sheet code will make this act modal by
    //         disabling the parent window (m_hwnd).  We need to fix this
    //         (#202885) by creating a dummy window and using that as the
    //         parent.

    psh.hwndParent = SHCreateWorkerWindow(NULL, m_hwnd, 0, 0, NULL, NULL);
    psh.dwSize = sizeof(psh);
    psh.dwFlags = (PSH_PROPTITLE | PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP);
    psh.hInstance = g_hinst;
    psh.pszCaption = szTitle;
    psh.nPages = 1;
    psh.nStartPage = 0;
    psh.ppsp = &psp;

    psp.dwSize = sizeof(psp);
    psp.dwFlags = PSP_DEFAULT;
    psp.hInstance = g_hinst;
    psp.pszTemplate = MAKEINTRESOURCE(IDD_FILEPROP);
    psp.pfnDlgProc = CFtpProp::DlgProc;
    psp.lParam = (LPARAM)this;

    PropertySheet(&psh);

    this->Release();
    FTPDebugMemLeak(DML_TYPE_THREAD | DML_END);

    SHOleUninitialize(hrOleInit);
    return 0;
}


/*****************************************************************************\
 *    CFtpProp_DoProp
 *
 *    Display a property sheet with stuff in it.
\*****************************************************************************/
HRESULT CFtpProp_DoProp(CFtpPidlList * pflHfpl, CFtpFolder * pff, HWND hwnd)
{
    CFtpProp * pfp;
    HRESULT hres = CFtpProp_Create(pflHfpl, pff, hwnd, &pfp);

    if (EVAL(SUCCEEDED(hres)))
    {
        HANDLE hThread;
        DWORD id;

        hThread = CreateThread(0, 0, CFtpProp::_PropertySheetThreadProc, (LPVOID) pfp, 0, &id);
        if (EVAL(hThread))
        {
            // It will release it self if the thread was created.
            CloseHandle(hThread);
            hres = S_OK;
        }
        else
        {
            pfp->Release();
            hres = E_UNEXPECTED;
        }
    }

    return hres;
}


/*****************************************************************************\
 *    CFtpProp_Create
 *
 *    Display a property sheet with stuff in it.
\*****************************************************************************/
HRESULT CFtpProp_Create(CFtpPidlList * pflHfpl, CFtpFolder * pff, HWND hwnd, CFtpProp ** ppfp)
{
    HRESULT hr = E_OUTOFMEMORY;
    CFtpProp * pfp;

    pfp = *ppfp = new CFtpProp();
    if (EVAL(pfp))
    {
        pfp->m_pff = pff;
        if (pff)
            pff->AddRef();

        pfp->m_pflHfpl = pflHfpl;
        if (pflHfpl)
            pflHfpl->AddRef();

        pfp->m_hwnd = hwnd;

        hr = S_OK;
    }

    return hr;
}



/****************************************************\
    Constructor
\****************************************************/
CFtpProp::CFtpProp() : m_cRef(1)
{
    DllAddRef();

    // This needs to be allocated in Zero Inited Memory.
    // Assert that all Member Variables are inited to Zero.
    ASSERT(!m_pff);
    ASSERT(!m_hwnd);

    LEAK_ADDREF(LEAK_CFtpProp);
}


/****************************************************\
    Destructor
\****************************************************/
CFtpProp::~CFtpProp()
{
    IUnknown_Set(&m_pff, NULL);
    IUnknown_Set(&m_pflHfpl, NULL);

    DllRelease();
    LEAK_DELREF(LEAK_CFtpProp);
}


//===========================
// *** IUnknown Interface ***
//===========================

ULONG CFtpProp::AddRef()
{
    m_cRef++;
    return m_cRef;
}

ULONG CFtpProp::Release()
{
    ASSERT(m_cRef > 0);
    m_cRef--;

    if (m_cRef > 0)
        return m_cRef;

    delete this;
    return 0;
}

HRESULT CFtpProp::QueryInterface(REFIID riid, void **ppvObj)
{
    if (IsEqualIID(riid, IID_IUnknown))
    {
        *ppvObj = SAFECAST(this, IUnknown *);
    }
    else
    {
        TraceMsg(TF_FTPQI, "CFtpProp::QueryInterface() failed.");
        *ppvObj = NULL;
        return E_NOINTERFACE;
    }

    AddRef();
    return S_OK;
}

⌨️ 快捷键说明

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