WINDOWS程序设计之Windows Data Types

The data types supported by Microsoft® Windows® are used to define function return values, function and message parameters, and structure members. They define the size and meaning of these elements.

The following table contains the following types: character, integer, Boolean, pointer, and handle. The character, integer, and Boolean types are common to most C compilers. Most of the pointer-type names begin with a prefix of P or LP. Handles refer to a resource that has been loaded into memory.

Type Definition
ATOM Atom. For more information, see Atoms.
BOOL Boolean variable (should be TRUE or FALSE).
BOOLEAN Boolean variable (should be TRUE or FALSE).
BYTE Byte (8 bits).
CALLBACK Calling convention for callback functions.
CHAR 8-bit Windows (ANSI) character. For more information, see Character Sets Used By Fonts.
COLORREF Red, green, blue (RGB) color value (32 bits). See COLORREF for information on this type.
CONST Variable whose value is to remain constant during execution.
CRITICAL_SECTION Critical-section object. For more information, see Critical Section Objects.
DWORD 32-bit unsigned integer.  
DWORD_PTR Unsigned long type for pointer precision. Use when casting a pointer to a long type to perform pointer arithmetic.
DWORD32 32-bit unsigned integer.
DWORD64 64-bit unsigned integer.
FLOAT Floating-point variable.
HACCEL Handle to an accelerator table.
HANDLE Handle to an object.
HBITMAP Handle to a bitmap.
HBRUSH Handle to a brush.
HCONV Handle to a dynamic data exchange (DDE) conversation.
HCONVLIST Handle to a DDE conversation list.
HCURSOR Handle to a cursor.
HDC Handle to a device context (DC).
HDDEDATA Handle to DDE data.
HDESK Handle to a desktop.
HDROP Handle to an internal drop structure.
HDWP Handle to a deferred window position structure.
HENHMETAFILE Handle to an enhanced metafile.
HFILE Handle to a file opened by OpenFile, not CreateFile.
HFONT Handle to a font.
HGDIOBJ Handle to a GDI object.
HGLOBAL Handle to a global memory block.
HHOOK Handle to a hook.
HICON Handle to an icon.
HIMAGELIST Handle to an image list.
HIMC Handle to input context.
HINSTANCE Handle to an instance.
HKEY Handle to a registry key.
HKL Input locale identifier.
HLOCAL Handle to a local memory block.
HMENU Handle to a menu.
HMETAFILE Handle to a metafile.
HMODULE Handle to a module.
HMONITOR Handle to a display monitor.
HPALETTE Handle to a palette.
HPEN Handle to a pen.
HRGN Handle to a region.
HRSRC Handle to a resource.
HSZ Handle to a DDE string.
HWINSTA Handle to a window station.
HWND Handle to a window.
INT 32-bit signed integer.
INT_PTR Signed integral type for pointer precision. Use when casting a pointer to an integer to perform pointer arithmetic.
INT32 32-bit signed integer.  
INT64 64-bit signed integer.  
LANGID Language identifier. For more information, see Locales.
LCID Locale identifier. For more information, see Locales.
LCTYPE Locale information type. For a list, see Locale and Language Information
LONG 32-bit signed integer.
LONG_PTR Signed long type for pointer precision. Use when casting a pointer to a long to perform pointer arithmetic.
LONG32 32-bit signed integer.
LONG64 64-bit signed integer.
LONGLONG 64-bit signed integer.
LPARAM Message parameter.
LPBOOL Pointer to a BOOL.
LPBYTE Pointer to a BYTE.
LPCOLORREF Pointer to a COLORREF value.
LPCRITICAL_SECTION Pointer to a CRITICAL_SECTION.
LPCSTR Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
LPCTSTR An LPCWSTR if UNICODE is defined, an LPCSTR otherwise.
LPCVOID Pointer to a constant of any type.
LPCWSTR Pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.
LPDWORD Pointer to a DWORD.
LPHANDLE Pointer to a HANDLE.
LPINT Pointer to an INT.
LPLONG Pointer to a LONG.
LPSTR Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
LPTSTR An LPWSTR if UNICODE is defined, an LPSTR otherwise.
LPVOID Pointer to any type.
LPWORD Pointer to a WORD.
LPWSTR Pointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.
LRESULT Signed result of message processing.
LUID Locally unique identifier.
PBOOL Pointer to a BOOL.
PBOOLEAN Pointer to a BOOL.
PBYTE Pointer to a BYTE.
PCHAR Pointer to a CHAR.
PCRITICAL_SECTION Pointer to a CRITICAL_SECTION.
PCSTR Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
PCTSTR A PCWSTR if UNICODE is defined, a PCSTR otherwise.
PCWCH Pointer to a constant WCHAR.
PCWSTR Pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.
PDWORD Pointer to a DWORD.
PFLOAT Pointer to a FLOAT.
PHANDLE Pointer to a HANDLE.
PHKEY Pointer to an HKEY.
PINT Pointer to an INT.
PLCID Pointer to an LCID.
PLONG Pointer to a LONG.
PLUID Pointer to a LUID.
POINTER_32 32-bit pointer. On a 32-bit system, this is a native pointer. On a 64-bit system, this is a truncated 64-bit pointer.  
POINTER_64 64-bit pointer. On a 64-bit system, this is a native pointer. On a 32-bit system, this is a sign-extended 32-bit pointer.
PSHORT Pointer to a SHORT.
PSTR Pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.
PTBYTE Pointer to a TBYTE.
PTCHAR Pointer to a TCHAR.
PTSTR A PWSTR if UNICODE is defined, a PSTR otherwise.
PUCHAR Pointer to a UCHAR.
PUINT Pointer to a UINT.
PULONG Pointer to a ULONG.
PUSHORT Pointer to a USHORT.
PVOID Pointer to any type.
PWCHAR Pointer to a WCHAR.
PWORD Pointer to a WORD.
PWSTR Pointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts.
REGSAM Security access mask for registry key.
SC_HANDLE Handle to a service control manager database. For more information, see SCM Handles.
SC_LOCK Handle to a service control manager database lock. For more information, see SCM Handles.
SERVICE_STATUS_HANDLE Handle to a service status value. For more information, see SCM Handles.
SHORT Short integer (16 bits).
SIZE_T The maximum number of bytes to which a pointer can point. Use for a count that must span the full range of a pointer.  
SSIZE_T Signed SIZE_T.
TBYTE A WCHAR if UNICODE is defined, a CHAR otherwise.
TCHAR A WCHAR if UNICODE is defined, a CHAR otherwise.
UCHAR Unsigned CHAR.
UINT Unsigned INT.
UINT_PTR Unsigned INT_PTR.
UINT32 Unsigned INT32.
UINT64 Unsigned INT64.
ULONG Unsigned LONG.
ULONG_PTR Unsigned LONG_PTR.
ULONG32 Unsigned LONG32.
ULONG64 Unsigned LONG64.
ULONGLONG 64-bit unsigned integer.
UNSIGNED Unsigned attribute.
USHORT Unsigned SHORT.
VOID Any type.
WCHAR 16-bit Unicode character. For more information, see Character Sets Used By Fonts.
WINAPI Calling convention for system functions.
WORD 16-bit unsigned integer.
WPARAM Message parameter.

要将WinForm程序设置为默认打开指定类型的文件,您需要在注册表中进行相应的设置,具体步骤如下: 1. 打开您的WinForm项目,添加一个新的Windows Form,例如“FileViewerForm”。 2. 在“FileViewerForm”上添加一个“Label”控件,用来显示文件名。 3. 在“FileViewerForm”的代码文件中,添加以下代码: ```csharp using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormDefaultApp { public partial class FileViewerForm : Form { public FileViewerForm(string filePath) { InitializeComponent(); label1.Text = filePath; } } } ``` 在这个例子中,我们使用“Label”控件来显示文件名,并在构造函数中将文件名作为参数进行传递。 4. 在“FileViewerForm”的设计视图中,右键单击表单并选择“属性”。找到“窗体”属性中的“文本”属性,并将其设置为“文件查看器”。 5. 添加一个新的类,例如“Program.cs”,并在其中添加以下代码: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormDefaultApp { static class Program { [STAThread] static void Main(string[] args) { if (args.Length > 0) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FileViewerForm(args[0])); } } } } ``` 在这个例子中,我们在“Main”方法中检查了命令行参数的数量。如果有参数,则创建一个新的“FileViewerForm”窗体,并将第一个参数作为文件路径传递给它进行显示。 6. 在“WinFormDefaultApp”项目中,右键单击“添加新项”,选择“安装程序”并添加一个新的安装程序项目。 7. 在“安装程序”项目中,打开“File Types”(文件类型)视图,并添加一个新的文件类型。设置文件类型的名称、描述和文件扩展名。 8. 在“文件类型”视图中,选择“打开操作”,添加一个新的打开操作,并设置其路径为您的应用程序的可执行文件路径(例如“C:\Program Files\MyApp\MyApp.exe”),并在末尾添加一个空格和“%1”参数。 9. 将您的WinForm项目编译为可执行文件。 10. 在“安装程序”项目中,右键单击“发布”并生成安装程序。 11. 运行安装程序并按照提示完成安装。现在您的WinForm应用程序已经设置为默认打开指定类型的文件了。 要获取打开文件的信息,您可以在“FileViewerForm”的构造函数中对文件进行处理。例如,您可以使用以下代码获取文件名、路径和扩展名: ```csharp public FileViewerForm(string filePath) { InitializeComponent(); label1.Text = filePath; string fileName = Path.GetFileName(filePath); string fileDir = Path.GetDirectoryName(filePath); string fileExt = Path.GetExtension(filePath); } ``` 在这个例子中,我们使用了“System.IO”命名空间中的“Path”类来获取文件名、路径和扩展名。然后,您可以对文件进行进一步的处理或显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值