Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32 API question

Status
Not open for further replies.

yumbelie

Programmer
Dec 31, 2002
96
GB
Hi, I'm fairly new to Visual Basic (release 6) and having a bit of trouble with a tutorial I'm following - - Basically, I'm unsure of what is going on here, and wondering if someone could just explain this specific hunk of code:
Code:
With Parent
    
    Do
        stTime& = GetTickCount()
        SetTextColor .hdc, Color
        TextOut .hdc, CurrentX, CurrentY, Caption, Len(Caption)
        Do Until GetTickCount - stTime > Speed
            DoEvents: If Not Scrolling Then Exit Sub
        Loop
        SetTextColor .hdc, GetBkColor(.hdc)
        TextOut .hdc, CurrentX, CurrentY, Caption, Len(Caption)
        SetNewPosition
        DoEvents: If Not Scrolling Then Exit Sub
    Loop
    
End With
My specific questions are:

1) What is the significance of the & after a variable? (stTime&) - I've also seen $ suffixing variables - what does this mean?

2) What exactly is going on with the line " SetTextColor .hdc, Color" ? I mean, the With statement is prefixing all calls to class objects with Parent ? So how exactly is this working? Should it not be Parent.(a given)hdc.SetTextColor = RED or whatever?

Many thanks for any assistance.
 
1. They are data type suffixes, & = Long, $ = String; considered a bit old fashioned these days. Many people use a prefix instead:

Dim strXYZ As String

2. Can't really tell without seeing the rest of the code but Parent seems to be returning an object that can have a Device Context such as a form.

Paul Bent
Northwind IT Systems
 
Thanks for the response, that's cleared up the & and $ - Just out of interest, does putting a & on the end of say, the stTime var cause typecasting? like, if you Dim it to a 32 bit Int, then & it to a 64 bit Long?

Re the second question, the URL I've provided links to the tutorial, I didn't wnat to paste it as fair bit of tutorial text in there. But basically, how is it referencing a method of an object (Parent is a instance of a form) in the manner it is, why does it not use the standard method:

Parent.hdc.SetTextColor = RED

? Or am I missing something (quite possible, pretty new)

Many Thanks for your help!
 
>Thanks for the response, that's cleared up the & and $ - Just out of interest, does putting a & on the end of say, the stTime var cause typecasting? like, if you Dim it to a 32 bit Int, then & it to a 64 bit Long?

No,
Code:
dim MyLong&
dim myOtherLong as long

both lines are equivalent, although most people now use the "as long" construct. You can't redefine a variable to a different type at runtime.

casting is supported by useing the type conversion functions ( enter Type conversion functions in MSDN search)


as for using the with construct...

It is more effecient.

you could rewrite (forexample)
SetTextColor .hdc, Color
with
SetTextColor Parent.hdc, Color

and also for each and every other property used. However, each and every time the VB runtime needs to resolve parent.hdc through the relevant object model. However, if most of that resoultion is already done, it is only the last part that needs to be done

I haven't explained that well, so If you are still unclear post again...


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Right, I've nearly got it (I think ;)) but how exactly is SetTextColor working? I mean, the assignments I've seen so far use:

x.y.z = attribute

But this line is using:

SetTextColor x.y, attribute

I'm not sure I understand how that works, where is SetTextColor coming from? is it a method? a property? and whats the significance of the , Why is it not x.y = attribute ?

Many thanks ;)
 
SetTextColor is a Windows API call; consider it a built-in function that you can call from your VB programs. The main requirement is that it be declared somewhere in the program so that VB knows how to call it. You should find something like:

Public Declare Function SetTextColor Lib "gdi32" Alias "SetTextColor" (ByVal hdc As Long, ByVal crColor As Long) As Long

somewhere in the example
 
Ahhhhhhhh - fantastic, it's all clicked - Many Thanks guys for all the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top