YOUR FEEDBACK
johnpetersen wrote: Great post. You hit some good points, and hopefully me sending this post. It wil...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


PBDJ Feature — Working with Windows Messages in PowerBuilder
Solving practical problems

PowerBuilder provides the send() function to send messages to the Windows objects. The information about its usage is fragmentary and widely dispersed throughout the help and manuals. Since searching for this information was quite tedious, I decided to write down what information I could gather.

I hesitated to start this article with the statement that PowerBuilder is a Windows application; it seemed ridiculous. However, that's the basis for this article. Windows has an event-driven user interface and we can use the events for our own purpose.

In addition to using the Windows functions to call the windows API, we can also send messages to Windows controls. Sometimes it's helpful to send messages to the controls since they're triggered by the operating system, for example, an emulated mouse click, a keystroke, or any other event.

In Windows, messages are sent with the Windows function:

SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );

And PowerBuilder script provides the same functionality in the send function. The syntax is:

Send ( handle, message#, lowword, long )

With:

  • 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.
Note: In Windows, not only Windows are "windows" but also almost every other visual control such as Buttons, Scrollbars, Editfields, etc., that you can get a handle to.

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))

We see that it's quite 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 looked through all the help files but couldn't find a place that contains all the information about the numbers and parameters. 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 http://msdn.microsoft.com/library/. Here you have a description of all the messages you can send.

You'll also need the winuser.h file. On most installations it 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, there are numerical equivalents in the winuser.h.

I could go on by just placing a table with the event IDs and parameters for you. However, as the saying goes: Give a man a fish, and you have fed him for today. Teach a man to fish, and he will sit in a boat and drink beer all day (or teach a man to fish, and you have fed him for a lifetime.)

So get your fishing rod (the "fish" will be at the end of the article ;-)) and go for the beer (or let us solve some practical problems).

How to Do It
The first task will be to tab out a field programmatically, which triggers the modified event of that field in some applications. 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 sent by the OS when we press Tab-Key. But what message is sent 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 found that it's not that well structured and intuitive. However, if you know that we are looking for a Notification (see Figure 1), searching with "Key pressed notification" brings us near enough to find "WM_KEYDOWN" at:

Win32 and COM Development > User Interface > Windows User Interface > User Input > Keyboard Input > Notification

This is the adequate system message, which is described as follows:

  • 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 Table 1.
  • Return Value: An application should return zero if it processes this message.
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         0x0100

This is the definition of the Windows constant WM_KEYDOWN as hex 0x0100, which is dec 256. (I use the windows Calculator in the scientific view for conversion.)

wParam has to be the ASCII-Code for the Tab-Key which is 9. lParam is set to Zero.

Our call is: send(Handle(this), 256,9, long(0,0))

Scroll a Window
If you want to emulate a scroll-down event for a window object, you must find the event that is sent to the window when the scroll bar is moved. You can find it at:

Win32 and COM Development > User Interface > Windows Shell > Windows Controls > Individual Control Information > Scroll Bars >


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

YOUR FEEDBACK
Kiran wrote: 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.
MICROSOFT .NET LATEST STORIES
OpenSpan and TIBCO have announced a technology and business partnership designed to extend TIBCO solutions to desktop environments. The partnership will enable TIBCO Service-Oriented Architecture, Business Process Management and Business Optimization solutions to more rapidly integrate...
In a move that looks tailor-made for an antitrust suit, Microsoft says it’s going to give away a consumer security kit that it’s building code named Morro. It should be available in the second half of next year – probably more like mid-year. The freebie widgetry is supposed to de...
Tidal Software has announced Intersperse 8.0, a product that monitors J2EE and .NET applications and their transaction component performance to produce meaningful metrics for managing applications and high-level business processes. The product leverages a combination of lightweight Ja...
DataGuise has announced their first masking in place solution for multi-database environments such as Oracle, Microsoft SQL Server, and others. The dgSolution Suite provides secure masking of database content and is designed for the highest level of flexibility and functionality across...
The BlackBerryR Technical Webcast Series is designed to help BlackBerry administrators better manage and leverage the capabilities of their BlackBerry solution. Each webcast is packed with detailed technical information, covering topics that are relevant to you. Our on-demand webcasts ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING NEWS FROM THE WIRES
Simba Technologies Inc., industry's choice for standards-based relational and multi-dimensional data...