Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Introduction to WMLiberty

Post new topic   Reply to topic    Bay Six Software Forum Index -> WMLiberty DLL -> WMLiberty Demos & Tutorials
View previous topic :: View next topic  
Author Message

PostPosted: Mar 18th, 2007, 10:29pm    Post subject: Introduction to WMLiberty Reply with quote

I wrote this paper a few months ago for school. It was intended to be part of a book about Windows API programming from LB, but I've neither the time nor talent to do so. That should explain the lack of end and beginning. In any event, hopefully this will help new WMLiberty users find their way around. I release it as public domain.

The Windows API may be fine and dandy for creating and managing controls, but unlike with native LB controls, we are not notified when events occur. Fortunately, we have WMLiberty.dll. WMLiberty.dll (commonly referred to as WMLiberty) enables you to trap Window Messages from the Windows API. In plain English, that means you can trap events from API-created controls without too much hacking.

Understanding WMLiberty requires at least a basic understanding of Window Messages. Window Messages, as you may have guessed, are messages sent to your window when an event occurs. They contain small bits of information that allow you to identify what sort of event has occurred.

But how are these messages received? Well, the Windows API uses a neat trick called a callback for exactly that purpose. When using callbacks, you send the Windows API the address of a function, which is stored in memory. Then, whenever it decides to do so (in this case, when a control event happens), the Windows API calls your function back. On top of that, you can return data to the Windows API. Hereís a chart showing the callback process:

[image goes here]

Thatís not so scary, is it? When used correctly, callbacks can greatly aide your programming experience.

With an understanding of callbacks under our belt, we can now delve in to WMLiberty. The problem with using Window Messages in plain LB is that Windows sends quite a few. In fact, so many messages are sent that the program crashes within a second after running. Try the sample program apiwindow.bas to see for yourself.

Since LB canít handle so many messages at such a speed, we need a way to filter out the messages we donít need, so we only get the messages we want to receive. Thatís where WMLiberty comes in. With a simple call to WMLiberty, we can trap the Window Messages we want, and use built-in windowing functions, too.

One way I like to use WMLiberty is to trap the WM_SIZE message. While LB does have a built-in resizehandler command, there is a short but visible delay between when the window itself is sized and when the resize handler is called. With WMLiberty and callbacks, there is no such delay. See the sample program trapwmsize.bas for an example.

There are a few disadvantages to using WMLiberty and callbacks. For instance, you cannot use the wait command. Instead, use the scan command, calling the Sleep function occasionally to make sure every available CPU cycle isnít consumed. An example of this is seen in every demo using callbacks. You can use the last example, trapwmsize.bas, to see it right now.

[note: the demos are somewhat incomplete at this time. If I ever get some free time, I'll wrap 'em up.]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> WMLiberty DLL -> WMLiberty Demos & Tutorials All times are GMT
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group