• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2274
  • Last Modified:

WS_TABSTOP is not working

Hi Experts.
I am good in C++. But I am new with Win32 Platform. i am using vc6.0.  i am creating one windows application with some controls.

i created controls as following:

m_hParentWnd = CreateWindow(szWindowClass, szTitle, DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU ,      CW_USEDEFAULT, 0, 400, 500,  NULL, NULL, hInstance, NULL);
/* ...*/
CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","test",WS_CHILD|ES_AUTOHSCROLL|WS_TABSTOP|WS_GROUP|
WM_PARENTNOTIFY   ,165, 120,155,25,m_hParentWnd,(HMENU)IDC_TXTUSERNAME1,NULL,NULL);      

CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","test",WS_CHILD|ES_AUTOHSCROLL|WS_TABSTOP|WS_GROUP|
WM_PARENTNOTIFY   ,165, 120,155,25,m_hParentWnd,(HMENU)IDC_TXTUSERNAME2,NULL,NULL);      

Problem is:
After executed, when i press TAB key, focus is not moving to next edit box.
Please provide related information. i do not want to go for manual setfocus (trapping Tab Key and setting focus to next edit).

I feel that providing link will not be helpful, since i read most of all the related pages of WS_TABSTOP. So i request you to provide information rather than links.

Regards
abith k
0
abith
Asked:
abith
  • 6
  • 5
  • 2
  • +2
3 Solutions
 
Infinity08Commented:
I'm not a Windows GUI API Guru, but afaik you need to treat the windows more like dialogs for this to work, ie. use something like this as your message loop :

    while (Getmessage(&msg, NULL, 0, 0)) {
      if (!IsDialogMessage(m_hParentWnd, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }

instead of just this :

    while (Getmessage(&msg, NULL, 0, 0)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }

Now the behaviour of your windows should be more like that of a dialog, especially with respect to keyboard behaviour ... note that there might also be downsides to this (if I'm not mistaken, ESC closes the application because of this ...).
0
 
Infinity08Commented:
Also try dropping the WS_GROUP styles just to see what that changes ...
0
 
itsmeandnobodyelseCommented:
>>>> but afaik you need to treat the windows more like dialogs

AFAIK, Infinity is right. The parent window needs to have the appropriate szWindowClass for a dialog class., which is "#32770".

Regards, Alex
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mrblueCommented:
"The parent window needs to have the appropriate szWindowClass for a dialog class"
However TAB works also without it - maybe something else doesn't.
0
 
mahesh1402Commented:
Simply setting the style is not going to really make the control a tab stop (Ex: if you circle the controls with the TAB key, the control to witch you
added WS_TABSTOP will not be in the list of controls touched, the same list thay you can get programaticly by using GetNextDlgTabItem).

Somehow try adding the WS_TABSTOP at runtime
e.g.

     GetDlgItem(IDC_EDIT1)->ModifyStyle(0, WS_TABSTOP);

-MAHESH
0
 
abithAuthor Commented:
Infinity08
-------
1. I changed the message loop as mentioned. when i press TAB key, it selects whole letters typed inside of EDIT box. its not moving to next Control.
2. Then I checked after removed WS_GROUP, but in result, no change .

 mahesh1402
-----------------
1. I developing win32 application.  i think i cannot use ModifyStyle( since it belongs to MFC).
2. GetNextDlgTabItem : for this i need to trap the TAB key, then i have to redirect. but i dont want to go for this one.

Expecting Better Suggestions
--Abith k
0
 
mrblueCommented:
Paste your code maybe.

I've generated (using wizard) simple win32 application with window saying "hello..." or somethig. I've created also 2 edits as child windows & I've modfied event loop like  Infinity08 suggested and it worked. I could use TAB to switch between these 2 edits.
0
 
Infinity08Commented:
>> 1. I changed the message loop as mentioned. when i press TAB key, it selects whole letters typed inside of EDIT box. its not moving to next Control.
What if you try the same with a default (single line) edit box with no extra options ? As I said, I'm not an expert in this, but I can imagine that certain people would want this tab behaviour in their edit boxes, hence there has to be a construct to allow this (and maybe that's what you have).

I didn't try the message loop change out myself, but apparently it worked for mrblue (thanks for testing it for me :)).
0
 
mrblueCommented:
No problem, I was curious myself ;)
0
 
mrblueCommented:
This is literally my code (maybe it will help). I checked it once again and it still works.

// Global Variables:
HINSTANCE hInst;                                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                                                // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];                                                // The title bar text
HWND hWnd;


// Foward declarations of functions included in this code module:
ATOM                        MyRegisterClass(HINSTANCE hInstance);
BOOL                        InitInstance(HINSTANCE, int);
LRESULT CALLBACK      WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK      About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
       // TODO: Place code here.
      MSG msg;
      HACCEL hAccelTable;

      // Initialize global strings
      LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
      LoadString(hInstance, IDC_TEST_589, szWindowClass, MAX_LOADSTRING);
      MyRegisterClass(hInstance);

      // Perform application initialization:
      if (!InitInstance (hInstance, nCmdShow))
      {
            return FALSE;
      }

      hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST_589);

      // Main message loop:
      while (GetMessage(&msg, NULL, 0, 0))
      {
            if(!IsDialogMessage(hWnd, &msg)) {
                  if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                  {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                  }
            };
      }

      return msg.wParam;
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   HWND h1 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "test", WS_CHILD|ES_AUTOHSCROLL|WS_TABSTOP|WS_GROUP/*|WM_PARENTNOTIFY*/|WS_VISIBLE,
                    165, 120, 155, 25, hWnd, (HMENU)1, NULL, NULL);
   HWND h2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "test", WS_CHILD|ES_AUTOHSCROLL|WS_TABSTOP|WS_GROUP/*|WM_PARENTNOTIFY*/|WS_VISIBLE,
                    165, 150, 155, 25, hWnd, (HMENU)2, NULL, NULL);

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}
0
 
mrblueCommented:
I even uncommented WM_PARENTNOTIFY and it still works.
0
 
Infinity08Commented:
Just out of curiosity, mrblue : when you use the original message loop, can you still use tab to change between the edit boxes ? If so, then maybe it's something else ...
0
 
mrblueCommented:
No. Documentation for IsDialogMessage() mentions even something about using TAB to switch controls.

MSDN:

"When IsDialogMessage processes a message, it checks for keyboard messages and converts them into selections for the corresponding dialog box. For example, the TAB key, when pressed, selects the next control or group of controls, and the DOWN ARROW key, when pressed, selects the next control in a group."
0
 
Infinity08Commented:
>> No. Documentation for IsDialogMessage() mentions even something about using TAB to switch controls.
Glad to hear that ... my gut feelings are still all right heh :)
0
 
mahesh1402Commented:
>>i think i cannot use ModifyStyle( since it belongs to MFC).

You can use SetWindowLong() with GWL_STYLE to modify style....

-MAHESH
0
 
abithAuthor Commented:
Experts,

 >>if(!IsDialogMessage(hWnd, &msg))

here for hwnd, i used msg.hwnd itself, since i created hWnd in Init.. function.
After changed that hWnd as global, my problem is solved.

Thanks Experts
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 6
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now