DrawFrameControl

EK1

Active member
Joined
Aug 20, 2003
Messages
28
I saw this code posted on another forum but I cant get it to work. Can someone test this and see if it works for them?

Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

<StructLayout(LayoutKind.Sequential)> _
Public Structure rect
Dim left As Int64
Dim top As Int64
Dim right As Int64
Dim bottom As Int64
End Structure

Public Declare Function DrawFrameControl Lib "user32" (ByVal hDC As Int32, ByRef lpRect As IntPtr, ByVal un1 As Int32, ByVal un2 As Int32) As Int32
Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
Dim rectTest As rect

With rectTest
.left = 20
.top = 10
.right = 900
.bottom = 900
End With
Dim rectPointer As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(rectTest))
Marshal.StructureToPtr(rectTest, rectPointer, True)
Dim myDC As System.Drawing.Graphics = Graphics.FromHwnd(Me.Handle)
Dim ptrHDC As IntPtr = myDC.GetHdc

Dim i As Int32 = DrawFrameControl(ptrHDC.ToInt32, rectPointer, 1, 2)
myDC.ReleaseHdc(ptrHDC)
myDC = Nothing
End Sub
End Class
 
What should it do? I ran it and it did nothing - although the call to DrawFramControl did return a value indicating it had failed <shrugs>
 
You should use Int32s not Int64s. Longs in VB are 32-bit, while Longs in .NET are 64-bit, so you need to translate longs to ints when going from VB6 to .NET.
 
Also, the various methods of the ControlPaint class are designed to wrap the DrawFrameControl API, you should check it out.
 
Back
Top