I am using VS2008, OS win vista. i am in the process of coding an application that would tab automatically (this is just an example, not the code i am intending to do).

So basically, what i expect is to write a C++ code that could press the 'tab' button twice from the code it it self. Can someone point me the correct google search terms or a tutorial to get familiar with these.

Thank you

Dani AI

Generated

If your goal is to advance focus through controls as if the user pressed TAB, do not emit the tab character. On Windows you should move focus explicitly or ask the dialog manager to do it for you.

  • Win32 dialog: you can tell the dialog to move to the next control in tab order.
// Move focus to the next control (call twice to mimic two tabs)
SendMessage(hDlg, WM_NEXTDLGCTL, 0, 0);

// Or pick the next control yourself and set focus
HWND next = GetNextDlgTabItem(hDlg, GetFocus(), FALSE);
SetFocus(next);

This relies on proper dialog-style navigation: controls must have WS_TABSTOP, and your message loop should pass messages to IsDialogMessage so TAB handling works automatically. See WM_NEXTDLGCTL, GetNextDlgTabItem, and IsDialogMessage.

  • MFC: you can get the next tab item and focus it, or use convenience helpers.
CWnd* next = GetNextDlgTabItem(GetFocus(), FALSE);
if (next) next->SetFocus();  // repeat for two tabs
  • WinForms (C++/CLI): ask the form to select the next control.
this->SelectNextControl(this->ActiveControl, true, true, true, true);

Avoid synthesizing keystrokes (e.g., SendInput for VK_TAB); it is brittle and bypasses built-in focus logic. Useful searches: win32 WM_NEXTDLGCTL, GetNextDlgTabItem MSDN, IsDialogMessage tab order, WinForms SelectNextControl.

Recommended Answers

All 5 Replies

What do you mean by "press the 'tab' button twice"?

If you want to use a tab to push console output to the right a few lines, use the '\t' escape character.

#include <iostream>

using namespace std;

int main() {
  cout << "\t\tThis output is tabbed over..." << endl;
  cout << "This output is not..." << endl;
  cin.get();
  return 0;
}

If you're trying to move through a GUI with the TAB, I'm afraid I can't help you.

No you got me wrong. For example. when we click the 'tab' button on the keyboard, it sets focus to the next tab index, right ?? so what i need to do is to enter these tabs from the code instead of using the keyboard to set focus to the next tab index.

hope i made it clear.

So you're trying to move around a GUI. As I mentioned before, I can't help you with that one... I don't do GUIs.

I know there is a way to set the default focus. Is that what you are trying to do is automatically set the focus? I believe you have to set the "tabstop" (or whatever the proper property name is) to 0 to make that the default focus. But that's all I can offer you.

what might be a possible google search to get around

I know there is a series of constants that can be used to identify the keys on the keyboard, you'll probably have to use one of those.

Try searching for "Windows Keyboard Codes" and similar. Then, if there is a way to send (rather than receive) the constant/code for a key, send the appropriate one for TAB.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.