Author Topic: Set focus to drawing area  (Read 2604 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Set focus to drawing area
« on: October 29, 2008, 03:08:37 PM »
Can someone point me in the right direction?  I know there's a way to set focus to the drawing area after, say, clicking a button on a modeless form.  I think it had something to do with getting the application title??  But I'm not 100% sure.

Anyone?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

deegeecees

  • Guest
Re: Set focus to drawing area
« Reply #1 on: October 29, 2008, 04:50:31 PM »
You mean like this?

Code: [Select]
Dim X As New EventClassModule

Sub InitializeEvents()
    Set X.App = ThisDrawing.Application
End Sub

Call InitializeEvents

Then I believe you can use Setfocus to the app X. I could be wrong, haven't coded in a while.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set focus to drawing area
« Reply #2 on: October 30, 2008, 08:31:24 AM »
You mean like this?

Code: [Select]
Dim X As New EventClassModule

Sub InitializeEvents()
    Set X.App = ThisDrawing.Application
End Sub

Call InitializeEvents

Then I believe you can use Setfocus to the app X. I could be wrong, haven't coded in a while.


Thanks!

I found something for AppActivate last night - that seems to have knocked the cobwebs loose.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

rogue

  • Guest
Re: Set focus to drawing area
« Reply #3 on: October 31, 2008, 06:48:19 AM »
You mentioned  a modeless window. Is this code being run from Inside of autocad? If so. remember that if your code ends up running into a Modal dialog, your'e sunk... your app will wait forever, and your code to close the window will never get called.

if it's being run from outside of autocad, and you are already using OLE on the Acad application, then each drawing window has its own hWnd, not just the parent application.  That means you wont have to tunnel down using the "FindWindow" and "EnumChildWindows" API calls.

I'd get "ThisDrawing.hwnd" before the dialog appears, and use the "SetActiveWindow" API call right to the hwnd:

Declare Function SetActiveWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Set focus to drawing area
« Reply #4 on: October 31, 2008, 08:28:07 AM »
Thanks!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io