windows data types

 Data Types

This topic lists the data types most commonly used in the Microsoft Foundation Class Library. Most of the data types are exactly the same as those in the Windows Software Development Kit (SDK), while others are unique to MFC.

Commonly used Windows SDK and MFC data types are as follows:

  • BOOL   A Boolean value.

  • BSTR   A 32-bit character pointer.

  • BYTE   An 8-bit integer that is not signed.

  • COLORREF   A 32-bit value used as a color value.

  • DWORD   A 32-bit unsigned integer or the address of a segment and its associated offset.

  • LONG   A 32-bit signed integer.

  • LPARAM   A 32-bit value passed as a parameter to a window procedure or callback function.

  • LPCSTR   A 32-bit pointer to a constant character string.

  • LPSTR   A 32-bit pointer to a character string.

  • LPCTSTR   A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.

  • LPTSTR   A 32-bit pointer to a character string that is portable for Unicode and DBCS.

  • LPVOID   A 32-bit pointer to an unspecified type.

  • LRESULT   A 32-bit value returned from a window procedure or callback function.

  • UINT   A 16-bit unsigned integer on Windows versions 3.0 and 3.1; a 32-bit unsigned integer on Win32.

  • WNDPROC   A 32-bit pointer to a window procedure.

  • WORD   A 16-bit unsigned integer.

  • WPARAM   A value passed as a parameter to a window procedure or callback function: 16 bits on Windows versions 3.0 and 3.1; 32 bits on Win32.

Data types unique to the Microsoft Foundation Class Library include the following:

  • POSITION   A value used to denote the position of an element in a collection; used by MFC collection classes.

  • LPCRECT   A 32-bit pointer to a constant (nonmodifiable) RECT structure.

C语言的学习,一般的方式是,先学C,然后是C++,最好还要有汇编语言和微机原理基础,然后才是Visual C++。这样的方式,对学习者来说,要花费很多时间和耐力。而在学校教学中,也没有时间深入学习Windows编程的实用技术了。

  其实,具有了C语言基础后,再有一些基本的C++类的概念,就可以直接学习Windows C编程了。

  一、走近Windows C语言

  很多语言都把显示一个“Hello,World!”做为第一个入门程序, C语言的第一个程序是这样的:

#include<stdio.h>
main()
{
 printf(“Hello,World!”);
}

  如果把main函数写成带参数的main函数,应该是:

#include<stdio.h>
main(int arge,char *argv[])
{
 printf(“Hello,World!”);
}

  Windows C的第一个程序和这个程序在形式和原理上都是一致的,只是有两点不同:

  1. 主函数接收的形参不只是命令行中的字符串的个数和字符串的首地址。

  2. C语言的很多函数在Windows C中都可以继续使用,但象printf()屏幕显示等函数就不能继续使用了。因为Windows是多任务操作系统,屏幕已不再为某一个应用程序所独有,Windows C应用程序要显示字符串,需要使用Windows提供的API函数,开自己的窗口

  下面是一个最简单的,显示“Hello,World!”的Windows C程序:

#include<windows.h>
APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nCmdShow)
{
 MessageBox(NULL,"Hello,World!","第一个Windows C程序",MB_OK|MB_ICONASTERISK);
}

  主函数的形参有四个:

  1) Hinstance:接收程序运行时当前实例的句柄;
  2) HprivInstance:前一个实例的句柄;
  3) LpCmdLine:程序命令行指针;
  4) nCmdShow:一个用来指定窗口显示方式的整数。

  这几个参数的使用我们会在深入的学习中介绍的。

  显示Hello,Word!字符串,我们使用了一个MessageBox函数,这个函数会在屏幕上显示一个对话框,它的原型是:

int MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UNIT uType)

  四个参数分别是:

  1) HWnd:父窗口的句柄;
  2) LpText:要显示字符串的指针;
  3) LpCaption:对话框标题字符串的指针;
  4) UType:显示在对话框上的小图标的类型。

  使用这个函数要包含windows.h头文件。

  调试一下,怎么样?窗口上弹出了一个“第一个Windows C程序”对话框,上面有一行字:“Hello,World!”。

  世界真的很美好啊!!

深入编程:

  在C语言中,函数的声明,如果没有指明返回值类型,缺省值为void,这个程序的主函数就没有返回值。不过,在Windows编程时,我们最好养成个好习惯,指明函数的返回值类型,因为在C++中,函数返回值类型是不可以缺省的。而我们在Windows C编程时,还是会用到C++的一些概念,这样做,有利于以后深入地学习。

规范一点的程序应该是这样的:

#include<windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nCmdShow)
{
MessageBox(NULL,"Hello,World!","第一个Windows C程序",MB_OK|MB_ICONASTERISK);
return 0;
}

  这里,我们声明的类型为int型,并且返回一个值0,这样的函数就可以使用在复杂一点的函数调用中了。

  在这一节中,我们有几处都提到了句柄的概念,句柄和指针的概念不同,它是作为操作系统内部索引表中的一个值来使用的,这样可以防止应用程序直接访问对象的内部结构,体现了Windows资源管理的优越性。譬如说,一个窗口打开之后,对应内存中的一个内存块,这个窗口所在的内存快地址往往会由操作系统做动态

的调整,但其却不会随之变化。不过,通过它可以访问这个窗口,所以在使用的时候,可以把它当做指针一样看待。


  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值