home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / webimage / wimgppg.cpp < prev    next >
C/C++ Source or Header  |  1997-10-09  |  6KB  |  206 lines

  1. //=--------------------------------------------------------------------------=
  2. // WImgPPG.Cpp
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995 - 1997 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // property page implementations for WebImage control.
  13. //
  14.  
  15. #include "IPServer.H"
  16.  
  17. #include "LocalObj.H"
  18. #include "WImgPPG.H"
  19. #include "WImgCtl.H"
  20. #include "Resource.H"
  21. #include "Util.H"
  22.  
  23.  
  24. // for ASSERT and FAIL
  25. //
  26. SZTHISFILE
  27.  
  28. //=--------------------------------------------------------------------------=
  29. // Property Page messages
  30. //=--------------------------------------------------------------------------=
  31. // in addition to regular windows messages you'll receive for a dialog box,
  32. // you'll receive the following messages in your property page implementation:
  33. //
  34. // PPM_NEWOBJECTS:
  35. //    wParam = 0;
  36. //    lParam = (LPARAM)(HRESULT *)hr
  37. //
  38. //  - in this message, you should call FirstControl() to get a pointer to a
  39. //    control, and initialize the values in the property page dialog with
  40. //    values from the control object.  put results from the operation in
  41. //    the HRESULT pointed to by LPARAM.
  42. //
  43. // PPM_APPLY:
  44. //    wParam = 0;
  45. //    lParam = (LPARAM)(HRESULT *)hr
  46. //
  47. //  - this message is sent to your dialog whenever the user clicks APPLY or OK
  48. //    in the dialog.  you should have a loop with the following code in it:
  49. //
  50. //      for (pUnk = FirstControl(&dwCookie) ; pUnk; pUnk = NextControl(&dwCookie)) {
  51. //            hr = pUnk->QueryInterface(IID_IMyCtlInterface, (void **)&pMyCtl);
  52. //            // set properties here!!!
  53. //      }
  54. //
  55. //    call PropPageException() if there is an error while setting propertites
  56. //    to show the exception set up by the property set routine.
  57. //
  58. // PPM_EDITPROPERTY:
  59. //    wParam = dispid
  60. //    lParam = (LPARAM)(HRESULT *)hr
  61. //
  62. //  - sent to your dialog when somebody wants you to set the focus to a specific
  63. //    property [typically, one will see a call to this when one returns a page
  64. //    from IPerPropertyBrowsing::MapPropertyToPage].  you can use this
  65. //    to bring up dialogs, or do whatever flaps your flagella.
  66. //
  67.  
  68.  
  69. //=--------------------------------------------------------------------------=
  70. // CWebImageGeneralPage::Create
  71. //=--------------------------------------------------------------------------=
  72. // global static creation function.
  73. //
  74. // Parameters:
  75. //    IUnknown *    - [in] controlling unknown
  76. //
  77. // Output:
  78. //    IUnknown *    - new prop page.
  79. //
  80. // Notes:
  81. //
  82. IUnknown *CWebImageGeneralPage::Create
  83. (
  84.     IUnknown *pUnkOuter
  85. )
  86. {
  87.     return (IUnknown *)new CWebImageGeneralPage(pUnkOuter);
  88. }
  89.  
  90. //=--------------------------------------------------------------------------=
  91. // CWebImageGeneralPage::CWebImageGeneralPage
  92. //=--------------------------------------------------------------------------=
  93. // constructor.
  94. //
  95. // Parameters:
  96. //    IUnknown *        - [in] controlling unknown.
  97. //
  98. // Notes:
  99. //
  100. CWebImageGeneralPage::CWebImageGeneralPage
  101. (
  102.     IUnknown *pUnkOuter
  103. )
  104. : CPropertyPage(pUnkOuter, OBJECT_TYPE_PPGWEBIMAGEGENERAL)
  105. {
  106.     // initialize local variables here.
  107. }
  108.  
  109. //=--------------------------------------------------------------------------=
  110. // CWebImageGeneralPage::~CWebImageGeneralPage
  111. //=--------------------------------------------------------------------------=
  112. // destructor.
  113. //
  114. // Notes:
  115. //
  116. CWebImageGeneralPage::~CWebImageGeneralPage()
  117. {
  118.     // clean up
  119. }
  120.  
  121. //=--------------------------------------------------------------------------=
  122. // CWebImageGeneralPage::DialogProc
  123. //=--------------------------------------------------------------------------=
  124. // our dialog proc.
  125. //
  126. // Parameters:
  127. //    - see win32sdk docs on DialogProc
  128. //
  129. // Notes:
  130. //
  131. BOOL CWebImageGeneralPage::DialogProc
  132. (
  133.     HWND   hwnd,
  134.     UINT   msg,
  135.     WPARAM wParam,
  136.     LPARAM lParam
  137. )
  138. {
  139.     HRESULT     hr;
  140.     IWebImage *pWebImage;
  141.     IUnknown   *pUnk;
  142.     DWORD       dwDummy;
  143.  
  144.     switch (msg) {
  145.  
  146.       // we've been given some new objects, so go and re-set up the dialog page.
  147.       //
  148.       case PPM_NEWOBJECTS:
  149.         {
  150.  
  151.         pUnk = FirstControl(&dwDummy);
  152.         if (!pUnk) return FALSE;
  153.  
  154.         hr = pUnk->QueryInterface(IID_IWebImage, (void **)&pWebImage);
  155.         if (FAILED(hr)) return FALSE;
  156.  
  157.         //VariantInit(&var);
  158.         BSTR bstr;
  159.         pWebImage->get_Image(&bstr);
  160.         //if( var.vt == VT_BSTR )
  161.         //{
  162.           MAKE_ANSIPTR_FROMWIDE(psz, bstr);//var.bstrVal);
  163.           SetDlgItemText(hwnd, IDC_URL, psz);
  164.           SysFreeString(bstr);//var.bstrVal);
  165.         //    }
  166.         pWebImage->Release();
  167.         }
  168.         return TRUE;
  169.  
  170.       case PPM_APPLY:
  171.         {
  172.         char      szTmp[120];
  173.  
  174.         // get all the controls we have to update.
  175.         //
  176.         for (pUnk = FirstControl(&dwDummy) ; pUnk; pUnk = NextControl(&dwDummy)) 
  177.         {
  178.             hr = pUnk->QueryInterface(IID_IWebImage, (void **)&pWebImage);
  179.             if (FAILED(hr)) continue;
  180.     
  181.             GetDlgItemText(hwnd, IDC_URL, szTmp, 128);
  182.             //VariantInit(&var);
  183.             //var.vt = VT_BSTR;
  184.             BSTR bstr;
  185.             //var.bstrVal = BSTRFROMANSI(szTmp);
  186.             bstr = BSTRFROMANSI(szTmp);
  187.             ASSERT(bstr, "Maggots!");
  188.             pWebImage->put_Image(bstr);
  189.             SysFreeString(bstr);
  190.             pWebImage->Release();
  191.         }
  192.         }
  193.         return TRUE;
  194.  
  195.       case WM_COMMAND:
  196.         switch (LOWORD(wParam)) {
  197.           case IDC_URL:
  198.             if (HIWORD(wParam) == EN_CHANGE)
  199.                 MakeDirty();
  200.         }
  201.         break;
  202.     }
  203.  
  204.     return(FALSE);
  205. }
  206.