Annotation of mstools/ole20/samples/ole2ui/convert.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * CONVERT.C
                      3:  *
                      4:  * Implements the OleUIConvert function which invokes the complete
                      5:  * Convert dialog.
                      6:  *
                      7:  * Copyright (c)1992 Microsoft Corporation, All Right Reserved
                      8:  */
                      9: 
                     10: #define STRICT  1
                     11: #include "ole2ui.h"
                     12: #include <stdlib.h>
                     13: #include "common.h"
                     14: #include "utility.h"
                     15: #include "geticon.h"
                     16: #include "regdb.h"
                     17: #include "convert.h" 
                     18: 
                     19: #define CF_CLIPBOARDMIN   0xc000
                     20: #define CF_CLIPBOARDMAX   0xffff
                     21: 
                     22: #define AUXUSERTYPE_SHORTNAME  USERCLASSTYPE_SHORT  // short name
                     23: 
                     24: static char szOLE2DLL[] = "ole2.dll";   // name of OLE 2.0 library
                     25: static char szVanillaDocIcon[] = "DefIcon";
                     26: 
                     27: /*
                     28:  * OleUIConvert
                     29:  *
                     30:  * Purpose:
                     31:  *  Invokes the standard OLE Change Type dialog box allowing the user
                     32:  *  to change the type of the single specified object, or change the
                     33:  *  type of all OLE objects of a specified type.
                     34:  *
                     35:  * Parameters:
                     36:  *  lpCV            LPOLEUICONVERT pointing to the in-out structure
                     37:  *                  for this dialog.
                     38:  *
                     39:  * Return Value:
                     40:  *  UINT            One of the following codes, indicating success or error:
                     41:  *                      OLEUI_SUCCESS           Success
                     42:  *                      OLEUI_ERR_STRUCTSIZE    The dwStructSize value is wrong
                     43:  */
                     44: 
                     45: STDAPI_(UINT) OleUIConvert(LPOLEUICONVERT lpCV)
                     46:     {
                     47:     UINT        uRet;
                     48:     HGLOBAL     hMemDlg=NULL;
                     49: 
                     50:     uRet=UStandardValidation((LPOLEUISTANDARD)lpCV, sizeof(OLEUICONVERT)
                     51:                              , &hMemDlg);
                     52: 
                     53:     if (OLEUI_SUCCESS!=uRet)
                     54:         return uRet;
                     55: 
                     56:     // Validate structure members passed in.
                     57: 
                     58:     if (!IsValidClassID(lpCV->clsid))
                     59:        uRet = OLEUI_CTERR_CLASSIDINVALID;
                     60: 
                     61:     if ( (lpCV->dwFlags & CF_SETCONVERTDEFAULT) 
                     62:          && (!IsValidClassID(lpCV->clsidConvertDefault)) )
                     63:        uRet = OLEUI_CTERR_CLASSIDINVALID;
                     64: 
                     65:     if ( (lpCV->dwFlags & CF_SETACTIVATEDEFAULT) 
                     66:          && (!IsValidClassID(lpCV->clsidActivateDefault)) )
                     67:        uRet = OLEUI_CTERR_CLASSIDINVALID;
                     68: 
                     69:     if ( (lpCV->dvAspect != DVASPECT_ICON) 
                     70:          && (lpCV->dvAspect != DVASPECT_CONTENT) )
                     71:        uRet = OLEUI_CTERR_DVASPECTINVALID;
                     72: 
                     73:     if ( (lpCV->wFormat >= CF_CLIPBOARDMIN) 
                     74:          && (lpCV->wFormat <= CF_CLIPBOARDMAX) )
                     75:     {
                     76:          char szTemp[8];
                     77: 
                     78:          if (0 == GetClipboardFormatName(lpCV->wFormat, (LPSTR)szTemp, 8))
                     79:            uRet = OLEUI_CTERR_CBFORMATINVALID;
                     80:     }
                     81: 
                     82: 
                     83:     if ( (NULL != lpCV->lpszUserType) 
                     84:         && (IsBadReadPtr(lpCV->lpszUserType, 1)) )
                     85:        uRet = OLEUI_CTERR_STRINGINVALID;
                     86: 
                     87: 
                     88:     if (OLEUI_ERR_STANDARDMIN <= uRet)
                     89:         {
                     90:         if (NULL!=hMemDlg)
                     91:             FreeResource(hMemDlg);
                     92: 
                     93:         return uRet;
                     94:         }
                     95: 
                     96:     //Now that we've validated everything, we can invoke the dialog.
                     97:     uRet=UStandardInvocation(ConvertDialogProc, (LPOLEUISTANDARD)lpCV,
                     98:                              hMemDlg, MAKEINTRESOURCE(IDD_CONVERT));
                     99: 
                    100:     return uRet;
                    101:     }
                    102: 
                    103: 
                    104: 
                    105: 
                    106: 
                    107: /*
                    108:  * ConvertDialogProc
                    109:  *
                    110:  * Purpose:
                    111:  *  Implements the OLE Convert dialog as invoked through the
                    112:  *  OleUIConvert function.
                    113:  *
                    114:  * Parameters:
                    115:  *  Standard
                    116:  *
                    117:  * Return Value:
                    118:  *  Standard
                    119:  *
                    120:  */
                    121: 
                    122: BOOL CALLBACK EXPORT ConvertDialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
                    123:     {
                    124:     LPCONVERT           lpCV;
                    125:     UINT                uRet = 0;   
                    126:     OLEUICHANGEICON     ci;
                    127: 
                    128:     //Declare Win16/Win32 compatible WM_COMMAND parameters.
                    129:     COMMANDPARAMS(wID, wCode, hWndMsg);
                    130: 
                    131:     //This will fail under WM_INITDIALOG, where we allocate it.
                    132:     lpCV=(LPCONVERT)LpvStandardEntry(hDlg, iMsg, wParam, lParam, (UINT FAR *)&uRet);
                    133: 
                    134:     //If the hook processed the message, we're done.
                    135:     if (0!=uRet)
                    136:         return (BOOL)uRet;
                    137: 
                    138:     //Process the temination message
                    139:     if (iMsg==uMsgEndDialog)
                    140:     {
                    141:         ConvertCleanup(hDlg, lpCV);
                    142:         StandardCleanup(lpCV, hDlg);
                    143:         EndDialog(hDlg, wParam);
                    144:         return TRUE;
                    145:     }
                    146: 
                    147:     // Process help message from Change Icon
                    148:     if (iMsg == uMsgHelp)
                    149:     {
                    150: 
                    151:       PostMessage(lpCV->lpOCV->hWndOwner, uMsgHelp, wParam, lParam);
                    152:       return FALSE;
                    153: 
                    154:     }
                    155: 
                    156:     switch (iMsg)
                    157:         {
                    158:         case WM_INITDIALOG:
                    159:             FConvertInit(hDlg, wParam, lParam);
                    160:             return TRUE;
                    161: 
                    162:         case WM_COMMAND:
                    163:             switch (wID)
                    164:             {
                    165:                 case IDCV_ACTIVATELIST:
                    166:                 case IDCV_CONVERTLIST:
                    167:                     switch (wCode)
                    168:                     {
                    169:                         case LBN_SELCHANGE:
                    170: 
                    171:                             // Change "Results" window to reflect current selection
                    172:                             SetConvertResults(hDlg, lpCV);
                    173: 
                    174:                             // Update the icon we display, if we are indeed
                    175:                             // displaying an icon.
                    176:                             if ( (lpCV->dwFlags & CF_SELECTCONVERTTO) 
                    177:                                  && (lpCV->dvAspect == DVASPECT_ICON) 
                    178:                                  && (!lpCV->fCustomIcon) )
                    179:                                UpdateCVClassIcon(hDlg, lpCV, hWndMsg);
                    180: 
                    181:                             break;
                    182: 
                    183:                         case LBN_DBLCLK:
                    184:                             //Same as pressing OK.
                    185:                             SendCommand(hDlg, IDOK, BN_CLICKED, hWndMsg);
                    186:                             break;
                    187:                     }
                    188:                     break;
                    189:                     
                    190:                 case IDCV_CONVERTTO:
                    191:                 case IDCV_ACTIVATEAS:
                    192:                 {
                    193:                     HWND    hList, hListInvisible;
                    194:                     LRESULT lRetVal;
                    195:                     BOOL    fState;
                    196: 
                    197:                     hList = lpCV->hListVisible;
                    198:                     hListInvisible = lpCV->hListInvisible;
                    199: 
                    200: 
                    201:                     if (IDCV_CONVERTTO == wParam)
                    202:                     {
                    203: 
                    204:                        // User just click on the button again - it was
                    205:                        // already selected.
                    206:                        if (lpCV->dwFlags & CF_SELECTCONVERTTO)
                    207:                           break;
                    208: 
                    209: 
                    210:                        // Turn painting updates off.
                    211:                        SendMessage(hDlg, WM_SETREDRAW, FALSE, 0L);
                    212: 
                    213: 
                    214:                        // If we're working with a linked object, don't
                    215:                        // add the activate list - just the object's 
                    216:                        // class should appear in the listbox.
                    217: 
                    218:                        SwapWindows(hDlg, 
                    219:                                    hList,
                    220:                                    hListInvisible);
                    221: 
                    222:                        lpCV->hListVisible = hListInvisible;
                    223:                        lpCV->hListInvisible = hList;
                    224: 
                    225:                        EnableWindow(lpCV->hListInvisible, FALSE);  
                    226:                        EnableWindow(lpCV->hListVisible, TRUE);
                    227: 
                    228:                        // Update our flags.
                    229:                        lpCV->dwFlags &= ~CF_SELECTACTIVATEAS;
                    230:                        lpCV->dwFlags |= CF_SELECTCONVERTTO;
                    231: 
                    232:                     }
                    233:                     else
                    234:                     {
                    235:                        if (lpCV->dwFlags & CF_SELECTACTIVATEAS)
                    236:                           break;
                    237: 
                    238:                        // Turn painting updates off.
                    239:                        SendMessage(hDlg, WM_SETREDRAW, FALSE, 0L);
                    240: 
                    241:                        SwapWindows(hDlg, 
                    242:                                    hList,
                    243:                                    hListInvisible);
                    244: 
                    245:                        lpCV->hListVisible = hListInvisible;
                    246:                        lpCV->hListInvisible = hList;
                    247: 
                    248:                        EnableWindow(lpCV->hListInvisible, FALSE);  
                    249:                        EnableWindow(lpCV->hListVisible, TRUE);
                    250: 
                    251: 
                    252:                        // Update our flags.
                    253:                        lpCV->dwFlags |= CF_SELECTACTIVATEAS;
                    254:                        lpCV->dwFlags &= ~CF_SELECTCONVERTTO;
                    255:                     }
                    256:                     
                    257: 
                    258:                     if (lpCV->dwFlags & CF_SELECTCONVERTTO)
                    259:                        lRetVal = SendMessage(lpCV->hListVisible, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)lpCV->lpszConvertDefault);
                    260: 
                    261:                     else
                    262:                        lRetVal = SendMessage(lpCV->hListVisible, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)lpCV->lpszActivateDefault);
                    263: 
                    264:                     if (LB_ERR == lRetVal)
                    265:                     {
                    266:                        char szCurrentObject[40];
                    267: 
                    268:                        GetDlgItemText(hDlg, IDCV_OBJECTTYPE, (LPSTR)szCurrentObject, 40);
                    269:                        SendMessage(lpCV->hListVisible, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)(LPSTR)szCurrentObject);
                    270:                     }
                    271: 
                    272:                     // Turn updates back on.
                    273:                     SendMessage(hDlg, WM_SETREDRAW, TRUE, 0L);
                    274: 
                    275:                     InvalidateRect(lpCV->hListVisible, NULL, TRUE);
                    276:                     UpdateWindow(lpCV->hListVisible);
                    277: 
                    278:                     if ((lpCV->dvAspect & DVASPECT_ICON) && (lpCV->dwFlags & CF_SELECTCONVERTTO))
                    279:                       UpdateCVClassIcon(hDlg, lpCV, lpCV->hListVisible);
                    280: 
                    281:                     // Hide the icon stuff when Activate is selected...show
                    282:                     // it again when Convert is selected.
                    283: 
                    284:                     fState = (lpCV->dwFlags & CF_SELECTACTIVATEAS) ? SW_HIDE : SW_SHOW;
                    285: 
                    286:                     StandardShowDlgItem(hDlg, IDCV_DISPLAYASICON, fState);
                    287:                     StandardShowDlgItem(hDlg, IDCV_CHANGEICON, fState);
                    288: 
                    289:                     // Only display the icon if convert is selected AND display
                    290:                     // as icon is checked.
                    291:                     if ((SW_SHOW == fState) && (DVASPECT_ICON != lpCV->dvAspect))
                    292:                        fState = SW_HIDE;
                    293: 
                    294:                     StandardShowDlgItem(hDlg, IDCV_ICON, fState);
                    295:                     StandardShowDlgItem(hDlg, IDCV_ICONLABEL1, fState);
                    296:                     StandardShowDlgItem(hDlg, IDCV_ICONLABEL2, fState);
                    297: 
                    298:                   SetConvertResults(hDlg, lpCV);
                    299: 
                    300:                 }
                    301:                 break;
                    302: 
                    303: 
                    304:                 case IDOK:
                    305:                 {
                    306: 
                    307:                     WORD  iCurSel;
                    308:                     LPSTR lpszCLSID;
                    309:                     char  szBuffer[256]; 
                    310: 
                    311:                     // Set OUT parameters
                    312: 
                    313:                     //
                    314:                     // Set output flags to current ones
                    315:                     //
                    316:                     lpCV->lpOCV->dwFlags = lpCV->dwFlags;
                    317: 
                    318: 
                    319:                     // Update the dvAspect and fObjectsIconChanged members
                    320:                     // as appropriate.
                    321:                     //
                    322:                     if (lpCV->dwFlags & CF_SELECTACTIVATEAS)
                    323:                     {
                    324:                       // DON'T update aspect if activate as was selected.
                    325:                       lpCV->lpOCV->fObjectsIconChanged = FALSE;
                    326:                     }
                    327:                     else
                    328:                       lpCV->lpOCV->dvAspect = lpCV->dvAspect;
                    329: 
                    330: 
                    331:                     //
                    332:                     // Get the new clsid
                    333:                     //
                    334:                     iCurSel = (WORD)SendMessage(lpCV->hListVisible, LB_GETCURSEL, 0, 0);
                    335:                     SendMessage(lpCV->hListVisible, LB_GETTEXT, iCurSel, (LPARAM)(LPSTR)szBuffer);
                    336: 
                    337:                     lpszCLSID = PointerToNthField((LPSTR)szBuffer, 2, '\t');
                    338: 
                    339:                     CLSIDFromString(lpszCLSID, (LPCLSID)(&(lpCV->lpOCV->clsidNew)));
                    340: 
                    341: 
                    342: 
                    343:                     // Free the hMetaPict we got in.
                    344:                     OleUIMetafilePictIconFree(lpCV->lpOCV->hMetaPict);
                    345: 
                    346:                     //
                    347:                     // Get the hMetaPict (if display as icon is checked)
                    348:                     //
                    349:                     if (DVASPECT_ICON == lpCV->dvAspect)
                    350:                     {
                    351:                        HICON hIcon;
                    352:                        char  szLabel[OLEUI_CCHLABELMAX];
                    353:                        int   Index;
                    354: 
                    355: 
                    356:                        // Create the hMetaPict here from icon, label,
                    357:                        // index, and path
                    358: 
                    359:                        hIcon = (HICON)SendDlgItemMessage(hDlg, IDCV_ICON, STM_GETICON, 0, 0L);
                    360: 
                    361:                        // the combined length of the 2 label lines won't ever be more than
                    362:                        // OLEUI_CCHLABELMAX.
                    363:                        Index = (int)SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, WM_GETTEXT, OLEUI_CCHLABELMAX, (LPARAM)(LPSTR)szLabel);
                    364: 
                    365:                        if (Index < OLEUI_CCHLABELMAX)
                    366:                        {
                    367:                           LPSTR lpszSecondLine = szLabel + Index;
                    368:                        
                    369: 
                    370:                           SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_GETTEXT, 
                    371:                                              OLEUI_CCHLABELMAX-Index, 
                    372:                                              (LPARAM)(LPSTR)lpszSecondLine);
                    373:                        }
                    374:                        lpCV->lpOCV->hMetaPict = 
                    375:                              OleUIMetafilePictFromIconAndLabel(hIcon, 
                    376:                                                                (LPSTR)szLabel, 
                    377:                                                                lpCV->lpszIconSource, 
                    378:                                                                lpCV->IconIndex);
                    379: 
                    380:                     }
                    381:                     else
                    382:                        lpCV->lpOCV->hMetaPict = (HGLOBAL)NULL;
                    383: 
                    384: 
                    385:                     //
                    386:                     // End the dialog
                    387:                     //
                    388:                     SendMessage(hDlg, uMsgEndDialog, OLEUI_OK, 0L);
                    389:                 }
                    390:                 break;
                    391: 
                    392:                 case IDCANCEL:
                    393:                     SendMessage(hDlg, uMsgEndDialog, OLEUI_CANCEL, 0L);
                    394:                     break;
                    395: 
                    396: 
                    397:                 case IDCV_HELP:
                    398:                     PostMessage(lpCV->lpOCV->hWndOwner, 
                    399:                                 uMsgHelp, (WPARAM)hDlg, MAKELPARAM(IDD_CONVERT, 0));
                    400:                     break;
                    401:                 
                    402:                 case IDCV_DISPLAYASICON:
                    403:                 {
                    404: 
                    405:                     int i;
                    406:                     BOOL fCheck;
                    407:                     
                    408:                     fCheck=IsDlgButtonChecked(hDlg, wID);
                    409:                     
                    410:                     if (fCheck)
                    411:                         lpCV->dvAspect = DVASPECT_ICON;
                    412:                     else
                    413:                         lpCV->dvAspect = DVASPECT_CONTENT;
                    414: 
                    415:                     if (fCheck && (!lpCV->fCustomIcon))
                    416:                        UpdateCVClassIcon(hDlg, lpCV, lpCV->hListVisible);
                    417: 
                    418:                     //Show or hide the icon depending on the check state.
                    419: 
                    420:                     i=(fCheck) ? SW_SHOWNORMAL : SW_HIDE;
                    421: 
                    422:                     StandardShowDlgItem(hDlg, IDCV_CHANGEICON, i);
                    423:                     StandardShowDlgItem(hDlg, IDCV_ICON, i);
                    424:                     StandardShowDlgItem(hDlg, IDCV_ICONLABEL1, i);
                    425:                     StandardShowDlgItem(hDlg, IDCV_ICONLABEL2, i);
                    426: 
                    427:                     SetConvertResults(hDlg, lpCV);
                    428: 
                    429:                 }
                    430:                 break;
                    431: 
                    432:                 case IDCV_CHANGEICON:
                    433:                 {
                    434:                     LPMALLOC pIMalloc;
                    435:                     LPSTR    pszString, pszCLSID;
                    436:                     int      iSel;
                    437:                     HICON    hIcon;
                    438:                     char     szLabel[OLEUI_CCHLABELMAX];
                    439:                     int      Index;
                    440: 
                    441: 
                    442:                     //Initialize the structure for the hook.
                    443:                     _fmemset((LPOLEUICHANGEICON)&ci, 0, sizeof(ci));
                    444: 
                    445: 
                    446:                     // Create the hMetaPict here from icon, label,
                    447:                     // index, and path
                    448: 
                    449:                     hIcon = (HICON)SendDlgItemMessage(hDlg, IDCV_ICON, STM_GETICON, 0, 0L);
                    450: 
                    451:                     // the combined length of the 2 label lines won't ever be more than
                    452:                     // OLEUI_CCHLABELMAX.
                    453: 
                    454:                     Index = (int)SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, WM_GETTEXT, OLEUI_CCHLABELMAX, (LPARAM)(LPSTR)szLabel);
                    455: 
                    456:                     if (Index < OLEUI_CCHLABELMAX)
                    457:                     {
                    458:                        LPSTR    lpszSecondLine;
                    459: 
                    460:                        lpszSecondLine = szLabel + Index;
                    461: 
                    462:                        SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_GETTEXT, 
                    463:                                           OLEUI_CCHLABELMAX-Index, 
                    464:                                           (LPARAM)(LPSTR)lpszSecondLine);
                    465:                     }
                    466: 
                    467:                     ci.hMetaPict = 
                    468:                           OleUIMetafilePictFromIconAndLabel(hIcon, 
                    469:                                                             (LPSTR)szLabel, 
                    470:                                                             lpCV->lpszIconSource, 
                    471:                                                             lpCV->IconIndex);
                    472: 
                    473:                     ci.cbStruct =sizeof(ci);
                    474:                     ci.hWndOwner=hDlg; 
                    475:                     ci.dwFlags  = CIF_SELECTCURRENT;
                    476: 
                    477:                     // Only show help if we're showing it for this dialog.
                    478:                     if (lpCV->dwFlags & CF_SHOWHELPBUTTON)
                    479:                       ci.dwFlags  |= CIF_SHOWHELP;
                    480: 
                    481:                     iSel = (int)SendMessage(lpCV->hListVisible, LB_GETCURSEL, 0, 0L);
                    482: 
                    483:                     CoGetMalloc(MEMCTX_TASK, &pIMalloc);
                    484: 
                    485:                     pszString = (LPSTR)pIMalloc->lpVtbl->Alloc(pIMalloc, OLEUI_CCHLABELMAX + OLEUI_CCHCLSIDSTRING);
                    486: 
                    487:                     // Get whole string
                    488:                     SendMessage(lpCV->hListVisible, LB_GETTEXT, iSel, (LONG)pszString);
                    489: 
                    490:                     // Set pointer to CLSID (string)
                    491:                     pszCLSID = PointerToNthField(pszString, 2, '\t');
                    492: 
                    493:                     // Get the clsid to pass to change icon.
                    494:                     CLSIDFromString((LPSTR)pszCLSID, (LPCLSID)&(ci.clsid));
                    495: 
                    496:                     pIMalloc->lpVtbl->Free(pIMalloc, (LPVOID)pszString);
                    497:                     pIMalloc->lpVtbl->Release(pIMalloc);
                    498: 
                    499:                     //Let the hook in to customize Change Icon if desired.
                    500:                     uRet=UStandardHook(lpCV, hDlg, uMsgChangeIcon
                    501:                                        , 0, (LONG)(LPSTR)&ci);
                    502: 
                    503:                     if (0==uRet)
                    504:                         uRet=(UINT)(OLEUI_OK==OleUIChangeIcon((LPOLEUICHANGEICON)&ci));
                    505:                       
                    506:                     //Update the display if necessary.
                    507:                     if (0!=uRet)
                    508:                     {
                    509:                         HICON hIcon;
                    510:                         char  szLabel[OLEUI_CCHLABELMAX];
                    511:                         DWORD dwWrapIndex;
                    512: 
                    513: 
                    514:                         hIcon = OleUIMetafilePictExtractIcon(ci.hMetaPict);
                    515: 
                    516:                         SendDlgItemMessage(hDlg, IDCV_ICON, STM_SETICON, (WPARAM)hIcon, 0L);
                    517: 
                    518:                         OleUIMetafilePictExtractIconSource(ci.hMetaPict, lpCV->lpszIconSource, &(lpCV->IconIndex));
                    519: 
                    520:                         OleUIMetafilePictExtractLabel(ci.hMetaPict, szLabel, OLEUI_CCHLABELMAX, &dwWrapIndex);
                    521: 
                    522:                         if (0 == dwWrapIndex)  // no second line
                    523:                         {
                    524:                            SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                    525:                            SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_SETTEXT, 0, (LPARAM)(LPSTR)"");
                    526:                         }
                    527:                         else
                    528:                         {
                    529:                            
                    530:                            LPSTR lpszSecondLine;
                    531: 
                    532:                            lpszSecondLine = szLabel + dwWrapIndex;
                    533:                            SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, 
                    534:                                               WM_SETTEXT, 0, (LPARAM)lpszSecondLine);
                    535: 
                    536:                            *lpszSecondLine = '\0';
                    537:                            SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, 
                    538:                                               WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                    539:                         }
                    540: 
                    541: 
                    542:                         // Update our custom/default flag
                    543: 
                    544:                         if (ci.dwFlags & CIF_SELECTDEFAULT)
                    545:                            lpCV->fCustomIcon = FALSE;   // we're in default mode (icon changes on each LB selchange)
                    546:                         else if (ci.dwFlags & CIF_SELECTFROMFILE)
                    547:                            lpCV->fCustomIcon = TRUE;    // we're in custom mode (icon doesn't change)
                    548:                         // no change in fCustomIcon if user selected current
                    549: 
                    550: 
                    551:                         lpCV->lpOCV->fObjectsIconChanged = TRUE;
                    552:                     }
                    553:                 }
                    554:                 break;
                    555:                 
                    556:             }
                    557:             break;
                    558:         }
                    559:     return FALSE;
                    560:     }
                    561: 
                    562: 
                    563: /*
                    564:  * FConvertInit
                    565:  *
                    566:  * Purpose:
                    567:  *  WM_INITIDIALOG handler for the Convert dialog box.
                    568:  *
                    569:  * Parameters:
                    570:  *  hDlg            HWND of the dialog
                    571:  *  wParam          WPARAM of the message
                    572:  *  lParam          LPARAM of the message
                    573:  *
                    574:  * Return Value:
                    575:  *  BOOL            Value to return for WM_INITDIALOG.
                    576:  */
                    577: 
                    578: BOOL FConvertInit(HWND hDlg, WPARAM wParam, LPARAM lParam)
                    579:     {
                    580:     LPCONVERT              lpCV;
                    581:     LPOLEUICONVERT         lpOCV;
                    582:     LPMALLOC               pIMalloc;
                    583:     HFONT                  hFont;  // non-bold version of dialog's font
                    584:     RECT                   rc;
                    585:     DWORD                  dw;
                    586:     int                    cItemsActivate;
                    587:     HKEY                   hKey;
                    588:     LONG                   lRet;
                    589: 
                    590: 
                    591:     //Copy the structure at lParam into our instance memory.
                    592:     lpCV=(LPCONVERT)LpvStandardInit(hDlg, sizeof(CONVERT), TRUE, (HFONT FAR *)&hFont);
                    593: 
                    594:     //PvStandardInit send a termination to us already.
                    595:     if (NULL==lpCV)
                    596:         return FALSE;
                    597: 
                    598:     lpOCV=(LPOLEUICONVERT)lParam;
                    599: 
                    600:     lpCV->lpOCV=lpOCV;
                    601: 
                    602:     lpCV->fCustomIcon = FALSE;
                    603: 
                    604:     //Copy other information from lpOCV that we might modify.
                    605:     lpCV->dwFlags = lpOCV->dwFlags;
                    606:     lpCV->clsid = lpOCV->clsid;
                    607:     lpCV->dvAspect = lpOCV->dvAspect;
                    608:     lpCV->hListVisible = GetDlgItem(hDlg, IDCV_ACTIVATELIST);
                    609:     lpCV->hListInvisible = GetDlgItem(hDlg, IDCV_CONVERTLIST);
                    610:     lpCV->lpszCurrentObject = lpOCV->lpszUserType;
                    611: 
                    612:     lpOCV->clsidNew = CLSID_NULL;
                    613: 
                    614:     lpOCV->fObjectsIconChanged = FALSE;
                    615: 
                    616:     //Allocate space for our strings
                    617:     if (NOERROR != CoGetMalloc(MEMCTX_TASK, &pIMalloc))
                    618:        return FALSE;
                    619: 
                    620:     lpCV->lpszConvertDefault = (LPSTR)pIMalloc->lpVtbl->Alloc(pIMalloc, OLEUI_CCHLABELMAX);
                    621:     lpCV->lpszActivateDefault = (LPSTR)pIMalloc->lpVtbl->Alloc(pIMalloc, OLEUI_CCHLABELMAX);
                    622:     lpCV->lpszIconSource = (LPSTR)pIMalloc->lpVtbl->Alloc(pIMalloc, OLEUI_CCHPATHMAX);
                    623: 
                    624:     //If we got a font, send it to the necessary controls.
                    625:     if (NULL!=hFont)
                    626:         {
                    627:         SendDlgItemMessage(hDlg, IDCV_OBJECTTYPE, WM_SETFONT, (WPARAM)hFont, 0L);
                    628:         SendDlgItemMessage(hDlg, IDCV_RESULTTEXT, WM_SETFONT, (WPARAM)hFont, 0L);
                    629:         SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, WM_SETFONT, (WPARAM)hFont, 0L);
                    630:         SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_SETFONT, (WPARAM)hFont, 0L);
                    631:         }
                    632: 
                    633:     //Hide the help button if necessary
                    634:     if (!(lpCV->dwFlags & CF_SHOWHELPBUTTON))
                    635:         StandardShowDlgItem(hDlg, IDCV_HELP, SW_HIDE);      
                    636: 
                    637:     //Fill the Object Type listbox with entries from the reg DB.
                    638:     FillClassList(lpOCV->clsid, 
                    639:                   lpCV->hListVisible, 
                    640:                   lpCV->hListInvisible, 
                    641:                   &(lpCV->lpszCurrentObject),
                    642:                   lpOCV->fIsLinkedObject,
                    643:                   lpOCV->wFormat);
                    644: 
                    645:     // Set the name of the current object.
                    646:     SetDlgItemText(hDlg, IDCV_OBJECTTYPE, (LPSTR)lpCV->lpszCurrentObject);
                    647: 
                    648:     // Disable the "Activate As" button if the Activate list doesn't
                    649:     // have any objects in it.
                    650: 
                    651:     cItemsActivate = (int)SendMessage(lpCV->hListVisible, LB_GETCOUNT, 0, 0L);
                    652: 
                    653:     if (1 >= cItemsActivate)  
                    654:       EnableWindow(GetDlgItem(hDlg, IDCV_ACTIVATEAS), FALSE);
                    655: 
                    656:     //Set the tab width in the list to push all the tabs off the side.
                    657:     GetClientRect(lpCV->hListVisible, (LPRECT)&rc);
                    658:     dw=GetDialogBaseUnits();
                    659:     rc.right =(8*rc.right)/LOWORD(dw);  //Convert pixels to 2x dlg units.
                    660:     SendMessage(lpCV->hListVisible, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)(&rc.right));
                    661:     SendMessage(lpCV->hListInvisible, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)(&rc.right));
                    662: 
                    663: 
                    664:     // Make sure that either "Convert To" or "Activate As" is selected
                    665:     // and initialize listbox contents and selection accordingly
                    666:     if (lpCV->dwFlags & CF_SELECTACTIVATEAS)
                    667:     {
                    668:       // Don't need to adjust listbox here because FillClassList 
                    669:       // initializes to the "Activate As" state.
                    670:        CheckRadioButton(hDlg, IDCV_CONVERTTO, IDCV_ACTIVATEAS, IDCV_ACTIVATEAS);
                    671: 
                    672:        // Hide the icon stuff when Activate is selected...it gets shown
                    673:        // again when Convert is selected.
                    674: 
                    675:        StandardShowDlgItem(hDlg, IDCV_DISPLAYASICON, SW_HIDE);
                    676:        StandardShowDlgItem(hDlg, IDCV_CHANGEICON, SW_HIDE);
                    677:        StandardShowDlgItem(hDlg, IDCV_ICON, SW_HIDE);
                    678:        StandardShowDlgItem(hDlg, IDCV_ICONLABEL1, SW_HIDE);
                    679:        StandardShowDlgItem(hDlg, IDCV_ICONLABEL2, SW_HIDE);
                    680:     }
                    681:     else
                    682:     {
                    683:       // Default case.  If user hasn't selected either flag, we will
                    684:       // come here anyway.  
                    685:       // swap listboxes.
                    686: 
                    687:       HWND hWndTemp = lpCV->hListVisible;
                    688: 
                    689: 
                    690:       lpCV->dwFlags |= CF_SELECTCONVERTTO; // Make sure flag is set
                    691:       CheckRadioButton(hDlg, IDCV_CONVERTTO, IDCV_ACTIVATEAS, IDCV_CONVERTTO);
                    692: 
                    693:       SwapWindows(hDlg, lpCV->hListVisible, lpCV->hListInvisible);
                    694: 
                    695:       lpCV->hListVisible = lpCV->hListInvisible;
                    696:       lpCV->hListInvisible = hWndTemp;
                    697: 
                    698:       EnableWindow(lpCV->hListInvisible, FALSE);  
                    699:       EnableWindow(lpCV->hListVisible, TRUE);
                    700:     }
                    701:     
                    702: 
                    703:   
                    704:     // Initialize Default strings.
                    705: 
                    706:     // Default convert string is easy...just user the user type name from
                    707:     // the clsid we got, or the current object
                    708:     if ( (lpCV->dwFlags & CF_SETCONVERTDEFAULT)
                    709:          && (IsValidClassID(lpCV->lpOCV->clsidConvertDefault)) )
                    710:     {
                    711:         dw = OleStdGetUserTypeOfClass((LPCLSID)(&lpCV->lpOCV->clsidConvertDefault),
                    712:                                       lpCV->lpszConvertDefault,
                    713:                                       OLEUI_CCHLABELMAX,
                    714:                                       NULL);
                    715: 
                    716:         if (0 == dw)
                    717:            lstrcpy((LPSTR)lpCV->lpszConvertDefault, (LPSTR)lpCV->lpszCurrentObject);
                    718:     }
                    719:     else
                    720:         lstrcpy((LPSTR)lpCV->lpszConvertDefault, (LPSTR)lpCV->lpszCurrentObject);
                    721: 
                    722: 
                    723: 
                    724:    // Default activate is a bit trickier.  We want to use the user type 
                    725:    // name if from the clsid we got (assuming we got one), or the current
                    726:    // object if it fails or we didn't get a clsid.  But...if there's a 
                    727:    // Treat As entry in the reg db, then we use that instead.  So... the 
                    728:    // logic boils down to this:
                    729:    //
                    730:    // if ("Treat As" in reg db)
                    731:    //    use it;
                    732:    // else
                    733:    //    if (CF_SETACTIVATEDEFAULT)
                    734:    //      use it;
                    735:    //    else
                    736:    //      use current object;
                    737: 
                    738: 
                    739: 
                    740:     lRet = RegOpenKey(HKEY_CLASSES_ROOT, "CLSID", (HKEY FAR *)&hKey);
                    741: 
                    742:     if (lRet != ERROR_SUCCESS)
                    743:       goto CheckInputFlag;
                    744: 
                    745:     else
                    746:     {
                    747:        LPSTR lpszCLSID;
                    748:        char  szKey[OLEUI_CCHKEYMAX];
                    749:        CLSID clsid;
                    750:        char  szValue[OLEUI_CCHKEYMAX];
                    751: 
                    752:        StringFromCLSID(&(lpCV->lpOCV->clsid), &lpszCLSID);
                    753:        lstrcpy(szKey, lpszCLSID);
                    754:        lstrcat(szKey, (LPSTR)"\\TreatAs");
                    755: 
                    756:        dw = OLEUI_CCHKEYMAX;
                    757:        lRet = RegQueryValue(hKey, (LPSTR)szKey, (LPSTR)szValue, (LPDWORD)&dw);
                    758: 
                    759:        if (lRet != ERROR_SUCCESS)
                    760:        {
                    761:           
                    762:           RegCloseKey(hKey);
                    763:           OleStdFreeString(lpszCLSID, NULL);
                    764:           goto CheckInputFlag;
                    765:        }
                    766:        else
                    767:        {
                    768:           CLSIDFromString((LPSTR)szValue, &clsid);
                    769:           if (0 == OleStdGetUserTypeOfClass(&clsid, 
                    770:                                    lpCV->lpszActivateDefault, 
                    771:                                    OLEUI_CCHLABELMAX,
                    772:                                    NULL))
                    773:           {
                    774:              RegCloseKey(hKey);
                    775:              OleStdFreeString(lpszCLSID, NULL);
                    776:              goto CheckInputFlag;
                    777:           }
                    778:        }
                    779:        RegCloseKey(hKey);
                    780:        OleStdFreeString(lpszCLSID, NULL);
                    781:        goto SelectStringInListbox;
                    782:     }
                    783: 
                    784: 
                    785: CheckInputFlag:
                    786:     if ( (lpCV->dwFlags & CF_SETACTIVATEDEFAULT)
                    787:          && (IsValidClassID(lpCV->lpOCV->clsidActivateDefault)) )
                    788:     {
                    789:         dw = OleStdGetUserTypeOfClass((LPCLSID)(&lpCV->lpOCV->clsidActivateDefault),
                    790:                                       lpCV->lpszActivateDefault,
                    791:                                       OLEUI_CCHLABELMAX,
                    792:                                       NULL);
                    793: 
                    794:         if (0 == dw)
                    795:            lstrcpy((LPSTR)lpCV->lpszActivateDefault, (LPSTR)lpCV->lpszCurrentObject);
                    796:     }
                    797:     else
                    798:         lstrcpy((LPSTR)(lpCV->lpszActivateDefault), (LPSTR)lpCV->lpszCurrentObject);
                    799: 
                    800:    
                    801: SelectStringInListbox:
                    802: 
                    803:     if (lpCV->dwFlags & CF_SELECTCONVERTTO)
                    804:        lRet = SendMessage(lpCV->hListVisible, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)(LPSTR)(lpCV->lpszConvertDefault));
                    805: 
                    806:     else
                    807:        lRet = SendMessage(lpCV->hListVisible, LB_SELECTSTRING, (WPARAM)-1, (LPARAM)(LPSTR)(lpCV->lpszActivateDefault));
                    808: 
                    809:     if (LB_ERR == lRet)
                    810:        SendMessage(lpCV->hListVisible, LB_SETCURSEL, (WPARAM)0, 0L);
                    811: 
                    812:   
                    813:     // Initialize icon stuff
                    814:     if (DVASPECT_ICON == lpCV->dvAspect )  
                    815:     {      
                    816:       SendDlgItemMessage(hDlg, IDCV_DISPLAYASICON, BM_SETCHECK, TRUE, 0L);
                    817: 
                    818:       if ((HGLOBAL)NULL != lpOCV->hMetaPict)
                    819:       {
                    820:          char  szLabel[OLEUI_CCHLABELMAX];
                    821:          HICON hIcon;
                    822:          DWORD dwWrapIndex;
                    823: 
                    824: 
                    825:          // Set the icon to the icon from the hMetaPict,
                    826:          // set the label to the label from the hMetaPict.
                    827: 
                    828:          if (0 != OleUIMetafilePictExtractLabel(lpOCV->hMetaPict, (LPSTR)szLabel, OLEUI_CCHLABELMAX, &dwWrapIndex))
                    829:          {
                    830:              if (0 == dwWrapIndex)  // no second line
                    831:              {
                    832:                 SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                    833:                 SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_SETTEXT, 0, (LPARAM)(LPSTR)"");
                    834:              }
                    835:              else
                    836:              {
                    837:                 
                    838:                 LPSTR lpszSecondLine;
                    839: 
                    840:                 lpszSecondLine = szLabel + dwWrapIndex;
                    841:                 SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, 
                    842:                                    WM_SETTEXT, 0, (LPARAM)lpszSecondLine);
                    843: 
                    844:                 *lpszSecondLine = '\0';
                    845:                 SendDlgItemMessage(hDlg, IDCV_ICONLABEL1, 
                    846:                                    WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                    847:              }
                    848: 
                    849: 
                    850:          }
                    851: 
                    852:          hIcon = OleUIMetafilePictExtractIcon(lpOCV->hMetaPict);
                    853: 
                    854:          if (NULL != hIcon)
                    855:          {
                    856:            SendDlgItemMessage(hDlg, IDCV_ICON, STM_SETICON, (WPARAM)hIcon, 0L);
                    857:            lpCV->fCustomIcon = TRUE;
                    858:          }
                    859: 
                    860:          OleUIMetafilePictExtractIconSource(lpOCV->hMetaPict, 
                    861:                                             (LPSTR)(lpCV->lpszIconSource), 
                    862:                                             &(lpCV->IconIndex));
                    863: 
                    864:       }
                    865:       else
                    866:          UpdateCVClassIcon(hDlg, lpCV, lpCV->hListVisible);
                    867:     }
                    868:     else 
                    869:     {  
                    870:       // Hide & disable icon stuff
                    871:       StandardShowDlgItem(hDlg, IDCV_ICON, SW_HIDE);
                    872:       StandardShowDlgItem(hDlg, IDCV_ICONLABEL1, SW_HIDE);
                    873:       StandardShowDlgItem(hDlg, IDCV_ICONLABEL2, SW_HIDE);
                    874:       StandardShowDlgItem(hDlg, IDCV_CHANGEICON, SW_HIDE);
                    875:     }
                    876: 
                    877:     // Call the hook with lCustData in lParam
                    878:     UStandardHook((LPVOID)lpCV, hDlg, WM_INITDIALOG, wParam, lpOCV->lCustData);
                    879: 
                    880:     // Update results window
                    881:     SetConvertResults(hDlg, lpCV);
                    882:     
                    883:     // Update caption if lpszCaption was specified
                    884:     if (lpCV->lpOCV->lpszCaption && !IsBadReadPtr(lpCV->lpOCV->lpszCaption, 1)
                    885:           && lpCV->lpOCV->lpszCaption[0] != '\0')
                    886:         SetWindowText(hDlg, (LPSTR)lpCV->lpOCV->lpszCaption);
                    887: 
                    888:     return TRUE;
                    889:     }
                    890: 
                    891: 
                    892: /*
                    893:  * FillClassList
                    894:  *
                    895:  * Purpose:
                    896:  *  Enumerates available OLE object classes from the registration
                    897:  *  database that we can convert or activate the specified clsid from.
                    898:  *
                    899:  *  Note that this function removes any prior contents of the listbox.
                    900:  *
                    901:  * Parameters:
                    902:  *  clsid           Class ID for class to find convert classes for
                    903:  *  hList           HWND to the listbox to fill.
                    904:  *  hListActivate   HWND to invisible listbox that stores "activate as" list.
                    905:  *  lpszClassName   LPSTR to put the (hr) class name of the clsid; we
                    906:  *                  do it here since we've already got the reg db open.       
                    907:  *  wFormat         WORD specifying the format of the original class.
                    908:  *
                    909:  * Return Value:                       
                    910:  *  UINT            Number of strings added to the listbox, -1 on failure.
                    911:  */
                    912: 
                    913: UINT FillClassList(CLSID clsid, HWND hList, HWND hListInvisible, LPSTR FAR *lplpszCurrentClass, BOOL fIsLinkedObject, WORD wFormat)
                    914: {
                    915: 
                    916:     DWORD       dw;
                    917:     UINT        cStrings=0;
                    918:     HKEY        hKey;
                    919:     LONG        lRet;
                    920:     char        szFormatKey[OLEUI_CCHKEYMAX];
                    921:     char        szClass[OLEUI_CCHKEYMAX];    
                    922:     char        szFormat[OLEUI_CCHKEYMAX];   
                    923:     char        szHRClassName[OLEUI_CCHKEYMAX];
                    924: 
                    925:     LPSTR       lpszCLSID;
                    926: 
                    927: 
                    928:     //Clean out the existing strings.
                    929:     SendMessage(hList, LB_RESETCONTENT, 0, 0L);
                    930:     SendMessage(hListInvisible, LB_RESETCONTENT, 0, 0L);
                    931: 
                    932:     //Open up the root key.
                    933:     lRet=RegOpenKey(HKEY_CLASSES_ROOT, (LPSTR)"CLSID", (HKEY FAR *)&hKey);
                    934: 
                    935:     if ((LONG)ERROR_SUCCESS!=lRet)
                    936:         return (UINT)-1;
                    937: 
                    938:     if (NULL == *lplpszCurrentClass)
                    939:     {
                    940:        // alloc buffer here...
                    941: 
                    942:         LPMALLOC pIMalloc = NULL;
                    943:         HRESULT  hrErr;
                    944: 
                    945: 
                    946:         hrErr = CoGetMalloc(MEMCTX_TASK, &pIMalloc);
                    947: 
                    948:         if (hrErr != NOERROR)
                    949:         {
                    950:             RegCloseKey(hKey);
                    951:             return FALSE;
                    952:         }
                    953: 
                    954:         // Allocate space for lpszCurrentClass
                    955:         *lplpszCurrentClass = (LPSTR)pIMalloc->lpVtbl->Alloc(pIMalloc, OLEUI_CCHKEYMAX);
                    956: 
                    957:         lRet = OleStdGetUserTypeOfClass((REFCLSID)&clsid, 
                    958:                                         *lplpszCurrentClass, 
                    959:                                         OLEUI_CCHLABELMAX,
                    960:                                         NULL);
                    961: 
                    962:         if (0 ==lRet)
                    963:         {
                    964:           RegCloseKey(hKey);
                    965:           return (UINT)-1;
                    966:         }
                    967:     }
                    968: 
                    969:     // Get the class name of the original class.
                    970:     StringFromCLSID((REFCLSID)&clsid, (LPSTR FAR *)&lpszCLSID);
                    971: 
                    972: 
                    973:     // Here, we step through the entire registration db looking for
                    974:     // class that can read or write the original class' format.  We
                    975:     // maintain two lists - an activate list and a convert list.  The
                    976:     // activate list is a subset of the convert list - activate == read/write
                    977:     // and convert == read. We swap the listboxes as needed with 
                    978:     // SwapWindows, and keep track of which is which in the lpCV structure.
                    979:     
                    980:     // Every item has the following format:
                    981:     //
                    982:     //     Class Name\tclsid\0
                    983: 
                    984: 
                    985:     cStrings=0;
                    986:     lRet=RegEnumKey(hKey, cStrings++, (LPSTR)szClass, OLEUI_CCHKEYMAX);
                    987: 
                    988:     while ((LONG)ERROR_SUCCESS==lRet)
                    989:     {
                    990:         // Check for a \Conversion\ReadWriteable\Main entry first - if its
                    991:         // readwriteable, then we don't need to bother checking to see if
                    992:         // its readable.
                    993: 
                    994:         lstrcpy((LPSTR)szFormatKey, (LPSTR)szClass);
                    995:         lstrcat((LPSTR)szFormatKey, (LPSTR)"\\Conversion\\Readwritable\\Main");
                    996: 
                    997:         dw=OLEUI_CCHKEYMAX;
                    998: 
                    999:         lRet=RegQueryValue(hKey, (LPSTR)szFormatKey, (LPSTR)szFormat, (LONG FAR *)&dw);
                   1000: 
                   1001:         if ( (LONG)ERROR_SUCCESS != lRet)
                   1002:         {
                   1003:           // Try \\DataFormats\DefaultFile too
                   1004: 
                   1005:           lstrcpy((LPSTR)szFormatKey, (LPSTR)szClass);
                   1006:           lstrcat((LPSTR)szFormatKey, (LPSTR)"\\DataFormats\\DefaultFile");
                   1007: 
                   1008:           dw=OLEUI_CCHKEYMAX;
                   1009: 
                   1010:           lRet=RegQueryValue(hKey, (LPSTR)szFormatKey, (LPSTR)szFormat, (LONG FAR *)&dw);
                   1011:         }
                   1012: 
                   1013: 
                   1014:         if ( ((LONG)ERROR_SUCCESS==lRet) 
                   1015:              && (FormatIncluded((LPSTR)szFormat, wFormat)) )
                   1016:         {
                   1017: 
                   1018:             // Here, we've got a list of formats that this class can read
                   1019:             // and write. We need to see if the original class' format is 
                   1020:             // in this list.  We do that by looking for wFormat in 
                   1021:             // szFormat - if it in there, then we add this class to the 
                   1022:             // both lists and continue.  If not, then we look at the
                   1023:             // class' readable formats.
                   1024: 
                   1025: 
                   1026:             dw=OLEUI_CCHKEYMAX;
                   1027:             lRet=RegQueryValue(hKey, (LPSTR)szClass, (LPSTR)szHRClassName, (LPDWORD)&dw);
                   1028: 
                   1029:             if ((LONG)ERROR_SUCCESS==lRet)
                   1030:             {  
                   1031: 
                   1032:                 lstrcat((LPSTR)szHRClassName, (LPSTR)"\t");
                   1033:                 lstrcat((LPSTR)szHRClassName, (LPSTR)szClass);
                   1034: 
                   1035:                 SendMessage(hList, LB_ADDSTRING, 0, (DWORD)(LPSTR)szHRClassName);
                   1036: 
                   1037:                 // add to convert list too.
                   1038:                 SendMessage(hListInvisible, LB_ADDSTRING, 0, (DWORD)(LPSTR)szHRClassName);
                   1039: 
                   1040:             }
                   1041: 
                   1042:         }
                   1043: 
                   1044: 
                   1045:         // We either didn't find the readwritable key, or the
                   1046:         // list of readwritable formats didn't include the 
                   1047:         // original class format.  So, here we'll check to 
                   1048:         // see if its in the readable list.
                   1049: 
                   1050: 
                   1051:         // We've got a special case for a linked object here.
                   1052:         // If an object is linked, then the only class that
                   1053:         // should appear in the convert list is the object's 
                   1054:         // class.  So, here we check to see if the object is
                   1055:         // linked.  If it is, then we compare the classes.  If
                   1056:         // they aren't the same, then we just go to the next key.
                   1057: 
                   1058:         else if ( (!fIsLinkedObject)
                   1059:                 || (lstrcmp((LPSTR)lpszCLSID, (LPSTR)szClass) == 0) )
                   1060:         {
                   1061: 
                   1062:             //Check for a \Conversion\Readable\Main entry
                   1063:             lstrcpy((LPSTR)szFormatKey, (LPSTR)szClass);
                   1064:             lstrcat((LPSTR)szFormatKey, (LPSTR)"\\Conversion\\Readable\\Main");
                   1065: 
                   1066:             dw=OLEUI_CCHKEYMAX;
                   1067: 
                   1068:             // Check to see if this class can read the original class
                   1069:             // format.  If it can, add the string to the listbox as
                   1070:             // CONVERT_LIST.
                   1071: 
                   1072:             lRet=RegQueryValue(hKey, (LPSTR)szFormatKey, (LPSTR)szFormat, (LPDWORD)&dw);
                   1073: 
                   1074:             if ( ((LONG)ERROR_SUCCESS==lRet)
                   1075:                  && (FormatIncluded((LPSTR)szFormat, wFormat)) )
                   1076:             {
                   1077: 
                   1078: 
                   1079:                 dw=OLEUI_CCHKEYMAX;
                   1080:                 lRet=RegQueryValue(hKey, (LPSTR)szClass, (LPSTR)szHRClassName, (LPDWORD)&dw);
                   1081: 
                   1082:                 if ((LONG)ERROR_SUCCESS==lRet)
                   1083:                 {
                   1084: 
                   1085:                     lstrcat((LPSTR)szHRClassName, (LPSTR)"\t");
                   1086:                     lstrcat((LPSTR)szHRClassName, (LPSTR)szClass);
                   1087: 
                   1088:                     SendMessage(hListInvisible, LB_ADDSTRING, 0, (DWORD)(LPSTR)szHRClassName);
                   1089:                 }  // end if
                   1090: 
                   1091:             } // end if
                   1092:         } // end else
                   1093: 
                   1094:         //Continue with the next key.
                   1095:         lRet=RegEnumKey(hKey, cStrings++, (LPSTR)szClass, OLEUI_CCHKEYMAX);
                   1096: 
                   1097:     }  // end while
                   1098: 
                   1099:     // If the original class isn't already in the list, add it.
                   1100: 
                   1101:     lstrcpy((LPSTR)szHRClassName, *lplpszCurrentClass);
                   1102:     lstrcat((LPSTR)szHRClassName, (LPSTR)"\t");
                   1103:     lstrcat((LPSTR)szHRClassName, lpszCLSID);
                   1104: 
                   1105:     lRet = SendMessage(hList, LB_FINDSTRING, (WPARAM)-1, (LPARAM)(LPSTR)szHRClassName);
                   1106: 
                   1107:     // only add it if it's not there already.
                   1108:     if (LB_ERR == lRet)
                   1109:         SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPSTR)szHRClassName);
                   1110: 
                   1111: 
                   1112:     lRet = SendMessage(hListInvisible, LB_FINDSTRING, (WPARAM)-1, (LPARAM)(LPSTR)szHRClassName);
                   1113: 
                   1114:     // only add it if it's not there already.
                   1115:     if (LB_ERR == lRet)
                   1116:         SendMessage(hListInvisible, LB_ADDSTRING, 0, (LPARAM)(LPSTR)szHRClassName);
                   1117: 
                   1118:     // Free the string we got from StringFromCLSID.
                   1119:     // OLE2NOTE:  StringFromCLSID uses your IMalloc to alloc a 
                   1120:     // string, so you need to be sure to free the string you 
                   1121:     // get back, otherwise you'll have leaky memory.
                   1122: 
                   1123:     OleStdFreeString(lpszCLSID, NULL);
                   1124: 
                   1125:     RegCloseKey(hKey);
                   1126: 
                   1127:     return cStrings;
                   1128: }
                   1129: 
                   1130: 
                   1131: /*
                   1132:  * FormatIncluded
                   1133:  *
                   1134:  * Purpose:
                   1135:  *  Parses the string for format from the word.
                   1136:  *
                   1137:  * Parameters:
                   1138:  *  szStringToSearch  String to parse
                   1139:  *  wFormat           format to find
                   1140:  *
                   1141:  * Return Value:
                   1142:  *  BOOL        TRUE if format is found in string,
                   1143:  *              FALSE otherwise.
                   1144:  */
                   1145: BOOL FormatIncluded(LPSTR szStringToSearch, WORD wFormat)
                   1146: {
                   1147: 
                   1148:    LPSTR        lpToken;
                   1149:    char         seps[] = ",";
                   1150:    static char  szFormat[255];  // max size of atom (what GetClipboardName returns)
                   1151: 
                   1152: 
                   1153:    if (wFormat < 0xC000)             // RegisterClipboardFormat returns values
                   1154:        _itoa(wFormat, szFormat, 10);  // between 0xC000 and 0xFFFF.
                   1155: 
                   1156:    else
                   1157:        GetClipboardFormatName(wFormat, szFormat, 255);
                   1158: 
                   1159: 
                   1160:    lpToken = (LPSTR)_fstrtok(szStringToSearch, seps);
                   1161: 
                   1162:    while (lpToken != NULL)
                   1163:    {
                   1164: 
                   1165:      if (0 == lstrcmpi(lpToken, szFormat))
                   1166:         return TRUE;
                   1167: 
                   1168:      else
                   1169:         lpToken = (LPSTR)_fstrtok(NULL, seps);
                   1170:    }
                   1171: 
                   1172:    return FALSE;
                   1173: }
                   1174: 
                   1175: 
                   1176: 
                   1177: 
                   1178: 
                   1179: 
                   1180: 
                   1181: 
                   1182: 
                   1183: 
                   1184: 
                   1185: /*
                   1186:  * UpdateCVClassIcon
                   1187:  *
                   1188:  * Purpose:
                   1189:  *  Handles LBN_SELCHANGE for the Object Type listbox.  On a selection
                   1190:  *  change, we extract an icon from the server handling the currently
                   1191:  *  selected object type using the utility function HIconFromClass.
                   1192:  *  Note that we depend on the behavior of FillClassList to stuff the
                   1193:  *  object class after a tab in the listbox string that we hide from
                   1194:  *  view (see WM_INITDIALOG).
                   1195:  *
                   1196:  * Parameters
                   1197:  *  hDlg            HWND of the dialog box.
                   1198:  *  lpCV            LPCONVERT pointing to the dialog structure
                   1199:  *  hList           HWND of the Object Type listbox.
                   1200:  *
                   1201:  * Return Value:
                   1202:  *  None
                   1203:  */
                   1204: 
                   1205: void UpdateCVClassIcon(HWND hDlg, LPCONVERT lpCV, HWND hList)
                   1206:     {
                   1207:     UINT        iSel;
                   1208:     DWORD       cb;
                   1209:     HGLOBAL     hMem;
                   1210:     LPSTR       pszName, pszCLSID;
                   1211:     CLSID       clsid;
                   1212:     HICON       hIcon, hOldIcon;
                   1213:     UINT        cch, uWrapIndex;
                   1214:     RECT        LabelRect;
                   1215:     char        szLabel[OLEUI_CCHLABELMAX];
                   1216:     HFONT       hFont;
                   1217:     HWND        hLabel1;
                   1218: 
                   1219:     /*
                   1220:      * When we change object type selection, get the new icon for that
                   1221:      * type into our structure and update it in the display.
                   1222:      */
                   1223: 
                   1224:     iSel=(UINT)SendMessage(hList, LB_GETCURSEL, 0, 0L);
                   1225: 
                   1226:     if (LB_ERR==(int)iSel)
                   1227:         return;
                   1228: 
                   1229:     //Allocate a string to hold the entire listbox string
                   1230:     cb=SendMessage(hList, LB_GETTEXTLEN, iSel, 0L);
                   1231: 
                   1232:     hMem=GlobalAlloc(GHND, cb+1);
                   1233: 
                   1234:     if (NULL==hMem)
                   1235:         return;
                   1236: 
                   1237:     pszName=GlobalLock(hMem);
                   1238: 
                   1239:     // Get whole string
                   1240:     SendMessage(hList, LB_GETTEXT, iSel, (LONG)pszName);
                   1241: 
                   1242:     // Set pointer to CLSID (string)
                   1243:     pszCLSID = PointerToNthField(pszName, 2, '\t');
                   1244: 
                   1245:     //Create the class ID with this string.
                   1246:     CLSIDFromString((LPSTR)pszCLSID, (LPCLSID)&clsid);
                   1247: 
                   1248:     hIcon = HIconAndSourceFromClass(&clsid, (LPSTR)(lpCV->lpszIconSource), &(lpCV->IconIndex));
                   1249: 
                   1250:     if (NULL == hIcon)  // Use Vanilla Document
                   1251:     {
                   1252:         lstrcpy((LPSTR)(lpCV->lpszIconSource), (LPSTR)szOLE2DLL);
                   1253:         lpCV->IconIndex = 0;    // 1st icon in OLE2.DLL
                   1254:         hIcon = ExtractIcon(ghInst, 
                   1255:                             (LPSTR)(lpCV->lpszIconSource), 
                   1256:                             lpCV->IconIndex);
                   1257:     }
                   1258: 
                   1259:     //Replace the current display with this new one.
                   1260:     hOldIcon = (HICON)SendDlgItemMessage(hDlg, IDCV_ICON, STM_SETICON, (WPARAM)hIcon, 0L);
                   1261: 
                   1262:     // Get the label
                   1263:     if ((cch = OleStdGetAuxUserType(&clsid, AUXUSERTYPE_SHORTNAME, 
                   1264:                 (LPSTR)szLabel, OLEUI_CCHLABELMAX, NULL)) == 0) {
                   1265:        // If we can't get the AuxUserType2, then try the long name
                   1266:        if ((cch = OleStdGetUserTypeOfClass(&clsid, (LPSTR)szLabel, 
                   1267:                    OLEUI_CCHKEYMAX, NULL)) == 0) {
                   1268:            // last resort; use "Document" as label
                   1269:            LoadString(ghInst,IDS_DEFICONLABEL,(LPSTR)szLabel,sizeof(szLabel));
                   1270:            cch = lstrlen((LPSTR)szLabel);
                   1271:        }
                   1272:     }
                   1273: 
                   1274:     hLabel1 = GetDlgItem(hDlg, IDCV_ICONLABEL1);
                   1275: 
                   1276:     GetWindowRect(hLabel1, &LabelRect);
                   1277: 
                   1278:     hFont = (HFONT)SendMessage(hLabel1, WM_GETFONT, 0, 0L);
                   1279: 
                   1280:     // Figure out where to split the label
                   1281:     uWrapIndex = OleStdIconLabelTextOut(NULL, hFont, 0, 0, 0, &LabelRect, (LPSTR)szLabel, cch, NULL);
                   1282: 
                   1283:     if (0 == uWrapIndex)
                   1284:     {
                   1285:        SendMessage(hLabel1, WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                   1286:        SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_SETTEXT, 0, (LPARAM)(LPSTR)"");
                   1287:     }
                   1288:     else
                   1289:     {
                   1290:        char  chKeep;
                   1291:        LPSTR lpszSecondLine;
                   1292: 
                   1293:        chKeep = szLabel[uWrapIndex];
                   1294:        szLabel[uWrapIndex] = '\0';
                   1295: 
                   1296:        SendMessage(hLabel1, WM_SETTEXT, 0, (LPARAM)(LPSTR)szLabel);
                   1297: 
                   1298:        szLabel[uWrapIndex] = chKeep;
                   1299:        lpszSecondLine = szLabel + uWrapIndex;
                   1300: 
                   1301:        SendDlgItemMessage(hDlg, IDCV_ICONLABEL2, WM_SETTEXT, 0, (LPARAM)lpszSecondLine);
                   1302:     }
                   1303: 
                   1304:     // get rid of the old icon
                   1305:     if ((HICON)NULL != hOldIcon)
                   1306:       DestroyIcon(hOldIcon);
                   1307: 
                   1308:     GlobalUnlock(hMem);
                   1309:     GlobalFree(hMem);
                   1310:     return;
                   1311:     }
                   1312: 
                   1313: 
                   1314: 
                   1315: 
                   1316: 
                   1317: 
                   1318: BOOL IsValidClassID(CLSID cID)
                   1319: {
                   1320:     if (0 == _fmemcmp(&cID, &CLSID_NULL, sizeof(CLSID)))  // if (CLSID_NULL == cID)
                   1321:       return FALSE;
                   1322:     else 
                   1323:       return TRUE;
                   1324: }
                   1325: 
                   1326: 
                   1327: 
                   1328: /*
                   1329:  * SetConvertResults
                   1330:  *
                   1331:  * Purpose:
                   1332:  *  Centralizes setting of the Result display in the Convert
                   1333:  *  dialog.  Handles loading the appropriate string from the module's
                   1334:  *  resources and setting the text, displaying the proper result picture,
                   1335:  *  and showing the proper icon.
                   1336:  *
                   1337:  * Parameters:
                   1338:  *  hDlg            HWND of the dialog box so we can access controls.
                   1339:  *  lpCV            LPCONVERT in which we assume that the dwFlags is
                   1340:  *                  set to the appropriate radio button selection, and
                   1341:  *                  the list box has the appropriate class selected.
                   1342:  *
                   1343:  * Return Value:
                   1344:  *  None
                   1345:  */
                   1346: 
                   1347: void SetConvertResults(HWND hDlg, LPCONVERT lpCV)
                   1348:    {
                   1349:     LPSTR       pszT,        // temp
                   1350:                 lpszOutput,  // text sent in SetDlgItemText
                   1351:                 lpszDefObj,  // string containing default object class 
                   1352:                 lpszSelObj,  // string containing selected object class
                   1353:                 lpszString;  // stirng we get from loadstring
                   1354: 
                   1355:     UINT        i, cch;
                   1356:     HGLOBAL     hMem;
                   1357: 
                   1358:     HWND        hList;  // handle to listbox (so we can just use SendMsg i
                   1359:                         // instead of SendDlgItemMsg).
                   1360: 
                   1361: 
                   1362:     hList = lpCV->hListVisible;
                   1363:     /*
                   1364:      * We need scratch memory for loading the stringtable string, loading
                   1365:      * the object type from the listbox, loading the source object
                   1366:      * type, and constructing the final string.  We therefore allocate 
                   1367:      * four buffers as large as the maximum message length (512) plus 
                   1368:      * the object type, guaranteeing that we have enough
                   1369:      * in all cases.
                   1370:      */
                   1371:     i=(UINT)SendMessage(hList, LB_GETCURSEL, 0, 0L);
                   1372: 
                   1373:     cch=512+(UINT)SendMessage(hList, LB_GETTEXTLEN, i, 0L);
                   1374: 
                   1375:     hMem=GlobalAlloc(GHND, (DWORD)(4*cch));
                   1376: 
                   1377:     if (NULL==hMem)
                   1378:         return;
                   1379: 
                   1380:     lpszOutput = (LPSTR)GlobalLock(hMem);
                   1381:     lpszSelObj = lpszOutput + cch;
                   1382:     lpszDefObj = lpszSelObj + cch;
                   1383:     lpszString = lpszDefObj + cch;
                   1384: 
                   1385:     // Get selected object and null terminate human-readable name (1st field).
                   1386:     SendMessage(hList, LB_GETTEXT, i, (LONG)lpszSelObj);
                   1387: 
                   1388:     pszT = PointerToNthField(lpszSelObj, 2, '\t');
                   1389: 
                   1390:     pszT = AnsiPrev(lpszSelObj, pszT);
                   1391: 
                   1392:     *pszT = '\0';
                   1393: 
                   1394: 
                   1395:     // Get default object
                   1396: 
                   1397:     GetDlgItemText(hDlg, IDCV_OBJECTTYPE, lpszDefObj, 512);
                   1398: 
                   1399: 
                   1400:     //Default is an empty string.
                   1401:     *lpszOutput=0;
                   1402: 
                   1403: 
                   1404:     if (lpCV->dwFlags & CF_SELECTCONVERTTO)
                   1405:     {
                   1406:         
                   1407:         if (lpCV->lpOCV->fIsLinkedObject)  // working with linked object
                   1408:           LoadString(ghInst, IDS_CVRESULTCONVERTLINK, lpszOutput, cch);
                   1409: 
                   1410: 
                   1411:         else
                   1412:         {
                   1413:             // converting to a new class
                   1414:           if (0 != lstrcmp(lpszDefObj, lpszSelObj))
                   1415:           {
                   1416:             if (0 != LoadString(ghInst, IDS_CVRESULTCONVERTTO, lpszString, cch))
                   1417:                wsprintf(lpszOutput, lpszString, lpszDefObj, lpszSelObj);
                   1418: 
                   1419:           }  
                   1420:           else  // converting to the same class (no conversion)
                   1421:           {
                   1422: 
                   1423:              if (0 != LoadString(ghInst, IDS_CVRESULTNOCHANGE, lpszString, cch))
                   1424:                wsprintf(lpszOutput, lpszString, lpszDefObj);
                   1425:           }
                   1426: 
                   1427:         }
                   1428: 
                   1429:         if (lpCV->dvAspect == DVASPECT_ICON)  // Display as icon is checked
                   1430:         {
                   1431:            if (0 != LoadString(ghInst, IDS_CVRESULTDISPLAYASICON, lpszString, cch))
                   1432:                 lstrcat(lpszOutput, lpszString);
                   1433:         }
                   1434:     }
                   1435: 
                   1436:     if (lpCV->dwFlags & CF_SELECTACTIVATEAS)
                   1437:     {
                   1438: 
                   1439:        if (0!=LoadString(ghInst, IDS_CVRESULTACTIVATEAS, lpszString, cch))
                   1440:           wsprintf(lpszOutput, lpszString, lpszDefObj, lpszSelObj);
                   1441: 
                   1442:        // activating as a new class
                   1443:        if (0 != lstrcmp(lpszDefObj, lpszSelObj))
                   1444:        {
                   1445:           if (0!=LoadString(ghInst, IDS_CVRESULTACTIVATEDIFF, lpszString, cch))
                   1446:              lstrcat(lpszOutput, lpszString);
                   1447:        }
                   1448:        else // activating as itself.
                   1449:        {
                   1450:          lstrcat(lpszOutput, ".");
                   1451:        }
                   1452:     }
                   1453:      
                   1454: 
                   1455:     //If LoadString failed, we simply clear out the results (*lpszOutput=0 above)
                   1456:     SetDlgItemText(hDlg, IDCV_RESULTTEXT, lpszOutput);
                   1457: 
                   1458:     GlobalUnlock(hMem);
                   1459:     GlobalFree(hMem);
                   1460:     return;
                   1461:     }
                   1462: 
                   1463: 
                   1464: 
                   1465: 
                   1466: 
                   1467: 
                   1468: /*
                   1469:  * ConvertCleanup
                   1470:  *
                   1471:  * Purpose:
                   1472:  *  Performs convert-specific cleanup before Convert termination.
                   1473:  *
                   1474:  * Parameters:
                   1475:  *  hDlg            HWND of the dialog box so we can access controls.
                   1476:  *
                   1477:  * Return Value:
                   1478:  *  None
                   1479:  */
                   1480: void ConvertCleanup(HWND hDlg, LPCONVERT lpCV)
                   1481: {
                   1482: 
                   1483:    LPMALLOC pIMalloc;
                   1484: 
                   1485: 
                   1486:    // Free our strings. Zero out the user type name string 
                   1487:    // the the calling app doesn't free to it.
                   1488: 
                   1489:    if (NOERROR != CoGetMalloc(MEMCTX_TASK, &pIMalloc))
                   1490:    {
                   1491:        pIMalloc->lpVtbl->Free(pIMalloc, (LPVOID)lpCV->lpszConvertDefault);
                   1492:        pIMalloc->lpVtbl->Free(pIMalloc, (LPVOID)lpCV->lpszActivateDefault);
                   1493:        pIMalloc->lpVtbl->Free(pIMalloc, (LPVOID)lpCV->lpszIconSource);
                   1494:        pIMalloc->lpVtbl->Free(pIMalloc, (LPVOID)lpCV->lpOCV->lpszUserType);
                   1495: 
                   1496:        lpCV->lpOCV->lpszUserType = NULL;
                   1497: 
                   1498:        pIMalloc->lpVtbl->Release(pIMalloc);
                   1499:    }
                   1500: 
                   1501:    return;
                   1502: }
                   1503: 
                   1504: 
                   1505: 
                   1506: 
                   1507: 
                   1508: /*
                   1509:  * SwapWindows
                   1510:  *
                   1511:  * Purpose:
                   1512:  *  Moves hWnd1 to hWnd2's position and hWnd2 to hWnd1's position.
                   1513:  *  Does NOT change sizes.
                   1514:  *  
                   1515:  *
                   1516:  * Parameters:
                   1517:  *  hDlg            HWND of the dialog box so we can turn redraw off
                   1518:  *
                   1519:  * Return Value:
                   1520:  *  None
                   1521:  */
                   1522: void SwapWindows(HWND hDlg, HWND hWnd1, HWND hWnd2)
                   1523: {
                   1524: 
                   1525:    RECT Rect1, Rect2;
                   1526: 
                   1527: 
                   1528:    GetWindowRect(hWnd1, &Rect1);
                   1529:    GetWindowRect(hWnd2, &Rect2);
                   1530: 
                   1531:    ScreenToClient(hDlg, (LPPOINT)&Rect1.left);
                   1532:    ScreenToClient(hDlg, (LPPOINT)&Rect1.right);
                   1533: 
                   1534:    ScreenToClient(hDlg, (LPPOINT)&Rect2.left);
                   1535:    ScreenToClient(hDlg, (LPPOINT)&Rect2.right);
                   1536: 
                   1537:    SetWindowPos(hWnd1, 
                   1538:                 NULL, 
                   1539:                 Rect2.left, 
                   1540:                 Rect2.top, 
                   1541:                 0, 
                   1542:                 0,
                   1543:                 SWP_NOZORDER | SWP_NOSIZE);
                   1544: 
                   1545:    SetWindowPos(hWnd2, 
                   1546:                 NULL, 
                   1547:                 Rect1.left, 
                   1548:                 Rect1.top, 
                   1549:                 0, 
                   1550:                 0,
                   1551:                 SWP_NOZORDER | SWP_NOSIZE);
                   1552: 
                   1553:    return;
                   1554: 
                   1555: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.