您的位置:首页 > 其它

超级模仿秀--挑战微软画图软件(1)

2006-11-01 15:53 323 查看
学习Visual C++编程,有一个速成的办法就是首先跟着案例做,接着模仿现成的软件,最后独立创新。

[align=left] --Highness[/align]
[align=left] [/align]
[align=left] 挑战微软“画图”软件,对于高手来说,其实并不是什么困难的事。对于刚入门的学习者利用VisualC++编一个跟微软“画图”软件一模一样的工程,有一条路可以走。这条路就是“建立基本框架,功能逐一完善”。我们从画图软件中的菜单栏开始,首先在ResouceView视图里面,选择Menu,IDR_MAINFRAME,使得菜单栏和画图一样。即:[/align]
[align=left]------------------------------------------------------------------------------------------[/align]
[align=left]文件(F)|编辑(E)|查看(V)|图像(I)|帮助(H) [/align]
[align=left]------------------------------------------------------------------------------------------[/align]
[align=left]建立好菜单,同时也明确了我们的任务。我们的主要任务是将菜单栏上每一个选项的功能逐一完善。那么我们的模仿秀基本就完成了。
万事皆从简单事情做起,编写软件更何况不是呢?我们从最简单的功能做起,一个一个将功能实现。[/align]
[align=left]下面以提问的方式介绍。[/align]
[align=left] 打开Visual C++,新建MFC APPWIZARD EXE工程,工程名为“Draw”,在向导的第1步“Step 1 of 6” ,选择单文档,在向导的第4步“Step 4 of 6”,将隐藏工具栏和打印和打印预览选项取消打勾。其它皆为缺省,点完成。[/align]
[align=left]-------------------------------------------------------------------------------------------
帮助(H)
帮助主题(H)
关于画图(A)
--------------------------------------------------------------------------------------------
1.如何实现帮助主题?
在微软画图软件中,点击帮助下的帮助主题,将会弹出一个后缀名为chm的文件,这个文件其实是在window/help/mspaint.chm,因为安装Microsoft公司的操作系统,一般都会自带画图软件,这样自然会自带mspaint.chm文件,这个文件要自己编写也可以,但是有现成的,我们只需要直接调用就行了。
帮助主题,其ID键名为“IDH_THEMEHELP” 在建立类向导中,在CDrawView下建立common函数--OnThemehelp() 。[/align]
[align=left]其代码如下:
void CDrawView::OnThemehelp()
{
// TODO: Add your command handler code here
::WinExec("HH mspaint.chm", SW_SHOW);

}
备注:WinExec()函数介绍(from MSDN)
This function is provided for compatibility with 16-bit Windows. Win32-based applications should use the CreateProcess function. [/align]
[align=left]UINT WinExec(
LPCSTR lpCmdLine, // 调用应用程序地址
UINT uCmdShow // 新应用软件的窗口类型
);[/align]
[align=left] 对nCmdShow特别介绍:
Specifies how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides aSTARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls, this parameter can be one of the following values: [/align]

[align=left]Value[/align]
[align=left]Meaning[/align]
[align=left]SW_FORCEMINIMIZE[/align]
[align=left]Windows NT 5.0 and later: Minimizes a window, even if the thread that owns the window is hung. This flag should only be used when minimizing windows from a different thread.[/align]
[align=left]SW_HIDE[/align]
[align=left]Hides the window and activates another window.[/align]
[align=left]SW_MAXIMIZE[/align]
[align=left]Maximizes the specified window.[/align]
[align=left]SW_MINIMIZE[/align]
[align=left]Minimizes the specified window and activates the next top-level window in the Z order.[/align]
[align=left]SW_RESTORE[/align]
[align=left]Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.[/align]
[align=left]SW_SHOW[/align]
[align=left]Activates the window and displays it in its current size and position. [/align]
[align=left]SW_SHOWDEFAULT[/align]
[align=left]Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. [/align]
[align=left]SW_SHOWMAXIMIZED[/align]
[align=left]Activates the window and displays it as a maximized window.[/align]
[align=left]SW_SHOWMINIMIZED[/align]
[align=left]Activates the window and displays it as a minimized window.[/align]
[align=left]SW_SHOWMINNOACTIVE[/align]
[align=left]Displays the window as a minimized window. The active window remains active.[/align]
[align=left]SW_SHOWNA[/align]
[align=left]Displays the window in its current state. The active window remains active.[/align]
[align=left]SW_SHOWNOACTIVATE[/align]
[align=left]Displays a window in its most recent size and position. The active window remains active.[/align]
[align=left]SW_SHOWNORMAL[/align]
[align=left]Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.[/align]
[align=left]
2.关于画图的实现?[/align]
[align=left] 关于画图,其ID键名为“ID_APP_ABOUT” 在建立类向导中,在CDrawView下建立common函数--[/align]
[align=left]OnAppAbout() 。[/align]
[align=left]void CDrawView::OnAppAbout()
{
// TODO: Add your command handler code here
ShellAbout(this->m_hWnd, "画图", "highness0520@gmail.com",NULL);

}[/align]
未完待续...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: