Using event handlers - (EasyVENT version 3.2)

Developed or developing a new product in PureBasic? Tell the world about it.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I'll just point out here that #OnUnhandledWinMessage is a rather specialised event and does require some careful treatment and a good read of the EasyVENT user guide.
This event is sent in the form of the underlying Windows message and consequently you should handle this accordingly.

For example, a #OnButtonClick event is, at the outset, sent to the #OnButtonClick handler attached to the underlying button.

However, at the Windows level this message corresponds to a #BN_CLICKED command message sent to the parent window of the button. Hence, if you are looking to process this event in response to a #OnUnhandledWinMessage message, then you must look for it in the #OnUnhandledWinMessage handler attached to the parent window of the button. It’s an important point and one which has caused a few developers a few headaches!
:)
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Is it possible to replace the "GetAncestor_(" function in EasyVent with GetParent or some combination of GetParent(s) that does the same job as Get Ancestor?

The reason is that by using GetAncestor you automatically stop Windows 95 machines from running programs that use EasyVent.

As I understand it, GetAncestor is the same as GetParent, but with added flags to go further back through the chain?

It seems a pity to do this for one (possibly replaceable) call.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The only place where I use GetAncestor_() (or at least the only reason I use it) is in order to be able to interface correctly with PB's drag/drop library.

As such, in order to trap #PB_Event_GadgetDrop in a subclassed procedure, I need to subclass the root ancestor which is the one receiving #PB_Event_GadgetDrop etc. If you remove the GetAncestor_() then either replace it with multiple GetParents_() in a loop or you'll have to make do without the drag / drop functionality etc.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I'll see what I can do about a replacement function, it looks like the GetAncestor isn't bug fixed until XP.

http://www.virtualdub.org/blog/pivot/entry.php?id=153
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Here is a section of code that appears to work ok.

I don't know if you want to keep the CompilerIf in (just in case you have problems with it in the future). But it worked with #Win98Plus=#False on my tests.

It should fit in and replace just the If/EndIf section in your latest posted version, the #Win98Plus should go at the top of your code.

I don't think it noticably slows things down. Please let me know what you think.

Code: Select all

#Win98Plus=#False

  If evtype = #OnDropItem
  	CompilerIf #Win98Plus=#True
	    anchWnd = GetAncestor_(hwnd, 2)
	  CompilerElse
	  	anchWnd=hwnd
	  	tempAnchWnd=GetParent_(hwnd)
	  	While Not tempAnchWnd
	  		anchWnd=tempAnchWnd
	  		tempAnchWnd = GetParent_(tempAnchWnd)
	  	Wend
	  CompilerEndIf
    result*EventRegisterControl(anchWnd)
  EndIf
  ProcedureReturn result
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

why not use OSVersion() ?
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Because the "GetAncestor_" causes it to crash while loading, not executing.

If you opened the system dll and then checked and called it by name then you can use OSVersion().

When you use the _() versions of calls, then you have to be sure that the library is installed on the system before execution.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I've tested your code with the mod I made and it works perfect with drag/drop on Win95 thru Vista. :)
Last edited by DoubleDutch on Thu Oct 11, 2007 12:02 pm, edited 1 time in total.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

DoubleDutch wrote:Because the "GetAncestor_" causes it to crash while loading, not executing.

If you opened the system dll and then checked and called it by name then you can use OSVersion().

When you use the _() versions of calls, then you have to be sure that the library is installed on the system before execution.

Ah, I didn't realise it was crashing on compilation or loading - I thought it was a runtime issue.

Now do I add this to the official package...? Anyone using Win 95 should be shot anyhow! :wink:
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

DoubleDutch wrote:I've tested your code with the mod I made and it works perfect with drag/drop on Win95 thru Vista. :)
Actually I think the OSVersion() is the way to go rather than ask the user to define a constant etc. I will adjust EasyVENT and load up the function through OpenLibrary_() etc.

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

imho, you should add it as the default "compilerif" because (if you go to the link) you will see that even if it loads then that function is unstable until XP.

Even if the function is there - it can have unpredictable results.

I have no idea how microsoft messed up such a simple function for 6 years! :roll:
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I've simply removed the GetAncestor_() then in favour of your code - no conditional compilation. :wink: It won't effect performance as it's only used when registering the drop event handlers anyhow.

I'll upload an update presently because I made one or two other alterations anyhow.

Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

I only made it a "compilerif" so that in the future if you suspected it was a problem you could easily test it.

What is great is running a program that has drag/drop and all then event stuff and it working on EVERY variety of windows since 95! :D
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

11th October 2007. (Purebasic 4.1 onwards). Release version 3.1.
Release version 3.1 incorporates all of the 3.0.x betas + the following :
  • Code supplied by DoubleDutch (my thanks) to make EasyVENT more compatible with Win 95 (boo!) 98 / ME etc.
  • Adjusted the events #OnItemSelected and #OnItemSelecting when used with panel gadgets. The developer is now informed how the user attempted to select a tab (mouse or keyboard etc.)
Anyone coming from earlier versions of EasyVENT who has not kept up with the version 3.0.x betas will need to read through the alterations detailed in the first post regarding these betas as there have been some significant updates / upgrades etc.

See the first post for the download link.
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

Tested it, no problems here - works great! :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply