The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RHL on April 09, 2012, 03:59:05 AM

Title: change style to STATIC control?
Post by: RHL on April 09, 2012, 03:59:05 AM
Hello guys , i have a static control and want change the windows style in runtime
how to do it?   :bg
I try do it with SendMessage:

invoke SendMessage,HANDLECONTROL,WS_BORDER,0,0

but I cannot...
thanks :)
Title: Re: change style to STATIC control?
Post by: dedndave on April 09, 2012, 04:04:07 AM
GetWindowLong - use to get the current style bits
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633584%28v=vs.85%29.aspx

then, OR your new bit onto the old style and...
SetWindowLong
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx
Title: Re: change style to STATIC control?
Post by: dedndave on April 09, 2012, 04:14:02 AM
        INVOKE  GetWindowLong,HANDLECONTROL,GWL_STYLE
        or      eax,WS_BORDER
        INVOKE  SetWindowLong,HANDLECONTROL,GWL_STYLE,eax


you also have to call SetWindowPos to force it to re-draw the window frame
(more correctly, to force the cached style value to be updated)

Swp_Flags = SWP_NOZORDER or SWP_NOMOVE or SWP_NOSIZE or SWP_FRAMECHANGED or SWP_SHOWWINDOW
        xor     eax,eax
        INVOKE  SetWindowPos,HANDLECONTROL,eax,eax,eax,eax,eax,Swp_Flags


EDIT: added SWP_SHOWWINDOW
Title: Re: change style to STATIC control?
Post by: RHL on April 09, 2012, 05:00:12 AM
 :eek
dedndave simply thank you very much, :|
all that just to change the style of a control :S
thanks!
Title: Re: change style to STATIC control?
Post by: RHL on April 09, 2012, 06:05:11 AM
dedndave a question... why use SetwindowPos?... : P
the API moves a windows or control, but in that code is not moved  ( the coordinates are  zero ) : P
Title: Re: change style to STATIC control?
Post by: dedndave on April 09, 2012, 08:07:59 AM
in the documentation for SetWindowLong
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633591%28v=vs.85%29.aspx

QuoteCertain window data is cached, so changes you make using SetWindowLong will not take effect
until you call the SetWindowPos function. Specifically, if you change any of the frame styles, you
must call SetWindowPos with the SWP_FRAMECHANGED flag for the cache to be updated properly.

however, they fail to mention what other flags should be used
SetWindowPos has several optional flags - it is sometimes difficult to figure out which ones you need - lol
you may have to try different combinations   :P

the flags i mention above...
SWP_NOZORDER - no change in Z-order (hWndInsertAfter parameter is ignored)
SWP_NOMOVE - do not move the window (position parameters are ignored)
SWP_NOSIZE - do not change window size (size parameters are ignored)
SWP_FRAMECHANGED - see SetWindowLong text, above
SWP_SHOWWINDOW - make window visible