Tab order again

This is a discussion on Tab order again within the Windows Programming forums, part of the Platform Specific Boards category; I'm having trouble with tabs in one of my projects. I've set the tab order, and I'm using the IsDialogMessage() ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Tab order again

    I'm having trouble with tabs in one of my projects.
    I've set the tab order, and I'm using the IsDialogMessage() function in the messageloop, still the tabstops don't work..
    I tried to hav a messageloop in another form, and it worked.
    Is this the solution? Should there be one message loops for every form?

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Is the dialog box modal or modeless? Show us the excerpt from the resource file that defines it.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Resource script for main form, this is the form with the message loop.
    Code:
    FRM_MAIN DIALOG DISCARDABLE  0, 0, 186, 134
    STYLE DS_SETFOREGROUND | DS_CENTER | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | 
        WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif"
    BEGIN
        CONTROL         "List2",LIST1,"SysListView32",LVS_REPORT | WS_BORDER | 
                        WS_TABSTOP,0,0,186,121
    END
    One of the child forms, without message loop:
    Code:
    FRM_SETUP DIALOGEX 0, 0, 258, 175
    STYLE DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
    EXSTYLE WS_EX_TOOLWINDOW
    FONT 8, "MS Sans Serif"
    BEGIN
        CONTROL         "List1",LIST1,"SysListView32",LVS_LIST | LVS_SINGLESEL | 
                        LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | 
                        WS_BORDER | WS_TABSTOP,3,4,43,153
        PUSHBUTTON      "&Lagre",CMD_OK,97,159,31,14
        PUSHBUTTON      "&Avbryt",CMD_CANCEL,130,159,31,14
    END
    Could the problem be something with the parent/child hierarchy? ie. all the forms have to be the child of the mainform?

    EDIT:
    The dialogboxes are modeless.

  4. #4
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    You have one dialog box as the child of the main window, and then another dialog box as a child of the first dialog box? For modeless dialog boxes, the messages are sent to its owner, that's why you have to include the IsDialogMessage() call within the message loop of the dialog box's parent. Do you do this for BOTH dialog boxes? Do both dialog boxes work by themselves (i.e. when each is just as a child from the main window, with no other dialog box). Do both dialog boxes NOT work currently? (i.e. are you having problems with both of them, or just one of them)?

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    The main window and all the other windows are dialogs.
    The other windows in the app are dialogs too(children/grandchildren)
    Tabs don't work in any of the dialogs.

    The app has a message loop in the main form, but i tried to create one in another form. Tabs then worked in this form, but not in it's children(a setup form with other dialogs as "tabstrips")

  6. #6
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I didn't realize the main window was a dialog box, itself. The IsDialogMessage() function processes messages for dialog boxes by converting keyboard messages into selection commands for that particular dialog box. Obviously, this is not being run when it should. How is the message loop being run continuously to allow for these conversions to take place on any keyboard command, as it would in a normal main window?

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Then maybe i should read some more Windowsprogramming...I thought you could use dialogs all over..
    Anyway, here's some of the code from the mainform:
    Code:
    int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int iShow){
    	MSG msg;
    
    	hInstMain=hThisInstance;  
    	hWndMain = CreateDialog(hThisInstance, MAKEINTRESOURCE(FRM_MAIN), HWND_DESKTOP, DialogProc);
    	while (GetMessage(&msg, NULL, 0, 0) > 0) {
        if(!IsDialogMessage(hWndMain, &msg)) {
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
      }
    
    	return(0);
    }
    
    BOOL CALLBACK DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
    	static bool inTray(false);	// If in systray or not
    	HMENU mPopup;	// Popupmenu for systray
    	char chRet(0);// return from dialogproc
    	POINT p1;			// Mousecoords
    	RECT r1;			// Rectangle for WM_SIZE
    
    	switch(uMsg){
    	case WM_INITDIALOG:
    		hWndMain=hwnd;
    		SetClassLong(hWndMain, GCL_HICON, (long)LoadImage(hInstMain, MAKEINTRESOURCE(IDI_ICON_1), IMAGE_ICON, 0, 0, LR_DEFAULTSIZE));
    		
    		if(!InitForm())
    			DestroyWindow(hWndMain);
    		ShowWindow(hWndMain, SW_SHOW);
    		chRet=0;		
    		break;
    	case WM_COMMAND:
    		switch(LOWORD(wParam)){
    		case MNU_FILE_CFG:	// Setupmenu
    			frmSetup(&hInstMain, hWndMain, &ThD);
    			break;
    		case MNU_FILE_QUIT:
    			SendMessage(hWndMain, WM_CLOSE, 0, 0);
    			break;
    		case MNU_TOOLS_CUST:
    			frmToolsCust(&hInstMain, hWndMain, &ThD);
    			break;
    		case MNU_TOOLS_PROD:
    			frmToolsProd(&hInstMain, hWndMain, &ThD);
    			break;
    		case MNU_TOOLS_TRANS:
    			frmToolsTrans(&hInstMain, hWndMain, &ThD);
    			break;
    		case MNU_TOOLS_FIRM:
    			frmToolsFirm(&hInstMain, hWndMain, &ThD);
    			break;
    		case MNU_HLP_ABOUT:
    			frmAbout(&hInstMain, hWndMain);
    			break;
    		}
    		SetTxt(hWndMain, "Windowtest");
    		break;
    	case WM_SIZE:
    		if(wParam==SIZE_MINIMIZED && ThD.bToTray){
    			sysTrayAdd(hWndMain, LoadIcon(hInstMain, MAKEINTRESOURCE(IDI_ICON_DD)), "Testapp");
    			ShowWindow(hWndMain, SW_HIDE);
    			inTray = true;
    		}else{
          GetClientRect(hWndMain, &r1);
          MoveWindow(ThD.hWndLst, 1, 1, r1.right-1, r1.bottom-1, TRUE);
    		}
    		break;
      case WM_ICONNOTIFY:
    		switch(lParam){
    		case WM_RBUTTONUP:
    			SetForegroundWindow(hWndMain);
    			GetCursorPos(&p1);
    			mPopup = CreatePopupMenu();
    			AppendMenu(mPopup, MF_STRING|MF_ENABLED, 1, "&Config");
    			AppendMenu(mPopup, MF_SEPARATOR, 0, 0);
    			AppendMenu(mPopup, MF_STRING|MF_ENABLED, 3, "&End");
    			switch(TrackPopupMenu(mPopup ,TPM_RIGHTALIGN|TPM_LEFTBUTTON|TPM_RETURNCMD, p1.x, p1.y,0, hWndMain , NULL)){
    			case 1:// Config
    				EnableWindow(hWndMain, FALSE);
    				frmSetup(&hInstMain, hWndMain, &ThD);
    				EnableWindow(hWndMain, TRUE);
    				break;
    			case 3:// End
    				SendMessage(hWndMain, WM_CLOSE, 0, 0); break;
    			}
    			break;
    		case WM_LBUTTONDBLCLK:
    			SetForegroundWindow(hWndMain);
    			sysTrayRemove();
    			inTray = false;
    			ShowWindow(hWndMain, SW_SHOWNORMAL);
    			break;
    		}
    		break;
    	case WM_CLOSE:	// Close request
    		return(b(hwnd, "Exit program?", "Windowtest", MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2)!=IDYES?
    			-1:DestroyWindow(hWndMain));
    	case WM_DESTROY:	// Unload
    		ThD.db->Close();
    		ReleaseMutex(ThD.mtDb);
    		if(inTray == true)
    			sysTrayRemove();
    		PostQuitMessage(0);
    		break;
    	}
    	return(chRet);
    }
    Am i supposed to create the mainwindow through WinAPI?

  8. #8
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Originally posted by knutso
    Code:
    	while (GetMessage(&msg, NULL, 0, 0) > 0) {
        if(!IsDialogMessage(hWndMain, &msg)) {
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
      }
    From MSDN IsDialogMessage Function:
    The IsDialogMessage function determines whether a message is intended for the specified dialog box and, if it is, processes the message.

    If this is the only messge loop in your program, the only dialog box you are testing for keyboard navigation and other dialog box functionality is the hWndMain dialog box. I would assume that this means this dialog box is working properly, and the rest are not.

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Of course!!
    I've done this before, in one of my other projects...I guess my brain has been disconnected for a while..
    Anyway: I inserted a few message loops, and everything now works as intended.
    Thanks for bearing with my stupid,simple questions, JasonD

  10. #10
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Not a problem. The questions weren't stupid, and we all learn from trying to solve each other's problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tab order in Tab Control
    By Halloko in forum Windows Programming
    Replies: 2
    Last Post: 05-09-2005, 12:08 AM
  2. Visual C++
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2003, 05:30 PM
  3. Tab order in graphically designed forms(MSVC)
    By knutso in forum Windows Programming
    Replies: 5
    Last Post: 05-16-2003, 02:02 AM
  4. Changing Tab Order
    By Tesita in forum Windows Programming
    Replies: 1
    Last Post: 01-11-2002, 08:43 AM
  5. V C++; dialog box; tab order; advancing thru
    By alzado in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2002, 03:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21