ImageVerifierCode 换一换
格式:DOCX , 页数:35 ,大小:54.19KB ,
资源ID:9587715      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9587715.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Windows程序设计实验.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Windows程序设计实验.docx

1、Windows程序设计实验Windows程序设计实验指导书2009-3-1目录实验一:VC+6.0开发环境熟悉 1实验二: API对话框应用程序设计 3实验三:API菜单使用 6实验四、API绘图程序 12实验一:VC+6.0开发环境熟悉一、 实验目的熟悉Visual C+ 6.0开发环境,掌握VC6中建立、维护、运行工程项目的方法,掌握VC6中调试的方法。二、 实验内容熟悉Visual C+ 6.0开发环境,如AppWizard、ClassWizard、工具栏、编译、运行普通的C+应用程序等,并能编写一个简单C+应用程序。熟悉调试过程。三、 实验要求1、按下图建立一个C+程序,实现菜单选择,

2、可以实现两个整数的加减。要求: 1、建立工程; 2、程序调试通过; 3、菜单和功能用一个类来实现。2、制作一个简单的公司职员的管理程序,这个程序要求涉及到类、结构、函数的基本使用。同时,这个程序涉及到了对Visual Stuido集成开发环境的使用,有关这方面的详细内容,请参阅本书的第二单元“Visual C+编程基础”。1、新建项目。使用Visual C+的应用程序向导生成一个控制台应用程序Demo。项目类型选择“Win32 Console Application”,在向导的第一步中将程序类型设置成“A Hello, World! application”。2、添加职员信息类。 在集成开发环

3、境的中选择Insert|New Class菜单进入添加类的对话框,将新增的类名设置成workmate。之后,分别修改workmate类的定义及实现文件。3、使用职员信息类。 四、思考题1、 如何实现两个复数的加减?附:一些小窍门1) 有时候,你可能在编译的时候,计算机突然非法关机了(可能某人不小心碰了电源或你的内存不稳定等原因)。当你重启机器后打开刚才的项目,重新进行编译,发现VC会崩掉。你或许以为你的VC编译器坏了,其实不然(你试试编译其它项目,还是好的!),你只要将项目的.ncb、.opt、.aps、.clw文件以及Debug、Release目录下的所有文件都删掉,然后重新编译就行了。 2

4、) 如果你想与别人共享你的源代码项目,但是把整个项目做拷贝又太大。你完全可以删掉以下文件:.dsw、.ncb、.opt、.aps、.clw、. plg文件以及Debug、Release目录下的所有文件。3) 当你的Workspace中包含多个Project的时候,你可能不能直观地、一眼看出来哪个是当前项目。可以如下设置:Tools-Options-Format,然后在Category中选择Workspace window,改变其默认的字体(比如设成Fixedsys)就行了。4) 如何给已有的Project改名字?将该Project关掉。然后以文本格式打开.dsp文件,替换原来的Project名

5、字即可。5) VC6对类成员的智能提示功能很有用,但有时候会失灵。你可以先关掉项目,将.clw和.ncb删掉,然后重新打开项目,点击菜单项View-ClassWizard,在弹出的对话框中按一下“Add All”按钮;重新Rebuild All。应该可以解决问题。实验二: API对话框应用程序设计一、 实验目的掌握VC6中建立API程序的方法。二、 实验内容练习手工生成API Windows应用程序框架,以及利用VC的应用程序生成模版AppWizard来生成API程序框架。三、 实验要求按下图建立一个API程序。要求: 1、手工生成应用程序; 2、使用AppWizard自动生成。四、 实验步骤

6、(一)使用AppWizard自动生成:1在“File”菜单中选择“New”,将新建的类型设置成“Projects”。同时将项目类型设置成“Win32 Application”。 2在应用程序向导的第二步中选择“A typical Hello World! application。” 3使用F5快捷键编译程序。 经过以上三个最简单的步骤,一个“Hello,World”程序便制作完毕。此时可以查看在该项目所在的文件夹下,生成了哪些文件,并应了解这些文件的具体用法(二)手工生成应用程序:1在“File”菜单中选择“New”,将新建的类型设置成“Projects”。同时将项目类型设置成“Win32 A

