Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

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.


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.
Enterprise Open Source Magazine Latest Stories . . .
Apache Deltacloud, the Red Hat-contributed ReSTful API that abstracts differences between clouds so services on any cloud can be managed – provided of course there’s a driver – has graduated from the Apache Foundation’s incubator and is now a full-fledged Top-Level Project (TLP). The...
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
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