Changing the TAB of the Edit control

This is a discussion on Changing the TAB of the Edit control within the Windows Programming forums, part of the Platform Specific Boards category; It's currently by default 16 or 8 I think. I would like it to be 4. How would I change ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Changing the TAB of the Edit control

    It's currently by default 16 or 8 I think. I would like it to be 4. How would I change this? Would I have to subclass?
    1978 Silver Anniversary Corvette

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Huh? What are you asking?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    You know when you use an edit control and then you hit the TAB key, it goes 16 (or maybe 8) spaces to the right (or left if you use SHIFT). How do I make the 16 (or 8) to 4?
    1978 Silver Anniversary Corvette

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I understand now! However. I don't know if I can help! If you are using a multiline editbox, you can send it EM_SETTABSTOPS message and set up the tabbing however you like, I don't think it works with single line edit boxes though, (you could always try).

    Another approach of course, is to trap the TAB key press and insert the number of spaces you want in your string, bit fiddly though.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Well, it is a multiline edit, so how would I use this message? Just send it this message? What value would the params be? Which param would hold the new tab value? Thanks!
    1978 Silver Anniversary Corvette

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    From MSDN...

    >>>
    An application sends an EM_SETTABSTOPS message to set the tab stops in a multiline edit control. When text is copied to the control, any tab character in the text causes space to be generated up to the next tab stop.

    This message is processed only by multiline edit controls.

    EM_SETTABSTOPS
    wParam = (WPARAM) cTabs; // number of tab stops
    lParam = (LPARAM) (LPDWORD) lpdwTabs; // tab stop array

    Parameters
    cTabs
    Value of wParam. Specifies the number of tab stops contained in the lpdwTabs parameter. If this parameter is zero, the lpdwTabs parameter is ignored and default tab stops are set at every 32 dialog template units. If this parameter is 1, tab stops are set at every n dialog template units, where n is the distance pointed to by the ldpwTabs parameter. If the cTabs parameter is greater than 1, lpdwTabs points to an array of tab stops.
    lpdwTabs
    Value of lParam. Pointer to an array of unsigned integers specifying the tab stops, in dialog template units. If the cTabs parameter is 1, lpdwTabs points to an unsigned integer containing the distance between all tab stops, in dialog template units.
    Return Values
    If all the tabs are set, the return value is TRUE; otherwise, it is FALSE.

    Remarks
    The EM_SETTABSTOPS message does not automatically redraw the edit control window. If the application is changing the tab stops for text already in the edit control, it should call the InvalidateRect function to redraw the edit control window.

    The values specified by the lpdwTabs parameter are in dialog template units, which are the device-independent units used in dialog box templates. To convert measurements from dialog template units to screen units (pixels), use the MapDialogRect function.
    <<<

    ... so if you wanted to set all the tabstops the same, I would try setting wParam to 1, and lParam to a pointer to an int with the required value in it. Use SendMessage() to send the message.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Can you give me a code example? I'm getting this runtime error and I think it has to do something with my pointer...
    1978 Silver Anniversary Corvette

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Sorry for the delay, I could say busy at work or something, but the simple truth is that the sun has been shining for the last few days after almost two months of miserable weather, so we've been doing a few things. Anyway, compile this and fiddle with the value of the TabSize variable.
    Attached Files Attached Files
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, thanks!
    1978 Silver Anniversary Corvette

  10. #10
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    I studied the code, and tried to now correctly set the tabs in my program, but it still isn't working! Here's my code:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static HWND    hwndMEdit;
        
        /* file varialbes */
        OPENFILENAME    fname;
        char            filename[64];   /* THE filename */
        static char     fn[256];    /* path and filename */
        char            filefilter[] = "Text\0*.TXT\0Assembly\0*.ASM\0\0\0";
        static FILE     *fp;
        char            filestring[256];
        unsigned int    dwTabs = 4;
        
        switch(message)                  /* handle the messages */
        {
            case WM_CREATE:
                hwndMEdit = CreateWindowEx(0, "edit", NULL,
                            WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                            ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL |
                            ES_AUTOVSCROLL,
                            0, 0, 0, 0, hwnd, (HMENU) ID_MEDIT, hInst, NULL);
                            
                SetEditFont(hwndMEdit, "Courier", 12, ANSI_CHARSET, FALSE, FALSE,
                            FALSE, FALSE);
                            
                SendMessage(hwndMEdit, EM_SETTABSTOPS, (WPARAM) 1, 
                                                    (LPARAM) &dwTabs);
                            
                SetFocus(hwndMEdit);
                return 0;
    This is just the beginning of the WndProc. What am I doing wrong?
    1978 Silver Anniversary Corvette

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I'll have a look at your code, (sun still shining...), but tell me, did the program I sent you work in your environment?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Well, I didn't compile your code, I just looked at how you implemented the EM_SETTABSTOPS message and tried to mirror it, but that wasn't successful.
    1978 Silver Anniversary Corvette

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Here is a modified version of my program using CreateWindowEx(), as you are, (although you don't need to use the Ex() version - but whatever). Compile it, it works.

    When I looked at your code something that struck me was that you are creating an edit box at 0,0 but was 0 pixels by 0 pixels wide. That has got to be a fault.

    What exactly is the problem you have?
    Attached Files Attached Files
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Originally posted by adrianxw
    Here is a modified version of my program using CreateWindowEx(), as you are, (although you don't need to use the Ex() version - but whatever). Compile it, it works.

    When I looked at your code something that struck me was that you are creating an edit box at 0,0 but was 0 pixels by 0 pixels wide. That has got to be a fault.

    What exactly is the problem you have?
    Oh, about the 0, 0, 0, 0 I move and resize the Edit Control in the WM_SIZE message. Is that a bad idea? But, I need that so if the user resizes the main window.

    The problem is when I run the program and hit TAB, it just goes one space. Nothing else...
    1978 Silver Anniversary Corvette

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Have you compiled and run either of mine? I want to know if they work in your environment. If so, we know the problem is with your program, if not then we know it is environmental.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Change cursor on single edit control
    By Niara in forum Windows Programming
    Replies: 3
    Last Post: 01-11-2009, 08:52 AM
  2. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  3. changing edit control font
    By bennyandthejets in forum Windows Programming
    Replies: 6
    Last Post: 12-22-2002, 02:17 AM
  4. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 03:08 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 02:12 AM

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