#include <iostream>
#include <Windows.h>
#include "HoverWindow.h"
#include <include/cef_browser.h>
#include <include/cef_app.h>
#include <include/cef_client.h>
class
MyChromeClient:
public
CefClient{
private
:
int
refCount;
public
:
MyChromeClient(){
refCount=1;
}
virtual
int
AddRef(){
refCount++;
return
refCount;
}
virtual
int
Release(){
refCount--;
return
refCount;
}
virtual
int
GetRefCt(){
return
refCount;
}
};
class
MyChromeApplication:
public
CefApp{
private
:
int
refCount;
public
:
MyChromeApplication(){
refCount=1;
}
virtual
int
AddRef(){
refCount++;
return
refCount;
}
virtual
int
Release(){
refCount--;
return
refCount;
}
virtual
int
GetRefCt(){
return
refCount;
}
};
class
ChromeWindow:
public
HoverWindow{
private
:
CefWindowInfo windowInfo;
MyChromeClient client;
CefRefPtr<CefBrowser> browser;
public
:
ChromeWindow(
HINSTANCE
hInstance,
const
char
* className,
const
char
* title,
int
x,
int
y,
int
w,
int
h,
DWORD
exStyle=NULL,
DWORD
windowStyle=WS_OVERLAPPEDWINDOW);
virtual
bool
onWindowMessage(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam);
};
ChromeWindow::ChromeWindow(
HINSTANCE
hInstance,
const
char
* className,
const
char
* title,
int
x,
int
y,
int
w,
int
h,
DWORD
exStyle,
DWORD
windowStyle)
:HoverWindow(hInstance,className,title,x,y,w,h,exStyle,windowStyle){
}
bool
ChromeWindow::onWindowMessage(
HWND
hWnd,
UINT
uMsg,
WPARAM
wParam,
LPARAM
lParam){
RECT rt;
switch
(uMsg){
case
WM_CREATE:
GetClientRect(hWnd,&rt);
windowInfo.SetAsChild(hWnd,rt);
this
->browser=CefBrowserHost::CreateBrowserSync(windowInfo,&client,CefString(
"http://www.hoverlees.com"
),CefBrowserSettings());
CefRunMessageLoop();
break
;
case
WM_SIZE:
GetClientRect(hWnd,&rt);
SetWindowPos(
this
->browser->GetHost()->GetWindowHandle(),0,rt.left,rt.top,rt.right,rt.bottom,0);
break
;
case
WM_CLOSE:
CefQuitMessageLoop();
PostQuitMessage(0);
break
;
default
:
return
false
;
}
return
true
;
}
int
WINAPI WinMain(
HINSTANCE
hInst,
HINSTANCE
hPrevInstance,
LPSTR
lpCmdLine,
int
nCmdShow){
MyChromeApplication app;
CefMainArgs main_args(hInst);
CefSettings settings;
settings.multi_threaded_message_loop =
false
;
int
exit_code = CefExecuteProcess(main_args,&app);
if
(exit_code >= 0)
return
exit_code;
CefInitialize(main_args,settings,&app);
window->startMessageLoop();
CefShutdown();
return
0;
}