⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rasconn.cpp

📁 WINDOWS CE 通信指南(附光盘) 本书配套光盘内容包括:本书的英文版电子书;SDK for Windows CE
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  {
    MessageBox (hDlgWnd, TEXT("Not enough memory"), szTitle, MB_OK);
    return FALSE;
  }

  // You must initialize the dwSize member of the first RASENTRYNAME 
  // structure in the array to the size of the structure in order to 
  // identify the version of the structure being passed.
  lpRasEntryName[0].dwSize = sizeof (RASENTRYNAME);

  // Size of the array in bytes
  dwSize = sizeof (RASENTRYNAME) * 20;

  // List all entry names in a remote access phone book.
  if ((RasEnumEntries (
          NULL,               // Reserved, must be NULL
          NULL,               // Phone book is stored in the registry
          lpRasEntryName,     // Buffer to receive the entries
          &dwSize,            // Size of the buffer in bytes
          &dwEntries)) != 0)  // Number of entries written to the 
                              // buffer
  {
    MessageBox (hDlgWnd, TEXT("Could not obtain RAS entries"), szTitle,
                MB_OK);
    return FALSE;
  }

  // Get the HWND of the listbox control.
  hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);

  // Remove all items from the listbox.
  SendMessage (hWndListBox, LB_RESETCONTENT, 0, 0);

  // Add the names of each RAS connection to the list box.
  for (index = 0; index < (int)dwEntries; ++index)
  {
    SendMessage (hWndListBox, LB_INSERTSTRING, index, 
                 (LPARAM)lpRasEntryName[index].szEntryName);
  }

  return TRUE;
}


/***********************************************************************

FUNCTION:
  MakeRasDial

PURPOSE:
  Shows how to establish a RAS connection between the windows CE device
  and the remote access server.

***********************************************************************/
BOOL MakeRasDial (HWND hDlgWnd)
{
  BOOL bPassword;
  DWORD dwError;
  TCHAR szBuffer[100];

  if (bUseCurrent)
  {
    // Get the last configuration parameters used for this connection. 
    // If the password was saved, then the login dialog box will not be
    // displayed.
    if (RasGetEntryDialParams (NULL, &RasDialParams, &bPassword) != 0)
    {
      MessageBox (hDlgWnd, 
                  TEXT("Could not get parameter details"), 
                  szTitle, 
                  MB_OK);
      return FALSE;
    }
  }
  else
  {
    // Bring up the Authentication dialog box.
    DialogBox (hInst, MAKEINTRESOURCE(IDD_AUTHDLG), hDlgWnd, 
               AuthDlgProc);

    // Set hRasConn to NULL before attempting to connect.
    hRasConn = NULL;

    // Initialize the structure.
    memset (&RasDialParams, 0, sizeof (RASDIALPARAMS));

    // Configure the RASDIALPARAMS structure. 
    RasDialParams.dwSize = sizeof (RASDIALPARAMS);
    RasDialParams.szPhoneNumber[0] = TEXT('\0');
    RasDialParams.szCallbackNumber[0] = TEXT('\0');
    wcscpy (RasDialParams.szEntryName, szRasEntryName);
    wcscpy (RasDialParams.szUserName, szUserName);
    wcscpy (RasDialParams.szPassword, szPassword);
    wcscpy (RasDialParams.szDomain, szDomain); 
  }

  // Try to establish a RAS connection.
  if ((dwError = RasDial (
          NULL,             // Extension is not supported in Windows CE
          NULL,             // Phone book is in the registry
          &RasDialParams,   // RAS configuration for the connection
          0xFFFFFFFF,       // Must use this value for Windows CE
          hDlgWnd,          // Window receives the notification message
          &hRasConn)) != 0) // Connection handle
  {
    wsprintf (szBuffer, TEXT("Could not connect using RAS. Error %x"), 
              dwError);
    MessageBox (hDlgWnd, szBuffer, szTitle, MB_OK);
    return FALSE;
  }

  wsprintf (szBuffer, TEXT("Dialing %s..."), szRasEntryName);

  // Set the dialing dialog box window name to szBuffer.
  SetWindowText (hDlgWnd, szBuffer);

  return TRUE;
}

/***********************************************************************

FUNCTION:
  GetConnStatus

PURPOSE:
  Gets the status of the current RAS connection. The return value is TRUE
  if successful, FALSE if not.

***********************************************************************/
BOOL GetConnStatus ()
{      
  DWORD dwReturn;
  TCHAR szBuffer[100];
  RASCONNSTATUS RasStatus;  

  // Check if hRasConn is a valid RAS connection handle. 
  if (hRasConn == NULL)
    return FALSE;

  // Get the connection status.
  RasStatus.dwSize = sizeof (RASCONNSTATUS);
  dwReturn = RasGetConnectStatus (hRasConn, &RasStatus);

  // If there is an error in getting the connection status, then return
  // FALSE.
  if (dwReturn)
  {
    wsprintf (szBuffer, TEXT("Failed getting connect status.\r\n")
              TEXT("Error (%ld)."), dwReturn);
    MessageBox (hMainWnd, szBuffer, TEXT("Warning"), MB_OK);
    return FALSE;
  }

  // Check if the Status dialog box has been created.
  if (!hDialingWnd)
    return TRUE;

  // Check if there is an error.
  if (RasStatus.dwError)
    wsprintf (szBuffer, TEXT("Error (%ld)"), RasStatus.dwError);
  else
    wsprintf (szBuffer, TEXT("No error"));

  // Display the error, device type, and device name.
  SetDlgItemText (hDialingWnd, IDC_ERROR, szBuffer);
  SetDlgItemText (hDialingWnd, IDC_DEVICETYPE, RasStatus.szDeviceType);
  SetDlgItemText (hDialingWnd, IDC_DEVICENAME, RasStatus.szDeviceName);

  if (RasStatus.rasconnstate == RASCS_Connected || 
      RasStatus.rasconnstate == RASCS_Disconnected)
    SetDlgItemText (hDialingWnd, IDC_PROGRESS, TEXT("DONE!"));
  else
  {
    if (RasStatus.dwError)
    {
      SetDlgItemText (hDialingWnd, IDC_PROGRESS, 
                      TEXT("DONE! ERROR OCCURED."));
      SetCursor (0);
    }
    else
      SetDlgItemText (hDialingWnd, IDC_PROGRESS, TEXT("WAIT...."));
  }

  return TRUE;
}

