March 28, 2024, 07:16:28 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Read only control

Started by Andy, June 05, 2020, 03:59:05 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

June 05, 2020, 04:51:54 AM #1 Last Edit: June 05, 2020, 06:42:54 AM by Brian
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

Andy

June 06, 2020, 03:53:16 AM #2 Last Edit: June 06, 2020, 03:58:27 AM by Andy
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

That's neat, Andy. Maybe GetFileAttributes would work, as well?

Brian

Andy

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.
 :)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.