中文

webapp - webkit based application

webapp, a webkit based application.

Download

webapp-0.1-1-win32.zip (For Windows)

Run

Windows: webapp.exe

Note:modify start_url in webapp.ini,to make webapp open your specified url.

webapp acid3 test result

webapp API

webapp.h

//
#ifndef WEBAPP_H
#define WEBAPP_H

#include <windows.h>

namespace gfx {
typedef HWND NativeWindow;
}; // namespace gfx

namespace webapp {

class IWebView
{
public:
	virtual gfx::NativeWindow NativeWindow() = 0;
	virtual gfx::NativeWindow ParentWindow() = 0;
	virtual void LoadURL(const char* url) = 0;
	virtual void LoadURL(const wchar_t* url) = 0;
};

class IWebViewEventListener
{
public:
	virtual gfx::NativeWindow OnGetNewWindowContainer(IWebView* webview) = 0;
	virtual void OnReceiveTitle(IWebView* webview, const wchar_t* title) = 0;
	virtual void OnStartLoad(IWebView* webview) = 0;
	virtual void OnFinishLoad(IWebView* webview) = 0;
};

}; // namespace webapp

extern "C" __declspec(dllexport) bool webapp_init(int argc, char **argv);
extern "C" __declspec(dllexport) bool webapp_create_webview(webapp::IWebView** webview, gfx::NativeWindow parent);
extern "C" __declspec(dllexport) bool webapp_delete_webview(webapp::IWebView** webview);
extern "C" __declspec(dllexport) bool webapp_add_webview_event_listener(webapp::IWebViewEventListener* listener);
extern "C" __declspec(dllexport) bool webapp_remove_webview_event_listener(webapp::IWebViewEventListener* listener);
extern "C" __declspec(dllexport) void webapp_run();
extern "C" __declspec(dllexport) void webapp_shutdown();

typedef bool (__cdecl *WEBAPP_INIT)(int argc, char **argv);
typedef bool (__cdecl *WEBAPP_CREATE_WEBVIEW)(webapp::IWebView** webview, gfx::NativeWindow container);
typedef bool (__cdecl *WEBAPP_DELETE_WEBVIEW)(webapp::IWebView** webview);
typedef bool (__cdecl *WEBAPP_ADD_WEBVIEW_EVENT_LISTENER)(webapp::IWebViewEventListener* listener);
typedef bool (__cdecl *WEBAPP_REMOVE_WEBVIEW_EVENT_LISTENER)(webapp::IWebViewEventListener* listener);
typedef void (__cdecl *WEBAPP_RUN)();
typedef void (__cdecl *WEBAPP_SHUTDOWN)();

#endif // WEBAPP_H

webapp testcase(webapp_test.tar.gz - download source code)

webapp_test.cc

#include "webapp_holder.h"
#include <windows.h>
#include <string>
#include "webview_event_listener.h"

#define WEBAPP_WINDOW_CLASS L"WebAppContainer_Win"

using namespace webapp;

WebAppHolder holder;

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam,
						 LPARAM lParam) {
	IWebView* webview = reinterpret_cast<IWebView*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
	if (webview) {
		switch (message) {
		case WM_DESTROY:
			holder.webapp_delete_webview(&webview);
			holder.webapp_shutdown();
		return 0;

		case WM_SIZE:
			RECT rc;
			GetClientRect(hwnd, &rc);
			MoveWindow(webview->NativeWindow(), 0, 0, rc.right, rc.bottom, TRUE);
			return 0;
		}
	}

  return DefWindowProc(hwnd, message, wParam, lParam);
}

void RegisterWindowClass()
{
	WNDCLASSEX wcex = {
		sizeof(WNDCLASSEX),
		CS_HREDRAW | CS_VREDRAW,
		WndProc,
		0,
		0,
		::GetModuleHandle(NULL),
		0,
		LoadCursor(NULL, IDC_ARROW),
		0,
		0,
		WEBAPP_WINDOW_CLASS,
		0,
	};
	RegisterClassEx(&wcex);
}

int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE, wchar_t*, int) {
	//
	RegisterWindowClass();
	//
	HWND mainWnd = CreateWindow(WEBAPP_WINDOW_CLASS, L"webapp test",
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
		NULL, NULL, ::GetModuleHandle(NULL), NULL);
	//
	holder.webapp_init(0, NULL);
	//
	IWebView* webview = NULL;
	holder.webapp_create_webview(&webview, mainWnd);
	ShowWindow(webview->NativeWindow(), SW_SHOW);
	SetWindowLongPtr(mainWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(webview));
	ShowWindow(mainWnd, SW_SHOW);
	//
	WebViewEventListener evt;
	holder.webapp_add_webview_event_listener(&evt);
	//
	wchar_t start_url[256];
	DWORD num = GetPrivateProfileString(L"webapp", L"start_url", L"", start_url, sizeof(start_url), L".\\webapp.ini");
	start_url[num] = 0;
	webview->LoadURL(start_url);

	holder.webapp_run();

	return 0;
}

webview_event_listener.h

#ifndef WEBVIEW_EVENT_LISTENER_H
#define WEBVIEW_EVENT_LISTENER_H

#include "webapp.h"

class WebViewEventListener : public webapp::IWebViewEventListener
{
public:
	WebViewEventListener();

	virtual gfx::NativeWindow OnGetNewWindowContainer(webapp::IWebView* webview);
	virtual void OnReceiveTitle(webapp::IWebView* webview, const wchar_t* title);
	virtual void OnStartLoad(webapp::IWebView* webview);
	virtual void OnFinishLoad(webapp::IWebView* webview);

};

#endif // WEBVIEW_EVENT_LISTENER_H

webview_event_listener.cc

#include "webview_event_listener.h"
#include "resource.h"

WebViewEventListener::WebViewEventListener()
{}

gfx::NativeWindow WebViewEventListener::OnGetNewWindowContainer(webapp::IWebView* webview)
{
	wchar_t className[128];
	GetClassName(webview->ParentWindow(), className, sizeof(className));
	return ::CreateWindow(className, L"",
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
		CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
		NULL, NULL, ::GetModuleHandle(NULL), NULL);
}

void WebViewEventListener::OnReceiveTitle(webapp::IWebView* webview, const wchar_t* title)
{
	::SetWindowText(webview->ParentWindow(), title);
}

void WebViewEventListener::OnStartLoad(webapp::IWebView* webview)
{
	::SendMessage(webview->ParentWindow(), WM_SETICON,TRUE,(LPARAM)::LoadIcon(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)));
}

void WebViewEventListener::OnFinishLoad(webapp::IWebView* webview)
{
	::SendMessage(webview->ParentWindow(), WM_SETICON,TRUE,(LPARAM)::LoadIcon(::GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2)));
}

Products: Sealion Seacat Seaflower Seaspider Seasnipe Seastar Seadog Jiong WBXL Xultray webapp
iDocSet iDocSetHelper Blink templateJS
(C) 2017 ZHUATANG.COM, All rights reserved

update: 2010-08-22