BBC BASIC for Windows
« Changing the style of a dialog control »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:55pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Changing the style of a dialog control  (Read 3208 times)
Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Changing the style of a dialog control
« Thread started on: Jun 14th, 2013, 5:32pm »

Hi,

I know I've seen this somewhere before, but for the life of me I can't find it.

I'm trying to switch the style of a control to and from a readonly state, but keeping the same look of it. That is, I don't want to turn the control off - SYS "EnableWindow", h%, TRUE | FALSE, which causes the contents to be greyed out.
What I want is to be able to turn it on and off e.g
PROC_editbox(dlg%, "", id%, x%, y%, cx%, cy%, ES_READONLY), which doesn't.

Can someone, please, point me in the direction of this.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Changing the style of a dialog control
« Reply #1 on: Jun 14th, 2013, 9:54pm »

on Jun 14th, 2013, 5:32pm, Matt wrote:
Can someone, please, point me in the direction of this.

You need look no further than the MSDN description of the ES_READONLY style:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464.aspx

There it explicitly states: "To change this style after the control has been created, use the EM_SETREADONLY message". With experience you will be able to find this kind of thing in MSDN yourself.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Changing the style of a dialog control
« Reply #2 on: Jun 15th, 2013, 06:11am »

on Jun 14th, 2013, 9:54pm, Richard Russell wrote:
You need look no further than the MSDN description of the ES_READONLY style:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb775464.aspx


Thanks. It wasn't where I'd seen it, but it does answer most of my query.

Quote:
"To change this style after the control has been created, use the EM_SETREADONLY message".


This works fine:
Code:
          SYS "GetDlgItem", !dlg%, id% TO h%
          SYS "GetWindowLong", h%, GWL_STYLE TO ws%
          SYS "SetWindowLong", h%, GWL_STYLE, ws% AND EM_SETREADONLY 

(Although it does leave the insert curser stuck visible in the first control.)

However, I can't seem to then change it back. 'AND NOT EM_SETREADONLY' doesn't seem to work, and I can't find any alternative constant. I've also tried doubling up on the above code (i.e. runing the code twice to 'undo' the AND) which, I believe, returns to the original ws% figure, but that doesn't work either, staying in RO mode. (Not sure about my logic, here.)

Quote:
With experience you will be able to find this kind of thing in MSDN yourself.

Experience and memory! Both of which I seem to lack in abundance.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Changing the style of a dialog control
« Reply #3 on: Jun 15th, 2013, 08:40am »

on Jun 15th, 2013, 06:11am, Matt wrote:
This works fine:

It may be that it does, and indeed some of the ES_ styles are specifically documented to be changed in that way, but MSDN clearly states, as you quoted, that the read-only status should not be changed using SetWindowLong but instead by sending the EM_SETREADONLY message.

I have to say that I am at a loss to understand why you would completely ignore the recommended method, and then complain that the alternative method you have used isn't working properly! I have no doubt that MSDN says to use the EM_SETREADONLY message, instead of SetWindowLong, for a good reason!

I am pretty confident that if you do it the way they say, it will work correctly and reliably.

Richard.
User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Changing the style of a dialog control
« Reply #4 on: Jun 15th, 2013, 2:47pm »

on Jun 15th, 2013, 08:40am, Richard Russell wrote:
It may be that it does, and indeed some of the ES_ styles are specifically documented to be changed in that way, but MSDN clearly states, as you quoted, that the read-only status should not be changed using SetWindowLong but instead by sending the EM_SETREADONLY message.


I'm sorry, but where does it state that? I've searched the page and related pages you suggested and I've not found that it states that, (and I certainly don't remember stating that, myself).

Quote:
I have to say that I am at a loss to understand why you would completely ignore the recommended method, and then complain that the alternative method you have used isn't working properly!

You're taking my comments too strongly. I'm not complaining that it's not working, just that I'm obviously not doing it correctly. And there is a difference between 'completely ignoring' the recommended method and not understanding the correct way. Assume that my lack of understanding (or memory in locating references) is frustrating, by all means, but please don't assume that I will just go ahead with my own way 'ignoring' what others say. The one thing I will always try to do is follow the correct rules if possible.

