marcoborn
Goto Top

Probleme bei API-Aufrufen bei der Portierung von VB6-Code nach VB.NET

Hallo Forum,
folgenden VB-Code habe ich aus Herber's Excel-Forum (http://www.herber.de/forum/archiv/792to796/t792649.htm):

Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long

Private FensterRegion&, Region&
Private Hauptfensternummer&, Clientfensternummer&
Private dummy As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Sub UserForm_Initialize()
Call FensterOhneKopf
End Sub

Sub FensterOhneKopf()
Dim Abmessung As RECT
Dim Abmessung1 As RECT
Dim Pos1x&, Pos1y&, Pos2x&, Pos2y&
If FensterRegion <> 0 Then Exit Sub
UserForm1.BorderStyle = fmBorderStyleSingle
Call Fensternummer(UserForm1, Abmessung, Abmessung1)
Pos1x = 0
Pos1y = (Abmessung1.Top - Abmessung.Top)
Pos2x = Abmessung.Right - Abmessung.Left
Pos2y = Abmessung.Bottom - Abmessung.Top
FensterRegion = SetWindowRgn(Hauptfensternummer, CreateRectRgn(Pos1x, Pos1y, Pos2x, Pos2y), True)
End Sub

Private Sub Fensternummer(Form As Object, Abmessung As RECT, Abmessung1 As RECT)
Dim Fenstername$, Suchstring$
Suchstring = "UserForm ohne Titelzeile"
Fenstername = Form.Caption
Form.Caption = Suchstring
Hauptfensternummer = FindWindow(vbNullString, Suchstring)
Form.Caption = Fenstername
Clientfensternummer = GetWindow(Hauptfensternummer, 5)
dummy = GetWindowRect(Hauptfensternummer, Abmessung)
dummy = GetWindowRect(Clientfensternummer, Abmessung1)
End Sub


Ich versuche, das Ganze nach VB.NET zu portieren, bekomme aber beim Aufruf von
"dummy = GetWindowRect(Hauptfensternummer, Abmessung)" folgende Fehlermeldung:
"Der Wert vom Typ "Long" kann nicht in "System.Runtime.InteropServices.HandleRef" konvertiert werden."

Die API-Funktionen habe ich jeweils gemäß der Syntax von www.pinvoke.net deklariert. Auch die RECT-Struktur ist neu deklariert worden. Scheinbar liegt das Problem an RECT-Struktur, die laut VB Long-Variablen zurückliefert, obwohl dort alle Eigenschaften als Integer gesetzt sind. Kann mir hier jemand weiterhelfen?

Vielen Dank,
M. Born

Content-Key: 190755

Url: https://administrator.de/contentid/190755

Printed on: April 18, 2024 at 12:04 o'clock

Member: MonoTone
MonoTone Sep 05, 2012 at 12:38:17 (UTC)
Goto Top
Was genau willst du eigentlich damit in .NET erreichen?
Bei einer .NET Windows Form das X oben entfernen?
Wenn ja, dann haben .NET Forms eine Eigenschaft ControlBox.
Diese auf False gesetzt und das X ist weg.
Member: MarcoBorn
MarcoBorn Sep 05, 2012 at 13:04:37 (UTC)
Goto Top
Ich will die komplette Titelzeile entfernen, nicht nur das X.
Member: MonoTone
MonoTone Sep 05, 2012 updated at 13:15:01 (UTC)
Goto Top
Setze FormBorderStyle auf "None".

Dann ist alles weg.

Alternativ:
http://stackoverflow.com/questions/1394197/show-or-hide-a-title-bar-on- ...
Member: MarcoBorn
MarcoBorn Sep 05, 2012 at 13:45:57 (UTC)
Goto Top
Vielen Dank, der Weg mit "FormBorderStyle=None" macht genau das, was ich gesucht habe. Jetzt kann ich endlich die ganzen APIs entfernen.