Got Focus Event for Modeless forms using AcFocusCtrl
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Got Focus Event for Modeless forms using AcFocusCtrl
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
Terry W. Dotson
Guest





Posted: Fri Apr 01, 2005 1:23 am    Post subject: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

UserForm_Activate fires when the form is activated, but when you click
over into the editor, then back on the form, how do you know when the
form is active again? The AcFocusCtrl has some options but none fire
when the form gets focus.

Thanks in advance,

Terry

Back to top
GTVic
Guest





Posted: Fri Apr 01, 2005 3:26 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Modeless forms seem to only get focus when you click on them and immediately lose focus when the mouse button is released.

Since modeless forms never have ongoing focus then even if you found some code that worked, your code would fire on every single click of the mouse.

If that is what you would want then the easiest (but not very elegant) way to do this would be to put your code in the click event of the form and the click events of everything on the form.
Back to top
bcoward
Guest





Posted: Fri Apr 01, 2005 8:05 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Terry,

I hope your not pulling your hair out but maybe I can at least give some assistance that will help.

You know that your form is active again via the API. A couple costants that I think will resolve this are SW_SHOWNOACTIVATE and/or WS_OVERLAPPEDWINDOW


To show a window without activating it you could....

When you use ShowWindow API. This API when called will show the window and the activation depends on the second parameter. This is where I'd use SW_SHOWNOACTIVATE.

Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWNOACTIVATE = 4

Also....giver this some thought.....I believe your answer is in an api that uses the SW_SHOWNOACTIVATE constant.

Private Sub Form_Load()
ShowWindow Me.hWnd, SW_SHOWNOACTIVATE
End Sub


Sorry for not being specific but I hope I stirred something.

Regards,

Bob Coward
CADS, Inc

800-366-0946
bcoward@mindspring.com

Back to top
GTVic
Guest





Posted: Fri Apr 01, 2005 8:49 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

When the load event exits the window is already going to be shown non-active. There is no other way to show it with the way Autodesk has configured VBA.

Aren't we talking VBA? Only VB has a hWnd property?
Back to top
bcoward
Guest





Posted: Fri Apr 01, 2005 8:56 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

hWnd property

Search the archives...it's there
Back to top
bcoward
Guest





Posted: Fri Apr 01, 2005 8:56 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

hWnd property

Search the archives...it's there

Take form_load as an example not a directive
Back to top
bcoward
Guest





Posted: Fri Apr 01, 2005 8:58 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

look at Frank's answer here....http://discussion.autodesk.com/thread.jspa?messageID=419087
Back to top
Mike Tuersley
Guest





Posted: Fri Apr 01, 2005 10:03 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Here, it's simple enough and I know it in my sleep :-)

Private Declare Function GetActiveWindow Lib "user32" () As Long

Public Property Get hwnd() As Long
'+--get forms handle
hwnd = GetActiveWindow()
End Property

GT - there is very little not possible with the Windows API. Go download a
copy of the API Guide [do a google for it]

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Back to top
bcoward
Guest





Posted: Fri Apr 01, 2005 10:03 am    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Terry,

I had a complete brain waste. I tried to make this too complicated I believe.

Why can't you use the GetActiveWindow API to not only determine if the form is active or not.

Or you could use the GetForeground window API.

GEtForeground API

The GetForegroundWindow function returns the handle of the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.

GetWindow API

The GetActiveWindow function retrieves the window handle to the active window associated with the thread that calls the function.

Hope this is mud that is easier to look through.

Good luck,

Bob Coward
CADS, Inc

800-366-0946
bcoward@mindspring.com
Back to top
Terry W. Dotson
Guest





Posted: Fri Apr 01, 2005 4:30 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

GTVic wrote:

Quote:
The problem is that a modeless VBA form in AutoCAD 2005 never has a
sustained focus. It gets focus when the mouse button is clicked down
and releases focus when the mouse button is released.

Unless you use the Autodesk supplied AcFocusCtrl or WinAPI calls. For
example if I have an textbox in my form and you click it, the cursor
will remain there blinking and my form has focus, until the user clicks
in the drawing editor. I don't have a problem with that.

I (and others I'm sure) would like an event when the modeless form gets
focus again so that the form could check for changes in the status of
the drawing. I would have expected one of the userform_ events to fire,
but the only one that does is mouseover. And that fires even if the
user has not clicked back in the modeless form again, so its not really
of use.

Terry
Back to top
Terry W. Dotson
Guest





Posted: Fri Apr 01, 2005 4:33 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

bcoward wrote:

Quote:
Why can't you use the GetActiveWindow API to not only determine if
the form is active or not. Or you could use the GetForeground window
API.

I suppose I could use one of these in mousemove (which does fire). I
just hate putting code in a mousemove event, it seems like a lot of cpu
overhead.

Terry
Back to top
Terry W. Dotson
Guest





Posted: Fri Apr 01, 2005 4:58 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Terry W. Dotson wrote:

Quote:
Unless you use the Autodesk supplied AcFocusCtrl ...

I've posted an example of this in autodesk.autocad.customer-files.

Terry
Back to top
James Buzbee
Guest





Posted: Fri Apr 01, 2005 7:21 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

No help but same problem in ObjectDCL (2.x). I just use a refresh button -
suxs I know.

jb
Back to top
Mike Tuersley
Guest





Posted: Fri Apr 01, 2005 7:57 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

There is a way around it but it might require a lot of time for you. Switch
your app to a .net assembly. You can then use a custom tool palette in
2k5-2k6 which has plenty of events.

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Back to top
Mike Tuersley
Guest





Posted: Fri Apr 01, 2005 7:58 pm    Post subject: Re: Got Focus Event for Modeless forms using AcFocusCtrl Reply with quote

Sorry if I was preaching to the choir. Your comment about vba not having a
hwnd property suggested otherwise.

-- Mike
___________________________
Mike Tuersley
___________________________
the trick is to realize that there is no spoon...
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB