没有合适的资源?快使用搜索试试~ 我知道了~
首页Windows XP API编程终极指南
Windows XP API编程终极指南
4星 · 超过85%的资源 需积分: 9 24 下载量 17 浏览量
更新于2023-07-17
评论 1
收藏 4.34MB PDF 举报
Win32 API的绝好参考资料,Charles Petzold的经典著作升级版!
资源详情
资源评论
资源推荐
Copyright© 1998 by Charles Petzold
Converted from HTML to Word97 by anarchriz (http://surf.to/anarchriz),
last update: 31 july 1999
2
Author's Note
Visit my web site www.cpetzold.com for updated information regarding this book, including possible bug reports
and new code listings. You can address mail regarding problems in this book to charles@cpetzold.com. Although I'll
also try to answer any easy questions you may have, I can't make any promises. I'm usually pretty busy, and my cat
refuses to learn the Windows API.
I'd like to thank everyone at Microsoft Press for another great job in putting together this book. I think this "10
th
Anniversary Edition" of Programming Windows is the best edition yet. Many other people at Microsoft (including
some of the early developers of Microsoft Windows) also helped out when I was writing the earlier editions, and
these fine people are listed in those editions.
Thanks also to my family and friends, and in particular those more recent friends (you know who you are!) whose
support has made this book possible. To you this book is dedicated.
Charles Petzold
October 5, 1998
3
Contents
Author's Note...........................................................................................................................................2
Contents....................................................................................................................................................3
Section I: The Basics....................................................................................................................13
Chapter 1 -- Getting Started.................................................................................................................13
The Windows Environment ................................................................................................................................ 13
A History of Windows .................................................................................................................................... 13
Aspects of Windows ....................................................................................................................................... 14
Dynamic Linking ............................................................................................................................................ 16
Windows Programming Options......................................................................................................................... 17
APIs and Memory Models .............................................................................................................................. 17
Language Options ........................................................................................................................................... 18
The Programming Environment...................................................................................................................... 18
API Documentation......................................................................................................................................... 19
Your First Windows Program............................................................................................................................. 19
A Character-Mode Model ............................................................................................................................... 19
The Windows Equivalent................................................................................................................................ 20
The Header Files............................................................................................................................................. 21
Program Entry Point........................................................................................................................................ 21
The MessageBox Function.............................................................................................................................. 22
Compile, Link, and Run.................................................................................................................................. 23
Chapter 2 -- An Introduction to Unicode............................................................................................25
A Brief History of Character Sets ....................................................................................................................... 25
American Standards........................................................................................................................................ 25
The World Beyond.......................................................................................................................................... 26
Extending ASCII............................................................................................................................................. 27
Double-Byte Character Sets............................................................................................................................ 28
Unicode to the Rescue..................................................................................................................................... 28
Wide Characters and C ....................................................................................................................................... 29
The char Data Type ........................................................................................................................................ 29
Wider Characters............................................................................................................................................. 30
Wide-Character Library Functions ................................................................................................................. 31
Maintaining a Single Source........................................................................................................................... 32
Wide Characters and Windows........................................................................................................................... 33
Windows Header File Types........................................................................................................................... 33
The Windows Function Calls.......................................................................................................................... 34
Windows’ String Functions............................................................................................................................. 35
Using printf in Windows................................................................................................................................. 35
A Formatting Message Box ............................................................................................................................ 37
Internationalization and This Book................................................................................................................. 38
Chapter 3 -- Windows and Messages...................................................................................................40
A Window of One’s Own ................................................................................................................................... 40
An Architectural Overview............................................................................................................................. 40
The HELLOWIN Program.............................................................................................................................. 41
Thinking Globally........................................................................................................................................... 44
The Windows Function Calls.......................................................................................................................... 44
New Data Types.............................................................................................................................................. 46
Getting a Handle on Handles .......................................................................................................................... 46
Hungarian Notation......................................................................................................................................... 47
Registering the Window Class........................................................................................................................ 48
Creating the Window ...................................................................................................................................... 52
4
Displaying the Window .................................................................................................................................. 53
The Message Loop.......................................................................................................................................... 54
The Window Procedure .................................................................................................................................. 55
Processing the Messages................................................................................................................................. 56
Playing a Sound File ....................................................................................................................................... 56
The WM_PAINT Message ............................................................................................................................. 57
The WM_DESTROY Message....................................................................................................................... 58
The Windows Programming Hurdles.................................................................................................................. 58
Don’t Call Me, I’ll Call You........................................................................................................................... 58
Queued and Nonqueued Messages.................................................................................................................. 59
Get In and Out Fast......................................................................................................................................... 61
Chapter 4 -- An Exercise in Text Output............................................................................................62
Painting and Repainting...................................................................................................................................... 62
The WM_PAINT Message ............................................................................................................................. 62
Valid and Invalid Rectangles .......................................................................................................................... 63
An Introduction to GDI....................................................................................................................................... 64
The Device Context ........................................................................................................................................ 64
Getting a Device Context Handle: Method One ............................................................................................. 65
The Paint Information Structure...................................................................................................................... 65
Getting a Device Context Handle: Method Two............................................................................................. 67
TextOut: The Details ....................................................................................................................................... 68
The System Font ............................................................................................................................................. 69
The Size of a Character................................................................................................................................... 70
Text Metrics: The Details ............................................................................................................................... 70
Formatting Text .............................................................................................................................................. 72
Putting It All Together .................................................................................................................................... 72
The SYSMETS1.C Window Procedure.......................................................................................................... 78
Not Enough Room .......................................................................................................................................... 79
The Size of the Client Area............................................................................................................................. 79
Scroll Bars........................................................................................................................................................... 80
Scroll Bar Range and Position ........................................................................................................................ 81
Scroll Bar Messages........................................................................................................................................ 83
Scrolling SYSMETS....................................................................................................................................... 85
Structuring Your Program for Painting........................................................................................................... 88
Building a Better Scroll....................................................................................................................................... 89
The Scroll Bar Information Functions ............................................................................................................ 89
How Low Can You Scroll?............................................................................................................................. 91
The New SYSMETS....................................................................................................................................... 91
But I Don’t Like to Use the Mouse................................................................................................................. 96
Chapter 5 -- Basic Drawing..................................................................................................................97
The Structure of GDI .......................................................................................................................................... 97
The GDI Philosophy ....................................................................................................................................... 97
The GDI Function Calls.................................................................................................................................. 98
The GDI Primitives......................................................................................................................................... 99
Other Stuff ...................................................................................................................................................... 99
The Device Context .......................................................................................................................................... 100
Getting a Device Context Handle ................................................................................................................. 100
Getting Device Context Information............................................................................................................. 102
The DEVCAPS1 Program ............................................................................................................................ 102
The Size of the Device.................................................................................................................................. 105
Finding Out About Color .............................................................................................................................. 109
The Device Context Attributes...................................................................................................................... 111
Saving Device Contexts ................................................................................................................................ 112
Drawing Dots and Lines ................................................................................................................................... 113
Setting Pixels ................................................................................................................................................ 113
5
Straight Lines................................................................................................................................................ 114
The Bounding Box Functions ....................................................................................................................... 118
Bezier Splines ............................................................................................................................................... 124
Using Stock Pens .......................................................................................................................................... 129
Creating, Selecting, and Deleting Pens ......................................................................................................... 130
Filling in the Gaps......................................................................................................................................... 132
Drawing Modes............................................................................................................................................. 132
Drawing Filled Areas........................................................................................................................................ 134
The Polygon Function and the Polygon-Filling Mode.................................................................................. 135
Brushing the Interior ..................................................................................................................................... 139
The GDI Mapping Mode................................................................................................................................... 141
Device Coordinates and Logical Coordinates............................................................................................... 142
The Device Coordinate Systems ................................................................................................................... 142
The Viewport and the Window..................................................................................................................... 143
Working with MM_TEXT ............................................................................................................................ 144
The Metric Mapping Modes.......................................................................................................................... 147
The “Roll Your Own” Mapping Modes........................................................................................................ 149
The WHATSIZE Program ............................................................................................................................ 154
Rectangles, Regions, and Clipping ................................................................................................................... 157
Working with Rectangles.............................................................................................................................. 157
Random Rectangles....................................................................................................................................... 158
Creating and Painting Regions...................................................................................................................... 162
Clipping with Rectangles and Regions ......................................................................................................... 163
The CLOVER Program................................................................................................................................. 163
Chapter 6 -- The Keyboard ................................................................................................................168
Keyboard Basics ............................................................................................................................................... 168
Ignoring the Keyboard .................................................................................................................................. 168
Who’s Got the Focus?................................................................................................................................... 169
Queues and Synchronization......................................................................................................................... 169
Keystrokes and Characters............................................................................................................................ 170
Keystroke Messages.......................................................................................................................................... 170
System and Nonsystem Keystrokes .............................................................................................................. 170
Virtual Key Codes......................................................................................................................................... 171
The lParam Information ............................................................................................................................... 174
Shift States .................................................................................................................................................... 175
Using Keystroke Messages ........................................................................................................................... 176
Enhancing SYSMETS for the Keyboard ...................................................................................................... 177
Character Messages .......................................................................................................................................... 182
The Four Character Messages....................................................................................................................... 183
Message Ordering ......................................................................................................................................... 183
Control Character Processing........................................................................................................................ 185
Dead-Character Messages............................................................................................................................. 185
Keyboard Messages and Character Sets............................................................................................................ 186
The KEYVIEW1 Program............................................................................................................................ 186
The Foreign-Language Keyboard Problem................................................................................................... 190
Character Sets and Fonts............................................................................................................................... 192
What About Unicode?................................................................................................................................... 203
TrueType and Big Fonts ............................................................................................................................... 204
The Caret (Not the Cursor) ............................................................................................................................... 209
The Caret Functions...................................................................................................................................... 209
The TYPER Program.................................................................................................................................... 210
Chapter 7 -- The Mouse......................................................................................................................216
Mouse Basics .................................................................................................................................................... 216
Some Quick Definitions................................................................................................................................ 217
The Plural of Mouse Is….............................................................................................................................. 217
剩余1116页未读,继续阅读
jianda999
- 粉丝: 3
- 资源: 67
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论4