Results 1 to 5 of 5

Thread: Stupid User Question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    45

    Stupid User Question

    Hi all,

    can anybody help me ?

    I'd like to do some API stuff.
    I got this code from VBAPI.com

    1) Declare Function LineTo Lib "gdi32.dll" (ByVal hdc As Long, x As Long, ByVal y As Long) As Long

    2)' Draw a red line from (0,40) to (100,50) on the window Form1.
    Dim pt As POINT_TYPE ' needed for another API function
    Dim retval As Long ' return value

    3)Form1.ForeColor = RGB(255, 0, 0) ' set the foreground drawing color of Form1 to red
    retval = MoveToEx(Form1.hdc, 0, 40, pt) ' set the current point to (0,40)
    retval = LineTo(Form1.hdc, 100, 50) ' draw a line from current point to (100,50)

    Questions :
    Where to declare 1) ???
    In General declarations ???

    Where to declare 2) ???

    Last question : I have to declare the POINT_TYPE structure with Type POINT_TYPE
    x as long
    y as long
    End Type

    Where to declare this ???

    Any help would be very much appreciated !!!

    Greets
    Tom

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    All ion General decleration section

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    45
    Thank you ver much amitabh !!

    Anyway, I don't get it !?

    General Declaration
    Declare Function LineTo Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
    Type POINT_Type
    x As Long
    y As Long
    End Type
    Dim pt As POINT_Type
    Dim retval As Long

    Private Sub Command1_Click()
    Form1.ForeColor = RGB(255, 0, 0)
    retval = MoveToEx(Form1.hdc, 0, 40, pt)
    retval = LineTo(Form1.hdc, 100, 50)
    End Sub

    gives the following error message:
    Compile error : Cannot define a public user-defined type within a private object module.

    ???

    Can you help me again, please ?!
    Thank you !!

    Thomas

  4. #4
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    If you wish to use the code in a form or a class module then the declarations must be private thus:

    Code:
    Private Declare Function LineTo Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long 
    
    Private Type POINT_Type 
      x As Long 
      y As Long 
    End Type
    Otherwise they must be declared in a .bas standard code module.

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    45
    Thanks MerrionComputin !

    It works !
    I was close sometimes but always forgot to declare the MoveToEx , and stupid enough NOT to understand the error message !

    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width