delphi - the tomes of delphi - win32 core api windows 2000 edition

759 398 0
delphi - the tomes of delphi - win32 core api windows 2000 edition

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TEAMFLY Team-Fly ® The Tomes of DelphiWin32 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). I. Title. QA76.76.O63 A97 2001 2001046842 005.265 dc21 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 10987654321 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 xvi Acknowledgments xviii Introduction xix Chapter 1 Delphi and the Windows API 1 Windows Data Types 1 Handles 3 Constants 4 Strings 4 Importing Windows Functions 4 Incorrectly Imported Functions 5 Callback Functions 5 Function Parameters 6 Unicode 6 Delphi vs. the Windows API 7 Chapter 2 Window Creation Functions 9 Creating Windows: The Basic Steps 9 Window Attributes 10 The Window Procedure 13 Hardcore Windows Programming 13 Window Types 15 Multiple Document Interface 17 Extending Functionality 23 Delphi vs. the Windows API 25 Window Creation and Registration Functions 26 CreateMDIWindow 26 CreateWindowEx 29 DestroyWindow 45 MessageBox 46 RegisterClass 49 RegisterClassEx 53 UnregisterClass 55 Chapter 3 Message Processing Functions 57 The Message Queue and Message Loop 57 Windows Hooks 58 Interprocess Communication 61 Delphi vs. the Windows API 61 Message Processing Functions 62 v BroadcastSystemMessage 63 CallNextHookEx 65 CallWindowProc 66 DefFrameProc 68 DefMDIChildProc 73 DefWindowProc 74 DispatchMessage 75 GetMessage 76 GetMessageExtraInfo 79 GetMessagePos 80 GetMessageTime 81 GetQueueStatus 81 InSendMessage 83 PeekMessage 84 PostMessage 86 PostQuitMessage 89 PostThreadMessage 89 RegisterWindowMessage 91 ReplyMessage 93 SendMessage 94 SendMessageCallback 95 SendMessageTimeout 97 SendNotifyMessage 100 SetMessageExtraInfo 102 SetWindowsHookEx 103 WH_CALLWNDPROC Hook Function 105 WH_CALLWNDPROCRET Hook Function 106 WH_CBT Hook Function 107 WH_DEBUG Hook Function 110 WH_FOREGROUNDIDLE Hook Function 111 WH_GETMESSAGE Hook Function 111 WH_JOURNALPLAYBACK Hook Function 112 WH_JOURNALRECORD Hook Function 114 WH_KEYBOARD Hook Function 115 WH_MOUSE Hook Function 116 WH_MSGFILTER Hook Function 117 WH_SHELL Hook Function 118 WH_SYSMSGFILTER Hook Function 120 TranslateMessage 122 UnhookWindowsHookEx 123 WaitMessage 123 Chapter 4 Memory Management Functions 125 The Win32 Virtual Memory Architecture 125 Categories of Memory Allocation Functions 126 Heaps 126 The 16-Bit Memory Functions 127 Virtual Memory 127 vi n Contents Three States of Memory 127 How Much Memory is Really There? 128 Multiple Heaps 128 Error Trapping 129 Thread Access 129 Speed 130 Delphi vs. the Windows API 130 Memory Management Functions 131 CopyMemory 132 FillMemory 133 GetProcessHeap 134 GlobalAlloc 135 GlobalDiscard 136 GlobalFlags 137 GlobalFree 138 GlobalHandle 138 GlobalLock 139 GlobalMemoryStatus 140 GlobalReAlloc 142 GlobalSize 145 GlobalUnlock 145 HeapAlloc 146 HeapCreate 148 HeapDestroy 150 HeapFree 150 HeapReAlloc 151 HeapSize 152 IsBadCodePtr 153 IsBadReadPtr 154 IsBadStringPtr 155 IsBadWritePtr 156 MoveMemory 157 VirtualAlloc 159 VirtualFree 163 VirtualProtect 164 VirtualQuery 166 ZeroMemory 168 Chapter 5 Dynamic-Link Library Functions 169 Importing/Exporting Functions 169 Calling Conventions 170 The Dynamic-Link Library Entry Point Function 170 Delphi vs. the Windows API 171 Dynamic-Link Library Functions 171 DLLMain 171 DisableThreadLibraryCalls 172 FreeLibrary 173 FreeLibraryAndExitThread 174 Contents n vii GetModuleFileName 178 GetModuleHandle 179 GetProcAddress 179 LoadLibrary 180 LoadLibraryEx 183 Chapter 6 Process and Thread Functions 187 Important Concepts 187 Processes 188 Threads 188 Priority Levels 188 Synchronization and Coordination 188 Deadlocks 189 Synchronization Objects 190 Critical Sections 190 Semaphores 190 Mutexes 190 Events 191 Synchronizing Processes with a Mutex 191 Delphi vs. the Windows API 192 Process and Thread Functions 192 CreateEvent 194 CreateMutex 197 CreateProcess 200 CreateSemaphore 206 CreateThread 210 DeleteCriticalSection 211 DuplicateHandle 211 EnterCriticalSection 214 ExitProcess 215 ExitThread 216 GetCurrentProcess 217 GetCurrentProcessId 217 GetCurrentThread 218 GetCurrentThreadId 218 GetExitCodeProcess 219 GetExitCodeThread 220 GetPriorityClass 221 GetThreadPriority 223 GetWindowThreadProcessId 225 InitializeCriticalSection 226 InterlockedDecrement 228 InterlockedExchange 230 InterlockedIncrement 231 LeaveCriticalSection 232 OpenEvent 232 OpenMutex 233 OpenProcess 234 viii n Contents OpenSemaphore 236 PulseEvent 237 ReleaseMutex 238 ReleaseSemaphore 239 ResetEvent 240 ResumeThread 240 SetEvent 241 SetPriorityClass 241 SetThreadPriority 243 Sleep 244 SuspendThread 244 TerminateProcess 245 TerminateThread 246 TlsAlloc 247 TlsFree 250 TlsGetValue 250 TlsSetValue 251 WaitForInputIdle 251 WaitForSingleObject 253 Chapter 7 Timer Functions 255 Emulating a Timer 255 Precise Timing 257 Delphi vs. the Windows API 259 Timer Functions 259 GetTickCount 259 KillTimer 260 QueryPerformanceCounter 262 QueryPerformanceFrequency 263 SetTimer 264 Chapter 8 Error Functions 267 Error Descriptions 267 Audible Error Cues 268 Delphi vs. the Windows API 269 Error Functions 270 Beep 270 ExitWindows 271 ExitWindowsEx 272 FatalAppExit 273 GetLastError 274 MessageBeep 275 SetLastError 276 Chapter 9 Graphical Device Interface Functions 279 Device Independence 279 Device Contexts 280 Device Context Types 280 Screen, Window, and Client Area Device Contexts 282 Contents n ix [...]... introduces the reader to The Tomes of Delphi: Win32 Core API Windows 2000 Edition It covers general Windows programming concerns and techniques, and explains various nuances of programming with the Win32 API in the Delphi environment Chapter 2: Window Creation Functions AM FL Y Creating a window is the most fundamental part of any Windows application Chapter 2 covers the low-level window creation and... functions usually differ only in the type of string information passed to a function, and the text within this book should adequately describe the Unicode function’s behavior Delphi vs the Windows API The Delphi development team did a world-class job of encapsulating the majority of important Windows API functionality into the VCL However, due to the vastness of the Windows API, it would be impossible and... step-by-step Windows programming tutorial, there are plenty of other fine books out there to get you started However, if you’ve got a nasty problem whose only hope of salvation is using the Windows API, if you want to extend the functionality of Delphi components and objects, or you want a down-and-dirty, no-holds-barred collection of Delphi Win32 API programming examples, then this book is for you You will... low-level Windows API functions Although there have been a few books that touched on the subject of using Windows API functions in Delphi, none have ever discussed the issue in depth There are numerous magazine articles that describe very specific subsets of the API, but unless the Delphi programmer had a background in C, and the time to convert a C example into Delphi, there was simply no recourse of. .. the world’s greatest development tool: Delphi Delphi gives you full access to the entire Windows API It is a tool designed to let you plumb the depths of the operating system, to best utilize the features that have made Windows the preeminent operating system in the world today Armed with these books on the Windows API, and a copy of Delphi, you can build any type of application you desire, and can be... manual for using Windows 32-bit API functions in the Delphi environment As such, it is not a Windows or Delphi programming tutorial, nor is it a collection of Delphi tricks that solve specific problems To date, this book is the most complete and accurate reference to the Windows API for the Delphi programmer It is not a complete reference, as the Windows API includes thousands upon thousands of functions... heap Internally, Windows keeps track of all of these handles, and the handle serves as the link through the operating system between the object and the application Using these handles, an application can easily refer to any of these objects, and the operating system instantly knows which object a piece of code wants to manipulate 1 Windows Data Type HLOCAL n Chapter Delphi and the Windows API 4 n Chapter... than the one you are holding However, this book covers the most common and important cross section of the Windows API Additionally, every function in this book is available under both Windows 95/98/Me and Windows NT /2000 Most of these functions will also work under Windows NT prior to the new version xix xx n Introduction The Chapters Chapter 1: Delphi and the Windows API This chapter introduces the. .. create a new type of window, such as the main window for an application, the developer must register a window class Delphi s encapsulation of the Windows API makes all of this transparent to the developer However, there may be certain instances when the developer needs to create a window the old-fashioned way Creating Windows: The Basic Steps Creating a window using low-level Windows API functions is... in the optimal possible manner No other compiler can bring you closer to the operating system, nor can any other compiler let you take better advantage of the operating system’s features These books are the Rosetta stone which forms the link between Delphi and the Windows API Readers will be able to use them to create the most powerful applications supported by the operating system My hat is off to the . 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. the above address. Telephone inquiries may be made by calling: (972) 42 3-0 090 Praise for The Tomes of Delphi 3: Win32 Core API The Tomes of Delphi is the definitive reference for the Win32 API. 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

Ngày đăng: 16/04/2014, 11:15

Từ khóa liên quan

Mục lục

  • sample.pdf

    • sterling.com

      • Welcome to Sterling Software

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan