Like Tree2Likes
  • 1 Post By CommonTater
  • 1 Post By adeyblue

Change window style

This is a discussion on Change window style within the Windows Programming forums, part of the Platform Specific Boards category; I want to make my console app window to be like this: A minimal style in other words... With no ...

  1. #1
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44

    Question Change window style

    I want to make my console app window to be like this:
    Name:  minimal window.png
Views: 437
Size:  64.8 KB

    A minimal style in other words...
    With no possibility to resize the window and with only the Close button
    How should I proceed?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    1) #include <windows.h> at the top of your program...

    2) If you are making your own window you manage styles by options in the CreateWindow() or your dialog resources.

    CreateWindow Function (Windows)

    2) if you need to change it on the fly you would use GetConsoleWindow() then SetWindowLong() and SetConsoleTitle()

    GetConsoleWindow Function (Windows)
    SetWindowLong Function (Windows)
    SetConsoleTitle Function (Windows)
    Last edited by CommonTater; 04-27-2011 at 04:03 PM.
    ekosix likes this.

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Note that you can't do this on XP, since the console window is owned by a system process which denies you access to fiddling the window styles. On Vista/7, use GetWindowLongPtr(hwnd, GWL_STYLE), mask off the minimize, maximize, and thickframe styles, and set the result with SetWindowLongPtr. Then you'll need to force the window to update with SetWindowPos(..., SWP_FRAMECHANGED)
    Last edited by adeyblue; 04-27-2011 at 04:10 PM.
    ekosix likes this.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by adeyblue View Post
    Note that you can't do this on XP, since the console window is owned by a system process which denies you access to fiddling the window styles. On Vista/7, use GetWindowLongPtr(hwnd, GWL_STYLE), mask off the minimize and maximize box styles, and set the result with SetWindowLongPtr. Then you'll need to force the window to update with SetWindowPos(..., SWP_FRAMECHANGED)
    Thanks for that... i don't use console mode very much so I was unaware of the permissions issue...

  5. #5
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    I did it, thanks!
    But, I had to modify the screen buffers, because horizontal and vertical scroll bars were appearing on the window. I just adjusted the screen buffers and ok.
    But I still have a little problem that I think it cannot be solved with screen buffers...

    When the app starts, the window is completely ok, adjusted... if I try to enlarge it, nothing will happen, BUT if I try to resize it to a smaller size, it will. That's the problem... I don't want the window to be resizeable.

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    23
    The console is limited to the maximum width of chars in its properties. This is restricted to modification with the mouse and explains why the window will resize to a certain extent then stop. However you may be able to subclass the console and intercept its WM_SIZE messages either by throwing them away or resetting its size every time the user attempts to modify it.

  7. #7
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    Gosh, isn't there an easier way to block resizing instead of capturing window events?

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by ekosix View Post
    Gosh, isn't there an easier way to block resizing instead of capturing window events?
    Msdn search, 12 seconds -- > Window Styles (Windows)

    Use SetWindowLong() to reset the style bits to one that does not allow resizing ... for example... WS_DLGFRAME | WS_CAPTION

  9. #9
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by ekosix View Post
    Gosh, isn't there an easier way to block resizing instead of capturing window events?
    mask off the minimize, maximize, and thickframe styles
    When you ask for help, it's a good idea to actually read the responses.

  10. #10
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    Quote Originally Posted by CommonTater View Post
    Msdn search, 12 seconds -- > Window Styles (Windows)

    Use SetWindowLong() to reset the style bits to one that does not allow resizing ... for example... WS_DLGFRAME | WS_CAPTION
    I used it with GWL_EXSTYLE, WS_EX_TOOLWINDOW and it is the same style as my attachment... but it is still resizeable...
    I tested other conbinations and values instead of WS_EX_TOOLWINDOW, but nothing works.
    I thought setting it as a tool box would block its resizing, but no, and that's the problem.

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Use GWL_STYLE ... you want the primary window styles not the extended ones.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. Change Style of An Existing Window
    By Queatrix in forum Windows Programming
    Replies: 1
    Last Post: 08-17-2006, 05:08 PM
  3. EditBox control style change
    By Devil Panther in forum Windows Programming
    Replies: 13
    Last Post: 11-13-2004, 12:54 PM
  4. How to change Windows Style
    By sean345 in forum Windows Programming
    Replies: 8
    Last Post: 07-30-2002, 03:06 PM
  5. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM

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