/***********************************************************************

FUNCTION:
  PhoneBookDlgProc

PURPOSE:
  Processes messages sent to the Phonebook Entries dialog box window.

***********************************************************************/
BOOL CALLBACK PhoneBookDlgProc (HWND hDlgWnd, UINT uMsg, WPARAM wParam, 
                                LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      GetPhonebookEntries (hDlgWnd);
      return TRUE;

    case WM_COMMAND:
      switch (LOWORD(wParam))
      {
        case IDC_USECURRENT:
          bUseCurrent = (bUseCurrent) ? FALSE : TRUE;
          return TRUE;

        case IDC_CREATE:
          CreateRasEntry (TEXT("New Entry"));
          GetPhonebookEntries (hDlgWnd);
          break;

        case IDC_COPY:
        {
          // Get the HWND of the list box control.
          HWND hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);
          
          // Find out which RAS entry was selected.
          DWORD dwSel = SendMessage (hWndListBox, LB_GETCURSEL, 0, 0);

          if (dwSel == LB_ERR)
          {
            MessageBox (hDlgWnd, 
                        TEXT("Failed in selecting a RAS connection!"),
                        TEXT("Error"), 
                        MB_OK);
            szRasEntryName[0] = TEXT('\0');
          }
          else
          {
            CopyRasEntry (lpRasEntryName[dwSel].szEntryName);
            GetPhonebookEntries (hDlgWnd);
          }

          return TRUE;
        }

        case IDC_RENAME:
        {
          // Get the HWND of the list box control.
          HWND hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);
          
          // Find out which RAS entry was selected.
          DWORD dwSel = SendMessage (hWndListBox, LB_GETCURSEL, 0, 0);

          if (dwSel == LB_ERR)
          {
            MessageBox (hDlgWnd, 
                        TEXT("Failed in selecting a RAS connection!"),
                        TEXT("Error"), 
                        MB_OK);
            szRasEntryName[0] = TEXT('\0');
          }
          else
          {
            // Insert code here to prompt users to enter the new name.
            // Hard code the new entry name as RenamedEntry.
            RenameRasEntry (lpRasEntryName[dwSel].szEntryName, 
                            TEXT("Renamed Entry"));
            GetPhonebookEntries (hDlgWnd);
          }

          return TRUE;
        }

        case IDC_DELETE:
        {
          // Get the HWND of the list box control.
          HWND hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);
          
          // Find out which RAS entry was selected.
          DWORD dwSel = SendMessage (hWndListBox, LB_GETCURSEL, 0, 0);

          if (dwSel == LB_ERR)
          {
            MessageBox (hDlgWnd, 
                        TEXT("Failed in selecting a RAS connection!"),
                        TEXT("Error"), 
                        MB_OK);
            szRasEntryName[0] = TEXT('\0');
          }
          else
          {
            DeleteRasEntry (lpRasEntryName[dwSel].szEntryName);
            GetPhonebookEntries (hDlgWnd);
          }

          return TRUE;
        }

        case IDOK:
        { 
          // Get the HWND of the list box control.
          HWND hWndListBox = GetDlgItem (hDlgWnd, IDC_RASNAMES);
          
          // Find out which RAS entry was selected.
          DWORD dwSel = SendMessage (hWndListBox, LB_GETCURSEL, 0, 0);

          if (dwSel == LB_ERR)
          {
            MessageBox (hDlgWnd, 
                        TEXT("Failed in selecting a RAS connection!"),
                        TEXT("Error"), 
                        MB_OK);
            szRasEntryName[0] = TEXT('\0');
          }
          else
            wcscpy (szRasEntryName, lpRasEntryName[dwSel].szEntryName);

          if (lpRasEntryName)
          {
            delete [] lpRasEntryName;
            lpRasEntryName = NULL;
          }

          EndDialog (hDlgWnd, IDOK);
          return TRUE;
        }

        case IDCANCEL:
          if (lpRasEntryName)
          {
            delete [] lpRasEntryName;
            lpRasEntryName = NULL;
          }

          EndDialog (hDlgWnd, IDCANCEL);
          return TRUE;
      }
      return 0;
  }
  return 0;
}


/***********************************************************************

FUNCTION:
  AuthDlgProc

PURPOSE:
  Processes messages sent to the Authentication dialog box window.

***********************************************************************/
BOOL CALLBACK AuthDlgProc (HWND hDlgWnd, UINT uMsg, WPARAM wParam, 
                           LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      // Set text limits on edit controls.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -