#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <comdef.h>
#include <exdisp.h>
#include <oledlg.h> using namespace std; // Constants namespace {
TCHAR * windowClassName = TEXT("win32host");
TCHAR * windowTitle = TEXT("Win32 interface");
int windowWidth = ;
int windowHeight = ;
} HWND container; LRESULT CALLBACK WindowProc( HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam )
{
switch(messg)
{
case WM_SIZE:
// Redimensionnement du conteneur quand la taille de la fenêtre change:
MoveWindow(container,,,LOWORD(lParam), HIWORD(lParam),);
break;
case WM_CLOSE:
// Détruire la fenêtre principale:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
// Envoyer le message de sortie du programme:
PostQuitMessage( );
break;
default:
//Retour:
return( DefWindowProc( hWnd, messg, wParam, lParam ) );
}
return ;
} int CALLBACK WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{ // Register our Window class
WNDCLASS wndclass;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.lpfnWndProc = &WindowProc;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = reinterpret_cast <HBRUSH> (COLOR_BTNFACE + );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName =windowClassName;
::RegisterClass(&wndclass); // Create our main, raw win32 API window
// We create the window invisible (meaning that we do not provide WS_VISIBLE as the window style parameter), because making it visible and then
// adding a HwndSource will make it flicker.
HWND mainWindow = ::CreateWindow(
windowClassName,
windowTitle,
,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
);
::ShowWindow (mainWindow, nCmdShow);
::UpdateWindow( mainWindow ); typedef HRESULT (WINAPI *PFonc)(IUnknown*, HWND,IUnknown**);
HINSTANCE hDLL2 = ::LoadLibrary(TEXT("atl.dll"));
if (!hDLL2)
return ; PFonc AtlAxAttachControl = (PFonc) ::GetProcAddress(hDLL2,"AtlAxAttachControl"); RECT rect;
::GetClientRect(mainWindow,&rect); container = ::CreateWindowEx(
WS_EX_CLIENTEDGE,
L"EDIT",
L"",WS_CHILD | WS_VISIBLE,
,
,
rect.right,
rect.bottom,
mainWindow,
,
hInstance,
); HRESULT hr = ::CoInitialize(); IWebBrowser2 *pIwb;
hr = ::CoCreateInstance(CLSID_WebBrowser,,CLSCTX_ALL,IID_IWebBrowser2,(void**)&pIwb);
hr = AtlAxAttachControl(pIwb,container,); if(FAILED(hr))
{
MessageBox(, L"FAILED(AtlAxAttachControl(pitd, container, NULL))", L"Error", MB_ICONERROR | MB_OK);
}
pIwb->GoHome();
pIwb->Navigate2((VARIANT*)L"www.google.com",,,,); // Start message processing
::MSG message;
while (::GetMessageA(&message, , , ))
{
switch (message.message) {
case WM_QUIT:
break;
default:
::TranslateMessage(& message);
::DispatchMessage(& message);
break;
}
} CoUninitialize();
FreeLibrary(hDLL2);
return ;
}
https://*.com/questions/14747157/attach-activex-into-win32-application