📄 vcc15.htm
字号:
<html>
<head>
<title>c++系列</title>
<meta content="text/html; charset=gb2312" http-equiv=Content-Type>
</head>
<p align="center"><script src="../../1.js"></script></a>
<body bgcolor="#ffffff" leftmargin="5" topmargin="1" marginheight="5" marginwidth="5">
<div align=center>
<table border=0 cellpadding=0 cellspacing=0 width=680 align="center">
<tbody>
<tr>
<td width=200 height="59">
</tr>
</tbody>
</table>
<table border=1 bordercolordark=#ffffff bordercolorlight=#ffffff cellpadding=0
cellspacing=0 width=685 align="center" height="70">
<tbody>
<tr>
<td bgcolor=#F9D23C height=14>
<div align=center class=H1> <b><font size="3" color="#FF0000"><b> 做一个DreamWeaver风格的程序
</font></b></font> </font><font color="#FF0000"></font><font
color=#ffa000><b></b></font></b></font></div>
</td>
</tr>
<tr valign=top>
<td class=H1 height=212>
<p align="left"><font color="#FF0000"> <br>
用过DreamWeaver的人都会发现DreamWeaver将每一个编辑的文件显示在任务栏上,并且用户任意关闭一窗口而不影响其他窗口,好象每一个窗口间没有关联,没有主窗口似的。但我们也能发现其实这些窗口间也有数据是共享的,如存盘的路径。
<br>
<br>
经过研究我发现其实这些窗口其实是属于同一程序的,并且实现方法也非常的简单。下面我用Inprise公司的C++ Builder为大家举一个简单的例子。
<br>
<br>
首先我们创建一个普通的应用程序。在这个程序中包含两个Form,其中Form1为主窗口,我们将Form2设为不由应用程序自动创建。 <br>
<br>
在Form1中加入一新的Public的属性: <br>
int FormCount; <br>
此属性用于记录系统建立的From2的实例的个数,在Form1的OnCreate事件中加入如下代码: <br>
<br>
int i=GetWindowLong(this- >Handle,GWL_STYLE);<br>
TForm2 *F,*G;<br>
F=new TForm2(NULL);<br>
G=new TForm2(NULL);<br>
F- >ParentWindow=GetDesktopWindow();<br>
F- >Caption="F";<br>
G- >ParentWindow=GetDesktopWindow();<br>
G- >Caption="G";<br>
this- >FormCount=2;<br>
SetWindowLong(G- >Handle,GWL_STYLE,i);<br>
SetWindowLong(F- >Handle,GWL_STYLE,i);<br>
F- >Show();<br>
G- >Show();<br>
<br>
其中GetWindowLong,SetWindowLong为获取/设置Window属性的API函数,具体请看C++ Builder带的Win32帮助。然后运行程序,我们就能发现程序在任务栏上显示了属于此程序的三个任务条。
<br>
接下来我们要做的事情有两个: <br>
1、 隐藏Form1及Application <br>
2、 让Form2的实例关闭应用程序 <br>
<br>
实现第一件事情的方法在网上很多地方都提到了,即修改WinMain函数下面是具体的代码(粗斜体为加入的代码): <br>
<br>
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)<br>
{<br>
try<br>
{<br>
Application- >Initialize();<br>
Application- >CreateForm(<br>
__classid(TForm1), &Form1);<br>
Application- >ShowMainForm=false;<br>
ShowWindow(Application- >Handle, SW_HIDE);<br>
Application- >Run();<br>
}<br>
catch (Exception &exception)<br>
{<br>
Application- >ShowException(&exception);<br>
}<br>
return 0;<br>
}<br>
<br>
<br>
在这个地方要注意的是光用“Application->ShowMainForm=false;”是不能隐藏主Form(Form1)的,必须将Form1的Visibled属性变为false。<br>
<br>
实现第二件事情需要用到Application的Terminate方法(结束应用程序)。我们只要在TForm2的OnClose事件中简单加入以下几句程序:
<br>
<br>
if (Form1- >FormCount>1)<br>
Form1- >FormCount--;<br>
else<br>
Application- >Terminate();<br>
<br>
运行程序,你就能发现程序在有任务拦上有两个提示,窗口F及窗口G,而且这两个窗口看起来就象独立的应用程序。 <br>
至此,一个DreamWeaver风格的程序就做完了,是不是很简单呢。 <br>
<br>
<br>
</span></font></font><font
color=#ffa000><b><br>
</td>
</tr>
</tbody>
</table>
</div>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -