Solved

Progamatically send CTRL + TAB message to tabs in dialog box

Posted on 1998-09-25
30
400 Views
Last Modified: 2013-12-03
I want to  send a "Ctrl + Tab" message from one application to a dialog box in another application.  I am using this with InstallShield to perform an automated setup of an application.  The application has a dialog box with a SysTabControl32 in it.  I need to be able to select one of the tabs behind the top level one showing in the dialog box.  I have tried using SendMessage with the WM_KEYDOWN message to no avail.  Any other suggestions?
0
Comment
Question by:kjmcconnell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
  • 6
  • +3
30 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1414809
If installshield has the focus, then you can use keybd_event().  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414810
If not, use spy++ or other utility to verify that you are sending the correct parameters with the messages.  Note you will need to send but keydown and key up messages.  Make sure the messages and parameters you send exactly match those generated by the real keyboard press.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1414811
Hi,

I know it is nice and silky to have colors, Sound, Controls...
 
MY suggestion is do not use any application while you do setup.

It is recommended to close all applications and you should do the same.

Follow the Commercial Pro and Prosper.

0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 22

Expert Comment

by:nietod
ID: 1414812
Opinions aren't answers.
0
 

Author Comment

by:kjmcconnell
ID: 1414813
a111a111a111, Your answer does nothing to help me. I am able to send other messages to the other application without any problems.  I just can't seem to be able to send a message to have the "Ctrl + Tab" command work.  Others have suggested using the keybd_event() function, however I have tried that and was unsuccessful.  I am probable using the function incorrectly.
0
 

Author Comment

by:kjmcconnell
ID: 1414814
a111a111a111, Your answer does nothing to help me. I am able to send other messages to the other application without any problems.  I just can't seem to be able to send a message to have the "Ctrl + Tab" command work.  Others have suggested using the keybd_event() function, however I have tried that and was unsuccessful.  I am probable using the function incorrectly.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414815
Post your code, that would help.

keybd_event is pretty easy to use and reliable, but it sends the key to the application with the focus, if the other application doesn't have the focus, it isn't going to work.  
0
 

Author Comment

by:kjmcconnell
ID: 1414816
The application in question does have the focus.  Below is the code I have for the keybd_event() function:
      
bVk = 148;
bScan = 0;
dwFlags = 0;
dwExtraInfo = 0;
keybd_event(bVk, bScan, dwFlags, dwExtraInfo);
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1414817
You can do this....

SetForegroundWindow(TheHandleToYourWindow);

and then use the keybd_event(...);

Regards,
Viktor Ivanov
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414818
SetForegroundWindow() is on its way out.  It doesn't give the window the focus in windows 98 or NT.  It makes the window flash or something, so the user will click on it to get the focus.  (Besides, I think that keybd_event was really my suggestion.)
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1414819
I know that, I just suggested the SetFore,,,,,() method.... I didn;'t know it doesn't work on Win98.... Please reject my answer so other experts can answer it ;->

regards,
Viktor Ivanov
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1414820
Have you tried WM_KEYDOWN and WM_KEYUP?
To which window have you send these, to the application's main window or to the window with the tab in it or to the tab window?

Regards, Madshi.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414821
kjmcconnell, sorry, I didn't see your last comment.

Try changing the scan code to 0x0F (15 decimal), the scan code for the tab key.  Let me know if that doesn't work.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414822
Actually, you have more problems than just that.  You will need 4 function calls as follows:
1.  Depress the control key,
2.  Depress the tab key.
3.  Release the tab key.
4.  Release the control key.

This should look like

keybd_event(VK_CONTROL,0x1D,0,0 ); // Control down
keybd_event(VK_TAB,0x0F,0,0 ); // Tab down.
keybd_event(VK_TAB,0x0F,KEYEVENF_KEYUP,0 ); // Tab up.
keybd_event(VK_CONTROL,0x1D,KEYEVENF_KEYUP,0 ); // Control up.
0
 

Author Comment

by:kjmcconnell
ID: 1414823
The application in question does have the focus.  Below is the code I have for the keybd_event() function:
      
bVk = 148;
bScan = 0;
dwFlags = 0;
dwExtraInfo = 0;
keybd_event(bVk, bScan, dwFlags, dwExtraInfo);
0
 
LVL 22

Expert Comment

by:nietod
ID: 1414824
Look at my last comment.  You will need 4 keybd_event() calls as I've shown.
0
 

Expert Comment