7、pplication”。 2在应用程序向导的第二步中选择“Empty application。” 3在“New”选择“C+Source”,按照课本上实例3-1的内容输入程序,。 4使用F5快捷键编译程序 经过以上三个最简单的步骤,一个“Hello,World”程序便制作完毕。此时可以查看在该项目所在的文件夹下,生成了哪些文件,并应了解这些文件的具体用法参考代码:#include #include LRESULT CALLBACK WinSunProc( HWND hwnd, / handle to window UINT uMsg, / message identifier WPARAM wP

8、aram, / first message parameter LPARAM lParam / second message parameter);int WINAPI WinMain( HINSTANCE hInstance, / handle to current instance HINSTANCE hPrevInstance, / handle to previous instance LPSTR lpCmdLine, / command line int nCmdShow / show state) WNDCLASS wndcls; wndcls.cbClsExtra=0; wndc

9、ls.cbWndExtra=0; wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); wndcls.hCursor=LoadCursor(NULL,IDC_CROSS); wndcls.hIcon=LoadIcon(NULL,IDI_ERROR); wndcls.hInstance=hInstance; wndcls.lpfnWndProc=WinSunProc; wndcls.lpszClassName=Computer2009; wndcls.lpszMenuName=NULL; wndcls.style=CS_HREDRAW

