Author Topic: Check/Uncheck box in dialog  (Read 4158 times)

0 Members and 1 Guest are viewing this topic.

quicksilver

  • Guest
Check/Uncheck box in dialog
« on: April 04, 2008, 09:44:31 AM »
I am a total newbie when it comes to the Windows API.  I need to be able to check/uncheck a box on a dialog box in Inventor.  I was hoping that someone could help talk me through this/where to get started?  I can get the dialog box open and active.

Thank you

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #1 on: April 04, 2008, 11:30:25 AM »
I take it you want to manipulate the dialog box from some kind of reactor or at very least a VB(a) program that opens the window and does some things ...

You need to know several things, depending upon which you get, will depend upon how many you need ..Lets start with the basics:

To manipulate a windows control via VB(a) you need to use SendMessage or SetWindowLong ... each has positives and negatives ... I'll let you research those ..
To send a message or set the style of a window or control, you need to know the handle, to get that you need to be able enumerate all of the controls on a specific window, that window you will have to find by its class or its handle .. so you see it all revolves around getting that all important handle to the checkbox you want to manipulate.
Handles change from instance to instance, so if you open the window now, it will be one thing, but the next time you open it, it will be different .. so how do we find this with some degree of accuracy ...

By the window caption, but since it isn't a topmost window, how do we know with any degree of certainty what that caption might be ..

We don't unless the caption is static, bet then we don't know that to be true either .. so we have to find the caption of the main application AutoCAD .. this is done relatively easily using the Application.Caption property in VB(a).

Once you have the caption, you can use the FindWindow API to get the handle of the AutoCAD application window. Armed with that, you can use EnumerateChildWindows until you find the class and/or caption of the window holding the control you want to manipulate. Clearly a wildcard comparison would be in order to ensure you have the correct window.

Once you locate the dialog box by its caption and/or class, then enumerate all of the controls until you find the one you want to manipulate. Of course you will need to do a little snoop work using Spy++ to determine the class, key, text or other uniquely identifiable item to know that you have the correct checkbox. EnumChildWindowsProc will identify the handle to the control you wish to manipulate.

Finally armed with the handle, you can use SendMessage or SetWindowLong to change the checkbox to a checked state.

Do a bit of research on the following:

FindWindow
EnumChildWindows
SendMessage
SetWindowLong

All constants required by the above procedures will also need to be investigated to determine which ones you need.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #2 on: April 04, 2008, 11:57:19 AM »
Thanks I will investigate that.

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #3 on: April 07, 2008, 10:42:07 AM »
Thanks for the help.  Looking into the commands it was definitely going way over the my head.  The time required to figure out the solution probably wouldn't have saved the time the automation would have required in the first place.  I am now doing this by sendkeys.  Right now it works and I will look at errors in the future as the arrive.

rogue

  • Guest
Re: Check/Uncheck box in dialog
« Reply #4 on: April 07, 2008, 01:12:59 PM »
good choice - because he forgot, or did you a favor and left out, the hardest part - actually telling WHEN the dialog box actually pops up.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #5 on: April 07, 2008, 01:21:10 PM »
good choice - because he forgot, or did you a favor and left out, the hardest part - actually telling WHEN the dialog box actually pops up.

I can get the dialog box open and active.

He already said he could open it, I presumed that if he can open it he would know when it opened .. but you are right, if you have to watch for a particular window to open, it is another set of problems.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #6 on: April 08, 2008, 07:21:27 AM »
Correct I could get it open.  It was trying to find the handle for it that I had a problem with using the windows API. 

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #7 on: April 08, 2008, 08:18:02 AM »
Perhaps if I find some time, I'll post a few code snippits that show it in action.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #8 on: April 08, 2008, 12:44:13 PM »
If you have time my thanks but please don't go out of your way if you don't.

rogue

  • Guest
Re: Check/Uncheck box in dialog
« Reply #9 on: April 09, 2008, 05:58:05 AM »
I'd be interested in seeing this (VBA?) code, myself. One of the problems I used to encounter, when hijacking the interface of another app, was grabbing a dialog as it popped up. Since this is a VBA forum, I'd assume the code was written in VBA, and the AddressOf operator isnt available - which means polling.

Polling meant being stuck in a loop, waiting, and using up resources. Adding Doevents helped in some ways - but also meant i might miss a dialog opening that may not *stay* open, as some do - and the possiblility of  your code being stuck in a loop.

And of course, if its a 'common dialog', it's parent Hwnd  may not necessarily be that of the calling app - so there can be some detective work involved. (When creating a common dialog thru the API, setting the 'parent' hwnd as the desktop hwnd is an easy way to get a non-modal dialog....)

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #10 on: April 09, 2008, 08:32:15 AM »
AddressOf operator isnt available

I have written an equivalent function to AddressOf, plus using system timers you can effectively notify a calling function of any activity.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #11 on: April 09, 2008, 09:48:39 AM »
Right now I can call the dialog through the applications API by name.  So it is one call and not interating though anything. 

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #12 on: April 09, 2008, 10:01:03 AM »
I don't have access to Inventor so I can't offer any guidance about specific things. Are you using an Inventor API to open the window? If so does it return the handle to the window? If not, does the caption of the window always stay the same?
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

quicksilver

  • Guest
Re: Check/Uncheck box in dialog
« Reply #13 on: April 09, 2008, 11:42:49 AM »
Yes I am using the inventor API. 
Set oCtrlDef = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingViewEditCtxCmd")
is the line to call up the dialog box. 
The caption is always the same "Drawing View"

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Check/Uncheck box in dialog
« Reply #14 on: April 09, 2008, 01:30:41 PM »
Ok ... I have taken the liberty of putting together a little bit of an example .. it should find the control of the "Drawing View" window whose caption you specify .. look at the code and put the information where specified in the Enum call back procedure.

Keep in mind that some controls use a caption with ampersands and/or tildes to designate an underscored letter. The caption must be EXACT or the function will fail.

If you are unsure of the exact caption, you can put in a message box to give you the caption of every control on the form, then you will know the exact string to use as a comparison.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie