|
|
1.1 ! root 1: /* ! 2: * OLE2UI.C ! 3: * ! 4: * Contains initialization routines and miscellaneous API implementations for ! 5: * the OLE 2.0 User Interface Support Library. ! 6: * ! 7: * Copyright (c)1992 Microsoft Corporation, All Right Reserved ! 8: */ ! 9: ! 10: #define STRICT 1 ! 11: ! 12: #include "ole2ui.h" ! 13: #include "common.h" ! 14: #include "utility.h" ! 15: #include "resimage.h" ! 16: #include "iconbox.h" ! 17: #include <commdlg.h> ! 18: ! 19: #define WINDLL 1 // make far pointer version of stdargs.h ! 20: #include <stdarg.h> ! 21: ! 22: ! 23: OLEDBGDATA_MAIN("OLE2UI") ! 24: ! 25: //The DLL instance handle shared amongst all dialogs. ! 26: HINSTANCE ghInst; ! 27: ! 28: //Registered messages for use with all the dialogs, registered in LibMain ! 29: UINT uMsgHelp=0; ! 30: UINT uMsgEndDialog=0; ! 31: UINT uMsgBrowse=0; ! 32: UINT uMsgChangeIcon=0; ! 33: UINT uMsgFileOKString=0; ! 34: UINT uMsgCloseBusyDlg=0; ! 35: ! 36: //Clipboard formats used by PasteSpecial ! 37: UINT cfObjectDescriptor; ! 38: UINT cfLinkSrcDescriptor; ! 39: UINT cfEmbedSource; ! 40: UINT cfEmbeddedObject; ! 41: UINT cfLinkSource; ! 42: UINT cfOwnerLink; ! 43: UINT cfFileName; ! 44: ! 45: // local function prototypes ! 46: BOOL CALLBACK EXPORT PromptUserDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam); ! 47: BOOL CALLBACK EXPORT UpdateLinksDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam); ! 48: ! 49: ! 50: // local definition ! 51: #define WM_U_UPDATELINK WM_USER ! 52: ! 53: ! 54: // local structure definition ! 55: typedef struct tagUPDATELINKS ! 56: { ! 57: LPOLEUILINKCONTAINER lpOleUILinkCntr; // pointer to Link Container ! 58: UINT cLinks; // total number of links ! 59: UINT cUpdated; // number of links updated ! 60: DWORD dwLink; // pointer to link ! 61: BOOL fError; // error flag ! 62: LPSTR lpszTitle; // title of the dialog box ! 63: } UPDATELINKS, *PUPDATELINKS, FAR *LPUPDATELINKS; ! 64: ! 65: ! 66: ! 67: STDAPI_(BOOL) OleUIInitialize(HINSTANCE hInstance) ! 68: { ! 69: HRSRC hr; ! 70: HGLOBAL hg; ! 71: LPWORD lpdata; ! 72: ! 73: OleDbgOut1("OleUIInitialize called.\r\n"); ! 74: ghInst=hInstance; ! 75: ! 76: // Verify that we have the correct resources added to our application. ! 77: if ((hr = FindResource(hInstance, "VERIFICATION", RT_RCDATA)) == NULL) ! 78: goto ResourceLoadError; ! 79: ! 80: if ((hg = LoadResource(hInstance, hr)) == NULL) ! 81: goto ResourceLoadError; ! 82: ! 83: if ((lpdata = (LPWORD)LockResource(hg)) == NULL) ! 84: goto ResourceLockError; ! 85: ! 86: if ((WORD)*lpdata != (WORD)OLEUI_VERSION_MAGIC) ! 87: goto ResourceReadError; ! 88: ! 89: // OK, resource versions match. Contine on. ! 90: UnlockResource(hg); ! 91: FreeResource(hg); ! 92: OleDbgOut1("OleUIInitialize: Resource magic number verified.\r\n"); ! 93: ! 94: // Register messages we need for the dialogs. If ! 95: uMsgHelp =RegisterWindowMessage(SZOLEUI_MSG_HELP); ! 96: uMsgEndDialog =RegisterWindowMessage(SZOLEUI_MSG_ENDDIALOG); ! 97: uMsgBrowse =RegisterWindowMessage(SZOLEUI_MSG_BROWSE); ! 98: uMsgChangeIcon=RegisterWindowMessage(SZOLEUI_MSG_CHANGEICON); ! 99: uMsgFileOKString = RegisterWindowMessage(FILEOKSTRING); ! 100: uMsgCloseBusyDlg = RegisterWindowMessage(SZOLEUI_MSG_CLOSEBUSYDIALOG); ! 101: ! 102: // Register Clipboard Formats used by PasteSpecial dialog. ! 103: cfObjectDescriptor = RegisterClipboardFormat(CF_OBJECTDESCRIPTOR); ! 104: cfLinkSrcDescriptor= RegisterClipboardFormat(CF_LINKSRCDESCRIPTOR); ! 105: cfEmbedSource = RegisterClipboardFormat(CF_EMBEDSOURCE); ! 106: cfEmbeddedObject = RegisterClipboardFormat(CF_EMBEDDEDOBJECT); ! 107: cfLinkSource = RegisterClipboardFormat(CF_LINKSOURCE); ! 108: cfOwnerLink = RegisterClipboardFormat(CF_OWNERLINK); ! 109: cfFileName = RegisterClipboardFormat(CF_FILENAME); ! 110: ! 111: ! 112: if (!FResultImageInitialize(hInstance)) ! 113: { ! 114: OleDbgOut1("OleUIInitialize: FResultImageInitialize failed. Terminating.\r\n"); ! 115: return 0; ! 116: } ! 117: ! 118: if (!FIconBoxInitialize(hInstance)) ! 119: { ! 120: OleDbgOut1("OleUIInitialize: FIconBoxInitialize failed. Terminating.\r\n"); ! 121: return 0; ! 122: } ! 123: ! 124: return TRUE; ! 125: ! 126: ResourceLoadError: ! 127: OleDbgOut1("OleUIInitialize: ERROR - Unable to find version verification resource.\r\n"); ! 128: return FALSE; ! 129: ! 130: ResourceLockError: ! 131: OleDbgOut1("OleUIInitialize: ERROR - Unable to lock version verification resource.\r\n"); ! 132: FreeResource(hg); ! 133: return FALSE; ! 134: ! 135: ResourceReadError: ! 136: OleDbgOut1("OleUIInitialize: ERROR - Version verification values did not compare.\r\n"); ! 137: ! 138: {char buf[255]; ! 139: wsprintf(buf, "resource read 0x%X, my value is 0x%X\n", (WORD)*lpdata, (WORD)OLEUI_VERSION_MAGIC); ! 140: OutputDebugString(buf); ! 141: } ! 142: ! 143: UnlockResource(hg); ! 144: FreeResource(hg); ! 145: return FALSE; ! 146: } ! 147: ! 148: ! 149: STDAPI_(BOOL) OleUIUnInitialize() ! 150: { ! 151: IconBoxUninitialize(); ! 152: ResultImageUninitialize(); ! 153: ! 154: return TRUE; ! 155: } ! 156: ! 157: ! 158: ! 159: /* ! 160: * OleUIAddVerbMenu ! 161: * ! 162: * Purpose: ! 163: * Add the Verb menu for the specified object to the given menu. If the ! 164: * object has one verb, we directly add the verb to the given menu. If ! 165: * the object has multiple verbs we create a cascading sub-menu. ! 166: * ! 167: * Parameters: ! 168: * lpObj LPOLEOBJECT pointing to the selected object. If this ! 169: * is NULL, then we create a default disabled menu item. ! 170: * ! 171: * lpszShortType LPSTR with short type name (AuxName==2) corresponding ! 172: * to the lpOleObj. if the string is NOT known, then NULL ! 173: * may be passed. if NULL is passed, then ! 174: * IOleObject::GetUserType will be called to retrieve it. ! 175: * if the caller has the string handy, then it is faster ! 176: * to pass it in. ! 177: * ! 178: * hMenu HMENU in which to make modifications. ! 179: * ! 180: * uPos Position of the menu item ! 181: * ! 182: * idVerbMin UINT ID value at which to start the verbs. ! 183: * verb_0 = wIDMVerbMin + verb_0 ! 184: * verb_1 = wIDMVerbMin + verb_1 ! 185: * verb_2 = wIDMVerbMin + verb_2 ! 186: * etc. ! 187: * ! 188: * bAddConvert BOOL specifying whether or not to add a "Convert" item ! 189: * to the bottom of the menu (with a separator). ! 190: * ! 191: * idConvert UINT ID value to use for the Convert menu item, if ! 192: * bAddConvert is TRUE. ! 193: * ! 194: * lphMenu HMENU FAR * of the cascading verb menu if it's created. ! 195: * If there is only one verb, this will be filled with NULL. ! 196: * ! 197: * ! 198: * Return Value: ! 199: * BOOL TRUE if lpObj was valid and we added at least one verb ! 200: * to the menu. FALSE if lpObj was NULL and we created ! 201: * a disabled default menu item ! 202: */ ! 203: ! 204: STDAPI_(BOOL) OleUIAddVerbMenu(LPOLEOBJECT lpOleObj, ! 205: LPSTR lpszShortType, ! 206: HMENU hMenu, ! 207: UINT uPos, ! 208: UINT uIDVerbMin, ! 209: BOOL bAddConvert, ! 210: UINT idConvert, ! 211: HMENU FAR *lphMenu) ! 212: { ! 213: LPPERSISTSTORAGE lpPS=NULL; ! 214: LPENUMOLEVERB lpEnumOleVerb = NULL; ! 215: OLEVERB oleverb; ! 216: LPUNKNOWN lpUnk; ! 217: LPSTR lpszShortTypeName = lpszShortType; ! 218: LPSTR lpszVerbName = NULL; ! 219: HRESULT hrErr; ! 220: BOOL fStatus; ! 221: BOOL fIsLink = FALSE; ! 222: BOOL fResult = FALSE; ! 223: BOOL fAddConvertItem = FALSE; ! 224: LONG lNextVerbExpected; ! 225: int cVerbs = 0; ! 226: UINT uFlags = MF_BYPOSITION; ! 227: static BOOL fFirstTime = TRUE; ! 228: static char szBuffer[OLEUI_OBJECTMENUMAX]; ! 229: static char szNoObjectCmd[OLEUI_OBJECTMENUMAX]; ! 230: static char szObjectCmd1Verb[OLEUI_OBJECTMENUMAX]; ! 231: static char szLinkCmd1Verb[OLEUI_OBJECTMENUMAX]; ! 232: static char szObjectCmdNVerb[OLEUI_OBJECTMENUMAX]; ! 233: static char szLinkCmdNVerb[OLEUI_OBJECTMENUMAX]; ! 234: static char szUnknown[OLEUI_OBJECTMENUMAX]; ! 235: static char szEdit[OLEUI_OBJECTMENUMAX]; ! 236: static char szConvert[OLEUI_OBJECTMENUMAX]; ! 237: ! 238: *lphMenu=NULL; ! 239: ! 240: // Set fAddConvertItem flag ! 241: if (bAddConvert & (idConvert != 0)) ! 242: fAddConvertItem = TRUE; ! 243: ! 244: // only need to load the strings the 1st time ! 245: if (fFirstTime) { ! 246: if (0 == LoadString(ghInst, IDS_OLE2UIEDITNOOBJCMD, ! 247: (LPSTR)szNoObjectCmd, OLEUI_OBJECTMENUMAX)) ! 248: return FALSE; ! 249: if (0 == LoadString(ghInst, IDS_OLE2UIEDITLINKCMD_1VERB, ! 250: (LPSTR)szLinkCmd1Verb, OLEUI_OBJECTMENUMAX)) ! 251: return FALSE; ! 252: if (0 == LoadString(ghInst, IDS_OLE2UIEDITOBJECTCMD_1VERB, ! 253: (LPSTR)szObjectCmd1Verb, OLEUI_OBJECTMENUMAX)) ! 254: return FALSE; ! 255: ! 256: if (0 == LoadString(ghInst, IDS_OLE2UIEDITLINKCMD_NVERB, ! 257: (LPSTR)szLinkCmdNVerb, OLEUI_OBJECTMENUMAX)) ! 258: return FALSE; ! 259: if (0 == LoadString(ghInst, IDS_OLE2UIEDITOBJECTCMD_NVERB, ! 260: (LPSTR)szObjectCmdNVerb, OLEUI_OBJECTMENUMAX)) ! 261: return FALSE; ! 262: ! 263: if (0 == LoadString(ghInst, IDS_OLE2UIUNKNOWN, ! 264: (LPSTR)szUnknown, OLEUI_OBJECTMENUMAX)) ! 265: return FALSE; ! 266: ! 267: if (0 == LoadString(ghInst, IDS_OLE2UIEDIT, ! 268: (LPSTR)szEdit, OLEUI_OBJECTMENUMAX)) ! 269: return FALSE; ! 270: ! 271: if ( (0 == LoadString(ghInst, IDS_OLE2UICONVERT, ! 272: (LPSTR)szConvert, OLEUI_OBJECTMENUMAX)) && fAddConvertItem) ! 273: return FALSE; ! 274: ! 275: } ! 276: ! 277: // Delete whatever menu may happen to be here already. ! 278: DeleteMenu(hMenu, uPos, uFlags); ! 279: ! 280: if (!lpOleObj) ! 281: goto AVMError; ! 282: ! 283: if (! lpszShortTypeName) { ! 284: // get the Short form of the user type name for the menu ! 285: OLEDBG_BEGIN2("IOleObject::GetUserType called\r\n") ! 286: hrErr = lpOleObj->lpVtbl->GetUserType( ! 287: lpOleObj, ! 288: USERCLASSTYPE_SHORT, ! 289: (LPSTR FAR*)&lpszShortTypeName ! 290: ); ! 291: OLEDBG_END2 ! 292: ! 293: if (NOERROR != hrErr) { ! 294: OleDbgOutHResult("IOleObject::GetUserType returned", hrErr); ! 295: } ! 296: } ! 297: ! 298: // check if the object is a link (it is a link if it support IOleLink) ! 299: hrErr = lpOleObj->lpVtbl->QueryInterface( ! 300: lpOleObj, ! 301: &IID_IOleLink, ! 302: (LPVOID FAR*)&lpUnk ! 303: ); ! 304: if (NOERROR == hrErr) { ! 305: fIsLink = TRUE; ! 306: OleStdRelease(lpUnk); ! 307: } ! 308: ! 309: // Get the verb enumerator from the OLE object ! 310: OLEDBG_BEGIN2("IOleObject::EnumVerbs called\r\n") ! 311: hrErr = lpOleObj->lpVtbl->EnumVerbs( ! 312: lpOleObj, ! 313: (LPENUMOLEVERB FAR*)&lpEnumOleVerb ! 314: ); ! 315: OLEDBG_END2 ! 316: ! 317: if (NOERROR != hrErr) { ! 318: OleDbgOutHResult("IOleObject::EnumVerbs returned", hrErr); ! 319: } ! 320: ! 321: if (!(*lphMenu = CreatePopupMenu())) ! 322: goto AVMError; ! 323: ! 324: lNextVerbExpected = 0; // we expect verbs to start at 0 ! 325: ! 326: // loop through all verbs ! 327: while (lpEnumOleVerb != NULL) { // forever ! 328: hrErr = lpEnumOleVerb->lpVtbl->Next( ! 329: lpEnumOleVerb, ! 330: 1, ! 331: (LPOLEVERB)&oleverb, ! 332: NULL ! 333: ); ! 334: if (NOERROR != hrErr) ! 335: break; // DONE! no more verbs ! 336: ! 337: /* OLE2NOTE: negative verb numbers and verbs that do not ! 338: ** indicate ONCONTAINERMENU should NOT be put on the verb menu ! 339: */ ! 340: if (oleverb.lVerb < 0 || ! 341: ! (oleverb.grfAttribs & OLEVERBATTRIB_ONCONTAINERMENU)) { ! 342: ! 343: /* OLE2NOTE: we must still free the verb name string */ ! 344: if (oleverb.lpszVerbName) ! 345: OleStdFreeString(oleverb.lpszVerbName, NULL); ! 346: continue; ! 347: } ! 348: ! 349: #if defined( OBSOLETE ) ! 350: /* OLE2NOTE: we only support consecutively numbered verbs ! 351: ** starting with verb 0. we will stop adding verbs to the ! 352: ** menu when the first gap in the verb numbers is ! 353: ** encountered. ! 354: */ ! 355: if (oleverb.lVerb != lNextVerbExpected) ! 356: break; // STOP -- gap in verb numbers encountered ! 357: ! 358: lNextVerbExpected++; // next verb should be consecutive ! 359: #endif ! 360: ! 361: // we must free the previous verb name string ! 362: if (lpszVerbName) ! 363: OleStdFreeString(lpszVerbName, NULL); ! 364: ! 365: lpszVerbName = oleverb.lpszVerbName; ! 366: ! 367: fStatus = InsertMenu( ! 368: *lphMenu, ! 369: (UINT)-1, ! 370: MF_BYPOSITION | (UINT)oleverb.fuFlags, ! 371: uIDVerbMin+(UINT)oleverb.lVerb, ! 372: (LPSTR)lpszVerbName ! 373: ); ! 374: if (! fStatus) ! 375: goto AVMError; ! 376: ! 377: cVerbs++; ! 378: } ! 379: ! 380: ! 381: // Add the separator and "Convert" menu item. Also add "Edit" item ! 382: // if cVerbs = 0 so that we can just fall into the switch statement ! 383: // below without any more Convert-specific code. ! 384: ! 385: if (fAddConvertItem) { ! 386: ! 387: #if defined( OBSOLETE ) ! 388: if (0 == cVerbs) { ! 389: fStatus = InsertMenu(*lphMenu, ! 390: (UINT)-1, ! 391: MF_BYPOSITION, ! 392: uIDVerbMin, ! 393: (LPCSTR)szEdit); ! 394: if (! fStatus) ! 395: goto AVMError; ! 396: ! 397: cVerbs++; ! 398: } ! 399: #endif ! 400: ! 401: if (cVerbs > 0) { ! 402: fStatus = InsertMenu(*lphMenu, ! 403: (UINT)-1, ! 404: MF_BYPOSITION | MF_SEPARATOR, ! 405: (UINT)0, ! 406: (LPCSTR)NULL); ! 407: if (! fStatus) ! 408: goto AVMError; ! 409: } ! 410: ! 411: /* add convert menu */ ! 412: fStatus = InsertMenu(*lphMenu, ! 413: (UINT)-1, ! 414: MF_BYPOSITION, ! 415: idConvert, ! 416: (LPCSTR)szConvert); ! 417: if (! fStatus) ! 418: goto AVMError; ! 419: ! 420: cVerbs++; ! 421: } ! 422: ! 423: ! 424: /* ! 425: * Build the appropriate menu based on the number of verbs found ! 426: * ! 427: * NOTE: Localized verb menus may require a different format. ! 428: * to assist in localization of the single verb case, the ! 429: * szLinkCmd1Verb and szObjectCmd1Verb format strings start ! 430: * with either a '0' (note: NOT '\0'!) or a '1': ! 431: * leading '0' -- verb type ! 432: * leading '1' -- type verb ! 433: */ ! 434: ! 435: if (cVerbs == 0) { ! 436: ! 437: //No verbs. Create a default using Edit as the verb. ! 438: LPSTR lpsz = (fIsLink ? szLinkCmd1Verb : szObjectCmd1Verb); ! 439: ! 440: if (*lpsz == '0') { ! 441: wsprintf(szBuffer, lpsz+1, (LPSTR)szEdit, ! 442: (lpszShortTypeName ? lpszShortTypeName : (LPSTR)"") ! 443: ); ! 444: } ! 445: else { ! 446: wsprintf(szBuffer, lpsz+1, ! 447: (lpszShortTypeName ? lpszShortTypeName : (LPSTR)""), ! 448: (LPSTR)szEdit ! 449: ); ! 450: } ! 451: ! 452: DestroyMenu(*lphMenu); ! 453: *lphMenu = NULL; ! 454: ! 455: } ! 456: else if ((cVerbs == 1) && !fAddConvertItem) { ! 457: //One verb without Convert, one item. ! 458: LPSTR lpsz = (fIsLink ? szLinkCmd1Verb : szObjectCmd1Verb); ! 459: ! 460: if (*lpsz == '0') { ! 461: wsprintf(szBuffer, lpsz+1, lpszVerbName, ! 462: (lpszShortTypeName ? lpszShortTypeName : (LPSTR)"") ! 463: ); ! 464: } ! 465: else { ! 466: wsprintf(szBuffer, lpsz+1, ! 467: (lpszShortTypeName ? lpszShortTypeName : (LPSTR)""), ! 468: lpszVerbName ! 469: ); ! 470: } ! 471: DestroyMenu(*lphMenu); ! 472: *lphMenu=NULL; ! 473: } ! 474: else { ! 475: ! 476: //Multiple verbs or one verb with Convert, add the cascading menu ! 477: wsprintf( ! 478: szBuffer, ! 479: (fIsLink ? (LPSTR)szLinkCmdNVerb:(LPSTR)szObjectCmdNVerb), ! 480: (lpszShortTypeName ? lpszShortTypeName : (LPSTR)"") ! 481: ); ! 482: uFlags |= MF_ENABLED | MF_POPUP; ! 483: uIDVerbMin=(UINT)*lphMenu; ! 484: } ! 485: ! 486: if (!InsertMenu(hMenu, uPos, uFlags, uIDVerbMin, szBuffer)) ! 487: ! 488: AVMError: ! 489: { ! 490: HMENU hmenuDummy = CreatePopupMenu(); ! 491: ! 492: InsertMenu(hMenu, uPos, MF_GRAYED | MF_POPUP | uFlags, ! 493: (UINT)hmenuDummy, (LPSTR)szNoObjectCmd); ! 494: fResult = FALSE; ! 495: goto done; ! 496: } ! 497: ! 498: fResult = TRUE; ! 499: ! 500: done: ! 501: if (lpszVerbName) ! 502: OleStdFreeString(lpszVerbName, NULL); ! 503: if (!lpszShortType && lpszShortTypeName) ! 504: OleStdFreeString(lpszShortTypeName, NULL); ! 505: if (lpEnumOleVerb) ! 506: OleStdVerifyRelease( ! 507: (LPUNKNOWN)lpEnumOleVerb, "IEnumOleVerb NOT released\r\n"); ! 508: return fResult; ! 509: } ! 510: ! 511: ! 512: /* PromptUserDlgProc ! 513: * ----------------- ! 514: * ! 515: * Purpose: ! 516: * Dialog procedure used by OleUIPromptUser(). Returns when a button is ! 517: * clicked in the dialog box and the button id is return. ! 518: * ! 519: * Parameters: ! 520: * hDlg ! 521: * iMsg ! 522: * wParam ! 523: * lParam ! 524: * ! 525: * Returns: ! 526: * ! 527: */ ! 528: BOOL CALLBACK EXPORT PromptUserDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) ! 529: { ! 530: switch (iMsg) { ! 531: case WM_INITDIALOG: ! 532: { ! 533: LPSTR lpszTitle; ! 534: char szBuf[256]; ! 535: char szFormat[256]; ! 536: va_list argptr; ! 537: ! 538: argptr = (va_list)lParam; ! 539: if (!lParam) { ! 540: EndDialog(hDlg, -1); ! 541: return FALSE; ! 542: } ! 543: ! 544: lpszTitle = va_arg(argptr, LPSTR); ! 545: SetWindowText(hDlg, lpszTitle); ! 546: ! 547: GetDlgItemText(hDlg, ID_PU_TEXT, (LPSTR)szFormat, 256); ! 548: wvsprintf((LPSTR)szBuf, (LPSTR)szFormat, argptr); ! 549: SetDlgItemText(hDlg, ID_PU_TEXT, (LPSTR)szBuf); ! 550: return TRUE; ! 551: } ! 552: case WM_COMMAND: ! 553: EndDialog(hDlg, wParam); ! 554: return TRUE; ! 555: ! 556: default: ! 557: return FALSE; ! 558: } ! 559: } ! 560: ! 561: ! 562: /* OleUIPromptUser ! 563: * --------------- ! 564: * ! 565: * Purpose: ! 566: * Popup a dialog box with the specified template and returned the ! 567: * response (button id) from the user. ! 568: * ! 569: * Parameters: ! 570: * nTemplate resource number of the dialog ! 571: * hwndParent parent of the dialog box ! 572: * ... title of the dialog box followed by argument list ! 573: * for the format string in the static control ! 574: * (ID_PU_TEXT) of the dialog box. ! 575: * The caller has to make sure that the correct number ! 576: * and type of argument are passed in. ! 577: * ! 578: * Returns: ! 579: * button id selected by the user (template dependent) ! 580: */ ! 581: int EXPORT FAR CDECL OleUIPromptUser(int nTemplate, HWND hwndParent, ...) ! 582: { ! 583: int nRet; ! 584: ! 585: va_list argptr; ! 586: ! 587: va_start(argptr, hwndParent); ! 588: nRet = DialogBoxParam(ghInst, MAKEINTRESOURCE(nTemplate), hwndParent, ! 589: PromptUserDlgProc, (LPARAM)argptr); ! 590: ! 591: va_end(argptr); ! 592: return nRet; ! 593: } ! 594: ! 595: ! 596: ! 597: /* UpdateLinksDlgProc ! 598: * ------------------ ! 599: * ! 600: * Purpose: ! 601: * Dialog procedure used by OleUIUpdateLinks(). It will enumerate all ! 602: * all links in the container and updates all automatic links. ! 603: * Returns when the Stop Button is clicked in the dialog box or when all ! 604: * links are updated ! 605: * ! 606: * Parameters: ! 607: * hDlg ! 608: * iMsg ! 609: * wParam ! 610: * lParam pointer to the UPDATELINKS structure ! 611: * ! 612: * Returns: ! 613: * ! 614: */ ! 615: BOOL CALLBACK EXPORT UpdateLinksDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam) ! 616: { ! 617: LPUPDATELINKS lpUL; ! 618: ! 619: switch (iMsg) { ! 620: case WM_INITDIALOG: ! 621: lpUL = (LPUPDATELINKS)lParam; ! 622: SetWindowText(hDlg, lpUL->lpszTitle); ! 623: PostMessage(hDlg, WM_U_UPDATELINK, 0, lParam); ! 624: return TRUE; ! 625: ! 626: case WM_COMMAND: // Stop button ! 627: EndDialog(hDlg, 0); ! 628: return TRUE; ! 629: ! 630: case WM_U_UPDATELINK: ! 631: { ! 632: HRESULT hErr; ! 633: int nPercent; ! 634: RECT rc; ! 635: char szPercent[5]; // 0% to 100% ! 636: HBRUSH hbr; ! 637: HDC hDC; ! 638: HWND hwndMeter; ! 639: MSG msg; ! 640: DWORD dwUpdateOpt; ! 641: ! 642: lpUL = (LPUPDATELINKS)lParam; ! 643: lpUL->dwLink = lpUL->lpOleUILinkCntr->lpVtbl->GetNextLink( ! 644: lpUL->lpOleUILinkCntr, ! 645: lpUL->dwLink ! 646: ); ! 647: ! 648: if (!lpUL->dwLink) { // all links processed ! 649: EndDialog(hDlg, 0); ! 650: return TRUE; ! 651: } ! 652: ! 653: hErr = lpUL->lpOleUILinkCntr->lpVtbl->GetLinkUpdateOptions( ! 654: lpUL->lpOleUILinkCntr, ! 655: lpUL->dwLink, ! 656: (LPDWORD)&dwUpdateOpt ! 657: ); ! 658: ! 659: if ((hErr == NOERROR) && (dwUpdateOpt == OLEUPDATE_ALWAYS)) { ! 660: ! 661: hErr = lpUL->lpOleUILinkCntr->lpVtbl->UpdateLink( ! 662: lpUL->lpOleUILinkCntr, ! 663: lpUL->dwLink, ! 664: FALSE, // fMessage ! 665: FALSE // ignored ! 666: ); ! 667: lpUL->fError |= (hErr != NOERROR); ! 668: lpUL->cUpdated++; ! 669: ! 670: // update percentage ! 671: nPercent = lpUL->cUpdated * 100 / lpUL->cLinks; ! 672: wsprintf((LPSTR)szPercent, "%d%%", nPercent); ! 673: SetDlgItemText(hDlg, ID_PU_PERCENT, (LPSTR)szPercent); ! 674: ! 675: // update indicator ! 676: hwndMeter = GetDlgItem(hDlg, ID_PU_METER); ! 677: GetClientRect(hwndMeter, (LPRECT)&rc); ! 678: rc.right = (rc.right - rc.left) * nPercent / 100 + rc.left; ! 679: hbr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)); ! 680: if (hbr) { ! 681: hDC = GetDC(hwndMeter); ! 682: if (hDC) { ! 683: FillRect(hDC, (LPRECT)&rc, hbr); ! 684: ReleaseDC(hwndMeter, hDC); ! 685: } ! 686: DeleteObject(hbr); ! 687: } ! 688: } ! 689: while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { ! 690: TranslateMessage(&msg); ! 691: DispatchMessage(&msg); ! 692: } ! 693: ! 694: PostMessage(hDlg, WM_U_UPDATELINK, 0, lParam); ! 695: return TRUE; ! 696: } ! 697: ! 698: default: ! 699: return FALSE; ! 700: } ! 701: } ! 702: ! 703: ! 704: /* OleUIUpdateLink ! 705: * --------------- ! 706: * ! 707: * Purpose: ! 708: * Update all links in the Link Container and popup a dialog box which ! 709: * shows the progress of the updating. ! 710: * The process is stopped when the user press Stop button or when all ! 711: * links are processed. ! 712: * ! 713: * Parameters: ! 714: * lpOleUILinkCntr pointer to Link Container ! 715: * hwndParent parent window of the dialog ! 716: * lpszTitle title of the dialog box ! 717: * cLinks total number of links ! 718: * ! 719: * Returns: ! 720: * TRUE all links updated successfully ! 721: * FALSE otherwise ! 722: */ ! 723: STDAPI_(BOOL) OleUIUpdateLinks(LPOLEUILINKCONTAINER lpOleUILinkCntr, HWND hwndParent, LPSTR lpszTitle, int cLinks) ! 724: { ! 725: LPUPDATELINKS lpUL = (LPUPDATELINKS)OleStdMalloc(sizeof(UPDATELINKS)); ! 726: BOOL fError; ! 727: ! 728: OleDbgAssert(lpOleUILinkCntr && hwndParent && lpszTitle && (cLinks>0)); ! 729: OleDbgAssert(lpUL); ! 730: ! 731: lpUL->lpOleUILinkCntr = lpOleUILinkCntr; ! 732: lpUL->cLinks = cLinks; ! 733: lpUL->cUpdated = 0; ! 734: lpUL->dwLink = 0; ! 735: lpUL->fError = FALSE; ! 736: lpUL->lpszTitle = lpszTitle; ! 737: ! 738: DialogBoxParam(ghInst, MAKEINTRESOURCE(IDD_UPDATELINKS), ! 739: hwndParent, UpdateLinksDlgProc, (LPARAM)lpUL); ! 740: ! 741: fError = lpUL->fError; ! 742: OleStdFree((LPVOID)lpUL); ! 743: ! 744: return !fError; ! 745: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.