////////////////////////////////////////////////////////////////
// Vckbase Online Journal -- Feb 2000
// Compiles with Visual C++ 6.0, runs on Windows 98 and probably NT too.
//
// ---
// AboutHtml shows how to implement an HTML About Dialog using a
// new class, CHtmlCtrl, that lets you use CHtmlView as a control in a dialog.
#include "StdAfx.h"
#include "resource.h"
#include "HtmlCtrl.h"
//#include <iostream>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////
// Ordinary main frame--very boring.
//
class CMainFrame : public CFrameWnd {
public:
CMainFrame(){ }
virtual ~CMainFrame() { }
protected:
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPaint();
DECLARE_DYNCREATE(CMainFrame)
DECLARE_MESSAGE_MAP()
};
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_PAINT()
END_MESSAGE_MAP()
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
cs.cx = 300;
cs.cy = 200;
return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.Create(this) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) {
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this)) {
return -1; // fail to create
}
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
return 0;
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this);
CRect rc;
GetClientRect(&rc);
dc.DrawText(_T("请点击查看按钮......"),
rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
}
class CMyApp : public CWinApp {
public:
CMyApp();
virtual BOOL InitInstance();
protected:
afx_msg void OnAppAbout();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// ON_COMMAND(ID_APP_BAIDU, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
CMyApp::CMyApp()
{
}
CMyApp theApp;
BOOL CMyApp::InitInstance()
{
// Create main frame window (don't use doc/view stuff)
//
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
m_pMainWnd = pMainFrame;
return TRUE;
}
//////////////////
// Specialized derivation to handle "button" click
//
class CMyHtmlCtrl : public CHtmlCtrl {
virtual void OnAppCmd(LPCTSTR lpszWhere);
};
/////////////////
// Handle "app:ok" link by closing dialog
//
void CMyHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
{
if (_tcsicmp(lpszWhere,_T("ok"))==0) {
GetParent()->SendMessage(WM_COMMAND,IDOK);
}
}
//////////////////
// About dialog uses HTML control to display contents.
//
class CAboutDialog : public CDialog {
DECLARE_DYNAMIC(CAboutDialog)
protected:
CMyHtmlCtrl m_page;
virtual BOOL OnInitDialog();
public:
CAboutDialog() : CDialog(IDD_ABOUTBOX, NULL) { }
};
IMPLEMENT_DYNAMIC(CAboutDialog, CDialog)
CString htmlmap()
{
CString html;
html="<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>";
html+="<html xmlns='http://www.w3.org/1999/xhtml'>";
html+="<head>";
html+="<meta http-equiv='content-type' content='text/html; charset=gbk' />";
html+="<title>google地图</title>";
html+="<script src='http://maps.google.com/maps?file=api&v=2' type='text/javascript'></script>";
html+="<script type='text/javascript'>";
html+="function load()";
html+="{";
html+="if (GBrowserIsCompatible())";
html+="{";
html+="var map = new GMap2(document.getElementById('map'));";
html+="map.enableScrollWheelZoom();";
html+="map.addControl(new GLargeMapControl());";
html+="map.addControl(new GMapTypeControl());";
html+="map.addControl(new GOverviewMapControl());";
html+="map.addControl(new GScaleControl());";
html+="var center = new GLatLng(31.342660073054077,121.59584283828735);";
html+="var marker = new GMarker(center, {draggable:false});";
html+="GEvent.addListener(marker, 'dragstart', function() {map.closeInfoWindow();});";
html+="GEvent.addListener(marker, 'dragend', function() {var lat = marker.getLatLng().lat();var lng = marker.getLatLng().lng();marker.openInfoWindowHtml('<b>纬度:</b>' + lat + '<br/><b>经度:</b>' + lng + '<br/><b>坐标值:</b>(' + lat + ', ' + lng + ')');});";
html+="map.addOverlay(marker);";
html+="GEvent.addListener(map, 'moveend', function() { var center = map.getCenter(); document.getElementById('message').innerHTML = center.toString();});";
html+="map.setCenter(center, 15);";
html+="window.setTimeout(function() {map.panTo(center);}, 1000);";
html+="}";
html+="}";
html+="</script>";
html+="</head>";
html+="<body onload='load()' onunload='GUnload()'>";
html+="<div id='map' style='width: 1000px; height: 700px;'>";
html+="</div>";
html+="<div style='margin: 1em auto 0 auto; text-align: center;margin: 1em auto 0 auto;text-align:center;' >";
html+="地图中心点经纬度:<span id='message'></span>";
html+="</div>";
html+="</body>";
html+="</html>";
return html;
}
BOOL CAboutDialog::OnInitDialog()
{
VERIFY(CDialog::OnInitDialog());
VERIFY(m_page.CreateFromStatic(IDC_HTMLVIEW, this));
// m_page.LoadFromResource(_T("about.htm"));
m_page.LoadFromResource(_T("map.htm"));
//freopen("map.htm","w",stdout);
//printf("%s",htmlmap());
//fclose(stdout);
//m_page.LoadFromResource(_T("map.htm"));
//MessageBox(htmlmap());
//m_page.LoadFromResource(htmlmap());
return TRUE;
}
void CMyApp::OnAppAbout()
{
static CAboutDialog dlg; // static to remember state of hyperlinks
dlg.DoModal(); // run it
}
/*
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gbk" />
<title>google地图</title>
<script src="http://maps.google.com/maps?file=api&v=2" type="text/javascript"></script>
<script type="text/javascript">
function load()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("map"));
map.enableScrollWheelZoom();
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GOverviewMapControl());
map.addControl(new GScaleControl());
var center = new GLatLng(31.342660073054077,121.59584283828735);
var marker = new GMarker(center, {draggable:false});
GEvent.addListener(marker, "dragstart", function() {map.closeInfoWindow();});
GEvent.addListener(marker, "dragend", function() {var lat = marker.getLatLng().lat();var lng = marker.getLatLng().lng();marker.openInfoWindowHtml("<b>纬度:</b>" + lat + "<br/><b>经度:</b>" + lng + "<br/><b>坐标值:</b>(" + lat + ", " + lng + ")");});
map.addOverlay(marker);
GEvent.addListener(map, "moveend", function() { var center = map.getCenter(); document.getElementById("message").innerHTML = center.toString();});
map.setCenter(center, 15);
window.setTimeout(function() {map.panTo(center);}, 1000);
}
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 1000px; height: 700px;">
</div>
<div style="margin: 1em auto 0 auto; text-align: center;margin: 1em auto 0 auto;text-align:center;" >
地图中心点经纬度:<