IonicWind Software

IWBasic => General Questions => Topic started by: Andy on June 05, 2020, 03:59:05 AM

Title: Read only control
Post by: Andy on June 05, 2020, 03:59:05 AM
Hi,

I have just added into the editor a drop down box to list all include files that a file has.

Now the vast majority of times we use the IWB include files, and as LarryMc told me once - we should not be changing them.

With that in mind, I want to load an IWB include file (if listed) and make the rich edit control read only - that's simple enough.

My question is this:
MSDN states that I can send a GetWindowLong message to see if the rich edit is read only or not - but it states I need to use the "GWL_STYLE" flag to do so - now when I read what styles it could return it does not mention read only.

Can anyone help me out please on this?

Thanks,
Andy.
Title: Re: Read only control
Post by: Brian on June 05, 2020, 04:51:54 AM
Don't understand. If all you are doing is creating a list of possible .inc files, you don't have to have any code for opening them at all, just show the list for reference

Brian

Edit: Take a look at EM_SETREADONLY
Title: Re: Read only control
Post by: Andy on June 06, 2020, 03:53:16 AM
Brian,

Not just to list includes, you can load them too which is why I don't want to allow IWB include files to be edited in this editor - view only.

So I have done done some research on this and you were right about EM_SETREADONLY and this is how to do what I want:

The EM_SETREADONLY value:
CONST EM_SETREADONLY = 0xCF

A read only style value to check against
UINT ReadOnlyV = 1351620804

Then set the rich edit (control id here of "1") to read only:
SENDMESSAGE (GETCONTROLHANDLE(w1,1),EM_SETREADONLY,TRUE,0)

Now to check if it has been set to read only:
SUB CheckReadOnly(),INT
INT RetVal = 0
UINT style = GetWindowLongA(GETCONTROLHANDLE(w1,1),GWL_STYLE)
IF style = ReadOnlyV
  ReadOnly = 1
  Editable = 0
  RetVal = 1
ELSE
  ReadOnly = 0
  Editable = 1
  RetVal = 0
ENDIF
RETURN RetVal
ENDSUB

PRINT CheckReadOnly()

Returns 1 for read only, 0 for editable.

To set the rich edit back to editable use the FALSE switch:
SENDMESSAGE (GETCONTROLHANDLE(w1,1),EM_SETREADONLY,FALSE,0)

Andy.
:)
Title: Re: Read only control
Post by: Andy on June 07, 2020, 03:41:17 AM
Well I has half right.... and here is the definitive answer:

The variable "style" returns a number, when we change that number to hex we get an 8 character value.

The last 4 characters are the answer.

If the last 4 characters are "18C4" then the rich edit is read only, otherwise it's not.

So with a slight amendment to the sub routine with this in mind we can now with 100 % guarantee the answer like this:

sub CheckReadOnly(),int
int RetVal = 0
uint style = GetWindowLongA(Getcontrolhandle(w1,1),GWL_STYLE)
string HexString = hex$(style)
HexString = mid$(HexString,5,4)
if ucase$(HexString) = "18C4"
   ReadOnly = 1
   Editable = 0
   RetVal = 1
else
   ReadOnly = 0
   Editable = 1
   RetVal = 0
endif
return RetVal
endsub

Andy.
:)
Title: Re: Read only control
Post by: Brian on June 07, 2020, 08:30:50 AM
That's neat, Andy. Maybe GetFileAttributes would work, as well?

Brian
Title: Re: Read only control
Post by: Andy on June 08, 2020, 03:50:20 AM
Brian,

Thanks, took some working out and having a brief search on the Internet nothing on this was documented - but I'm probably wrong.

I can't use GetFileAttributes as I am looking at the rich edit control itself rather than the actual file - but all good ideas are always welcome!

Andy.
 :)