1. Unable to unset WS_VISIBLE flag for some win32lib controls
- Posted by AlanO Jun 04, 2009
- 1075 views
Hello!
I was trying to set up some win32lib (v0.70.4 17-Jun-2008) controls on WinXP SP2 that they are not visible by default. Most controls I tried work with the code below, eg LText, but not RichEdit or MleText.
include win32lib.ew constant mainw = create(Window,"", 0, 0, 0,640,460, 0), mycontrol = create(LText,"some text", mainw,10, 10, 20, 80, or_bits({WS_VISIBLE},0))
With RichEdit or MleText, I get a popup that says Fatal error, error code 461 Failed to acquire a hWnd when creating a control.
I can get around the problem by not setting the flags, and setVisible(controlname,0) or by commenting out (cringe) WS_VISIBLE in the win32lib RichEdit control. Neither is ideal! I didn't see this issue in the old euphoria posts. Any ideas?
Regards Alan
2. Re: Unable to unset WS_VISIBLE flag for some win32lib controls
- Posted by AlanOxley Jun 05, 2009
- 1039 views
I have checked the flags in the win32lib constants file. All flags seem to be bits in a 4 byte field; if I add these up for RichEdit, I get #54A1A044 (as expressed in hexadecimal, same as win32lib constants). The WS_VISIBLE is defined as #10000000. If I subtract that from #54A1A044, I get #44A1A044. Trying to set the flags then without using bit twiddling functions:
mycontrol = create(RichEdit,"",owningwindow,10,10,20,80,#54A1A044)
works as expected, but changing that to #44A1A044 does not. Is there something so obvious that I am not seeing it..? Possibly I am completely off course?
Regards Alan
3. Re: Unable to unset WS_VISIBLE flag for some win32lib controls
- Posted by LarryMiller Jun 05, 2009
- 1051 views
I have checked the flags in the win32lib constants file. All flags seem to be bits in a 4 byte field; if I add these up for RichEdit, I get #54A1A044 (as expressed in hexadecimal, same as win32lib constants). The WS_VISIBLE is defined as #10000000. If I subtract that from #54A1A044, I get #44A1A044. Trying to set the flags then without using bit twiddling functions:
mycontrol = create(RichEdit,"",owningwindow,10,10,20,80,#54A1A044)
works as expected, but changing that to #44A1A044 does not. Is there something so obvious that I am not seeing it..? Possibly I am completely off course?
Regards Alan
In Win32Lib the style flags used by a control are the defaults or'd with those you specify. This is very convenient because you need only specify those you wish to add. Unsetting a default flag isn't so commonly used and not as convenient to do. One way is to specify the flags as a one element sequence - {flags}. This will completely override the defaults and you must specify all necessary flags. For many controls this is not very convenient. If this needs to be done often you could define a variable or preferably constant with these flags. The usual method is simply to define the control as usual and then setVisible(control, 0). This makes it clear that the control will be initially hidden.
4. Re: Unable to unset WS_VISIBLE flag for some win32lib controls
- Posted by AlanOxley Jun 05, 2009
- 1018 views
OK thanks Larry, I will try setting up a modified defaults flag as a constant, and use that wherever I have a control that should be not visible initially. I know is not as easy to code as simply using setVisible(control,0) but I feel its a bit lame to define something only to immediately change it again before you have even used it.
Cheers, Alan
5. Re: Unable to unset WS_VISIBLE flag for some win32lib controls
- Posted by ghaberek (admin) Jun 09, 2009
- 985 views
OK thanks Larry, I will try setting up a modified defaults flag as a constant, and use that wherever I have a control that should be not visible initially. I know is not as easy to code as simply using setVisible(control,0) but I feel its a bit lame to define something only to immediately change it again before you have even used it.
Actually, I find it quite common to "create" a control on one line, then "set it up" on several more. Seems to me that there are sections to a program: include, create, initialize, events, and finally, run.
-- include include Win32Lib.ew without warning -- create constant Window1 = create( Window, "TextBox", 0, Default, Default, 400, 300, 0 ) constant LText1 = create( LText, "Enter your text here:", Window1, 10, 10, 370, 20, 0 ) constant RichEdit1 = create( RichEdit, "", Window1, 10, 30, 370, 230, 0 ) -- initialize addStyle( Window1, {0,WS_EX_CLIENTEDGE} ) setTextColor( LText1, BrightRed ) setFont( RichEdit1, "Courier New", 10, Normal ) -- events --(none) -- run WinMain( Window1, Normal )
-Greg