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
Here are what the arguments to MoveMemory mean:
destPointer to the destination buffer
srcPointer to the source buffer
lengthNumber of bytes to move
To allocate memory, we used GlobalAlloc to get a handle to a memory area; to use that memory, we used GlobalLock to get a pointer to the memory area. To unlock memory, you pass a pointer to that memory to GlobalUnlock:
Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
To free memory, you pass a memory handle to GlobalFree:
Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long
Lets see this at work. Here, we add the declarations of the functions well use to the program we developed in the previous topic, as well as a buffer, inbuffer, to store the data we read:
Const DataLength = 40
Const GMEM_MOVEABLE = &H2
Dim outbuffer As String * DataLength
Dim inbuffer As String * DataLength
Dim memHandle As Long
Dim memPointer As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long,_
ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) _
As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory"
(ByVal dest As Any, ByVal src As Any, ByVal length As Long)
Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) _
As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) _
As Long
Then, when the user clicks Command2, we can use the memory pointer we created in the program in the previous topic, hMemoryPointer, with MoveMemory, to copy the string to the buffer:
Private Sub Command2_Click()
Call MoveMemory(inbuffer, hMemoryPointer, DataLength)
...
Now we can move the string to Text2 from inbuffer:
Private Sub Command2_Click()
Call MoveMemory(inbuffer, hMemoryPointer, DataLength)
Text2.Text = inbuffer
...
Finally, we unlock and free the memory weve used:
Private Sub Command2_Click()
Call MoveMemory(inbuffer, hMemoryPointer, DataLength)
Text2.Text = inbuffer
GlobalUnlock (hMemoryPointer)
GlobalFree (hMemory)
End Sub
Thats itwhen you run the program, as shown in Figure 23.10, and click the Store Text In Memory button, the text in the top text box, Text1, is stored in memory. When you click the Read Text From Memory button, the string is read back and displayed in the bottom text box, Text2, as you see in Figure 23.10. Now were using memory with the Windows API.
Figure 23.10 Storing and reading memory data.
The code for this example is located in the winmemory folder on this books accompanying CD-ROM.
Making A Window Topmost
You can use SetWindowPos to make a window topmost, which means itll always stay on top of other windows:
Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal _
hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal _
cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Heres what the arguments to this function mean:
hwndHandle of the window to work with.
hWndInsertAfterHandle to the window that will precede this window in the Z-order. This parameter can be a window handle set to one of the following values: HWND_BOTTOM (= 1; places the window at the bottom of the Z-order), HWND_TOP (= 0; places the window at the top of the Z-order), HWND_TOPMOST (= 1; places the window above all non-topmost windows), or HWND_NOTOPMOST (= 2; repositions the window to the top of all non-topmost windows).
xSpecifies the new position of the left side of the window.
ySpecifies the new position of the top of the window.
cxSpecifies the new width of the window.
cySpecifies the new height of the window.
wFlagsSpecifies sizing and positioning options, as shown in Table 23.5.
Table 23.5 SetWindowPos flags.
Constant
Meaning
SWP_DRAWFRAME (= &H20)
Draws a frame (defined when the window was created) around the window.
SWP_FRAMECHANGED (= &H20)
Sends a WM_NCCALCSIZE message to the window, even if the windows size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the windows size is being changed.
SWP_HIDEWINDOW (=&H80)
Hides the window.
SWP_NOACTIVATE (= &H10)
Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or the non-topmost group (depending on the setting of the hWndInsertAfter parameter).
SWP_NOCOPYBITS (= &H100)
Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE (= 2)
Retains current position (ignores the x and y parameters).
SWP_NOOWNERZORDER (= &H200)
Does not change the owner windows position in the Z-order.
SWP_NOREDRAW (= 8)
Does not redraw changes. If this flag is set, no repainting of any kind occurs.
SWP_NOREPOSITION (= &H200)
Same as SWP_NOOWNERZORDER.
SWP_NOSIZE (= 1)
Retains current size (ignores the cx and cy parameters).
SWP_NOZORDER (= 4)
Retains current ordering (ignores hWndInsertAfter).
SWP_SHOWWINDOW (=&H40)
Displays the window.
Lets see an example. Here, well size a window to 100 x 100 pixels and make it a topmost window. We start by declaring SetWindowPos in our program, as well as the constants well use, SWP_SHOWWINDOW, SWP_DRAWFRAME, and HWND_TOPMOST:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long,
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const SWP_SHOWWINDOW = &H40
Const SWP_DRAWFRAME = &H20
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:
BS EN 806 pt3812 scenariusze zabaw bozonarodzeniowych2805 806BS EN 806 pt5BS EN 806 pt2809 812804 806806 807ReadMe (812)mbdch20 806index (812)nbt0909 806BS EN 806 pt1index (806)więcej podobnych podstron