用DrawText写字,但无法设置Tab的宽度, DT_TABSTOP如何用?谢谢!

解决方案 »

  1.   

    DT_TABSTOP
    Sets tab stops. Bits 15-8 (high-order byte of the low-order word) of the uFormat parameter specify the number of characters for each tab. The default number of characters per tab is eight
      

  2.   

    var
      c:integer;
    c:=8;
    SendMessage(Memo1.Handle,EM_SETTABSTOPS,1,integer(@c));
      

  3.   

    xzgyb(老达摩) 老哥,这是SDK中的我也看了,还是不懂!cg1120(代码最优化-§新年祝福你,好运伴着你§) , 你这是设Memo的Tab宽度,我是要DrawText写字时如何设置宽度?
      

  4.   

    procedure TMainForm.Button1Click(Sender: TObject);
    var
      r: TRect;
    begin
      r := ClientRect;
      DrawText(Canvas.Handle, 'Hello,'#9'XZGYB', -1, r,  $0F00 or  DT_TABSTOP or DT_CENTER or DT_VCENTER or DT_EXPANDTABS);
    end;就是
    加上DT_TABSTOP还需加上DT_EXPANDTABS;
    然后
    $0800就代表tab字符输出为8各字符
    也就是uFormat参数的低位字的高位字节
    但msdn说建议用DrawTextExMSDN真是不错
    MSDN中的一段话If your text contains tab characters (`\t' or 0x09), you need to include the flag DT_EXPANDTABS. By default, the tab stops are set at every eighth character position. You can specify a different tab setting by using the flag DT_TABSTOP, in which case the upper byte of iFormat contains the character-position number of each new tab stop. I recommend that you avoid using DT_TABSTOP, however, because the upper byte of iFormat is also used for some other flags. The problem with the DT_TABSTOP flag is solved by a newer DrawTextEx function that has an extra argument: DrawTextEx (hdc, pString, iCount, &rect, iFormat, &drawtextparams) ;The last argument is a pointer to a DRAWTEXTPARAMS structure, which is defined like so: typedef struct tagDRAWTEXTPARAMS
    {
        UINT cbSize ;         // size of structure
        int  iTabLength ;     // size of each tab stop
        int  iLeftMargin ;    // left margin
        int  iRightMargin ;   // right margin
        UINT uiLengthDrawn ;  // receives number of characters processed
    } DRAWTEXTPARAMS, * LPDRAWTEXTPARAMS ;