   Trying to change a windows style but it won't work! HELP!
  I'm trying to change the style of a window that was already created but it disappears, here is what I tried:SetWindowLongPtr( hWnd, GWL_STYLE, WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SIZEBOX | WS_EX_NOPARENTNOTIFY );SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DRAWFRAME );Any idea what I'm doing wrong?[Edited by - CodaKiller on May 22, 2009 3:12:35 PM]
  I figured it out, I needed to define the visible flag.  [lol]I'm a little confused about how to change a flag in the style though.I have a bool that is suppose to set if the flag is set or not but how do I remove the flag if the bool variable is false and add the flag if the bool variable is true?void set_minimize( bool minimize ){SetWindowLongPtr( hWnd, GWL_STYLE, GetWindowLongPtr( hWnd, GWL_STYLE ) );SetWindowPos( hWnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_DRAWFRAME );}I need to see if the flag is already defined in the style so I can make this work.   ;  Use GetWindowLongPtr to retrieve the style. Use a bitwise AND to determine if the flag is set. If it's not set then set it. style = GetWindowLongPtr(hwnd,...);isset = style & flag;if (!isset) { // if not set, then set SetWindowLongPtr(hwnd,...); ...};Quote:Original post by LessBreadUse GetWindowLongPtr to retrieve the style. Use a bitwise AND to determine if the flag is set. If it's not set then set it. style = GetWindowLongPtr(hwnd,...);isset = style & flag;if (!isset) { // if not set, then set SetWindowLongPtr(hwnd,...); ...}Though it works I get a warning:Quote:1>.\Main.cpp(1164) : warning C4800: 'long' : forcing value to bool 'true' or 'false' (performance warning)I tried to cast it but I still get the warning, how can I make it compiler friendly?EDIT:Never mind, if I use && it seems to not give a warning so thanks LessBread!   ;  A boolean and && is not the same as a bitwise and &. style && flag != style & flagtryBOOL isset = (BOOL)(style & flag);;Quote:Original post by LessBreadA boolean and && is not the same as a bitwise and &. style && flag != style & flagtryBOOL isset = (BOOL)(style & flag);I did try to cast it as I said before but it still gives a warning. && works perfect so there is no problem.   ;Quote:I did try to cast it as I said before but it still gives a warning. && works perfect so there is no problem.No, it does something completely different, as LessBread says (did you even read the links he posted?). Either ignore the warning, do the cast as Lessbread suggests (uppercase BOOL, not lowercase), but don't do what you're doing. It is wrong and gives incorrect results. To be specific, you're doing two tests:- "style" testing whether *any* flag is set - "flag" whether the numerical value of "flag" is different from 0Since the letter test will always return true and the && combines the two tests, it basically checks the first only. So "style && flag" is in this case the same as "style != 0"The test you want is to check whether "flag" is set in "style". That is "flag & style" (or if you absolutely must quench that dumb warning: "flag & style = style").   ;Quote:Original post by KippesoepQuote:I did try to cast it as I said before but it still gives a warning. && works perfect so there is no problem.No, it does something completely different, as LessBread says (did you even read the links he posted?). Either ignore the warning, do the cast as Lessbread suggests (uppercase BOOL, not lowercase), but don't do what you're doing. It is wrong and gives incorrect results. To be specific, you're doing two tests:- "style" testing whether *any* flag is set - "flag" whether the numerical value of "flag" is different from 0Since the letter test will always return true and the && combines the two tests, it basically checks the first only. So "style && flag" is in this case the same as "style != 0"The test you want is to check whether "flag" is set in "style". That is "flag & style" (or if you absolutely must quench that dumb warning: "flag & style = style").Lessbread was right and all I needed to do was use BOOL instead of bool to bypass the warning but the problem with this is that luabind will not work with BOOL...   ;  Is this a good idea?bool isset = !!(style & WS_CAPTION);It checks if the value is not not. lol   ;Quote:Original post by CodaKillerIs this a good idea?Quite ugly.bool isset = (style & WS_CAPTION) != 0;bool isset = (style & WS_CAPTION) != FALSE;the second one is perhaps a bit clearer but it's less portable. However, as you're coding for windows I wouldn't care, but it's something I think you should be aware of.