예제 #1
0
HRESULT CBasePropSetter::AddPropFromWindowText(HWND hwnd, const TCHAR* szName)
{
   TCHAR *tszProp = 0;
                
    AllocGetWindowText(hwnd, &tszProp);

    if (tszProp == 0)
    {
        return E_OUTOFMEMORY;
    }

    Add(szName, tszProp);
    CoTaskMemFree(tszProp);
    return S_OK;
}
예제 #2
0
//  Dialog proc for the "Open URL" dialog.
INT_PTR CALLBACK OpenUrlDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    static OpenUrlDialogInfo *pUrl = NULL;

    BOOL result = FALSE;

    switch (message)
    {
    case WM_INITDIALOG:
        // The caller sends a pointer to an OpenUrlDialogInfo structure as the 
        // lParam. This structure stores the URL.
        pUrl = (OpenUrlDialogInfo*)lParam;
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDOK:
            if (pUrl)
            {
                // Get the URL from the edit box in the dialog. This function 
                // allocates memory. The caller must call CoTaskMemAlloc.
                if (SUCCEEDED(AllocGetWindowText(GetDlgItem(hDlg, IDC_EDIT_URL), 
                    &pUrl->pszURL, &pUrl->cch)))
                {
                    result = TRUE;
                }
            }
            EndDialog(hDlg, result ? IDOK : IDABORT);
            break;

        case IDCANCEL:
            EndDialog(hDlg, LOWORD(IDCANCEL));
            break;
        }
        return (INT_PTR)FALSE;
    }
    return (INT_PTR)FALSE;
}
예제 #3
0
INT_PTR CALLBACK CPropSetter::EditDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HWND hList,     // Listbox in the parent dialog
                hEditProp, // Property Name edit box
                hEditVal;  // Property Value edit box 

    static int iSelection; // Current selection in the listbox.
    static CPropSetter *pProp;

    switch (msg) 
    {
        case WM_INITDIALOG:
        {
            pProp = (CPropSetter*)lParam;

            hList = GetDlgItem(GetParent(hDlg), IDC_PROPLIST);
            hEditProp = GetDlgItem(hDlg, IDC_PROPNAME);
            hEditVal = GetDlgItem(hDlg, IDC_PROPVAL);
            iSelection = pProp->m_iSelection;

            if (iSelection == LB_ERR) 
            {
                // We're adding a new property.
                SetWindowText(hDlg, TEXT("Add Property"));
            }
            else 
            {
                // We're editing an existing property. Display the name/value
                USES_CONVERSION;
                SetWindowText(hDlg, TEXT("Edit Property"));
                SetWindowText(hEditProp, OLE2T(pProp->Name(iSelection)));
                SetWindowText(hEditVal, OLE2T(pProp->Val(iSelection)));
            }

            return FALSE;
        }
        
        case WM_COMMAND:
        {
            switch (LOWORD(wParam))
            {
                case IDOK:   // Accept property change or new property
                {
                    TCHAR *tszProp, *tszValue;
                
                    AllocGetWindowText(hEditProp, &tszProp);
                    AllocGetWindowText(hEditVal, &tszValue);
                
                    if (tszProp && tszValue)
                    {
                        if (iSelection == LB_ERR) // Add a new property
                        {
                            pProp->Add(tszProp, tszValue);

                            SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)tszProp);
                            SendMessage(hList, LB_SETCURSEL, pProp->Count() - 1, 0);
                        }
                        else    // Update an existing property
                        {
                            pProp->Update(iSelection, tszProp, tszValue);

                            SendMessage(hList, LB_DELETESTRING, iSelection, 0);
                            SendMessage(hList, LB_INSERTSTRING, iSelection, (LPARAM)tszProp);
                            SendMessage(hList, LB_SETCURSEL, iSelection, 0); 
                        }
                    }

                    CoTaskMemFree(tszProp);
                    CoTaskMemFree(tszValue);
                
                }
                // Fall through

                case IDCANCEL:
                    EndDialog( hDlg, LOWORD(wParam) );
                    break;
            }
        }
        
        default:
            return FALSE;  // Did not handle message
    }

    return TRUE;
}