home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / mapi / manager.sh / smhwiz.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-11  |  10.9 KB  |  411 lines

  1. /*
  2.  *  S M H W I Z . C
  3.  *
  4.  *  Sample mail handling hook configuration wizard
  5.  *  Copyright 1992-95 Microsoft Corporation.  All Rights Reserved.
  6.  */
  7.  
  8. #include "_pch.h"
  9.  
  10. extern SPropTagArray sptConfigProps;
  11.  
  12. /*
  13.  *  Wizard global and external variables
  14.  */
  15. static LPMAPIPROP lpmpWiz = NULL;
  16. static LPSPropValue lpvalWiz = NULL;
  17. static UINT ipgCur = (UINT)(-1);
  18.  
  19. /*
  20.  *  MAPI Initialization structure.
  21.  *
  22.  *  By initializing MAPI, the wizard can allocate and/or free memory
  23.  *  using MAPIAllocateBuffer(), MAPIAllocateMore(), and MAPIFreeBuffer()
  24.  */
  25. static const MAPIINIT mapiinit = { MAPI_INIT_VERSION, 0 };
  26.  
  27. /* Wizard page enumeration */
  28.  
  29. enum {ipgSentMail, ipgDeleted, ipgInbound, ipgUnread, cpgMax};
  30.  
  31.  
  32. /*
  33.  *  TogglePage()
  34.  *
  35.  *  Purpose:
  36.  *
  37.  *      Toggles the state of the current page to be either enabled and
  38.  *      visible or disabled and hidden.
  39.  *
  40.  *      IMPORTANT: This function relies on the dialog control IDs as
  41.  *      defined in _SMH.RH.  Each page exists in a certain range and all
  42.  *      controls in each page must have contiguous IDs starting at the
  43.  *      page ID value.
  44.  *
  45.  *  Arguments:
  46.  *
  47.  *      hdlg            the dialog
  48.  *      ipg             the page index (0 - cpgMax)
  49.  *      fEnable         boolean used to either enable for disable the page
  50.  */
  51. VOID
  52. TogglePage (HWND hdlg, UINT ipg, BOOL fEnable)
  53. {
  54.     UINT ictl = 0;
  55.     HANDLE hctl;
  56.  
  57.     if (ipg >= cpgMax)
  58.         return;
  59.  
  60.     while (hctl = GetDlgItem (hdlg, (WIZ_BASE + (ipg * PAGE_INC) + ictl++)))
  61.     {
  62.         EnableWindow (hctl, fEnable);
  63.         ShowWindow (hctl, (fEnable ? SW_SHOW : SW_HIDE));
  64.     }
  65. }
  66.  
  67.  
  68. /*
  69.  *  EnablePage()
  70.  *
  71.  *  Purpose:
  72.  *
  73.  *      Toggles the state of the current page controls to be either
  74.  *      enabled or disabled.
  75.  *
  76.  *      IMPORTANT: This function relies on the dialog control IDs as
  77.  *      defined in _SMH.RH.  Each page exists in a certain range and all
  78.  *      controls in each page must have contiguous IDs starting at the
  79.  *      page ID value.
  80.  *
  81.  *  Arguments:
  82.  *
  83.  *      hdlg            the dialog
  84.  *      ipg             the page index (0 - cpgMax)
  85.  *      fEnable         boolean used to either enable for disable the page
  86.  */
  87. VOID
  88. EnablePage (HWND hdlg, UINT ipg, BOOL fEnable)
  89. {
  90.     UINT ictl = 0;
  91.     HANDLE hctl;
  92.  
  93.     if (ipg >= cpgMax)
  94.         return;
  95.  
  96.     while (hctl = GetDlgItem (hdlg, (WIZ_BASE + (ipg * PAGE_INC) + ictl++)))
  97.         EnableWindow (hctl, fEnable);
  98. }
  99.  
  100.  
  101. /*
  102.  *  ShowPage()
  103.  *
  104.  *  Purpose:
  105.  *
  106.  *      Toggles the state of the current page controls to be either
  107.  *      visible or hidden.
  108.  *
  109.  *      IMPORTANT: This function relies on the dialog control IDs as
  110.  *      defined in _SMH.RH.  Each page exists in a certain range and all
  111.  *      controls in each page must have contiguous IDs starting at the
  112.  *      page ID value.
  113.  *
  114.  *  Arguments:
  115.  *
  116.  *      hdlg            the dialog
  117.  *      ipg             the page index (0 - cpgMax)
  118.  *      fEnable         boolean used to either show or hide the page
  119.  */
  120. VOID
  121. ShowPage (HWND hdlg, UINT ipg, BOOL fEnable)
  122. {
  123.     UINT ictl = 0;
  124.     HANDLE hctl;
  125.  
  126.     if (ipg >= cpgMax)
  127.         return;
  128.  
  129.     while (hctl = GetDlgItem (hdlg, (WIZ_BASE + (ipg * PAGE_INC) + ictl++)))
  130.         ShowWindow (hctl, (fEnable ? SW_SHOW : SW_HIDE));
  131. }
  132.  
  133.  
  134. /*
  135.  *  WizardPage_INITDIALOG()
  136.  *
  137.  *  Purpose:
  138.  *
  139.  *      Responds to the WM_INITDIALOG message.
  140.  *
  141.  *  Returns:
  142.  *
  143.  *      TRUE iff the initialization was successful
  144.  */
  145. BOOL
  146. WizardPage_INITDIALOG (HWND hdlg, HWND hwndFocus, LPARAM lParam)
  147. {
  148.     ULONG cval;
  149.     ULONG ulFlags;
  150.  
  151.     if (!FAILED (MAPIInitialize ((LPMAPIINIT)&mapiinit)) &&
  152.         !HR_FAILED (lpmpWiz->lpVtbl->GetProps (lpmpWiz,
  153.                                         (LPSPropTagArray)&sptConfigProps,
  154.                                         0,
  155.                                         &cval,
  156.                                         &lpvalWiz)))
  157.     {
  158.         ulFlags = (lpvalWiz[ipFlags].ulPropTag == PR_SMH_FLAGS)
  159.             ? lpvalWiz[ipFlags].Value.l
  160.             : 0;
  161.  
  162.         CheckDlgButton (hdlg, ID_SentMail, !!(ulFlags & SMH_FILTER_SENTMAIL));
  163.         CheckDlgButton (hdlg, ID_SentMailYr, !!(ulFlags & SMH_FILTER_SENTMAIL_YR));
  164.         CheckDlgButton (hdlg, ID_Deleted, !!(ulFlags & SMH_FILTER_DELETED));
  165.         CheckDlgButton (hdlg, ID_DeletedYr, !!(ulFlags & SMH_FILTER_DELETED_YR));
  166.         CheckDlgButton (hdlg, ID_Inbound, !!(ulFlags & SMH_FILTER_INBOUND));
  167.         CheckDlgButton (hdlg, ID_Unread, !!(ulFlags & SMH_UNREAD_VIEWER));
  168.         lpvalWiz[ipFlags].ulPropTag = PR_SMH_FLAGS;
  169.         lpvalWiz[ipFlags].Value.l = ulFlags;
  170.         DebugTrace ("SMH: wizard initialized\n");
  171.         return TRUE;
  172.     }
  173.     else
  174.     {
  175.         DebugTrace ("SMH: wizard initializion failed\n");
  176.         return FALSE;
  177.     }
  178. }
  179.  
  180.  
  181. /*
  182.  *  WizardPage_COMMAND()
  183.  *
  184.  *  Purpose:
  185.  *
  186.  *      Responds to the WM_COMMAND message.
  187.  *
  188.  *      IMPORTANT: This function relies on the dialog control IDs as
  189.  *      defined in _SMH.RH.  Each page exists in a certain range and all
  190.  *      controls in each page must have contiguous IDs starting at the
  191.  *      page ID value.
  192.  *
  193.  *  Returns:
  194.  *
  195.  *      TRUE iff the command was processed by the wizard page
  196.  */
  197. BOOL
  198. WizardPage_COMMAND (HWND hdlg, UINT id, HWND hwndCtl, UINT codeNotify)
  199. {
  200.     UINT cpgJmp = 1;
  201.  
  202.     switch (id)
  203.     {
  204.       case ID_SentMail:
  205.       case ID_Deleted:
  206.  
  207.         /* Check/uncheck the companion checkbox */
  208.  
  209.         EnableWindow (GetDlgItem (hdlg, id + 1), !!IsDlgButtonChecked (hdlg, id));
  210.         break;
  211.  
  212.       case WIZ_PREV:
  213.  
  214.         cpgJmp = (UINT)(-((INT)cpgJmp));
  215.  
  216.         /* Fall through! */
  217.  
  218.       case WIZ_NEXT:
  219.  
  220.         DebugTrace ("SMH: PREV/NEXT'd from pg %d to pg %d\n", ipgCur, ipgCur + cpgJmp);
  221.  
  222.         /* Disable/hide the current page and enable target page */
  223.         TogglePage (hdlg, ipgCur, FALSE);
  224.         EnablePage (hdlg, ipgCur += cpgJmp, TRUE);
  225.  
  226.         switch (ipgCur)
  227.         {
  228.           case ipgSentMail:
  229.  
  230.             EnableWindow (GetDlgItem (hdlg, ID_SentMailYr),
  231.                 !!IsDlgButtonChecked (hdlg, ID_SentMail));
  232.             break;
  233.  
  234.           case ipgDeleted:
  235.  
  236.             EnableWindow (GetDlgItem (hdlg, ID_DeletedYr),
  237.                 !!IsDlgButtonChecked (hdlg, ID_Deleted));
  238.             break;
  239.  
  240.           case ipgInbound:
  241.           case ipgUnread:
  242.  
  243.             break;
  244.  
  245.           case cpgMax:
  246.  
  247.             if (IsDlgButtonChecked (hdlg, ID_SentMail))
  248.             {
  249.                 lpvalWiz[ipFlags].Value.l |= SMH_FILTER_SENTMAIL;
  250.                 if (IsDlgButtonChecked (hdlg, ID_SentMailYr))
  251.                     lpvalWiz[ipFlags].Value.l |= SMH_FILTER_SENTMAIL_YR;
  252.                 else
  253.                     lpvalWiz[ipFlags].Value.l &= ~SMH_FILTER_SENTMAIL_YR;
  254.             }
  255.             else
  256.                 lpvalWiz[ipFlags].Value.l &= ~(SMH_FILTER_SENTMAIL | SMH_FILTER_SENTMAIL_YR);
  257.  
  258.             if (IsDlgButtonChecked (hdlg, ID_Deleted))
  259.             {
  260.                 lpvalWiz[ipFlags].Value.l |= SMH_FILTER_DELETED;
  261.                 if (IsDlgButtonChecked (hdlg, ID_DeletedYr))
  262.                     lpvalWiz[ipFlags].Value.l |= SMH_FILTER_DELETED_YR;
  263.                 else
  264.                     lpvalWiz[ipFlags].Value.l &= ~SMH_FILTER_DELETED_YR;
  265.             }
  266.             else
  267.                 lpvalWiz[ipFlags].Value.l &= ~(SMH_FILTER_DELETED | SMH_FILTER_DELETED_YR);
  268.  
  269.             if (IsDlgButtonChecked (hdlg, ID_Inbound))
  270.                 lpvalWiz[ipFlags].Value.l |= SMH_FILTER_INBOUND;
  271.             else
  272.                 lpvalWiz[ipFlags].Value.l &= ~SMH_FILTER_INBOUND;
  273.  
  274.             if (IsDlgButtonChecked (hdlg, ID_Unread))
  275.                 lpvalWiz[ipFlags].Value.l |= SMH_UNREAD_VIEWER;
  276.             else
  277.                 lpvalWiz[ipFlags].Value.l &= ~SMH_UNREAD_VIEWER;
  278.  
  279.             lpmpWiz->lpVtbl->SetProps (lpmpWiz, cpMax, lpvalWiz, NULL);
  280.             lpmpWiz->lpVtbl->SaveChanges (lpmpWiz, KEEP_OPEN_READWRITE);
  281.             break;
  282.         }
  283.  
  284.         /* Unhide the target page */
  285.  
  286.         ShowPage (hdlg, ipgCur, TRUE);
  287.         return (BOOL)cpgJmp;
  288.  
  289.       default:
  290.  
  291.         return FALSE;
  292.     }
  293.  
  294.     return TRUE;
  295. }
  296.  
  297.  
  298. /*
  299.  *  SMH_WizProc()
  300.  *
  301.  *  Purpose:
  302.  *
  303.  *      The wizard page dialog proceedure.
  304.  *
  305.  *  Arguments:
  306.  *
  307.  *      hdlg        the dialog
  308.  *      wMsgID      the message
  309.  *      wParam
  310.  *      lParam
  311.  */
  312. BOOL STDAPICALLTYPE
  313. SMH_WizProc (HWND hdlg,
  314.     UINT wMsgID,
  315.     WPARAM wParam,
  316.     LPARAM lParam)
  317. {
  318.     //static UINT ipgCur = (UINT)(-1);
  319.     static LPSPropValue lpval = NULL;
  320.  
  321.     switch (wMsgID)
  322.     {
  323.       case WM_INITDIALOG:
  324.  
  325.         return (BOOL)FHandleWm (WizardPage, hdlg, INITDIALOG, wParam, lParam);
  326.  
  327.       case WIZ_QUERYNUMPAGES:
  328.  
  329.         DebugTrace ("SMH: wizard page count %d\n", cpgMax);
  330.         return (BOOL)cpgMax;
  331.  
  332.       case WM_CLOSE:
  333.  
  334.         DebugTrace ("SMH: wizard closed\n");
  335.  
  336.         ipgCur = (UINT)(-1);
  337.         MAPIFreeBuffer (lpvalWiz);
  338.         MAPIUninitialize ();
  339.         lpvalWiz = NULL;
  340.  
  341.         UlRelease (lpmpWiz);
  342.         lpmpWiz = NULL;
  343.         break;
  344.  
  345.       case WM_COMMAND:
  346.  
  347.         return (BOOL)FHandleWm (WizardPage, hdlg, COMMAND, wParam, lParam);
  348.  
  349.       default:
  350.  
  351.         return FALSE;
  352.     }
  353.  
  354.     return TRUE;
  355. }
  356.  
  357. /*
  358.  *  WizardEntry()
  359.  *
  360.  *  Purpose:
  361.  *
  362.  *      This is the initial entrypoint for the MAPI 1.0 configuration
  363.  *      wizard.  This function tells the wizard DLL how many pages the
  364.  *      configuration for this service requires as well as the dialog
  365.  *      procedure to call for each individual event.
  366.  *
  367.  *  Arguments:
  368.  *
  369.  *      hInstance       the instance of my dll, this can be used to
  370.  *                      retrieve resources out of my DLL, etc.
  371.  *
  372.  *      lpszRsrcName    [OUT]   on return, this buffer is filled with
  373.  *                              the full name of the dialog resource ID.
  374.  *                              Note that this requires the name to be a
  375.  *                              text value and not something generated
  376.  *                              with the MAKEINTRESOURCE() macro
  377.  *
  378.  *      lpfnDlgProc     [OUT]   on return, holds a function pointer to
  379.  *                              the dialog proc to call for each event
  380.  *
  381.  *      lpMapiProp      the pointer to a IMAPIProp object that is my
  382.  *                      interface to the profile.
  383.  *
  384.  *  Returns:
  385.  *
  386.  *      (SCODE)         S_OK
  387.  */
  388. ULONG STDAPICALLTYPE
  389. SMH_WizEntry (HINSTANCE hInstance,
  390.     LPTSTR FAR * lppszRsrcName,
  391.     DLGPROC FAR * lpfnDlgProc,
  392.     LPMAPIPROP lpMapiProp,
  393.     LPVOID lpsup)
  394. {
  395.     Unreferenced (lpsup);
  396.     
  397.     /*  Stash the MAPIPROP object in global for use in the
  398.      *  configuration wizard
  399.      */
  400.     lpmpWiz = lpMapiProp;
  401.     UlAddRef (lpmpWiz);
  402.  
  403.     /*  tell the configuration wizard the dialog template name
  404.      *  and the window proceedure to use
  405.      */
  406.     *lppszRsrcName = (LPTSTR)szWizardDialog;
  407.     *lpfnDlgProc = (DLGPROC)SMH_WizProc;
  408.  
  409.     return S_OK;
  410. }
  411.