Sourceverwaltung und PowerBuilder

Download Report

Transcript Sourceverwaltung und PowerBuilder

Window Message und
PowerBuilder
Ludwin Feiten
Power People
Ludwin Feiten
•
•
•
•
•
Motivation
Send Function
Beispiel
Suchen in der Win-API Help
Beispiel für PB Custom
Events
• …
Fahrplan
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 2/29
Ludwin Feiten
Motivation
• PowerBuilder hat die
Send()-Funktion
• Die Informationen
darüber sind verstreut
und mühsam zu finden.
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 3/29
Ludwin Feiten
Window Events
• PowerBuilder ist eine Windows Anwendung
• Windows hat ein Event gesteuertes User
Interface, das von PowerBuilder genutzt
werden kann.
• Triggern von Events durch senden von
Messages an Controls.
• SendMessage(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam );
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 4/29
Ludwin Feiten
SendMessage Function
In Windows sind nicht nur Windows
“windows” sondern auch fast alle
anderen visuellen Control wie
Buttons, Scrollbars, Editfields, etc.
Zur Identifizierung gibt es einen
handle
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 5/29
Ludwin Feiten
Send Function in PowerBuilder
• Send ( handle, message#, lowword, long )
– handle: A long whose value is the system handle of a
window (that you have created in PowerBuilder or
another application) to which you want to send a
message.
– message#: An UnsignedInteger whose value is the
system message number of the message you want to
send.
– Lowword: A long whose value is the integer value of
the message. If this argument is not used by the
message, enter 0.
– Long: The long value of the message or a string.
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 6/29
Ludwin Feiten
Send Function: Beispiele
• Dieses Statement scrollt das Fenster
w_emp eine Seite hoch:
– Send(Handle(w_emp), 277, 2, 0)
• Das folgende Statements click den
CommandButton cb_OK:
– Send(Handle(Parent), 273, 0,
Handle(cb_OK))
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 7/29
Ludwin Feiten
Messages: Wie kann man sie finden?
• windows API help
– http://msdn.microsoft. com/library/
• winuser.h
– C:\Program
Files\Sybase\Shared\PowerBuilder\c
gen\h\nt\winuser.h
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 8/29
Ludwin Feiten
Bspl.: Tab out a field
Suchen in der Windows API Hilfe mit
– „Key pressed notification“
Führt zu:
– „WM_KEYDONW
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 9/29
Ludwin Feiten
Syntax WM_KEYDOWN
•
•
•
•
•
•
•
•
WM_KEYDOWN
WPARAM wParam
LPARAM lParam
•
wParam: Specifies the virtual-key code of the
nonsystem key.
lParam: Specifies the repeat count, scan code,
extended-key flag, context code, previous key-state
flag, and transition-state flag, as shown in the following
table.
0-15: Specifies the repeat count for the current
message. The value is the number of times the
keystroke is autorepeated as a result of the user
holding down the key. If the keystroke is held long
enough, multiple messages are sent. However, the
repeat count is not cumulative.
16-23: Specifies the scan code. The value depends on
the OEM
24: Specifies whether the key is an extended key, such
as the right-hand ALT and CTRL keys that appear on an
enhanced 101- or 102-key keyboard. The value is 1 if it
is an extended key; otherwise, it is 0,
25-28: Reserved; do not use
PBUGG
Düsseldorf 26.05.2006
•
•
•
•
•
•
•
•
•
29: Specifies the context code. The value is always 0
for a WM_KEYDOWN message
30: Specifies the previous key state. The value is 1 if
the key is down before the message is sent, or it is zero
if the key is up
31: Specifies the transition state. The value is always
zero for a WM_KEYDOWN message
Return Value: An application should return zero if it
processes this message.
24: Specifies whether the key is an extended key, such
as the right-hand ALT and CTRL keys that appear on an
enhanced 101- or 102-key keyboard. The value is 1 if it
is an extended key; otherwise, it is 0,
25-28: Reserved; do not use
29: Specifies the context code. The value is always 0
for a WM_KEYDOWN message
30: Specifies the previous key state. The value is 1 if
the key is down before the message is sent, or it is zero
if the key is up
31: Specifies the transition state. The value is always
zero for a WM_KEYDOWN message
Return Value: An application should return zero if it
processes this message.
Window Messages und PowerBuilder
Folie 10/29
Ludwin Feiten
Nächster Schritt
• winuser.h
– #define WM_KEYDOWN
0x0100
• hex 0x0100 ist dec 256.
(Windows Rechner in Wissenschaftlicher Ansicht)
• wParam muss der ASCII-Code for the Tab-Key sein:
Das ist 9.
• lParam ist Null.
• Der Aufruf ist: send(Handle(this), 256,9, long(0,0))
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 11/29
Ludwin Feiten
Besp. Scroll a window
Win32 and COM Development > User Interface > Windows
Shell > Windows Controls > Individual Control
Information > Scroll Bars
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 12/29
Ludwin Feiten
Syntax WM_VSCROLL
• WM_VSCROLL
•
– WPARAM wParam
– LPARAM lParam;
•
•
wParam:
–
–
The high-order word specifies the
current position of the scroll box if
the low-order word is
SB_THUMBPOSITION or
SB_THUMBTRACK; otherwise, this
word is not used.
•
•
The low-order word specifies a scroll
bar value that indicates the user's
scrolling request. This parameter can
be one of the following values.
•
•
•
•
•
•
SB_THUMBPOSITION: The user has
dragged the scroll box (thumb) and released
the mouse button. The high-order word
indicates the position of the scroll box at
the end of the drag operation.
SB_THUMBTRACK: The user is dragging
the scroll box. This message is sent
repeatedly until the user releases the
mouse button. The high-order word
indicates the position that the scroll box
has been dragged to.
SB_TOP: Scrolls to the upper left.
lParam:
–
If the message is sent by a scroll bar,
this parameter is the handle to the scroll
bar control. If the message is not sent
by a scroll bar, this parameter is NULL.
SB_BOTTOM: Scrolls to the lower right.
SB_ENDSCROLL: Ends scroll.
SB_LINEDOWN: Scrolls one line down.
SB_LINEUP: Scrolls one line up.
SB_PAGEDOWN: Scrolls one page down.
SB_PAGEUP: Scrolls one page up.
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 13/29
Ludwin Feiten
Nächster Schritt:
• winuser.h
– #define WM_VSCROLL 0x0115
• hex 0x0115 ist dec 277.
• SB_PAGEDOWN ist 3
• lParam ist Null.
• Der Aufruf ist: send(Handle(this), 277,3, long(0,0))
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 14/29
Ludwin Feiten
Strategien zur Suche
Suche in: MSDN Home > MSDN Library > Win32
and COM Development > User
Interface > Windows Shell > Windows Controls
Subtopics:
• “General Control Information”
• “Individual Control Information”
Suche unter:
• "Messages" and "Notifications"
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 15/29
Ludwin Feiten
Strategien zur Suche
Suche in winusers.h
nach brauchbaren Schlagwörtern.
Mappen von PB-Events auf WNEvents
Suche in spezieller Liste:
-> www.powerpeople.de
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 16/29
Ludwin Feiten
PowerBuilder custom events
• pbm_custom01 event ID maps to wm_user+0
• pbm_custom02 event ID maps to wm_user+1,
• …
• pbm_custom75 event ID to wm_user+74.
• WM_USER is defined in winusers.h:
• #define WM_USER0x0400
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 17/29
= 1024
Ludwin Feiten
Application Ping-Pong
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 18/29
Ludwin Feiten
Ping - Pong
• Suche der Instanzen des Programms
(Find Instances)
• Schicken eines Pings (Send Ping)
• Empfangen des Ping (ue_ping)-> Pong
• Empfangen des Pong (ue_pong)
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 19/29
Ludwin Feiten
Find Instances
•
•
// Original autor: Karl E. Peterson
// Aus VB "geklaut"
•
•
ulong
•
•
•
•
•
•
string
•
•
constant integer FWP_STARTSWITH = 1
constant integer FWP_CONTAINS = 0
•
constant integer GW_HWNDNEXT = 2
•
•
•
•
TitleStart = parent.title// "Application Ping Pong"
mle_windows.text = ""
setnull(lpClassName)
setnull(lpWindowName)
•
•
•
•
•
•
•
•
•
•
•
hWndTmp,&
FindWindowPartial
lpClassName,&
lpWindowName,&
TitleTmp,&
TitleStart
integer
nRet
integer method
•
•
•
•
•
•
hWndTmp = FindWindow(lpClassName, lpWindowName)
Do Until hWndTmp = 0
//
// Make sure this window has no parent.
//
If GetParent(hWndTmp) = 0 Then
//
// Retrieve caption text from current window.
//
TitleTmp = Space(256)
nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))
PBUGG
Düsseldorf 26.05.2006
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
If nRet > 0 Then
//
// Clean up return string, preparing for
// case-insensitive comparison.
//
TitleTmp = upper(Left(TitleTmp, nRet))
//
// Use appropriate method to determine if
// current window//s caption either starts
// with or contains passed string.
//
CHOOSE Case Method
Case FWP_STARTSWITH
If pos(TitleTmp, upper(TitleStart)) = 1 Then
FindWindowPartial = hWndTmp
mle_windows.text += TitleTmp + ' HWND: ' +
string(FindWindowPartial) + '~r~n'
//Exit
End If
Case FWP_CONTAINS
If pos(TitleTmp, upper(TitleStart)) > 0 Then
FindWindowPartial = hWndTmp
mle_windows.text += TitleTmp + ' HWND: ' +
string(FindWindowPartial) + '~r~n'
// Exit
End If
End CHOOSE
End If
End If
//
// Get next window in master window list and continue.
//
hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
Loop
Window Messages und PowerBuilder
Folie 20/29
Ludwin Feiten
Send ping
unsignedlong
hndl_me,&
hndl_you
hndl_me = handle(parent)
hndl_you = long(em_win_handle.text)
IF hndl_you > 0 THEN
// Send a ping to pbm_custom01 and transmit my handle and
instance number in the params
send (hndl_du, 1024, hndl_ich, il_nummer ) ;
ELSE
MessageBox("Oups", em_window.text + " is not running!")
END IF
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 21/29
Ludwin Feiten
ue_ping
event ue_ping pbm_custom01
Messagebox("Here is window:
"+string(handle(this))," Got a Ping from: " +
string (wparam) + " with Instance No.
"+string(lparam) )
// Pong to sender of the Ping (Event Id:1025)
send (wparam, 1025, handle(this), il_number ) ;
end event
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 22/29
Ludwin Feiten
ue_pong
event ue_ping pbm_custom02
Messagebox("Here is window:
"+string(handle(this))," Got the Pong from: "
+ string (wparam) + " with Instance No.
"+string(lparam) )
end event
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 23/29
Ludwin Feiten
Starting Syscommands
Start Screensaver
To start the screen saver write:
/*
** WM_SYSCOMMAND 0x0112 274
** SC_SCREENSAVE 0xF140 61760
*/
send(handle(This),274,61760,0)
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 24/29
Ludwin Feiten
Starting Syscommands
Maximize a frame
To maximize a window when it opens put the following code into
the Open event.
CONSTANT Integer WM_SYSCOMMAND = 274
CONSTANT UInt SC_MAXIMIZE = 61488
//
Send(Handle(This), WM_SYSCOMMAND, SC_MAXIMIZE, 0)
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 25/29
Ludwin Feiten
Starting Syscommands
CONSTANT Integer WM_SYSCOMMAND = 274
CONSTANT UInt SC_MAXIMIZE = 61488
CONSTANT UInt SC_CLOSE
= 61536
// 0xF060
CONSTANT UInt SC_SCREENSAVE = 61760 // 0xF140
CONSTANT UInt SC_RESTORE = 61728 // 0xF120
CONSTANT UInt
SC_MINIMIZE = 61472 // 0xF020
Send(Handle(w_test), WM_SYSCOMMAND, SC_MINIMIZE, long(0,0) )
…………
send(Handle(Parent),16,0,0) //Close
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 26/29
Ludwin Feiten
Ein Window ohne Titlebar verschieben
Um ein Window ohne Titlebar zu
verschieben muss der folgende Code in
das mousedown event.
CONSTANT uint WM_NCLBUTTONDOWN = 161
CONSTANT uint HTCAPTION = 2
Post( Handle( this ), WM_NCLBUTTONDOWN,
HTCAPTION, Long( xpos, ypos ) )
PBUGG
Düsseldorf 26.05.2006
Window Messages und PowerBuilder
Folie 27/29
Ludwin Feiten
Einige Events …
message
lowword
long
Keyboard
WM_KEYDOWN = 256
WM_KEYUP = 257
ASCII Value of the nonsystem
Key
Backspace
8
Tab
9
carriage return
13
0
Mouse
WM_LBUTTONDBLCLK=
515
MK_LBUTTON
MK_RBUTTON
MK_SHIFT
MK_CONTROL
MK_MBUTTON
Slider
WM_HSCROLL = 276
WM_VSCROLL = 277
SB_LINEUP
0
SB_LINELEFT
0
SB_LINEDOWN
1
SB_LINERIGHT
1
SB_PAGEUP
2
SB_PAGELEFT
2
SB_PAGEDOWN
3
SB_PAGERIGHT
3
SB_THUMBPOSITION 4
SB_THUMBTRACK
5
SB_TOP
6
SB_LEFT
6
SB_BOTTOM
7
SB_RIGHT
7
SB_ENDSCROLL
8
PBUGG
Düsseldorf 26.05.2006
0x0001
0x0002
0x0004
0x0008
0x0010
The low-order word specifies
the x-coordinate of the
cursor.
The high-order word specifies
the y-coordinate of the
cursor.
The coordinate is relative to the
upper-left corner of the
client area.
0
Window Messages und PowerBuilder
Folie 28/29
Ludwin Feiten
Sind noch Fragen offen?
Bei Rückfragen oder Anregungen bitte an:
Ludwin Feiten
Power People
Inh. Ludwin Feiten
Am Borsigturm 50
D-13507 Berlin
fon +49 (0)30 43032350
fax +49 (0)30 43032355
Kontakt
PBUGG
Düsseldorf 26.05.2006
http://www.powerpeople.de
mailto:[email protected]
Window Messages und PowerBuilder
Folie 29/29
Ludwin Feiten