教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 范文大全 > 资料大全 >

Windows程序设计实验报告

来源:网络收集 时间:2026-09-20
导读: Windows程序设计实验报告 专业:计算机科学与技术 班级: 0309402 学号: 姓名: Windows程序设计实验 实验一错误处理 一、实验目的 1、了解windows系统的错误处理方式、方法。 2、定义自己的错误代码,加深对windows系统错误处理方式的理解。 二、实验环境

Windows程序设计实验报告

专业:计算机科学与技术

班级: 0309402 学号:

姓名:

Windows程序设计实验

实验一错误处理

一、实验目的

1、了解windows系统的错误处理方式、方法。

2、定义自己的错误代码,加深对windows系统错误处理方式的理解。

二、实验环境

Windows Xp

Visual studio 6.0

三、实验内容

编写一个错误查找程序,输入错误代号,得到相应的错误描述信息。

四、实验方法、步骤

代码:

/************************* GetErrorInformation.h **************************/ #include "windows.h"

#include "Tchar.h"

//对错误处理的封装类

class GetErrorInformation

{

private:

HLOCAL m_hlocal;

int m_iErrorCode;

TCHAR *m_pcErrorInformation;

public:

GetErrorInformation();

~GetErrorInformation();

void SetErrorCode(int ErrorCode);

TCHAR * GetErrorString();

protected:

private:

};

/************************* GetErrorInformation.cpp **************************/ #include "StdAfx.h"

#include "Windows.h"

#include "Tchar.h"

#include "GetErrorInformation.h"

- 2 -

Windows程序设计实验

GetErrorInformation::GetErrorInformation()

{

m_hlocal = NULL;

m_pcErrorInformation = NULL;

}

GetErrorInformation::~GetErrorInformation()

{

if (m_hlocal != NULL)

{

LocalFree(m_hlocal);

}

else

{

free(m_pcErrorInformation);

}

}

void GetErrorInformation::SetErrorCode(int ErrorCode)

{

this->m_iErrorCode = ErrorCode;

}

TCHAR * GetErrorInformation::GetErrorString()

{

// Get the error code's textual description

BOOL fOk = FormatMessage(

FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_MAX_WIDTH_MASK,

NULL, m_iErrorCode, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),

(PTSTR) &m_hlocal, 0, NULL);

if (!fOk) {

// Is it a network-related error?

HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL,

DONT_RESOLVE_DLL_REFERENCES);

if (hDll != NULL) {

FormatMessage(

FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_MAX_WIDTH_MASK,

hDll, m_iErrorCode, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (PTSTR) &m_hlocal, 0, NULL);

- 3 -

Windows程序设计实验

FreeLibrary(hDll);

}

}

if (m_hlocal!=NULL)

{

m_pcErrorInformation = (char*)m_hlocal;

}

else

{

m_pcErrorInformation = (TCHAR *)malloc(30*sizeof(TCHAR));

TCHAR *charError = {_TEXT("你所查找的错误代码不存在")};

lstrcpy(m_pcErrorInformation,charError);

}

return m_pcErrorInformation;

}

/************************* errorClassDlg.cpp **************************/

void CErrorClassDlg::OnButtonErrorInformationFind()

{

// TODO: Add your control notification handler code here

int errorCode;

GetErrorInformation gei;

errorCode = GetDlgItemInt(IDC_EDIT_ERROR_CODE);

gei.SetErrorCode(errorCode);

SetDlgItemText(IDC_EDIT_ERROR_INFORMATION,gei.GetErrorString());

}

五、实验结果记录与分析

截图:

- 4 -

Windows程序设计实验

- 5 -

Windows程序设计实验

实验二字符和字符串处理

一、实验目的

1、了解windows中的Unicode字符和ANSI字符、字符串类型。

2、掌握ANSI字符类型与Unicode的区别及转换。

3、掌握Unicode字符的使用和处理方式。

二、实验环境

Windows Xp

Visual studio 6.0

三、实验内容

编写一个Unicode字符及字符串处理程序。使用TCHAR、LPTSTR、LPCTSTR等数据类型,掌握这类数据类型的使用。

四、实验方法、步骤

代码:

/************************* UChar.h **************************/

#ifndef _UCHAR_H_

#define _UCHAR_H_

#include "windows.h"

#include "iostream"

using namespace std;

class UChar

{

friend ostream &operator<<(ostream &os,UChar &uc)

{

os<<uc.m_pUChar<<endl;

os<<uc.m_Length<<endl;

return os;

}

private:

LPTSTR m_pUChar;

UINT m_Length;

public:

UChar();

UChar(const TCHAR *pChar);

UChar& operator+(UChar uchar2);

- 6 -

Windows程序设计实验

UChar& operator=(const TCHAR * pStr2);

UChar& operator=(UChar uchar2);

BOOL operator>(UChar uchar2);

UINT Length();

virtual ~UChar();

protected:

private:

};

#endif

/************************* UChar.cpp **************************/

#include "UChar.h"

UChar::UChar()

{

m_pUChar = NULL;

m_Length = 0;

}

UChar::UChar(const TCHAR *pChar)

{

int iCLen;

iCLen = lstrlen(pChar)+sizeof(TCHAR);

m_Length = iCLen-sizeof(TCHAR);

m_pUChar = (TCHAR *)malloc(iCLen*sizeof(TCHAR));

lstrcpy(m_pUChar,pChar);

}

UChar& UChar::operator+(UChar uchar2)

{

int iCLen;

LPTSTR pTem;

iCLen = lstrlen(this->m_pUChar)+lstrlen(uchar2.m_pUChar)+sizeof(TCHAR);

m_Length = iCLen-sizeof(TCHAR);

pTem = (PTSTR)malloc(iCLen*sizeof(TCHAR));

lstrcpy(pTem,this->m_pUChar);

if (this->m_pUChar != NULL)

{

free(this->m_pUChar);

}

lstrcat(pTem,uchar2.m_pUChar);

this->m_pUChar = pTem;

- 7 -

Windows程序设计实验

return *this;

}

UChar& UChar::operator=(const TCHAR * pStr2)

{

int iCLen;

iCLen = lstrlen(pStr2)+sizeof(TCHAR);

m_Length = iCLen-sizeof(TCHAR);

if (this->m_pUChar != NULL)

{

free(this->m_pUChar);

}

this->m_pUChar = (TCHAR *)malloc(iCLen);

lstrcpy(this->m_pUChar,pStr2);< …… 此处隐藏:5546字,全部文档内容请下载后查看。喜欢就下载吧 ……

Windows程序设计实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/fanwen/2191280.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)