Presentation is loading. Please wait.

Presentation is loading. Please wait.

Window Message und PowerBuilder

Similar presentations


Presentation on theme: "Window Message und PowerBuilder"— Presentation transcript:

1 Window Message und PowerBuilder
Ludwin Feiten Power People

2 Window Messages und PowerBuilder
Motivation Send Function Beispiel Suchen in der Win-API Help Beispiel für PB Custom Events Fahrplan PBUGG Düsseldorf Window Messages und PowerBuilder

3 Window Messages und PowerBuilder
Motivation PowerBuilder hat die Send()-Funktion Die Informationen darüber sind verstreut und mühsam zu finden. PBUGG Düsseldorf Window Messages und PowerBuilder

4 Window Messages und PowerBuilder
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 ); In addition to using Windows Functions by calling the windows API we can also send messages to Windows Controls. Some time it is helpful to send messages to controls since they’re trigged by the operating system, for example, an emulated mouse click, a keystroke, or any other event. windows messages are sent with the Windows function PBUGG Düsseldorf Window Messages und PowerBuilder

5 Window Messages und PowerBuilder
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 Window Messages und PowerBuilder

6 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 Window Messages und PowerBuilder

7 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)) Here are same examples from the PowerBuilder helpfile: This statement scrolls the window w_emp up one page: Send(Handle(w_emp), 277, 2, 0) The following statements click the CommandButton cb_OK: Send(Handle(Parent), 273, 0, Handle(cb_OK)) 273 = WM_Command ; 0 = BN_CLICKED PBUGG Düsseldorf Window Messages und PowerBuilder

8 Messages: Wie kann man sie finden?
windows API help com/library/ winuser.h C:\Program Files\Sybase\Shared\PowerBuilder\cgen\h\nt\winuser.h We see that it is quit easy to send Windows messages if you know the message numbers and parameters. But how do you know them? This seemed (to me) to be the most difficult part. I’ve been looking through all the help files but couldn’t find a place that contains all the information about the numbers and parameters are gathered. So I started searching. What I found: It’s not too difficult to find the information you need about messages when you know where to search You need access to the windows API help which can be found at: com/library/. Here you have a description of all Messages you can send. You’ll need the winuser.h file. On most installations if can be found at: C:\Program Files\Sybase\Shared\PowerBuilder\cgen\h\nt\winuser.h. (A More complete version is the winuser.h that comes with MS Visual Studio.) While the API help uses Constants like WM_KEYDOWN in its description, you find there numerical equivalent in the winuser.h. PBUGG Düsseldorf Window Messages und PowerBuilder

9 Window Messages und PowerBuilder
Bspl.: Tab out a field Suchen in der Windows API Hilfe mit „Key pressed notification“ Führt zu: „WM_KEYDONW The first task we will be to tab out a column field programmatically which triggers the modified event of that field. This is easily done by emulating the message of a pressed Tab-Key from the keyboard, i.e. we have to send the message to the window that is the same as the one which is send by the OS when we press the Tab-Key. But what message is send by the keyboard? We have to look in the Windows API help. This is a challenge and you need luck as well as a keen understanding of the Windows API help. I’ve fond that it’s not well structured and intuitive. However, if you know that we are looking for a notification searching with “Key pressed notification” (see Figure 1) brings us near enough to find “WM_KEYDOWN” at: PBUGG Düsseldorf Window Messages und PowerBuilder

10 Window Messages und PowerBuilder
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 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 The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed. Syntax WM_KEYDOWN WPARAM wParam LPARAM lParam Parameters 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 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. PBUGG Düsseldorf Window Messages und PowerBuilder

11 Window Messages und PowerBuilder
Nächster Schritt winuser.h #define WM_KEYDOWN x0100 hex 0x0100 ist dec (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)) The next step is to find the number of this system event. This is where winuser.h steps in. Here we search for WM_KEYDOWN and we find: #define WM_KEYDOWN x0100 This is the definition of the Windows constant WM_KEYDOWN as hex 0x0100 which is dec 256. (I use the windows Calculator in scientific view for conversion). wParam has to be the ASCII-Code for the Tab-Key which is 9. lParam is set to Zero. So our call is: send(Handle(this), 256,9, long(0,0)) PBUGG Düsseldorf Window Messages und PowerBuilder

12 Window Messages und PowerBuilder
Besp. Scroll a window Win32 and COM Development >  User Interface >  Windows Shell >  Windows Controls >  Individual Control Information >  Scroll Bars  If you want to emulate a scroll down event for a window object you must find the event that is send to the window when then scroll bar is moved. You find it as WM_VSCROLL notification at: Win32 and COM Development >  User Interface >  Windows Shell >  Windows Controls >  Individual Control Information >  Scroll Bars >  The WM_VSCROLL [LF1] message is sent to a window when a scroll event occurs in the window's standard vertical scroll bar. This message is also sent to the owner of a vertical scroll bar control when a scroll event occurs in the control.  [LF1]I changed the caption PBUGG Düsseldorf Window Messages und PowerBuilder

13 Window Messages und PowerBuilder
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_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. 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. The WM_KEYDOWN message is posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is pressed when the ALT key is not pressed. Syntax WM_KEYDOWN WPARAM wParam LPARAM lParam Parameters 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 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. PBUGG Düsseldorf Window Messages und PowerBuilder

14 Window Messages und PowerBuilder
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)) In winuser.h we find: WM_VSCROLL 0x0115 which is dec 277. SB_PAGEDOWN is 3 lParam is set to Zero. So our call is: send(Handle(this), 277,3, long(0,0)). PBUGG Düsseldorf Window Messages und PowerBuilder

