795 800




Visual Basic 6 Black Book:Connecting To The Windows API And Visual C++
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




This program is a fairly complex one, involving lots of Visual Basic code, and it appears in Listing 23.1 for reference. This program, screencap, puts together almost all of the Windows API operations we’ve seen so far in this chapter, so it’s worth taking a look at as an example of a substantial program that uses the Windows API.

Listing 23.1 screencap.frm


VERSION 6.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4755
ClientLeft = 1425
ClientTop = 2175
ClientWidth = 6495
LinkTopic = "Form1"
PaletteMode = 1 'UseZOrder
ScaleHeight = 317
ScaleMode = 3 'Pixel
ScaleWidth = 433
Begin VB.PictureBox Picture1
AutoRedraw = -1 'True
BackColor = &H00FFFFFF&
Height = 3735
Left = 480
ScaleHeight = 3675
ScaleWidth = 5595
TabIndex = 0
Top = 120
Width = 5655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim blnStartCapture As Boolean
Dim blnAmCapturing As Boolean
Dim intHandleDisplay As Integer
Dim intStartX As Integer
Dim intStartY As Integer
Dim intMouseX As Integer
Dim intMouseY As Integer
Dim intOldMouseX As Integer
Dim intOldMouseY As Integer

Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) _
As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal _
lpDriverName As String, ByVal lpDeviceName As String, ByVal _
lpOutput As String, lpInitData As DEVMODE) As Long
Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal_
nDrawMode As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long,
ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x _
As Long, ByVal y As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal _
nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal _
ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As _
Long, lpPoint As POINTAPI) As Long

Const SRCCOPY = &HCC0020
Const R2_NOT = 6

Private Sub Form_Load()
Dim devDevMode As DEVMODE

blnStartCapture = False
blnAmCapturing = False

intHandleDisplay = CreateDC("DISPLAY", 0&, 0&, devDevMode)
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As _
Single, y As Single)
Dim ptPoint As POINTAPI

If Button = 1 Then
blnStartCapture = True
intRetVal = SetCapture(hwnd)
End If

If blnStartCapture And Button = 2 Then

ptPoint.x = x
ptPoint.y = y
retval = ClientToScreen(hwnd, ptPoint)
intStartX = ptPoint.x
intStartY = ptPoint.y

intOldMouseX = intStartX
intOldMouseY = intStartY

blnAmCapturing = True
End If
End Sub
Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y _
As Single)

If blnAmCapturing Then

EraseOld x, y

intOldMouseX = intMouseX
intOldMouseY = intMouseY

DrawNew x, y

End If
End Sub

Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As_
Single)
Dim intLeftX As Integer
Dim intLeftY As Integer

If blnAmCapturing Then
ReleaseCapture
blnStartCapture = False
blnAmCapturing = False

EraseOld x, y

intLeftX = intMouseX
If intStartX < intMouseX Then
intLeftX = intStartX
End If

intLeftY = intMouseY
If intStartY < intMouseY Then
intLeftY = intStartY
End If

Picture1.Cls
intRetVal = BitBlt(Picture1.hdc, 0, 0, Abs(intStartX - _
intMouseX), Abs(intStartY - intMouseY), intHandleDisplay, _
intLeftX, intLeftY, SRCCOPY)

End If
End Sub

Private Sub EraseOld(ByVal x As Integer, ByVal y As Integer)
Dim ptPoint As POINTAPI

intRetVal = SetROP2(intHandleDisplay, R2_NOT)

ptPoint.x = x
ptPoint.y = y
retval = ClientToScreen(hwnd, ptPoint)
intMouseX = ptPoint.x
intMouseY = ptPoint.y

lngRetVal = MoveToEx(intHandleDisplay, intOldMouseX, intOldMouseY, _
ptPoint)
intRetVal = LineTo(intHandleDisplay, intStartX, intOldMouseY)
intRetVal = LineTo(intHandleDisplay, intStartX, intStartY)
intRetVal = LineTo(intHandleDisplay, intOldMouseX, intStartY)
intRetVal = LineTo(intHandleDisplay, intOldMouseX, intOldMouseY)

End Sub

Private Sub DrawNew(ByVal x As Integer, ByVal y As Integer)
Dim ptPoint As POINTAPI

intRetVal = SetROP2(intHandleDisplay, R2_NOT)

ptPoint.x = x
ptPoint.y = y
retval = ClientToScreen(hwnd, ptPoint)
intMouseX = ptPoint.x
intMouseY = ptPoint.y

lngRetVal = MoveToEx(intHandleDisplay, intMouseX, intMouseY, _
ptPoint)
intRetVal = LineTo(intHandleDisplay, intStartX, intMouseY)
intRetVal = LineTo(intHandleDisplay, intStartX, intStartY)
intRetVal = LineTo(intHandleDisplay, intMouseX, intStartY)
intRetVal = LineTo(intHandleDisplay, intMouseX, intMouseY)

End Sub

Private Sub Form_Unload(Cancel As Integer)
intRetVal = DeleteDC(intHandleDisplay)
End Sub


Getting A Window Handle For Any Window On The Screen
To work with windows in the Windows API, you need a window handle. One way of getting a handle for any window on the screen is to use the WindowFromPoint function. You just pass that function the x- and y-coordinates (in screen coordinates) of a point inside the window for which you want the handle:


Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As _
Long, ByVal yPoint As Long) As Long


Let’s see an example. Here, we’ll let the users click a command button, Command1, with the caption Choose Window. When they do, they can move the mouse to any window on the screen, click the window, and get a handle for that window.
When the users click the Choose Window button, we’ll set up a form-wide Boolean variable, blnChoose, to True, so we know the next time the users click the mouse, they’re indicating the window for which they want a handle:


Dim blnChoose As Boolean






Previous
Table of Contents
Next






Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.



Wyszukiwarka

Podobne podstrony:
NumPath 800 Bick 15V M561 87
Życie umysłowe i kulturalne w Polsce epoki oświecenia ~800
Serwisowka Kody Komputera Rover 100; 200; 400; 600; 800 [D]
800 zł na taką emeryturę może liczyć przedsiębiorca
Catane 800 EC
index (795)
Fagor 800 TGi [CHC] L841 85m
INSTRUKCJA OBSŁUGI MODEM ASDL SAGEM USB FAST 800 840 PL
Pilot radiowy do PVR 800 PVR800TCK
MJW 800 karta katalogowa
LECTURE 4 Anglo Saxons@0 800?
NumPath 800 PC50 M584 87
7 45 800

więcej podobnych podstron