C++ windows.h详解

目录

1 概述

Win32程序的开头都可看到:

#include <windows.h>

WINDOWS.H是一个最重要的头文件,它包含了其他Windows头文件,这些头文件的某些也包含了其他头文件。这些头文件中最重要的和最基本的是:

WINDEF.H 基本数据类型定义。

WINNT.H 支持Unicode的类型定义。

WINBASE.H Kernel(内核)函数

WINUSER.H 用户界面函数

WINGDI.H 图形设备接口函数

这些头文件定义了Windows的所有资料型态、函数调用、资料结构和常数识别字,它们是Windows文件中的一个重要部分。

文件路径 Windows 64位系统:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include[Windows 7 SDK]

C:\Program Files (x86)\Windows Kits\8.0\Include\um [Windows 8 SDK]

C:\Program Files (x86)\Windows Kits\8.1\Include\um [Windows 8.1 SDK]

不同版本的SDK位置不一样,x86的在C:\Program Files\ 相应的SDK下。

2 文件内容

/**
 * @file windows.h
 * copyright 2012, 2013 MinGW.org project
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * fitness FOR A PARTIculaR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR copYRIGHT HOLDERS BE LIABLE FOR ANY CLaim, damAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
/* Written by Anders norlander <anorland@hem2.passagen.se> */
#ifndef _WINDOWS_H
#define _WINDOWS_H
#pragma GCC system_header
#include <_mingw.h>

/* translate GCC target defines to MS equivalents. Keep this synchronized
   with winnt.h. */
#if defined(__i686__) && !defined(_M_IX86)
#define _M_IX86 600
#elif defined(__i586__) && !defined(_M_IX86)
#define _M_IX86 500
#elif defined(__i486__) && !defined(_M_IX86)
#define _M_IX86 400
#elif defined(__i386__) && !defined(_M_IX86)
#define _M_IX86 300
#endif

#if defined(_M_IX86) && !defined(_X86_)
#define _X86_
#elif defined(_M_ALPHA) && !defined(_ALPHA_)
#define _ALPHA_
#elif defined(_M_PPC) && !defined(_PPC_)
#define _PPC_
#elif defined(_M_MRX000) && !defined(_MIPS_)
#define _MIPS_
#elif defined(_M_M68K) && !defined(_68K_)
#define _68K_
#endif

#ifdef RC_INVOKED
/* winresrc.h includes the necessary headers */
#include <winresrc.h>
#else

#include <stdarg.h>
#include <windef.h>
#include <wincon.h>
#include <winbase.h>
#ifndef NOGDI
#include <wingdi.h>
#endif
#include <winuser.h>
#include <winnls.h>
#include <winver.h>
#include <winnetwk.h>
#include <winreg.h>
#include <winsvc.h>

#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
#include <dlgs.h>
#include <imm.h>
#include <lzexpand.h>
#include <mmsystem.h>
#include <nb30.h>
#include <rpc.h>
#include <shellapi.h>
#include <winperf.h>

#ifndef NOGDI
#include <commdlg.h>
#include <winspool.h>
#endif

/* __USE_W32_SOCKETS is a __CYGWIN__ guard */
#if defined(__USE_W32_SOCKETS) || !(defined(__CYGWIN__) || defined(__MSYS__))
#include <winsock.h>
#endif

#ifndef NOGDI
/* In older versions we disallowed COM declarations in __OBJC__
   because of conflicts with @interface directive.  Define _OBJC_NO_COM
   to keep this behavIoUr.  */ 
#if !defined (_OBJC_NO_COM) 
#include <ole2.h>
#endif /* _OBJC_NO_COM */
#endif

#endif /* WIN32_LEAN_AND_MEAN */

#endif /* RC_INVOKED */

#ifdef __OBJC__
/* FIXME: Not undefining BOOL here causes all BOOLs to be WINBOOL (int),
   but undefining it causes trouble as well if a file is included after
   windows.h
*/
#undef BOOL
#endif

#endif

3 用法

C/C++ 程序在源文件前面写 #include <windows.h>即可

4 作用

文件封装了库函数以及一些类,将一些复杂的工作由库函数处理,而用户不必把精力放在这些地方。比如说cout<<,为标准输出流,其实说到底还是函数调用,不过这个函数有些特殊,用的是运算符重载,确切地说是重载了“<<”运算符,作用是将键盘输入的在屏幕上打印出来,这个功能要是由我们去写,估计也得学个两三年才有可能。所以就简化了操作。

而这一系列的函数都在头文件中包含(是一个函数库)。在调用时包涵后便可直接用。

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...