在mfc编程中创建web风格的图形用户界面(三)

王朝other·作者佚名  2007-01-04
窄屏简体版  字體: |||超大  

用CHtmlView类显示html格式

我们需要将程序界面中的html代码做一些改动,让他们看起来和IE中看到的略有不同。

在MFC程序中显示html格式是很容易的事情。只需要我们调用CHtmlView类就可以完成这项工作。首先我们要创建一个新的“MFC AppWizard(exe)”工程,选择单文档结构视图并打开多文档Document View结构支持。然后在CLass Wizard中创建并将ChtmlView类设定为基类。最后,把html格式的页面加入到系统资源中。

为了使我们的web界面看起来更象是一个程序的界面而不是IE的窗口,对html页面的代码必须做一些必要的修改。

♦ 将html背景的颜色设定成标准的windows应用程序背景的颜色。

♦ 将html页面的右键菜单禁止,除非是用于editbox框中的右键菜单。

♦ 禁止html页面中的文字被鼠标框中,同样,editbox框中的文字例外。

♦ 禁止鼠标指针划过静态文字的时候改变形态,在IE中,鼠标指针划过静态文字的时候会变成“工”字形,在editbox框中也是如此。而在windows应用程序中这种现象应该避免。

下面的这段代码实现了上述的四项需要:

<SCRIPT LANGUAGE="JScript">

// Forbid user’s mouse selecting for the content

// (allow text selection in EditBox only)

function onSelect1(){

if ( window.event.srcElement.tagName !="INPUT" ) {

window.event.returnValue = false;

window.event.cancelBubble = true;

}

}

// Forbid IE context menu

// (allow in EditBox only)

// (if the real context menu must be shown - Advanceв Hosting

// Interfaces must be used)

function onContextMenu(){

if ( window.event.srcElement.tagName !="INPUT" ) {

window.event.returnValue = false;

window.event.cancelBubble = true;

return false;

}

}

// Install Context Menu and Mark handlers on HTML loading.

//

function onLoad()

{

// forbid cursor change (except "INPUT"

// entry box and "A" hyperlink) for HTML text.

var Objs = document.all;

for (i=0; i< Objs.length; i++)

// "INPUT" entry box and "A" hyperlink

if (Objs(i).tagName!="INPUT" && Objs(i).tagName!="A")

Objs(i).style.cursor = "default";

// event handler – content selection

document.onselectstart = onSelect1;

// event handler – context menu

document.oncontextmenu = onContextMenu;

}

</SCRIPT>

<BODY onload="onLoad();"

leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0

style = "background-color: buttonface;" >

// the HTML background color will be as in Windows Applications

用上述的方法,我们已经可以用html来实现我们的程序界面了。而菜单、工具条以及静态线都保留了下来,毕竟我们并不是要强制放弃所有的传统控件的使用。这种方式下,我们获得了更大的弹性。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航