Solved

Progamatically send CTRL + TAB message to tabs in dialog box

Posted on 1998-09-25
30
392 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
  • 10
  • 10
  • 6
  • +3
30 Comments
 
LVL 22

Expert Comment

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

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Opinions aren't answers.
0
 

Author Comment

by:kjmcconnell
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You can do this....

SetForegroundWindow(TheHandleToYourWindow);

and then use the keybd_event(...);

Regards,
Viktor Ivanov
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 22

Expert Comment

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

Expert Comment

by:gre
Comment Utility
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
Comment Utility
kjmconnell, did you try the 4 ketbd_event() fucntions I listed?  You will need all 4.
0
 

Expert Comment

by:gre
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now