Archived

This topic is now archived and is closed to further replies.

Toolmaker

Updating a Win32 control's style after creating it?

Recommended Posts

I have created an edit control. However, I want to be able to add or remove scrollbars during runtime. So far I found out I can only do this by recreating the control, which isn''t the solution for me. Does anyone have a clue? This is the code I use now, but it doesn''t work, while spy++ shows me the style has been updated.
    HWND m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
                            WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                            ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_MULTILINE,
                            7, 10, 165, 100,
                            Wnd.GetHandle(), (HMENU)999,
                            Wnd.GetInstance(), NULL);

    // Check if control was created

    // Change font

    HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
    SendMessage(m_hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));

    ShowWindow(m_hWnd, SW_HIDE);
    SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_HSCROLL);
    ShowWindow(m_hWnd, SW_SHOW);
    UpdateWindow(m_hWnd);
Any ideas? Toolmaker
-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
In MFC use the ModifyStyle/ModifyStyleEx, in plain Win32 API you have to do it yourself:

Look into GetWindowLong( hwnd, GWL_STYLE / GWL_STYLEEX )
(or GetWindowLongPtr), modify your styles and use
SetWindowLong[Ptr] to set your new style(s).

Share this post


Link to post
Share on other sites
But what if I want to change another style? I am writing a win32 wrapper and want to be able to change the style during runtime. So far, it always fails, such as adding/removing scrollbars, changing to multiline, etc.

Ideas?

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) | WS_HSCROLL);
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);

This code adds the horizontal scrollbar. See this (the Remarks section) for explanation. I can''t set ES_MULTILINE this way, thogh. I''m not sure why.

Share this post


Link to post
Share on other sites
Damn, that means I need to recreate the control if I want to update those styles. Ah well, too bad

Toolmaker



-Earth is 98% full. Please delete anybody you can.

Share this post


Link to post
Share on other sites