PowerBuilder: Article

PBDJ Feature — Working with Windows Messages in PowerBuilder

Solving practical problems

WM_VSCROLL Notification
The WM_VSCROLL 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.

SYNTAX

WM_VSCROLL
    WPARAM wParam
    LPARAM lParam;

PARAMETERS
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.

In winuser.h, we find that WM_VSCROLL is 0x0115 which is dec 277. SB_PAGEDOWN is 3.

    wParam is 3 for SB_PAGEDOWN.
    lParam is set to Zero.
    So send(Handle(this), 277,3, long(0,0)) scrolls one page down.
    Table 2 provides a list of some common events.

STRATEGIES FOR 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.

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    = 124

Application Ping-Pong
Figure 2 and Figure 3 provides an example of a ping - pong between several instances of an application.

In the open event I searched for instances that have already started; this is shown in a listbox. In addition in an instance variable il_number I store the instance that I am. (die wievielte?)

For the interapplication communication, I have 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. The event displays a messagebox and answers with a pong.

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

ue_pong receives the message send from ue_ping where the sender's window handle and its Instance-Number are transmitted in the wparam and lparam displays a messagebox.

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

To send a ping I type one of the window handles of a running instance in an edit-field (em_win_handle) and press a button where the script for the clicked event sends a "ping" to that window:

In the button Control clicked event
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

More Examples
STARTING SYSCOMMANDS WITH SEND()
Another unusual use of the send() function is to start System Commands. If you search for SYSCOMMAND Notification, you'll find several parameters that trigger various actions, one of which is SC_SCREENSAVE to start the screensaver.

START SCREENSAVER
To start the screensaver, write:

/* ** WM_SYSCOMMAND 0x0112    274
** SC_SCREENSAVE 0xF140    61760
*/
send(handle(This),274,61760,0)

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)

MOVE A WINDOW WITHOUT A TITLEBAR
To move a window without a titlebar, place the following code in the mousedown event:

CONSTANT uint WM_NCLBUTTONDOWN = 161
CONSTANT uint HTCAPTION = 2

Post( Handle( this ), WM_NCLBUTTONDOWN, HTCAPTION, Long( xpos, ypos ) )

MAKE THE ENTER KEY ACT AS A TAB KEY
First, define a user event to correspond with the pbm_dwnprocessenter event on a DataWindow. In that event, code:

Send(Handle(this),256,9,Long(0,0))

OPEN A DDDW VIA POWERSCRIPT

[external function declaration]
SUBROUTINE keybd_event( int bVk, int bScan, int dwFlags, int dwExtraInfo) &
LIBRARY "user32.dll"

[powerscript]
constant integer VK_F4 = 115

dw_1.SetFocus()
dw_1.SetColumn( "dept_head_id" ) // the DDDW
keybd_event( VK_F4,0,0,0 ) // F4 key down
keybd_event( VK_F4,0,2,0 ) // F4 key up

More Stories By Ludwin Feiten

Ludwin Feiten is a senior consultant with Power People and has many years of experience in software development. He started working with PowerBuilder with version 3.1a. Ludwin runs the German PowerBuilder User Group and is a frequent speaker at PBUG meetings.

Comments (1) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Kiran 09/11/06 12:20:42 PM EDT

Am new to Powerbuilder, this article describes how to send windows message but i would like to know how to interpret the message sent by another application, ie, how to receive and process the message using powerbuilder. Could any one help me in this regard.

Regards,
Kiran.