10、 | CS_VREDRAW; RegisterClass(&wndcls); HWND hwnd; hwnd=CreateWindow(Computer2009,桂林电子科技大学应用科技学院,WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL); ShowWindow(hwnd,SW_SHOWNORMAL); UpdateWindow(hwnd); MSG msg; while(GetMessage(&msg,NULL,0,0) TranslateMessage(&msg); DispatchMessage(&msg); retur

11、n 0;LRESULT CALLBACK WinSunProc( HWND hwnd, / handle to window UINT uMsg, / message identifier WPARAM wParam, / first message parameter LPARAM lParam / second message parameter) switch(uMsg) case WM_CHAR: char szChar20; sprintf(szChar,char is %d,wParam); MessageBox(hwnd,szChar,weixin,0); break; case

12、 WM_LBUTTONDOWN: MessageBox(hwnd,mouse clicked,weixin,0); HDC hdc; hdc=GetDC(hwnd); TextOut(hdc,0,50,Widows程序设计实验,strlen(Widows程序设计实验); ReleaseDC(hwnd,hdc); break; case WM_PAINT: HDC hDC; PAINTSTRUCT ps; hDC=BeginPaint(hwnd,&ps); TextOut(hDC,0,0, 程序设计实验,strlen(程序设计实验); EndPaint(hwnd,&ps); break; cas

13、e WM_CLOSE: if(IDYES=MessageBox(hwnd,是否真的结束?,Compuer,MB_YESNO) DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd,uMsg,wParam,lParam); return 0;五、 思考题1、 Window程序和控制台程序有什么区别?2、 如何添加事件处理?六、常用函数或者结构体参数的定义(详细参见MSDN)HICON LoadIcon( HINSTANCE hInstan

14、ce, / handle to application instance LPCTSTR lpIconName / name string or resource identifier);HCURSOR LoadCursor( HINSTANCE hInstance, / handle to application instance LPCTSTR lpCursorName / name or resource identifier);表 图标样式ValueDescriptionIDI_APPLICATIONDefault application icon.IDI_ASTERISKSame a

15、s IDI_INFORMATION.IDI_ERRORHand-shaped icon.IDI_EXCLAMATIONSame as IDI_WARNING.IDI_HANDSame as IDI_ERROR. IDI_INFORMATIONAsterisk icon.IDI_QUESTIONQuestion mark icon.IDI_WARNINGExclamation point icon.IDI_WINLOGOWindows logo icon.HCURSOR LoadCursor( HINSTANCE hInstance, / handle to application instan

16、ce LPCTSTR lpCursorName / name or resource identifier);表 光标样式ValueMeaningIDC_APPSTARTINGStandard arrow and small hourglassIDC_ARROWStandard arrowIDC_CROSSCrosshairIDC_HANDWindows2000: HandIDC_HELPArrow and question markIDC_IBEAMI-beamIDC_ICONObsolete for applications marked version 4.0 or later.IDC_

17、NOSlashed circleIDC_SIZEObsolete for applications marked version 4.0 or later. Use IDC_SIZEALL.IDC_SIZEALLFour-pointed arrow pointing north, south, east, and westIDC_SIZENESWDouble-pointed arrow pointing northeast and southwestIDC_SIZENSDouble-pointed arrow pointing north and southIDC_SIZENWSEDouble

18、-pointed arrow pointing northwest and southeastIDC_SIZEWEDouble-pointed arrow pointing west and eastIDC_UPARROWVertical arrowIDC_WAITHourglass窗口类结构体typedef struct _WNDCLASS UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HINSTANCE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrB

19、ackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; WNDCLASS, *PWNDCLASS; Class StylesThe class styles define additional elements of the window class. Two or more styles can be combined by using the bitwise OR (|) operator. To assign a style to a window class, assign the style to the style membe

20、r of the WNDCLASSEX structure. The class styles are as follows. 表 窗口类风格StyleActionCS_BYTEALIGNCLIENTAligns the windows client area on a byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.CS_BYTEALIGNWINDOWAligns the window on a

21、byte boundary (in the x direction). This style affects the width of the window and its horizontal placement on the display.CS_CLASSDCAllocates one device context to be shared by all windows in the class. Because window classes are process specific, it is possible for multiple threads of an applicati

22、on to create a window of the same class. It is also possible for the threads to attempt to use the device context simultaneously. When this happens , the system allows only one thread to successfully finish its drawing operation. CS_DBLCLKSSends a double-click message to the window procedure when th

23、e user double-clicks the mouse while the cursor is within a window belonging to the class. CS_GLOBALCLASSSpecifies that the window class is an application global class. For more information, see Application Global Classes.CS_HREDRAWRedraws the entire window if a movement or size adjustment changes t

24、he width of the client area.CS_NOCLOSEDisables Close on the window menu.CS_OWNDCAllocates a unique device context for each window in the class. CS_PARENTDCSets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PAREN

25、TDC style bit receives a regular device context from the systems cache of device contexts. It does not give the child the parents device context or device context settings. Specifying CS_PARENTDC enhances an applications performance. CS_SAVEBITSSaves, as a bitmap, the portion of the screen image obs

26、cured by a window of this class. When the window is removed, the system uses the saved bitmap to restore the screen image, including other windows that were obscured. Therefore, the system does not send WM_PAINT messages to windows that were obscured if the memory used by the bitmap has not been dis

27、carded and if other screen actions have not invalidated the stored image. This style is useful for small windows (for example, menus or dialog boxes) that are displayed briefly and then removed before other screen activity takes place. This style increases the time required to display the window, be

28、cause the system must first allocate memory to store the bitmap.CS_VREDRAWRedraws the entire window if a movement or size adjustment changes the height of the client area.创建窗口函数:HWND CreateWindow( LPCTSTR lpClassName, / registered class name LPCTSTR lpWindowName, / window name DWORD dwStyle, / windo

29、w style int x, / horizontal position of window int y, / vertical position of window int nWidth, / window width int nHeight, / window height HWND hWndParent, / handle to parent or owner window HMENU hMenu, / menu handle or child identifier HINSTANCE hInstance, / handle to application instance LPVOID

30、lpParam / window-creation data);Window StylesThe following styles can be specified wherever a window style is required. After the control has been created, these styles cannot be modified, except as noted. 表 窗口样式StyleMeaningWS_BORDERCreates a window that has a thin-line border.WS_CAPTIONCreates a window that has a title bar (includes the WS_BORDER style).WS_CHILDCreates a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style.WS_CHILDWINDOWSame as the WS_CHILD style.WS_CLIPC

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1