Quote:
I have no doubt that MSDN says to use the EM_SETREADONLY message, instead of SetWindowLong, for a good reason!

I am pretty confident that if you do it the way they say, it will work correctly and reliably.


Doing it this way:
Code:
          SYS "GetDlgItem", !dlg%, id% TO h%
          SYS "GetWindowLong", h%, GWL_STYLE TO ws%
          IF ro% THEN SYS "SetWindowLong", h%, GWL_STYLE, ws% AND ES_READONLY \
          \      ELSE SYS "SetWindowLong", h%, GWL_STYLE, ws% AND NOT ES_READONLY
 

works correctly, but it's not how they say. There's no memory leakage, so I can't see how this might be a problem.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Changing the style of a dialog control
« Reply #5 on: Jun 15th, 2013, 4:53pm »

on Jun 15th, 2013, 2:47pm, Matt wrote:
I'm sorry, but where does it state that?

Compare, for example, the description of the ES_LOWERCASE and ES_READONLY styles. Under ES_LOWERCASE it says this: "To change this style after the control has been created, use SetWindowLong" and under ES_READONLY it says this: "To change this style after the control has been created, use the EM_SETREADONLY message".

Now whilst I willingly concede that the ES_READONLY text doesn't actually say not to use SetWindowLong, the fact that it tells you to use EM_SETREADONLY (and doesn't mention SetWindowLong at all) is a pretty clear indication that it should be done in a specific way.

Quote:
There's no memory leakage, so I can't see how this might be a problem.

Windows is a very complex Operating System, with subtle and frequently non-obvious interactions between its components. It's impossible to deduce, from the limited information available from MSDN, whether doing something contrary to the recommendations will be acceptable or not. It's best to assume it isn't.

To me it's a 'no brainer'; MSDN tells you that to change the Read Only status of an edit control (after it is created) you should send it an EM_SETREADONLY message. On the page to which I linked, the EM_SETREADONLY text is a hyperlink to this page:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb761655.aspx

There the messages you need to send are described in great detail, corresponding to these BBC BASIC statements:

Code:
SYS "SendMessage", hEditControl%, EM_SETREADONLY, 1, 0 : REM Set Read Only state
SYS "SendMessage", hEditControl%, EM_SETREADONLY, 0, 0 : REM Clear Read Only state 

Richard.
« Last Edit: Jun 15th, 2013, 7:38pm by admin » User IP Logged

Matt
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 210
xx Re: Changing the style of a dialog control
« Reply #6 on: Jun 15th, 2013, 7:41pm »

on Jun 15th, 2013, 4:53pm, Richard Russell wrote:
To me it's a 'no brainer'

I wish it was that easy for me.

Quote:
There the details of the messages you need to send are listed in great detail, corresponding to these BBC BASIC statements:

Code:
SYS "SendMessage", hEditControl%, EM_SETREADONLY, 1, 0 : REM Set Read Only state
SYS "SendMessage", hEditControl%, EM_SETREADONLY, 0, 0 : REM Clear Read Only state 

Richard.


Thanks. Now all I have to do is find a way of making comboboxes and buttons(incl. radio buttons and checkboxes) RO as well.

Matt
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Changing the style of a dialog control
« Reply #7 on: Jun 15th, 2013, 10:12pm »

on Jun 15th, 2013, 7:41pm, Matt wrote:
I wish it was that easy for me.

If you are not familiar with the SendMessage function then you really shouldn't be attempting to program the Windows API. Spend some time learning the basics, then come back to the task.

Quote:
Now all I have to do is find a way of making comboboxes and buttons(incl. radio buttons and checkboxes) RO as well.

Since you can't ever 'write' to buttons, there's no concept of them being 'read only'! As far as comboboxes are concerned, a 'read only' combobox would simply be a List Box (remember that a combobox is a combination of a text box - which you can write to - and a list box - which you can't)!

Richard.
« Last Edit: Jun 15th, 2013, 10:33pm by admin » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls