AfxInputBox

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

AfxInputBox

Post by deltarho[1859] »

@Josep Roca

Can you spare me a minute?

I am having problems with AfxInputBox again.

I would have thought that clicking on Cancel or the Close box would leave the sixth parameter (cwsText) as found.

However, the following code sees the text to edit being purged when we Cancel or Close.

Code: Select all

'#console on
#Define UNICODE
#Include Once "Afx\CWindow.inc"
Using Afx

Dim As CWSTR ExistingCommandLine, NewCommandLine
ExistingCommandLine = "blah, blah, blah"
NewCommandLine = AfxInputBox( Null, 0, 0, "CSwitches - Edit", "Additional compiler option switches (optional)", _
  ExistingCommandLine )
Print NewCommandLine, Len(NewCommandLine )
Sleep
I have looked at AfxInputBoxWindowProc and IDCANCEL and WM_CLOSE neither of which seem to do any purging. IDOK sends WM_GETTEXT which is to be expected.

Needless to say, presently I cannot see what I am doing wrong. :)
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: AfxInputBox

Post by deltarho[1859] »

I searched WinFBE's source code and found AfxInputBox being used. Something is done only if the length of the return string is positive otherwise nothing is done.

So, I am now doing the same thing.

The only problem with that is if I emptied the input string, then the length of the output string is zero, causing nothing to be done. So, I introduced an input string existing of only two double quotes normally associated with an empty string. In that case, I execute this:

Code: Select all

If  NewCommandLine = Chr(34,34) Then
  WritePrivateProfileString "Compiler", "CompilerSwitches", "", iniPath 
This will cause CompilerSwitches in WinFBE to be empty.

Why would I want to do that? That is another story.

It still does not explain why the text to edit is purged when we Cancel or Close.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: AfxInputBox

Post by Josep Roca »

The string to be edited is ExistingCommandLine, not NewCommandLine.

I have modified the PRINT line to

Print NewCommandLine, Len(NewCommandLine ), ExistingCommandLine

and after clicking Cancel or the Close button it prints the original content "blah, blah, blah".

... and NewCommandLine returns an empty string.

This is wrong

NewCommandLine = Chr(34,34)

It does not return "", but an empty string.

To check it use

If LEN(NewCommandLine) Then ' it contains text - the user has clicked Accept
If LEN(NewCommandLine) = 0 Then ' it does not contains text - the user has clicked cancel or close

or

If NewCommandLine <> "" Then ' it contains text - the user has clicked Accept
If NewCommandLine = "" Then ' it does not contains text - the user has clicked cancel or close

Chr(34,34) is not an empty string, but a string that contains two quotation marks.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: AfxInputBox

Post by deltarho[1859] »

Thanks, José.
José wrote:The string to be edited is ExistingCommandLine, not NewCommandLine.
In the opening post, we have:

Code: Select all

NewCommandLine = AfxInputBox( Null, 0, 0, "CSwitches - Edit", "Additional compiler option switches (optional)", _
  ExistingCommandLine )
So, the string to be edited is ExistingCommandLine.
and after clicking Cancel or the Close button it prints the original content "blah, blah, blah".
Well it would - the string ExistingCommandLine has not been changed.
... and NewCommandLine returns an empty string.
That is clearly a misunderstanding on my part, and will accept NewCommandLine returning an empty string.
Chr(34,34) is not an empty string, but a string that contains two quotation marks.
Precisely and my intention – see my second post. Instead of two quotation marks I could have used 'empty', or anything for that matter, and if the code sees 'empty', or whatever, it then ensures that CompilerSwitches in WinFBE becomes empty. I chose two quotation marks because we all associate two quotation marks as an empty string.
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: AfxInputBox

Post by Josep Roca »

> I chose two quotation marks because we all associate two quotation marks as an empty string.

Sorry. I misunderstood the code and thought that you were assigning them to a variable. I need to go to sleep.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: AfxInputBox

Post by deltarho[1859] »

José wrote:I need to go to sleep.
And there is me thinking that you coded in your sleep with the amount of code that you have knocked out over the years. I could do the same if I lived for 425 years; give or take. :)
Josep Roca
Posts: 564
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: AfxInputBox

Post by Josep Roca »

I can't keep up this pace anymore. I'm getting old and besides, I have other interests. These are difficult times.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: AfxInputBox

Post by deltarho[1859] »

I'm getting old
I was 75 the other week, but I mustn't grumble – I don't feel a day older than 73.
These are difficult times.
Indeed.
Post Reply