[C++] - text alignment

This is a discussion on [C++] - text alignment within the Windows Programming forums, part of the Platform Specific Boards category; i did these code for change the text alignment: Code: void setTextAlignment(int textalignment) { long s; if(textalignment!=intTextAlignment) { //delete the ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    121

    [C++] - text alignment

    i did these code for change the text alignment:
    Code:
    void setTextAlignment(int textalignment)
        {
            long s;
            if(textalignment!=intTextAlignment)
            {
                //delete the last text alignment
                if(intTextAlignment==0)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s & ~(SS_LEFT);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
                else if (intTextAlignment==1)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s & ~(SS_CENTER);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
                else if(intTextAlignment==2)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s & ~(SS_RIGHT);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
    
                textalignment=intTextAlignment;
    
                //put the new text alignment
                if(textalignment==0)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s | (SS_LEFT);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
                else if (textalignment==1)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s | (SS_CENTER);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
                else if(textalignment==2)
                {
                    s = GetWindowLongPtr(hwnd,GWL_STYLE);
                    s = s | (SS_RIGHT);
                    SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
                }
                SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                        SWP_NOZORDER| SWP_NOSIZE | SWP_NOMOVE|SWP_NOACTIVATE |SWP_NOCOPYBITS | SWP_DRAWFRAME);
            }
        }
    but, by some reason, the aligment isn't changed... and i don't understand why
    can anyone explain what i'm doing wrong?

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    121
    finaly i found the problem.. was the 's'...
    heres the code changed:
    Code:
    void setTextAlignment(int textalignment)
        {
            intTextAlignment=textalignment;
            LONG_PTR new_style=0;
    
            if(textalignment==0)
                new_style = SS_LEFTNOWORDWRAP;
            else if( textalignment == 1 )
                new_style = SS_CENTER;
            else if(textalignment==2)
                new_style =SS_RIGHT;
            else if(textalignment==3)
                new_style =SS_RIGHTJUST;
    
            LONG_PTR s = GetWindowLongPtr( hwnd, GWL_STYLE );
    
            s = ( s & ~( SS_LEFT | SS_CENTER | SS_RIGHT | SS_LEFTNOWORDWRAP ) ) | new_style;
    
            SetWindowLongPtr( hwnd, GWL_STYLE, s );
            SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                        SWP_NOZORDER| SWP_NOSIZE | SWP_NOMOVE|SWP_NOACTIVATE |SWP_NOCOPYBITS | SWP_DRAWFRAME);
        }
    the MSDN documentation is, sometimes, confused... so i ask here: is there any way for justify the text alignment?
    i belive that the number 3 isn't right

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text Formatting: alignment FILE
    By JIM13 in forum C Programming
    Replies: 15
    Last Post: 12-12-2012, 12:37 AM
  2. Text Alignment
    By stdq in forum C Programming
    Replies: 3
    Last Post: 05-04-2011, 06:31 PM
  3. Text Alignment
    By LoveTractor in forum C Programming
    Replies: 5
    Last Post: 09-19-2010, 05:36 PM
  4. alignment
    By Frank_Rye in forum C Programming
    Replies: 9
    Last Post: 10-28-2005, 03:18 PM
  5. set() alignment
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2002, 03:20 AM

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