confirm.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //****************************************************************************
  2. //
  3. //  Module:     RNAUI.DLL
  4. //  File:       confirm.c
  5. //  Content:    This file contains all the functions for connect confirmation
  6. //              dialog.
  7. //  History:
  8. //      Tue 19-Mar-1996 09:25:38  -by-  Viroon  Touranachun [viroont]
  9. //
  10. //  Copyright (c) Microsoft Corporation 1991-1996
  11. //
  12. //****************************************************************************
  13. #include "rnaui.h"
  14. #include "contain.h"
  15. #include "subobj.h"
  16. #include "rnahelp.h"
  17. #define ID_CC_TIMER         100
  18. #define CC_POLLING_INTERVAL 5000
  19. typedef struct tagCCDlg {
  20.     HRASCONN        hrasconn;
  21.     LPSTR           pszEntry;
  22.     UINT            idTimer;
  23.     RASCONNSTATUS   rcs;
  24.     HBITMAP         hbm;
  25.     HFONT           hFont;
  26. }   CCDLG, *PCCDLG;
  27. LONG CALLBACK ConfirmConnectDlgProc (HWND hDlg, UINT message,
  28.                                      WPARAM wParam, LPARAM lParam);
  29. /*----------------------------------------------------------
  30. Purpose: Display the connection confirmation dialog box
  31. Returns: None
  32. Cond:    --
  33. */
  34. void NEAR PASCAL ConfirmConnection (HWND hwnd, LPSTR szEntry)
  35. {
  36.   RNASETTING si;
  37.   // Check whether we should display the dialog box
  38.   //
  39.   RnaGetDialSettings(&si);
  40.   if (si.dwDialUI & DIALUI_NO_CONFIRM)
  41.     return;
  42.   // Yes, we will display the dialog box
  43.   //
  44.   DialogBoxParam(ghInstance,
  45.                  MAKEINTRESOURCE(IDD_CONFIRMCONNECT),
  46.                  hwnd, ConfirmConnectDlgProc, (LPARAM)szEntry);
  47.   return;
  48. }
  49. /*----------------------------------------------------------
  50. Purpose: Initialize the dialog appearence
  51. Returns: None
  52. Cond:    --
  53. */
  54. void NEAR PASCAL _InitRedCarpetDialog(HWND hwndDlg)
  55. {
  56.     HBITMAP hbm;
  57.     HWND    hwndCtl;
  58.     NONCLIENTMETRICS ncm;
  59.     PCCDLG  pCCDlg;
  60.     pCCDlg   =   (PCCDLG)GetWindowLong(hwndDlg, DWL_USER);
  61.     if (hwndCtl = GetDlgItem(hwndDlg, IDC_WELCOME_MON))
  62.     {
  63.         RECT rc;
  64.         // set the position so that dithered colors won't leave a border.
  65.         GetWindowRect(hwndCtl, &rc);
  66.         hbm = (HBITMAP)LoadImage(ghInstance, MAKEINTRESOURCE(IDB_WELCOME_MON),
  67.                                  IMAGE_BITMAP,
  68.                                  rc.right - rc.left,
  69.                                  rc.bottom - rc.top,
  70.                                  LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS);
  71.         if (hbm)
  72.         {
  73.             SendMessage(hwndCtl, STM_SETIMAGE, 0, (LPARAM)hbm);
  74.             pCCDlg->hbm = hbm;
  75.         }
  76.     }
  77.     // Make the You know font to be bold...
  78.     ncm.cbSize = sizeof(ncm);
  79.     if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0))
  80.     {
  81.         HFONT hfontTemp;
  82.         // make the bold font
  83.         ncm.lfMenuFont.lfWeight = FW_BOLD;
  84.         hfontTemp = CreateFontIndirect(&ncm.lfMenuFont);
  85.         if (hfontTemp)
  86.         {
  87.             SendDlgItemMessage(hwndDlg, IDC_CC_NAME,
  88.                     WM_SETFONT, (WPARAM)hfontTemp, 0);
  89.             pCCDlg->hFont = hfontTemp;
  90.         }
  91.     }
  92. }
  93. /*----------------------------------------------------------
  94. Purpose: Initializes the connection confirmation dialog box
  95. Returns: None
  96. Cond:    --
  97. */
  98. DWORD NEAR PASCAL InitConfirmConnectDlg (HWND hwnd, LPSTR pszEntry)
  99. {
  100.   PCCDLG pCCDlg;
  101.   char   szFmt[MAXMESSAGE], szShortName[MAXNAME], szText[MAXSTRINGLEN];
  102.   // Allocate buffer for the connection info
  103.   //
  104.   pCCDlg = (PCCDLG)LocalAlloc(LPTR, sizeof(*pCCDlg));
  105.   SetWindowLong(hwnd, DWL_USER, (LPARAM)pCCDlg);
  106.   if (pCCDlg == NULL)
  107.   {
  108.     return ERROR_OUTOFMEMORY;
  109.   };
  110.   // Get the connection handle
  111.   //
  112.   if ((pCCDlg->hrasconn = Remote_GetConnHandle(pszEntry)) == NULL)
  113.   {
  114.     return ERROR_INVALID_HANDLE;
  115.   };
  116.   // Display the connection name
  117.   //
  118.   pCCDlg->pszEntry = pszEntry;
  119.   ShortenName(pszEntry, szShortName, sizeof(szShortName));
  120.   GetDlgItemText(hwnd, IDC_CC_NAME, szFmt, sizeof(szFmt));
  121.   wsprintf(szText, szFmt, szShortName);
  122.   SetDlgItemText(hwnd, IDC_CC_NAME, szText);
  123.   // Initialize the dialog appearence
  124.   //
  125.   _InitRedCarpetDialog(hwnd);
  126.   // Set the polling timer
  127.   //
  128.   pCCDlg->rcs.dwSize = sizeof(RASCONNSTATUS);
  129.   pCCDlg->idTimer = SetTimer(hwnd, ID_CC_TIMER, CC_POLLING_INTERVAL, NULL);
  130.   return ERROR_SUCCESS;
  131. }
  132. /*----------------------------------------------------------
  133. Purpose: Deinitializes the connection confirmation dialog box
  134. Returns: None
  135. Cond:    --
  136. */
  137. void NEAR PASCAL DeinitConfirmConnectDlg (HWND hwnd)
  138. {
  139.   PCCDLG pCCDlg;
  140.   pCCDlg = (PCCDLG)GetWindowLong(hwnd, DWL_USER);
  141.   if (pCCDlg != NULL)
  142.   {
  143.     // Kill the polling timer
  144.     //
  145.     if (pCCDlg->idTimer != 0)
  146.     {
  147.       KillTimer(hwnd, pCCDlg->idTimer);
  148.     };
  149.     if (pCCDlg->hbm != NULL)
  150.     {
  151.       DeleteObject(pCCDlg->hbm);
  152.     };
  153.     if (pCCDlg->hFont != NULL)
  154.     {
  155.       DeleteObject(pCCDlg->hFont);
  156.     };
  157.     // Free the connection info buffer
  158.     //
  159.     LocalFree((HLOCAL)pCCDlg);
  160.   };
  161.   return;
  162. }
  163. /*----------------------------------------------------------
  164. Purpose: Checks the connection status
  165. Returns: None
  166. Cond:    --
  167. */
  168. DWORD NEAR PASCAL CheckConnectionStatus (HWND hwnd)
  169. {
  170.   PCCDLG pCCDlg;
  171.   pCCDlg = (PCCDLG)GetWindowLong(hwnd, DWL_USER);
  172.   // Get the connection status
  173.   //
  174.   return (RasGetConnectStatus(pCCDlg->hrasconn, &pCCDlg->rcs));
  175. }
  176. /*----------------------------------------------------------
  177. Purpose: Display the connection confirmation dialog box
  178. Returns: None
  179. Cond:    --
  180. */
  181. LONG CALLBACK ConfirmConnectDlgProc (HWND hDlg, UINT message, WPARAM wParam,
  182.                                     LPARAM lParam)
  183. {
  184.   switch(message)
  185.   {
  186.     case WM_INITDIALOG:
  187.         if (InitConfirmConnectDlg(hDlg, (LPSTR)lParam) != ERROR_SUCCESS)
  188.         {
  189.           EndDialog(hDlg, IDCANCEL);
  190.         };
  191.         return TRUE;
  192.     case WM_COMMAND:
  193.         switch(GET_WM_COMMAND_ID(wParam, lParam))
  194.         {
  195.           case IDC_CC_WHATSNEXT:
  196.             WhatNextHelp (hDlg);
  197.             break;
  198.           case IDOK:
  199.           {
  200.             if (IsDlgButtonChecked(hDlg, IDC_CC_NO_CONFIRM))
  201.             {
  202.               RNASETTING si;
  203.               // Do not prompt this dialog in the future
  204.               //
  205.               RnaGetDialSettings(&si);
  206.               si.dwDialUI |= DIALUI_NO_CONFIRM;
  207.               RnaSetDialSettings(&si);
  208.             };
  209.             EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  210.             break;
  211.           }
  212.           default:
  213.             break;
  214.         }
  215.         break;
  216.     case WM_TIMER:
  217.         if (CheckConnectionStatus(hDlg) != ERROR_SUCCESS)
  218.         {
  219.           EndDialog(hDlg, IDCANCEL);
  220.         };
  221.         break;
  222.     case WM_DESTROY:
  223.         DeinitConfirmConnectDlg(hDlg);
  224.         break;
  225.     case WM_HELP:
  226.     case WM_CONTEXTMENU:
  227.       ContextHelp(gaConfirm, message, wParam, lParam);
  228.       break;
  229.     default:
  230.         break;
  231.   };
  232.   return FALSE;
  233. }