by:gre
ID: 1414825
I am trying to do the exact same thing, run a VB program that will automatically
give install shield info so that I can install automatically.

Did you find a solution. I am very interested!


 

0
 
LVL 22

Expert Comment

by:nietod
ID: 1414826
kjmconnell, did you try the 4 ketbd_event() fucntions I listed?  You will need all 4.
0
 

Expert Comment

by:gre
ID: 1414827
I think I may have found a solution. You need to add the SetForegroundWindow &
SetActiveWindow to your program
You have to query and find the hWnd to the dialog box you want to talk to:

Call SetForgroundWindow(hWnd to Install-shield main window) 'make Install-shield active
Call SetActiveWindow(hWnd to the first dialog box) 'make dialog box active
SendKeys "^{TAB}", True  'send CNTL TAB  to this box(  ^ = CNTL)

This worked for me. The problem is that this works for the first dailog window.
when the next one comes up, you have to find it's hWnd and do the last two steps above.
I think it should work for you.
0
 

Author Comment

by:kjmcconnell
ID: 1414828
nietod, I did try the four keybd_event() functions to no avail. I will try gre's solution and let you know.  Thanks.
0
 

Author Comment

by:kjmcconnell
ID: 1414829
nietod, I did try the four keybd_event() functions to no avail. I will try gre's solution and let you know.  Thanks.
0
 

Expert Comment

by:gre
ID: 1414830
This is becoming pretty complex.

I am able to automatically get through several windows that just have
buttons on them, but some other issues have popped up(pun intended).

If you have a list box within a dialog box, and you need to access that list box directly(say scroll down through some options) sending keys to the main dialog hWnd will not work.

You have to find the hWnd to that specific list box. The problem is that list boxes are of class "List Box" and do not necessary have any window text. So, therefore, you cannot itterate through the current window processes and grab it because there are many list boxes active at any given time and you might grab the wrong one.

What I now have to do,  is find the ID of the list box and then grab it's handle.
Each object on a dialog box has a specific ID. So once you know its ID you
can get its handle

By using GetDlgItem and GetNextDlgTabItem i believe I can accomplish this.

I am busy on other projects, but I will try and work more on this by the end of the
week.

0
 

Author Comment

by:kjmcconnell
ID: 1414831
gre, Your solution to call the "SetForegroundWindow" and then the "SetActiveWindow" worked.  The one thing I needed to add was a one second "Delay" between each of the functions and between the "keybd_event" keys.  Thanks for the suggestion.
0
 

Accepted Solution

by:
gre earned 50 total points
ID: 1414832
I might also need to add the delay, since I am getting some wacky info sometimes,

I was using the VB call Sendkeys, I think I might have to switch to the
keybd_eventEx API call, do you know where I can get i the values for the keyboard
buttons? I need to know what the value is for each key.
Also, Why did you have to put in the delay? I assume it was because it was
going to fast to read the key?


0
 
LVL 22

Expert Comment

by:nietod
ID: 1414833
I should warn you guys that supposidly SetForegroundWindow() does not work (intentionally) in windows 98.  The same will be true in the next version of NT.
0
 

Author Comment

by:kjmcconnell
ID: 1414834
gre,  The reason for the delays was because the script was running too fast.  I found the input values for the keys from a table in the Micorsoft SDK.
0
 

Expert Comment

by:gre
ID: 1414835
Thanks for the info nietod,
but luckily I only have to support NT 4.0.
Sucks these API's arn't cross platformable.
Who know whats going to work on NT 5.0 and 98.
makes our jobs a lot harder!!!


0
 

Author Comment

by:kjmcconnell
ID: 1414836
Currently the stuff I'm working on is in support of NT 4.0, however we will eventually be going to 5.0.  I agree with gre's comment about these API's not working across platfroms.
0
 

Expert Comment

by:gre
ID: 1414837
kjmcconnell,

do you work in QA or Development?

I work in QA, I am using the program I wrote to automate an install that I have to due all the time. This way I can install without having to manually press all the buttons each time
I want to do an install to run a test.

Help speed up the process, hopefully!

I'm sure NT 5.0 will cause problems somewhere. I have NT 5.0
beta that I still need to install and try out. That is one
thing about microsoft, thier stuff is definately not cross
os compliant! Hopefully everything will go into one 32 bit
OS and then we don't have to worry about this bs.


0
 

Author Comment

by:kjmcconnell
ID: 1414838
gre,

I work in Systems Engineering.  I too am automating some install procedures which we commonly perform.  The main quest is to have something which is repeatable without errors.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question