开发者

Change Win32 Window Style

Is there a win32 function to change the style of a window after it has been created? I would like to change the style flags that are specified in CreateWindowEx. Specifically, I would like to convert a standard window to a window with no border and 开发者_运维知识库no resize.


I think SetWindowLongPtr should do that. Note that you need to call SetWindowPos afterwards if you changed the border style, as pointed out in the remarks.

Some styles only take effect during window creation and so can not be set by this call. MSDN normally calls out styles that CAN be set afterwards.


HWND windowHandle = FindWindow(NULL, L"Various tests");
    SetWindowLongPtr(windowHandle, GWL_STYLE, WS_SYSMENU); //3d argument=style
    SetWindowPos(windowHandle, HWND_TOPMOST, 100, 100, Width, Height, SWP_SHOWWINDOW);

did it for me :D


You should try this window style in the createwindowex or SetWindowLongPtr: WS_POPUPWINDOW|WS_TABSTOP |WS_VISIBLE


The way i solved it by using combination of SetWindowPos and ShowWindow methods.

NOTE that calling showWindow is must here otherwise it won't work.

Here is the full source code below. Just call setConsoleWindowStyle() method and set new window style.

#define _WIN32_WINNT 0x0501
#include <stdio.h>
#include <windows.h>

LONG_PTR setConsoleWindowStyle(INT,LONG_PTR);

int main()
{
    LONG_PTR new_style =  WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL;
    setConsoleWindowStyle(GWL_STYLE,new_style);
    return 0;
}

LONG_PTR setConsoleWindowStyle(INT n_index,LONG_PTR new_style)
{
 /*The function does not clear the last error information. if last value was zero.*/
 SetLastError(NO_ERROR);        

 HWND hwnd_console = GetConsoleWindow();
 LONG_PTR style_ptr = SetWindowLongPtr(hwnd_console,n_index,new_style);
 SetWindowPos(hwnd_console,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_DRAWFRAME);

 //show window after updating
 ShowWindow(hwnd_console,SW_SHOW);

 return style_ptr;  
}


SetWindowLong(hWnd, GWL_STYLE, newStyle); ShowWindow(hWnd, SW_SHOW);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