logo资料库

最好的DELPHI WINAPI编程宝典(人家说的).pdf

第1页 / 共759页
第2页 / 共759页
第3页 / 共759页
第4页 / 共759页
第5页 / 共759页
第6页 / 共759页
第7页 / 共759页
第8页 / 共759页
资料共759页,剩余部分请下载后查看
sample.pdf
sterling.com
Welcome to Sterling Software
TEAMFLY Team-Fly®
The Tomes of Delphi™ Win32 Core API Windows 2000 Edition John Ayres Wordware Publishing, Inc.
Library of Congress Cataloging-in-Publication Data Ayres, John. Tomes of Delphi: Win32 Core API Windows 2000 edition / by John Ayres. p. cm. Includes bibliographical references and index. ISBN 1-55622-750-7 (pbk.) 1. Microsoft Win32. 2. Delphi (Computer file). QA76.76.O63 A97 2001 005.265--dc21 I. Title. 2001046842 CIP Copyright © 2002, Wordware Publishing, Inc. All Rights Reserved 2320 Los Rios Boulevard Plano, Texas 75074 No part of this book may be reproduced in any form or by any means without permission in writing from Wordware Publishing, Inc. Printed in the United States of America ISBN 1-55622-750-7 10 9 8 7 6 5 4 3 2 1 0110 Delphi is a trademark of Borland Software Corporation in the United States and other countries. Windows is a registered trademark of Microsoft Corporation in the United States and/or other countries. Other product names mentioned are used for identification purposes only and may be trademarks of their respective companies. All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the above address. Telephone inquiries may be made by calling: (972) 423-0090
Praise for The Tomes of Delphi 3: Win32 Core API “The Tomes of Delphi is the definitive reference for the Win32 API expressed in the Object Pascal language. It’s a must-have for application and component developers look- ing to extend their reach beyond the capabilities of the Visual Component Library.” Steve Teixeira, Director Core Technology Zone Labs, Inc. and co-author of Delphi 6 Developer’s Guide *************************** “The Tomes of Delphi 3: Win32 Core API is an excellent resource for Delphi programmers needing to go beyond drag and drop development. This book not only discusses the API in depth, but also provides solid examples of using Delphi to access the power of Windows provided through the API.” Xavier Pacheco, President and CEO Xapware Technologies, Inc and co-author of the best-selling Delphi 6 Developer’s Guide *************************** “One of the features I liked most when I first approached Delphi was its power to go down to the Windows API-level, something most other visual tools still lack. But this is not an easy task, and no book like The Tomes of Delphi 3: Win32 Core API can help you under- stand Windows from the Delphi perspective.” Marco Cantu, author of the best-selling Mastering Delphi 6 *************************** “Delphi lets developers work ‘under the hood’ with the Win32 API. The Tomes of Delphi 3: Win32 Core API gives every Delphi developer the knowledge to use the Win32 API powerfully, creatively, and effectively.” Michael Swindell, Director of Product Management RAD Tools Group, Borland Software Corporation *************************** “The Tomes of Delphi 3: Win32 Core API is my number one resource when looking for information about how to use the Win32 core API in Delphi. I especially enjoy the helpfile that contains the complete text from the book and can be accessed directly when programming.” Bob Swart (a.k.a. “Dr. Bob”), Author, trainer, consultant *************************** “Not only were these the first Delphi books to concentrate on API-level programming, they set the standard for all future Delphi API books.” Alan C. Moore, Contributing Editor Delphi Informant Magazine
Dedication I would like to dedicate this book to the following people and/or deities who have had a profound influence in my life: First, to God, whom I’ve been growing much closer to these last few years, for giving me the intelligence to wade through the confusing and sometimes maddening sea of Windows API documentation and make sense of it all; sec- ond, to my family, for putting up with my lack of participation in family activities during this project; and finally, but most of all, to my wife and soulmate, Marci, who made sure I had clothes to wear in the morning and food in the evening, fixed my lunches, and gener- ally took up all of my housework responsibilities so I could concentrate on the book. She encouraged me and prodded me along when the weight of this project became unbearable, and because of this she is directly responsible for this work being completed. She is a very inspiring task master; cracking the whip to bring me in line when I would have rather been playing X-Wing vs. Tie Fighter. I am unworthy of such a devoted and loving wife, and I thank God every day for providing me with such a perfect companion. Baby, this one’s for you.
Contents Foreword . . . . . . . . . . Acknowledgments . . . . . . Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 1 Delphi and the Windows API . Windows Data Types . . . . . . . . . . . . . . . . . Handles . . . . . . . . . . Constants . . . . . . . . Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Importing Windows Functions . . . . . . . . . . . . . . . . . . . . . . . Incorrectly Imported Functions . . . . . . . . Callback Functions . . . . . . . Function Parameters. . . . . . . Unicode . . . . . . . . . . . Delphi vs. the Windows API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvi . . . xviii . . . xix . . . 1 . . . 1 . . . 3 . . . 4 . . 4 . 4 . . . . 5 . . 5 . . 6 . . . 6 . 7 . . . . . . . . . . . . . . . . . . . 9 . . . 9 . 10 . 13 . 13 . . . 15 . 17 . 23 . 25 . . . 26 . 26 . . 29 . . . 45 . . . 46 . 49 . . . 53 . . . 55 Chapter 2 Window Creation Functions . . . . . . . . . . . . . . . . . . . . . . Creating Windows: The Basic Steps . . . . . Window Attributes . . . . . . The Window Procedure . . . . . . Hardcore Windows Programming . . Window Types . . . . . . . . . . . . Multiple Document Interface . . Extending Functionality . . . Delphi vs. the Windows API. . Window Creation and Registration Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CreateMDIWindow . . . CreateWindowEx . . . DestroyWindow . . . . . . MessageBox . . . . . . . RegisterClass . . . . . . RegisterClassEx . . . . . . UnregisterClass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3 Message Processing Functions. . . . . . The Message Queue and Message Loop . . . . . Windows Hooks . . . . . . . . . Interprocess Communication . . . . . Delphi vs. the Windows API. . Message Processing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 . . . 57 . . 58 . . . 61 . . . 61 . . 62 . . . . . . . . . . . . . . . . . v
vi n Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . BroadcastSystemMessage. . . . CallNextHookEx . . . . CallWindowProc . . . . . . DefFrameProc . . . . . . . DefMDIChildProc . . . DefWindowProc. . . . . . DispatchMessage . . . . GetMessage . . . . . . . . GetMessageExtraInfo . . . . GetMessagePos . . . . . . GetMessageTime . . . . GetQueueStatus . . . . . . InSendMessage . . . . . . PeekMessage . . . . . . . . PostMessage. . . . . . . PostQuitMessage . . . . PostThreadMessage . . . RegisterWindowMessage . . ReplyMessage . . . . . . . SendMessage . . . . . . . . . SendMessageCallback . SendMessageTimeout . . . . SendNotifyMessage . . . SetMessageExtraInfo . . . SetWindowsHookEx. . . WH_CALLWNDPROC Hook Function . . WH_CALLWNDPROCRET Hook Function . . . . . WH_CBT Hook Function . . WH_DEBUG Hook Function . . . . WH_FOREGROUNDIDLE Hook Function . . WH_GETMESSAGE Hook Function . . WH_JOURNALPLAYBACK Hook Function . . WH_JOURNALRECORD Hook Function . . WH_KEYBOARD Hook Function . . WH_MOUSE Hook Function . . . . . WH_MSGFILTER Hook Function . . WH_SHELL Hook Function . . . . . WH_SYSMSGFILTER Hook Function . . TranslateMessage . . . . . . UnhookWindowsHookEx . . WaitMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 . 65 . 66 . 68 . . . 73 . . 74 . 75 . 76 . . . 79 . . 80 . 81 . . 81 . . 83 . . 84 . . 86 . 89 . . . 89 . 91 . 93 . 94 . 95 . . . 97 . . 100 . 102 . . 103 . . 105 . . . 106 . 107 . . 110 . . 111 . 111 . . 112 . 114 . 115 . 116 . . 117 . . 118 . . . 120 . . . 122 . 123 . . . 123 Chapter 4 Memory Management Functions. . . . . The Win32 Virtual Memory Architecture . . Categories of Memory Allocation Functions . . . . . Heaps . . . . . . . . . . . . . . The 16-Bit Memory Functions . . . . Virtual Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 . . . 125 . . . 126 . . . 126 . . 127 . . 127 . . . . . . . . .
Contents n vii . . . Three States of Memory . . . . . . How Much Memory is Really There? . . Multiple Heaps . . . . . . . Error Trapping . . . . . . . Thread Access . . . . . . . Speed . . . . . . . . . . . . . . Delphi vs. the Windows API . . Memory Management Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 . 128 . . . 128 . . . 129 . . . 129 . . . 130 . 130 . 131 . 132 . 133 . . 134 . 135 . 136 . . 137 . . . . 138 . . . 138 . . . 139 . . . 140 . 142 . . 145 . 145 . . 146 . . . . 148 . . . 150 . . 150 . . . 151 . . 152 . . . 153 . . . 154 . 155 . 156 . 157 . . . 159 . . . 163 . . . 164 . . . 166 . . . 168 . . 169 . 169 . . 170 . . 170 . . 171 . . . 171 . . 171 . 172 . . . 173 . 174 CopyMemory. . . . . . . . FillMemory. . . . . . . . GetProcessHeap . . . . GlobalAlloc . . . . . . GlobalDiscard . . . . . . . GlobalFlags. . . . . . . . GlobalFree . . . . . . . . GlobalHandle. . . . . . . . GlobalLock . . . . . . . . GlobalMemoryStatus. . . GlobalReAlloc . . . . . . . GlobalSize . . . . . . . . GlobalUnlock . . . . . . . HeapAlloc . . . . . . . . HeapCreate . . . . . . . . HeapDestroy . . . . . . . . HeapFree . . . . . . . . . . HeapReAlloc . . . . . . . . HeapSize . . . . . . . . . . IsBadCodePtr. . . . . . . . IsBadReadPtr . . . . . . . . IsBadStringPtr . . . . . . . IsBadWritePtr . . . . . . . MoveMemory . . . . . . . VirtualAlloc . . . . . . . . VirtualFree . . . . . . . . VirtualProtect. . . . . . . . VirtualQuery . . . . . . . . ZeroMemory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5 Dynamic-Link Library Functions . Importing/Exporting Functions . . Calling Conventions . . . . . . . . . The Dynamic-Link Library Entry Point Function . . . . . . . . . . . Delphi vs. the Windows API . . Dynamic-Link Library Functions . . . . . DLLMain . . . . . . . . DisableThreadLibraryCalls . . FreeLibrary . . . . . . . FreeLibraryAndExitThread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
分享到:
收藏