15 Window Messages und PowerBuilder
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" Strategies to the help. If you want to learn more about window Controls or to look for something special, go to the MSDN at MSDN Home >  MSDN Library >  Win32 and COM Development >  User Interface >  Windows Shell >  Windows Controls and look for "Messages" and "Notifications" in the subtopics “General Control Information” and “Individual Control Information”. Another approach is to look in the winusers.h for something that seems to suit your needs. PBUGG Düsseldorf Window Messages und PowerBuilder

16 Window Messages und PowerBuilder
Strategien zur Suche Suche in winusers.h nach brauchbaren Schlagwörtern. Mappen von PB-Events auf WN-Events Suche in spezieller Liste: -> PBUGG Düsseldorf Window Messages und PowerBuilder

17 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_USER 0x0400 = 1024 Send messages to PowerBuilder custom events. You can also send messages to PowerBuilder custom events. You may need that to communicate between two PowerBuilder applications. The pbm_custom01 event ID maps to wm_user+0, pbm_custom02 maps to wm_user+1, and so on, through pbm_custom75, which maps to wm_user+74. WM_USER is defined in winusers.h: #define WM_USER 0x0400 = 1024 PBUGG Düsseldorf Window Messages und PowerBuilder

18 Application Ping-Pong
PBUGG Düsseldorf Window Messages und PowerBuilder

19 Window Messages und PowerBuilder
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) It sends message to other running instances of the application (ping) and receives a massage as response (pong). In the open event I search for instances that have already been started and show them with their windows handle in a listbox. In addition every instance gets an incremented number as a kind of ‘name’ which is sent with the pings and pongs. For the inter application communication I use two events (ue_ping and ue_pong) that map to custom controls. Ue_ping receives a message from another instance where the sender’s window handle and its instance-number are transmitted in the wparam and lparam parameter. The event displays a messagebox and answers wit h a pong. PBUGG Düsseldorf Window Messages und PowerBuilder

20 Window Messages und PowerBuilder
Find Instances 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 // Exit End CHOOSE // Get next window in master window list and continue. hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT) Loop // Original autor: Karl E. Peterson // Aus VB "geklaut" ulong hWndTmp,& FindWindowPartial string lpClassName,& lpWindowName,& TitleTmp,& TitleStart integer nRet integer method 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 = 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 Window Messages und PowerBuilder

21 Window Messages und PowerBuilder
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 Window Messages und PowerBuilder

22 Window Messages und PowerBuilder
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 It sends message to other running instances of the application (ping) and receives a massage as response (pong). In the open event I search for instances that have already been started and show them with their windows handle in a listbox. In addition every instance gets an incremented number as a kind of ‘name’ which is sent with the pings and pongs. For the inter application communication I use two events (ue_ping and ue_pong) that map to custom controls. Ue_ping receives a message from another instance where the sender’s window handle and its instance-number are transmitted in the wparam and lparam parameter. The event displays a messagebox and answers wit h a pong. PBUGG Düsseldorf Window Messages und PowerBuilder

23 Window Messages und PowerBuilder
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 event ue_pong 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 Window Messages und PowerBuilder

24 Window Messages und PowerBuilder
Starting Syscommands Start Screensaver To start the screen saver write: /* ** WM_SYSCOMMAND 0x ** SC_SCREENSAVE 0xF */ send(handle(This),274,61760,0) PBUGG Düsseldorf Window Messages und PowerBuilder

25 Window Messages und PowerBuilder
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 Window Messages und PowerBuilder

26 Window Messages und PowerBuilder
Starting Syscommands CONSTANT Integer WM_SYSCOMMAND = 274 CONSTANT UInt SC_MAXIMIZE = 61488 CONSTANT UInt SC_CLOSE = // 0xF060 CONSTANT UInt SC_SCREENSAVE = // 0xF140 CONSTANT UInt SC_RESTORE = // 0xF120 CONSTANT UInt SC_MINIMIZE = // 0xF020 Send(Handle(w_test), WM_SYSCOMMAND, SC_MINIMIZE, long(0,0) ) ………… send(Handle(Parent),16,0,0) //Close PBUGG Düsseldorf Window Messages und PowerBuilder

27 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 Window Messages und PowerBuilder

28 Window Messages und PowerBuilder
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 Mouse WM_LBUTTONDBLCLK= 515 MK_LBUTTON 0x0001 MK_RBUTTON 0x0002 MK_SHIFT 0x0004 MK_CONTROL 0x0008 MK_MBUTTON 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. Slider WM_HSCROLL = 276 WM_VSCROLL = 277 SB_LINEUP SB_LINELEFT SB_LINEDOWN SB_LINERIGHT SB_PAGEUP SB_PAGELEFT SB_PAGEDOWN SB_PAGERIGHT SB_THUMBPOSITION 4 SB_THUMBTRACK SB_TOP SB_LEFT SB_BOTTOM SB_RIGHT SB_ENDSCROLL PBUGG Düsseldorf Window Messages und PowerBuilder

29 Window Messages und PowerBuilder
Sind noch Fragen offen? Bei Rückfragen oder Anregungen bitte an: Ludwin Feiten Power People Inh. Ludwin Feiten Am Borsigturm 50 D Berlin fon +49 (0) fax +49 (0) Kontakt PBUGG Düsseldorf Window Messages und PowerBuilder


Download ppt "Window Message und PowerBuilder"

Similar presentations


Ads by Google