推荐回答
// TestBrowser.cpp : Defines the entry point for the application.//#include "stdafx.h"#include "TestBrowser.h"////////////////////////////////////////////////////////#include #include #include #include #include ////////////////////////////////////////////////////////#define MAX_LOADSTRING 100// Global Variables:HINSTANCE hInst; // current instanceTCHAR szTitle; // the main window class name// Forward declarations of functions included in this code module:ATOM MyRegisterClassHINSTANCE hInstance;BOOL InitInstanceHINSTANCE, int;LRESULT CALLBACK WndProcHWND, UINT, WPARAM, LPARAM;INT_PTR CALLBACK AboutHWND, UINT, WPARAM, LPARAM;////////////////////////////////////////////////////////CComModule _Module;CAxWindow WinContainer; CComPtr pWebBrowser;#pragma commentlib,"atl"////////////////////////////////////////////////////////int APIENTRY _tWinMainHINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow{ UNREFERENCED_PARAMETERhPrevInstance; UNREFERENCED_PARAMETERlpCmdLine; ////////////////////////////////////////////////////// // CoInitializeNULL; AtlAxWinInit; // ////////////////////////////////////////////////////// MSG msg; HACCEL hAccelTable; // Initialize global strings LoadStringhInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING; LoadStringhInstance, IDC_TESTBROWSER, szWindowClass, MAX_LOADSTRING; MyRegisterClasshInstance; // Perform application initialization: if !InitInstance hInstance, nCmdShow { return FALSE; } hAccelTable = LoadAcceleratorshInstance, MAKEINTRESOURCEIDC_TESTBROWSER; // Main message loop: while GetMessage&msg, NULL, 0, 0 { if !TranslateAcceleratormsg.hwnd, hAccelTable, &msg { TranslateMessage&msg; DispatchMessage&msg; } } ////////////////////////////////////////////////////// // CoUninitialize; // ////////////////////////////////////////////////////// return int msg.wParam;}//// FUNCTION: MyRegisterClass//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage are only necessary if you want this code// to be compatible with Win32 systems prior to the ''RegisterClassEx''// function that was added to Windows 95. It is important to call this function// so that the application will get ''well formed'' small icons associated// with it.//ATOM MyRegisterClassHINSTANCE hInstance{ WNDCLASSEX wcex; wcex.cbSize = sizeofWNDCLASSEX; wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIconhInstance, MAKEINTRESOURCEIDI_TESTBROWSER; wcex.hCursor = LoadCursorNULL, IDC_ARROW; wcex.hbrBackground = HBRUSHCOLOR_WINDOW+1; wcex.lpszMenuName = MAKEINTRESOURCEIDC_TESTBROWSER; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIconwcex.hInstance, MAKEINTRESOURCEIDI_SMALL; return RegisterClassEx&wcex;}//// FUNCTION: InitInstanceHINSTANCE, 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 InitInstanceHINSTANCE hInstance, int nCmdShow{ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindowszWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL; if !hWnd { return FALSE; } ShowWindowhWnd, nCmdShow; UpdateWindowhWnd; return TRUE;}//// FUNCTION: WndProcHWND, UINT, WPARAM, LPARAM//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProcHWND hWnd, UINT message, WPARAM wParam, LPARAM lParam{ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; HRESULT hr; RECT rc; switch message { ///////////////////////////////////////////////// // case WM_CREATE: { GetClientRecthWnd,&rc; WinContainer.CreatehWnd, &rc, L"Shell.Explorer", WS_CHILD | WS_VISIBLE; hr = WinContainer.QueryControl__uuidofIWebBrowser2, void**&pWebBrowser; if FAILEDhr { return -1L; } VARIANT vt; vt.vt = VT_BSTR; vt.bstrVal = L"http://www.bing.com"; hr = pWebBrowser->Navigate2&vt, NULL, NULL, NULL, NULL; } break; case WM_SIZE: { int cx, cy; cx = LOWORDlParam; cy = HIWORDlParam; WinContainer.MoveWindow0, 0, cx, cy; } break; /// ////////////////////////////////////////////////////// case WM_COMMAND: wmId = LOWORDwParam; wmEvent = HIWORDwParam; // Parse the menu selections: switch wmId { case IDM_ABOUT: DialogBoxhInst, MAKEINTRESOURCEIDD_ABOUTBOX, hWnd, About; break; case IDM_EXIT: DestroyWindowhWnd; break; default: return DefWindowProchWnd, message, wParam, lParam; } break; case WM_PAINT: hdc = BeginPainthWnd, &ps; // TODO: Add any drawing code here... EndPainthWnd, &ps; break; case WM_DESTROY: ///////////////////////////////////////////// // pWebBrowser.Release; WinContainer.DestroyWindow; // ///////////////////////////////////////////// PostQuitMessage0; break; default: return DefWindowProchWnd, message, wParam, lParam; } return 0;}// Message handler for about box.INT_PTR CALLBACK AboutHWND hDlg, UINT message, WPARAM wParam, LPARAM lParam{ UNREFERENCED_PARAMETERlParam; switch message { case WM_INITDIALOG: return INT_PTRTRUE; case WM_COMMAND: if LOWORDwParam == IDOK || LOWORDwParam == IDCANCEL { EndDialoghDlg, LOWORDwParam; return INT_PTRTRUE; } break; } return INT_PTRFALSE;}随手给你写了一个。看看是不是你所需要的。大部分代码是自动生成的,我写的代码都通过注释方式给括起来了,希望能理解。
黄白玲2019-11-03 16:00:10
提示您:回答为网友贡献,仅供参考。