TheSwamp

Code Red => VB(A) => Topic started by: Keith™ on March 19, 2004, 12:10:09 AM

Title: Public Event blah blah blah .....
Post by: Keith™ on March 19, 2004, 12:10:09 AM
Has anyone had experience coding new event procedures in VBA?

I am looking at defining some custom events for a specific need but I'll admit I am having some difficulty with this aspect of VBA....Specifically, attaching the event to the object defining how the event will determine when it should fire and what values should be sent....
I also need this to be transparent, such as a new class....
Title: Public Event blah blah blah .....
Post by: Trev on March 19, 2004, 06:19:56 AM
Sounds interesting Keith.

Am I interpreting this right, that you would like to set an event procedure to act when, say for example you select a particular entity in a drawing
your program would then test for info & then do stuff.
An example being.
selecting a block moving it to a new location, your program would then send an updated insert co-ordinate point to a database or something similar?

If so that would come under the begincommand event.
or am i looking at this a little to simplistically?
Title: Public Event blah blah blah .....
Post by: Keith™ on March 19, 2004, 08:51:49 AM
You are partly correct.
Keep in mind that the events currently available in VBA are typical DRAWING events that are based on user interaction. What I would like to do is implement for example an "OnPaint" event, so that whenever the AutoCAD window is redrawn (either by panning, regen, redraw, regenauto etc...) This might then trigger an event.
Currently you can only monitor events with the drawing and the drawing window, but not application level events.
This would be a much more in depth implementation allowing more control over the AutoCAD object, for example an "OnMouseOver" event that would allow you to display pertinent information stored as extended data in a help tip window sortof like when you hover over a toolbar button. This way, you could attach notes and grab potential information without having to list the item. I can envision even a bit of code that would show the user certain requested information, or the option to browse the entity list just by hovering over the object.
I can implement several of these things with the events already in place, but the problem is that many of these events take control of the drawing while the event is being fired. This prevents the event from further monitoring while that particular event is running.
Does that make sense?
Title: Public Event blah blah blah .....
Post by: Trev on March 19, 2004, 06:47:12 PM
Yep!
sounds tricky.
I like it. Might have to look at VB rather than VBA though.
I'm sure I've seen something around to locate your curser position on the screen which then can be used to locate an entity.
hmmm hunting time.  I'll be back
Title: Public Event blah blah blah .....
Post by: Trev on March 19, 2004, 07:45:26 PM
Ok here is what I have found so far.
For locating the current mouse position
take a look at the InputPointMonitor class in Tony Tanzillo's AcadX.arx:
http://www.caddzone.com
Unfortunately I get nowhere with that link so maybe their server is down at the moment.

The following stuff is probably better though.

Another thing I found is that you can locate your mouse position by using the user32.dll
Function name : GetCursorPos
returns : Boolean
arguments : ref mousepos mousepos2

Also take a look at this link, Create Custom ToolTips with multiline text and Balloon shape. It's VB6 but will give you a good idea of how it's done
http://www.andreavb.com/tip050007.html

here is another handy one
http://www.vbcity.com/forums/faq.asp?fid=38&cat=Mouse

That should keep you ocupied for a while :)
Title: Public Event blah blah blah .....
Post by: Keith™ on March 19, 2004, 09:23:16 PM
:lol: I like .....

Ok, one more thing.....

I have a routine that I would like to run AFTER the MText dialog is shown, indeed while it is still on the screen ... in the background .... but before the dialog is closed.... kinda like grabbing the contents of the MText editor window before it is closed... If I use an BeginCommand event, the event is fired BEFORE the dialog is drawn, and if I use an EndCommand event, it is drawn AFTER the dialog is closed....  I know that classes CAN run independently of a command call, but I want to run it AFTER the dialog is drawn and BEFORE the dialog is closed....
Title: Public Event blah blah blah .....
Post by: Trev on March 20, 2004, 03:35:36 AM
hmmm that ones much tougher.
I'll have to invest in a bigger thinking hat :)
At a guess I would say definately go the VB route rather than VBA. VBA might not cut it for that one.
At least with VB it's running externally so maybe you can call a command and basically pause for either user input or to do what ever you wish before continuing with the command.
Might take some searching for that one.
Title: Public Event blah blah blah .....
Post by: Keith™ on March 20, 2004, 08:21:00 AM
What about a timer event? We did a timer before and it seemed to work ok...what if I create a timer event,  set it at BeginCommand to execute like 1 second later, then on the EndCommand turn off the timer....do you think that would work???

Also I have been able to enumerate the controls in the MText Editor dialog, but I cannot find the text window. I could use a little bit of help finding it.. you wouldn't happen to know how to grab it would you? I page through all of the HWND objects and find them all (I think) but I cannot "guess" which one is the text window (because I don't know exactly what kind of control it is, if it is indeed a control at all)
Title: Public Event blah blah blah .....
Post by: Trev on March 20, 2004, 11:32:22 AM
Hey the timer might just work, I didn't think of that.

I haven't tried anything like enumerating the controls of any existing dialog. I would imagine the text window should be a control, sort of like a textbox formated as memo. Now one thing I am thinking is an unrealted post earlier of changing the background colour, which from what I could or should say couldn't find is that it can't be done (the colour as you know is the same as the acad screen colour. So where am I headed with this? ummm
maybe it's controlled differently, bywhat I don't know. You might be breaking new ground here Keith.
Title: Public Event blah blah blah .....
Post by: Keith™ on March 20, 2004, 11:00:33 PM
Well, it is indeed new ground for me....I am attempting to hone my skills in manipulating different windows and traits of windows simply by using VBA, even changing attributes of windows. I also would like to be able to add controls and/or delete or disable controls so that an administrator could further customize AutoCAD to suit their needs. For example, I remember a request some time ago from someone wanting to disable a specific control for whatever reason... I was able to do it by hacking the dialog resource, BUT that option is not available to everyone, plus it was a pretty tedious operation.

I have lots of new ideas coming to mind as I write this...
Title: Public Event blah blah blah .....
Post by: Ron Heigh on March 22, 2004, 08:17:34 PM
here is the link to Tony's site.

http://members.bellatlantic.net/~vze2vjds/acadx/AcadX.htm
Title: Public Event blah blah blah .....
Post by: Keith™ on March 23, 2004, 12:19:33 AM
Ok... more reading for me I can see......