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

📄 browse.cpp

📁 在Windows Mobile 5.0 Pocket PC下
💻 CPP
字号:

// NOTE: start.html, news.html, and supplies.html must be present
//   on the device at the root directory for this sample to function.

#include "stdafx.h"
#include "browse.h"

// forward defines (instead of using string tables)		
#define IDS_APP_TITLE			TEXT("Browse")
#define IDS_START_PAGE			TEXT("file://\\Program Files\\Browse\\start.html")
#define WM_LAUNCHBROWSER		(WM_USER + 1)

// Global Variables:
HINSTANCE			g_hInst;				// The current instance

// Forward declarations of functions 
ATOM MyRegisterClass(
	HINSTANCE,
	LPTSTR
	);
BOOL InitInstance(
	HINSTANCE, 
	int
	);
LRESULT CALLBACK WndProc(
	HWND,
	UINT,
	WPARAM,
	LPARAM
	);


//
//  FUNCTION: WinMain()
//
//  PURPOSE: Entry point for the application and sets up the Msg loop
//
int WINAPI WinMain(	
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow
	)
{
	MSG msg;
	
	
	// Perform application initialization:
	if (FALSE == InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}
	
	// Main Msg loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);		
	}
	
	return msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(
	HINSTANCE hInstance, 
	LPTSTR szWindowClass
	)
{
	WNDCLASS	wc;
	
    wc.style			= CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc		= (WNDPROC) WndProc;
    wc.cbClsExtra		= 0;
    wc.cbWndExtra		= 0;
    wc.hInstance		= hInstance;
    wc.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BROWSE));
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= szWindowClass;
	
	return RegisterClass(&wc);
}

//
//  FUNCTION: InitInstance(HANDLE, int)
//
//  PURPOSE: Saves instance handle and creates main window
//
//  COMMENTS:
//
//    In this function, we save the instance handle in a global variable and
//    create and display the main program window.
//
BOOL InitInstance(
	HINSTANCE hInstance, 
	int nCmdShow
	)
{
	HWND hWnd = NULL;
	
	g_hInst = hInstance;		// Store instance handle in our global variable
	
	//If it is already running, then focus on the window
	hWnd = FindWindow(IDS_APP_TITLE, IDS_APP_TITLE);	
	if (NULL != hWnd) 
	{
		SetForegroundWindow (hWnd);
		return FALSE;
	} 
	
	MyRegisterClass(hInstance, IDS_APP_TITLE);
	
	RECT rect;
	GetClientRect(hWnd, &rect);
	
	// create a full-screen window for the browser control
	hWnd = CreateWindow(IDS_APP_TITLE, IDS_APP_TITLE, WS_VISIBLE,
		0,0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 
		NULL, NULL, hInstance, NULL);
	if (NULL == hWnd)
	{	
		return FALSE;
	}
	
	// use the GAPI function GXOpenDisplay to ensure exclusive access to the entire screen
	GXOpenDisplay(hWnd, GX_FULLSCREEN);
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	
	return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_NOTIFY		 - Handle specific system notifications
//  WM_CREATE	     - This code runs when the app starts
//	WM_PAINT	     - Paint the main window
//  WM_DESTROY	     - post a quit Msg and return
//  WM_LAUNCHBROWSER - This code starts the browser control and loads a start page
//
//
LRESULT CALLBACK WndProc(
	HWND hWnd, 
	UINT Msg, 
	WPARAM wParam, 
	LPARAM lParam)
{
	WCHAR wszURL[1000];
    HWND hWndHtml;

	switch (Msg) 
	{
	case WM_NOTIFY:
        {
			NM_HTMLVIEW* pnmHTMLView = (NM_HTMLVIEW*)lParam;
			
            switch (pnmHTMLView->hdr.code)
            {
            // this code is processed when a user clicks on a hyperlink
			case NM_HOTSPOT:
                // read the target string
				mbstowcs(wszURL, (const char *)pnmHTMLView->szTarget, 1000);
				
				// if the link is just "exit", then exit
				if(wcscmp(wszURL, L"exit") == 0)
				{
					SendMessage(hWnd, WM_CLOSE, NULL, NULL);
                    // Returning TRUE indicates that we have handled the Msg
                    // and the control will not do its default processing.
                    return TRUE;
				}
				break;
			}			
		}
        // Returning FALSE indicates to the html control that it should do
        // the default processing.
		return FALSE;
		
	case WM_CREATE:
		// launch the browser control on startup
		PostMessage(hWnd, WM_LAUNCHBROWSER, NULL, NULL);						
		break;
		
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	case WM_LAUNCHBROWSER:
		
		// the only function call required to create a browser control instance
		if (TRUE == InitHTMLControl(g_hInst))
		{
			// create the window for the control
			hWndHtml = CreateWindow(TEXT("DISPLAYCLASS"), NULL, WS_VISIBLE, 0, 0, 
				GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 
				hWnd, NULL, g_hInst, NULL);
			ShowWindow(hWndHtml, SW_SHOW);
			UpdateWindow(hWndHtml);
			
			// load the start page into the browser window
			SendMessage(hWndHtml, DTM_NAVIGATE, 0, (LPARAM)(LPTSTR)IDS_START_PAGE);					
		}
		else
		{
			MessageBox(hWnd, TEXT("Unable to Launch Browser"), TEXT("Browser Control Problem:") , NULL);
			DestroyWindow(hWnd);
		}
		break;
		
	default:
		return DefWindowProc(hWnd, Msg, wParam, lParam);
	}
	return 0;
}

⌨️ 快捷键说明

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