You are not logged in.

Peter

Trainee

  • "Peter" is male
  • "Peter" started this thread

Posts: 69

Date of registration: Nov 24th 2008

Location: Cologne, Germany

Occupation: Second Vice President of Distributed Junk and Trash Development

  • Send private message

1

Monday, February 2nd 2009, 10:47am

Eigenes Fensterhandle ermitteln

Hallo,

wie kann man das Handle des eigenen Fensters oder UserControls ermitteln?

in VB würde ich das so machen:

Jabaco Source

1
myHandle = Me.hWnd


Gibt es in Jabaco was vergleichbares?

Danke im voraus & Grüße ... Peter

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

2

Monday, February 2nd 2009, 3:19pm

how to get a window's handle

Hi,

if all else fails you can try it this way:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Private WinApi Function WindowFromPoint Lib "user32.dll" ( _
   ByVal xPoint As Integer, ByVal yPoint As Integer) As Integer
Private WinApi Function GetDC Lib "user32.dll" ( _
   ByVal hwnd As Integer) As Integer
Private WinApi Function LineTo Lib "gdi32.dll" ( _
   ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
Private m_bhwnd As Boolean
Private m_hWnd  As Integer
Private m_bhDC  As Boolean
Private m_hDC   As Integer
Public Sub Command1_Click()
   Label1.Caption = CStr(Me.hwnd)
   Label2.Caption = CStr(Me.hDC)
   Call LineTo(Me.hDC,10,10)
   Call LineTo(Me.hDC,100,20)
   Call LineTo(Me.hDC,110,100)
   Call LineTo(Me.hDC,10,90)
   Call LineTo(Me.hDC,10,10)
End Sub
Public Property Get hWnd() As Integer
   If Not m_bhwnd Then
      Dim x As Integer, y As Integer
      x = Me.Left + Me.Width - Me.ScaleWidth + 1
      y = Me.Top + Me.Height - Me.ScaleHeight + 1
      m_hWnd = WindowFromPoint(x, y)    
      m_bhwnd = True
   End If
   hWnd = m_hWnd
End Property
Public Property Get hDC() As Integer
   If Not m_bhDC Then
      m_hDC = GetDC(Me.hWnd)
      m_bhDC = True
   End If
   hDC = m_hDC
End Property


it draws a few lines just to see it working ;)

ich glaub das englisch war schon verständlich oder ^^

greetings

OlimilO

Peter

Trainee

  • "Peter" is male
  • "Peter" started this thread

Posts: 69

Date of registration: Nov 24th 2008

Location: Cologne, Germany

Occupation: Second Vice President of Distributed Junk and Trash Development

  • Send private message

3

Monday, February 2nd 2009, 4:18pm

RE: how to get a window's handle

Hallo OlimilO,

if all else fails you can try it this way:

danke für den Code! Leider ist er so für mich nicht brauchbar. Was ist, wenn sich ein anderes Fenster über meinem befindet?

Grüße ... Peter

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Monday, February 2nd 2009, 4:47pm

Quoted

what if there is another window overlapping my window?

yes good question


just take the other possibility :)

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Private WinApi Function GetDC Lib "user32.dll" ( _
   ByVal hwnd As Integer) As Integer
Private WinApi Function LineTo Lib "gdi32.dll" ( _
   ByVal hdc As Integer, ByVal x As Integer, ByVal y As Integer) As Integer
   
Private WinApi Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As Integer, ByVal lpWindowName As String) As Integer
   
Private m_bhwnd As Boolean
Private m_hWnd  As Integer
Private m_bhDC  As Boolean
Private m_hDC   As Integer

Public Sub Command1_Click()
   Label1.Caption = CStr(Me.hwnd)
   Label2.Caption = CStr(Me.hDC)
   Call LineTo(Me.hDC,10,10)
   Call LineTo(Me.hDC,100,20)
   Call LineTo(Me.hDC,110,100)
   Call LineTo(Me.hDC,10,90)
   Call LineTo(Me.hDC,10,10)
End Sub

Public Property Get hWnd() As Integer
   If Not m_bhwnd Then
      Dim title As String
      title = Me.Caption
      m_hWnd  = FindWindow(0, Me.Caption)
      m_bhwnd = True
   End If
   hWnd = m_hWnd
End Property
Public Property Get hDC() As Integer
   If Not m_bhDC Then
      m_hDC = GetDC(Me.hWnd)
      m_bhDC = True
   End If
   hDC = m_hDC
End Property


maybe someone finds another possiblity?

OlimilO

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

5

Monday, February 2nd 2009, 5:27pm

Quoted

wie kann man das Handle des eigenen Fensters oder UserControls ermitteln?
In Swing benötigst du in der Regel kein Fensterhandle und auch keinen Device Context. Nur dein eigentliches Formular besitzt ein Handle und dieses leitet die Ein-/Ausgabe an eine Java-Klassen weiter.

Quoted

Gibt es in Jabaco was vergleichbares?
Es gibt sicher eine vergleichbare Lösung für dein Problem, aber dafür müsstest du dein Ziel etwas genauer beschreiben.

edel

Beginner

Posts: 3

Date of registration: Jan 30th 2009

  • Send private message

6

Monday, February 2nd 2009, 6:00pm

Wie sieht das denn mit fremden Fensterklassen aus, kann ich diese denn, ohne ein Fensterhandle,
auf bzw in ein Usercontrol einbauen?

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

7

Monday, February 2nd 2009, 6:18pm

Quoted

Wie sieht das denn mit fremden Fensterklassen aus, kann ich diese denn, ohne ein Fensterhandle,
auf bzw in ein Usercontrol einbauen?
Dafür gibt es verschiedene Möglichkeiten, wenn es eine Java-Klasse ist, dann musst du nur einen Verweis hinzufügen. Wenn es eine C++ Klasse ist, dann solltest du nach einem Java-Wrapper dafür suchen, oder du musst dir einen schreiben. Du kannst auch eine VB6 / ActiveX-Klasse in Java verwenden. Eine Möglichkeit dafür wäre zum Beispiel JavaActiveX-Bridge. Es kommt sehr stark auf deine Problemstellung an. Ich persönlich würde immer den Java-Weg bevorzugen. Für die meisten Controls wirst du eine Alternative in Java finden.

Rate this thread
WoltLab Burning Board