You are not logged in.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Monday, February 1st 2010, 12:28pm

Create Windows control on Jabaco form

Hello community,
I have a question about creating a Windows control on Jabaco form. Look at the following example:

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'-Begin-----------------------------------------------------------------

  '-External functions--------------------------------------------------
    Private WinAPI Function FindWindow Lib "user32.dll" _ 
      Alias "FindWindowW" (ByVal lpClassName As String, _ 
      ByVal lpWindowName As String) As Long 
    
    Private WinAPI Function GetWindowLong Lib "user32.dll" _
      Alias "GetWindowLongA" (ByVal hwnd As Long, _
      ByVal nIndex As Long) As Long

    Private WinAPI Function CreateWindowEx Lib "user32.dll" _
      Alias "CreateWindowExA" (ByVal dwExStyle As Long, _
      ByVal lpClassName As String, ByVal lpWindowName As String, _
      ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, _
      ByVal nWidth As Long, ByVal nHeight As Long, _
      ByVal hWndParent As Long, ByVal hMenu As Long, _
      ByVal hInstance As Long, lpParam As Long) As Long

    Private WinAPI Function UpdateWindow Lib "user32.dll" _
      (ByVal hwnd As Long) As Long

  '-Constants-----------------------------------------------------------
    Private Const GWL_HINSTANCE As Long = -6

  '-Function Control----------------------------------------------------
    Private Function Control(ClassName As String, _
      WindowName As String, Style As Long, X As Integer, Y As Integer, _
      Width As Integer, Height As Integer, hWndParent As Long, _
      hMenu As Long, hInstance As Long, ExtStyle As Long) As Long
      Dim VarPtr As New VarPtr()
      VarPtr.Init()
      Dim ClientCreateStruct As Long = _
        VarPtr.CreateVar("ClientCreateStruct", "Array", 8)
      Control = CreateWindowEx(ExtStyle, ClassName, WindowName, _
        Style, X, Y, Width, Height, hWndParent, hMenu, hInstance, _
        ClientCreateStruct)
      VarPtr.UnInit()
    End Function

  '-Main----------------------------------------------------------------
    Public Sub Command1_Click()
      Dim hWnd As Long = FindWindow(Null, "Jabaco Form")
      If hWnd Then
        Dim hInstance As Long = GetWindowLong(hWnd, GWL_HINSTANCE)
        If hInstance Then
          Dim hCtrl = Control("STATIC", "Test", &H50000001, 0, 100, _
            300, 15, hWnd, 0, hInstance, 0)
          UpdateWindow(hWnd)  
        End If  
      End If
    End Sub

'-End-------------------------------------------------------------------


The example works but after press the button I can not terminate the program with the close button.
Thanks for tips.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Monday, February 1st 2010, 3:49pm

Cool sample!

I guess you have to implement certain event handlers for every window.
There is no termination handler for your newly created window.
The Swing window management is not aware of your new window.
Therefore, the parent window cannot close properly but waits forever.
You might have to execute an explicit "DestroyWindow()" to get rid of the new Window.

What happens, if you comment-out the "Form1.SetDefaultClose()" in Module1?
What about panning, resizing, repainting, ...?

Success!

A1880

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

3

Wednesday, February 3rd 2010, 12:28pm

Hi A1880,
thanks for your hints, but unfortunately it solve not the problem. I check with DestroyWindow and PostQuitMessage but without any new result. So I look at VisualVM and see, after press the close button, a new thread which work and work and work... Have a look at the first part of the thread dump:
2010-02-02 23:03:38Full thread dump Java HotSpot(TM) Client VM (16.0-b13 mixed mode, sharing):
"Thread-1" daemon prio=6 tid=0x03009400 nid=0x418 runnable [0x034cf000]
java.lang.Thread.State: RUNNABLE
at sun.awt.windows.WToolkit.shutdown(Native Method)
at sun.awt.windows.WToolkit.access$200(Unknown Source)
at sun.awt.windows.WToolkit$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Locked ownable synchronizers:
- None
If I press the close button in a "normal" Jabaco form, the AWT-Window thread is terminated, but in my test program it opens this new thread.
Mhmm, I will test and hope the best.

Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

Rate this thread
WoltLab Burning Board