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 / basectl / card / cardppg.cpp < prev    next >
C/C++ Source or Header  |  1997-10-05  |  8KB  |  289 lines

  1. //=--------------------------------------------------------------------------=
  2. // CardPPG.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 Card control.
  13. //
  14. #include "IPServer.H"
  15.  
  16. #include "LocalObj.H"
  17. #include "CARDPPG.H"
  18. #include "CARDCtl.H"
  19. #include "Resource.H"
  20. #include "Util.H"
  21.  
  22.  
  23. // for ASSERT and FAIL
  24. //
  25. SZTHISFILE
  26.  
  27. //=--------------------------------------------------------------------------=
  28. // Property Page messages
  29. //=--------------------------------------------------------------------------=
  30. // in addition to regular windows messages you'll receive for a dialog box,
  31. // you'll receive the following messages in your property page implementation:
  32. //
  33. // PPM_NEWOBJECTS:
  34. //    wParam = 0;
  35. //    lParam = (LPARAM)(HRESULT *)hr
  36. //
  37. //  - in this message, you should call FirstControl() to get a pointer to a
  38. //    control, and initialize the values in the property page dialog with
  39. //    values from the control object.  put results from the operation in
  40. //    the HRESULT pointed to by LPARAM.
  41. //
  42. // PPM_APPLY:
  43. //    wParam = 0;
  44. //    lParam = (LPARAM)(HRESULT *)hr
  45. //
  46. //  - this message is sent to your dialog whenever the user clicks APPLY or OK
  47. //    in the dialog.  you should have a loop with the following code in it:
  48. //
  49. //      for (pUnk = FirstControl(&dwCookie) ; pUnk; pUnk = NextControl(&dwCookie)) {
  50. //            hr = pUnk->QueryInterface(IID_IMyCtlInterface, (void **)&pMyCtl);
  51. //            // set properties here!!!
  52. //      }
  53. //
  54. //    call PropPageException() if there is an error while setting propertites
  55. //    to show the exception set up by the property set routine.
  56. //
  57. // PPM_EDITPROPERTY:
  58. //    wParam = dispid
  59. //    lParam = (LPARAM)(HRESULT *)hr
  60. //
  61. //  - sent to your dialog when somebody wants you to set the focus to a specific
  62. //    property [typically, one will see a call to this when one returns a page
  63. //    from IPerPropertyBrowsing::MapPropertyToPage].  you can use this
  64. //    to bring up dialogs, or do whatever flaps your flagella.
  65. //
  66.  
  67.  
  68. //=--------------------------------------------------------------------------=
  69. // CCardGeneralPage::Create
  70. //=--------------------------------------------------------------------------=
  71. // global static creation function.
  72. //
  73. // Parameters:
  74. //    IUnknown *    - [in] controlling unknown
  75. //
  76. // Output:
  77. //    IUnknown *    - new prop page.
  78. //
  79. // Notes:
  80. //
  81. IUnknown *CCardGeneralPage::Create
  82. (
  83.     IUnknown *pUnkOuter
  84. )
  85. {
  86.     return (IUnknown *)new CCardGeneralPage(pUnkOuter);
  87. }
  88.  
  89. //=--------------------------------------------------------------------------=
  90. // CCardGeneralPage::CCardGeneralPage
  91. //=--------------------------------------------------------------------------=
  92. // constructor.
  93. //
  94. // Parameters:
  95. //    IUnknown *        - [in] controlling unknown.
  96. //
  97. // Notes:
  98. //
  99. CCardGeneralPage::CCardGeneralPage
  100. (
  101.     IUnknown *pUnkOuter
  102. )
  103. : CPropertyPage(pUnkOuter, OBJECT_TYPE_PPGCARDGENERAL)
  104. {
  105.     // initialize local variables here.
  106. }
  107.  
  108. //=--------------------------------------------------------------------------=
  109. // CCardGeneralPage::~CCardGeneralPage
  110. //=--------------------------------------------------------------------------=
  111. // destructor.
  112. //
  113. // Notes:
  114. //
  115. CCardGeneralPage::~CCardGeneralPage()
  116. {
  117.     // clean up
  118. }
  119.  
  120. static int SimpleAtoi( const char *str )
  121. {
  122.     int num = 0;
  123.     const char *s;
  124.  
  125.     for( s = (*str == '-' ? str+1 : str); *s >= '0' && *s <= '9'; s++ )
  126.         num = num * 10 + (*s - '0');
  127.  
  128.     return( *str == '-' ? -num : num );
  129. }
  130.  
  131. static void SetDropDown( HWND hwnd, const char *strs[], int id, short set )
  132. {
  133.     short newset;
  134.     int i;
  135.  
  136.     newset = -1000;
  137.     for( i = 0; strs[i]; i++ )
  138.     {
  139.         SendMessage( GetDlgItem( hwnd, id ), CB_ADDSTRING, 
  140.             0, (LPARAM) strs[i] );
  141.         if( SimpleAtoi(strs[i]) == set )
  142.             newset = i;
  143.     }
  144.     if( newset != -1000 )
  145.         SendMessage( GetDlgItem( hwnd, id ), CB_SETCURSEL,
  146.                 (WPARAM) newset, 0 );
  147. }
  148.  
  149. //=--------------------------------------------------------------------------=
  150. // CCardGeneralPage::DialogProc
  151. //=--------------------------------------------------------------------------=
  152. // our dialog proc.
  153. //
  154. // Parameters:
  155. //    - see win32sdk docs on DialogProc
  156. //
  157. // Notes:
  158. //
  159. BOOL CCardGeneralPage::DialogProc
  160. (
  161.     HWND   hwnd,
  162.     UINT   msg,
  163.     WPARAM wParam,
  164.     LPARAM lParam
  165. )
  166. {
  167.     HRESULT     hr;
  168.     ICard *pCard;
  169.     IUnknown   *pUnk;
  170.     DWORD       dwDummy;
  171.     enumCardNumber number;
  172.     enumCardSuite suite;
  173.     enumCardAlignment cardalignment;
  174.     VARIANT_BOOL invert;
  175.  
  176.     static const char *numstr[] = {
  177.         "1   - Ace",
  178.         "2", "3", "4", "5", "6", "7", "8", "9", "10",
  179.         "11  - Jack",
  180.         "12  - Queen",
  181.         "13  - King",
  182.             "14  - Joker",
  183.         NULL };
  184.  
  185.     static const char *alignstr[] = {
  186.         "0   - Top Left",
  187.         "1   - Top Center",
  188.         "2   - Top Right",
  189.         "3   - Center Left",
  190.         "4   - Center",
  191.         "5   - Center Right",
  192.         "6   - Bottom Left",
  193.         "7   - Bottom Center",
  194.         "8   - Bottom Right",
  195.         "9   - Stretch",
  196.         NULL };
  197.  
  198.     static const char *suitestr[] = {
  199.         "0   - Invisible",
  200.         "1   - Clubs", 
  201.         "2   - Spades", 
  202.         "3   - Hearts", 
  203.         "4   - Diamonds",
  204.         "-1  - Card Back: Weave 1",        
  205.         "-2  - Card Back: Weave 2",        
  206.         "-3  - Card Back: Robot",        
  207.         "-4  - Card Back: Roses",        
  208.         "-5  - Card Back: Vine 1 (black)",
  209.         "-6  - Card Back: Vine 2 (blue)",        
  210.         "-7  - Card Back: Fish 1 (light blue)",        
  211.         "-8  - Card Back: Fish 2 (dark blue)",        
  212.         "-9  - Card Back: Seashell",        
  213.         "-10 - Card Back: Castel",
  214.         "-11 - Card Back: Beach",
  215.         "-12 - Card Back: Hand",
  216.         "-13 - Card Back: Casino", 
  217.         NULL };
  218.  
  219.     switch (msg) {
  220.  
  221.       // we've been given some new objects, so go and re-set up the dialog page.
  222.       //
  223.       case PPM_NEWOBJECTS:
  224.         {
  225.  
  226.         pUnk = FirstControl(&dwDummy);
  227.         if (!pUnk) return FALSE;
  228.  
  229.         hr = pUnk->QueryInterface(IID_ICard, (void **)&pCard);
  230.         if (FAILED(hr)) return FALSE;
  231.  
  232.         pCard->get_Number(&number);
  233.         pCard->get_Suite(&suite);
  234.         pCard->get_Invert(&invert);
  235.     pCard->get_CardAlignment(&cardalignment);
  236.  
  237.     SetDropDown( hwnd, suitestr, IDC_SUITE, suite );
  238.     SetDropDown( hwnd, numstr, IDC_NUMBER, number );
  239.     SetDropDown( hwnd, alignstr, IDC_ALIGNMENT, cardalignment );
  240.  
  241.     CheckDlgButton( hwnd, IDC_INVERT, invert == VARIANT_TRUE ? 1 : 0 );
  242.  
  243.         pCard->Release();
  244.         }
  245.         return TRUE;
  246.  
  247.       case PPM_APPLY:
  248.         {
  249.         char      szTmp[128];
  250.  
  251.         // get all the controls we have to update.
  252.         //
  253.         for (pUnk = FirstControl(&dwDummy) ; pUnk; pUnk = NextControl(&dwDummy)) 
  254.         {
  255.             hr = pUnk->QueryInterface(IID_ICard, (void **)&pCard);
  256.             if (FAILED(hr)) continue;
  257.     
  258.             GetDlgItemText(hwnd, IDC_NUMBER, szTmp, 128);
  259.         number = (enumCardNumber) SimpleAtoi(szTmp);
  260.             GetDlgItemText(hwnd, IDC_SUITE, szTmp, 128);
  261.         suite = (enumCardSuite) SimpleAtoi(szTmp);
  262.             GetDlgItemText(hwnd, IDC_ALIGNMENT, szTmp, 128);
  263.         cardalignment = (enumCardAlignment) SimpleAtoi(szTmp);
  264.         invert = IsDlgButtonChecked( hwnd, IDC_INVERT ) ? VARIANT_TRUE : VARIANT_FALSE;
  265.         
  266.             pCard->put_Number(number);
  267.         pCard->put_Suite(suite);
  268.         pCard->put_Invert(invert);
  269.         pCard->put_CardAlignment(cardalignment);
  270.             pCard->Release();
  271.         }
  272.         }
  273.         return TRUE;
  274.  
  275.       case WM_COMMAND:
  276.         switch (LOWORD(wParam)) {
  277.           case IDC_SUITE: case IDC_NUMBER: case IDC_ALIGNMENT:
  278.             if (HIWORD(wParam) == CBN_SELCHANGE)
  279.                 MakeDirty();
  280.       case IDC_INVERT:
  281.         if( HIWORD(wParam) == BN_CLICKED )
  282.         MakeDirty();
  283.         }
  284.         break;
  285.     }
  286.  
  287.     return(FALSE);
  288. }
  289.