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

📄 cehttp.cpp

📁 WINDOWS CE 通信指南(附光盘) 本书配套光盘内容包括:本书的英文版电子书;SDK for Windows CE
💻 CPP
📖 第 1 页 / 共 2 页
字号:

***********************************************************************/
BOOL CALLBACK DialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, 
                          LPARAM lParam)  
{
  switch (uMsg)
  {
    case WM_INITDIALOG:
      SetDlgItemText (hwndDlg, IDC_ADDRESS, g_szIAddName); 
      SetDlgItemText (hwndDlg, IDC_PROXY, g_szProxySvr);

      SendDlgItemMessage (hwndDlg, IDC_PROXY, WM_ENABLE, g_bProxy, 0);

      SendDlgItemMessage (hwndDlg, IDC_OPENURL, BM_SETCHECK, 
                          g_bOpenURL, 0);
      SendDlgItemMessage (hwndDlg, IDC_PROXYSERVER, BM_SETCHECK, 
                          g_bProxy, 0);
      return TRUE;

    case WM_COMMAND:
      switch (LOWORD (wParam))
      {
        case IDC_OPENURL:
          g_bOpenURL = (!g_bOpenURL) ? TRUE : FALSE;
          return TRUE;

        case IDC_PROXYSERVER:
          g_bProxy = (!g_bProxy) ? TRUE : FALSE;
          SendDlgItemMessage (hwndDlg, IDC_PROXY, WM_ENABLE, 
                              g_bProxy, 0);
          return TRUE;

        case IDOK:
          GetDlgItemText (hwndDlg, IDC_ADDRESS, g_szIAddName, 200);

          if (g_bProxy)
            GetDlgItemText (hwndDlg, IDC_PROXY, g_szProxySvr, 200);

          EndDialog (hwndDlg, IDOK);
          return TRUE;

        case IDCANCEL:
          g_szIAddName[0] = TEXT('\0');
          EndDialog (hwndDlg, IDCANCEL);
          return TRUE;
      }
      break;
  }

  return FALSE;
}


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

FUNCTION: 
  WndProc

PURPOSE: 
  Processes messages sent to the main window.
                                                    
***********************************************************************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, 
                          LPARAM lParam)
{
  switch (uMsg)
  {
    case WM_CREATE:
    {  
      // Specify the edit control window style.
      DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER |
                      ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL;
     
      // Create the edit control window.
      g_hwndEdit = CreateWindow (
                TEXT("edit"),   // Class name
                NULL,           // Window text
                dwStyle,        // Window style
                0,              // X-coordinate of the upper-left corner
                0,              // Y-coordinate of the upper-left corner
                CW_USEDEFAULT,  // Width of the edit control window
                CW_USEDEFAULT,  // Height of the edit control window
                hwnd,           // Window handle of parent window
                (HMENU)ID_EDIT, // Control identifier
                g_hInst,        // Instance handle
                NULL);          // Specify NULL for this parameter when 
                                // creating a control

      // Create the command bar and insert the menu.
      g_hwndCB = CommandBar_Create (g_hInst, hwnd, 1);
      CommandBar_InsertMenubar (g_hwndCB, g_hInst, IDR_CEHTTPMENU, 0);
      
      // Add the close button (X) to the command bar. 
      CommandBar_AddAdornments (g_hwndCB, 0, 0);

      return 0;
    }

    case WM_SETFOCUS :
      SetFocus (g_hwndEdit);
      return 0;

    case WM_SIZE : 
      {
        // Get the command bar height.
        int iCBHeight = CommandBar_Height (g_hwndCB); 

        // Resize the Edit Control window.
        MoveWindow (g_hwndEdit, 0, iCBHeight, LOWORD (lParam), 
                    HIWORD (lParam) - iCBHeight, TRUE);
        return 0;
      }
    
    case WM_COMMAND:
      switch (LOWORD (wParam))
      {
        case IDM_OPEN:
          DialogBox (g_hInst, MAKEINTRESOURCE (IDD_ADDRESS), g_hwndMain,
                     DialogProc);

          if (g_szIAddName[0] != TEXT('\0'))
          {
            // Set the cursor as an hourglass.
            SetCursor (LoadCursor (NULL, IDC_WAIT));

            // Open the internet address. 
            if (!GetInternetFile (g_szIAddName, g_szProxySvr))
            {
              // Set the cursor to the normal state.
              SetCursor (0);

              MessageBox (g_hwndMain, 
                          TEXT("Cannot open the internet address"),
                          TEXT("Error"),
                          MB_OK);
            }
            else
            {
              // Include the internet address in the window title.
              wsprintf (g_szCaption, TEXT("%s - %s"), g_szTitle, 
                        g_szIAddName);

              // Set the window title.
              SetWindowText (g_hwndMain, g_szCaption);

              // Set the cursor to the normal state.
              SetCursor (0);
            }
          }

          return 0;
        
        case IDM_ABOUT:
          DialogBox (g_hInst, MAKEINTRESOURCE (IDD_ABOUT), g_hwndMain, 
                     AboutDialogProc);
          return 0;
        
        case IDM_EXIT:
          SendMessage (hwnd, WM_CLOSE, 0, 0);
          return 0;
      }
      break;

    case WM_PUTTEXT:
      {
        // Append new text to the current text in the edit control.
        int iTextLength = Edit_GetSel (g_hwndEdit);
        Edit_SetSel (g_hwndEdit, iTextLength, iTextLength);
        Edit_ReplaceSel (g_hwndEdit, lParam); 
        return 0;
      }

    case WM_CLOSE:
      CommandBar_Destroy (g_hwndCB);
      DestroyWindow (hwnd);
      return 0;

    case WM_DESTROY:
      PostQuitMessage (0);
      return 0;
  }

  return DefWindowProc (hwnd, uMsg, wParam, lParam);
}   
  
