how can i change the windows styles?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void setBorder(bool border)
    {
        long s;
        if(border==false)
            s = WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
        else
            s = WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;

        SetWindowLongPtr(this->hwnd,GWL_EXSTYLE,(LONG_PTR)s);
        
        //the SetWindowPos() is for update the control
        SetWindowPos(NULL, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME,true);
    }

i'm trying add the border to a child window(STATIC) i tryied use the SetWindowLongPtr() for get the actual style, but without sucess.
with GetLastError: 6 - ERROR_INVALID_HANDLE.
what i'm doing wrong?
I am going to assume that this function is part of a class that you define HWND variable in it... since you used "this->hwnd" and did not complain about an error message that says : "class NAME has no member "hwnd"

if that function is not in a class then "this" keyword will return a pointer to the process handle and not the class object (which I think is not what you want... a process can have more than one window! with more than one hwnd!)

can you show us the code in which you create your window? the segment of your code where you call CreateWindow() or CreateWindowEX() function... you should define HWND variable and use that to store the window handle that returns from these functions... then you can use that window handle to customize your window...

also is the way you use SetWindowPos correct?
according to http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx the 4 int parameters are the (3rd, 4th, 5th and the 6th) but you pass the 0, 0, 0, 0, as the (2nd, 3rd, 4th and the 5th) so you are passing 0 for hWndInsertAfter parameter which will be HWND_TOP according to the same link. but still you need to add (HWND) before the zero to cast it...

SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE| SWP_DRAWFRAME are being passed as cy parameter!

also the last parameter?! boolean? true? i dont think uFlags accept that...

last how the windows suppose to know what window to change position if you passed NULL as window handle?? (first parameter)

that can be solved by passing the hwnd that you get from creating a window instead of passing NULL...
1. Pass the HWND to SetWindowPos.
2. Make sure the HWND is a valid one.
heres the new code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void setBorder(int border)
    {
        long s=0;
        if(border==0)
        {
            s = GetWindowLongPtr(hwnd,GWL_EXSTYLE);
            s = s & ~(WS_EX_STATICEDGE) & ~(WS_EX_CLIENTEDGE);
            SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);

            s = GetWindowLongPtr(hwnd,GWL_STYLE);
            s = s & ~(WS_BORDER);
            SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
        }
        else if(border==1)
        {
            s = GetWindowLongPtr(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE;
            SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);
        }
        else if(border==2)
        {
            s = GetWindowLongPtr(hwnd,GWL_STYLE) | WS_BORDER;
            SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
        }
        else if(border==3)
        {
            s = GetWindowLongPtr(hwnd,GWL_EXSTYLE) | WS_EX_STATICEDGE;
            SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);
        }
        //the SetWindowPos() is for update the control
        SetWindowPos(hwnd, 0, 0, 0, 0, 0,
            SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
            SWP_DRAWFRAME | SWP_FRAMECHANGED);
    }

thanks to all
Topic archived. No new replies allowed.