/***********************************************************************

FUNCTION: 
  InitApplication

PURPOSE: 
  Initializes and registers a windows class.

***********************************************************************/
BOOL InitApplication (HINSTANCE hInstance)
{  
  WNDCLASS wndclass;

  wndclass.style = CS_HREDRAW | CS_VREDRAW;
  wndclass.lpfnWndProc = (WNDPROC)WndProc;
  wndclass.cbClsExtra = 0;
  wndclass.cbWndExtra = 0;
  wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_CEHTTP));
  wndclass.hInstance = hInstance;
  wndclass.hCursor = NULL;
  wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wndclass.lpszMenuName = NULL;
  wndclass.lpszClassName = g_szClassName;
  
  return RegisterClass (&wndclass);
}

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

FUNCTION: 
  InitInstance

PURPOSE: 
  Creates and displays the main window.

***********************************************************************/
BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
{
  g_hInst = hInstance;

  g_hwndMain = CreateWindow (
                  g_szClassName,  // Registered class name                 
                  g_szTitle,      // Application window name
                  WS_OVERLAPPED,  // Window style
                  0,              // Horizontal position of the window
                  0,              // Vertical position of the window
                  CW_USEDEFAULT,  // Window width
                  CW_USEDEFAULT,  // Window height
                  NULL,           // Handle to the parent window
                  NULL,           // Handle to the menu identifier
                  hInstance,      // Handle to the application instance
                  NULL);          // Pointer to the window-creation data

  // If it failed to create the window, return FALSE.
  if (!g_hwndMain)
  {
    return FALSE;
  }

  ShowWindow (g_hwndMain, nCmdShow);
  UpdateWindow (g_hwndMain);

  return TRUE;
}


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

FUNCTION: 
  WinMain

PURPOSE: 
  Called by the system as the initial entry point for this Windows 
  CE-based application.

***********************************************************************/
int WINAPI WinMain (
              HINSTANCE hInstance,    // Handle to the current instance
              HINSTANCE hPrevInstance,// Handle to the previous instance
              LPTSTR lpCmdLine,       // Pointer to the command line
              int nCmdShow)           // Shows the state of the window
{
  MSG msg;
   
  // Load the window and window class name strings.
  LoadString (hInstance, IDS_TITLE, g_szTitle, 
              sizeof (g_szTitle) / sizeof (TCHAR));

  LoadString (hInstance, IDS_CLASSNAME, g_szClassName, 
              sizeof (g_szClassName) / sizeof (TCHAR));

  if (!hPrevInstance)
  {
    if (!InitApplication (hInstance))
      return 0; 
  }

  if (!InitInstance (hInstance, nCmdShow))
    return 0;
  
  while (GetMessage (&msg, NULL, 0, 0))
  {
    TranslateMessage (&msg);
    DispatchMessage (&msg);
  }
  
  return msg.wParam;
}
// END OF CEHTTP.CPP
  

⌨️ 快捷键说明

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