April 25, 2024, 09:23:26 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Adding date to an edit box from a calendar control

Started by AdrianFox, January 04, 2014, 12:15:48 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

Can somebody tell me what I need to do with my calendar control to overcome this problem?   The problem is that the text returned gives the current date, plus the selected date which is repeated twice.  If I simply use setcontroltext to display the selected date alone, there is no problem.

SUB main_handler
SELECT @MESSAGE
CASE @IDSIZE
'code for calendar control response is here
case @IDCONTROL
if @controlid=main_CALENDAR1
ccGetCurSel main, main_CALENDAR1, m, d, y 'gets month, day and year from the calendar
gosub monthdefine  'just a routine to convert months to month names!

SelectedDate=str$(d)+" "+month$+" "+str$(y)
'get the existing text in the editbox
CurrentText=getcontroltext(main,main_edit1)
'add the current text to the date string
CurrentText=CurrentText+SelectedDate
'display the text plus the selected date in the editbox
setcontroltext main,main_EDIT1,CurrentText 
setfocus main,main_edit1
'following should place cursor at end of text in editbox
controlcmd main,main_edit1,@EDSETSELECTION,0,-3
endif

ENDSELECT
RETURN FALSE
ENDSUB


All I am simply trying to do is to add the selected date from the calendar control at the cursor position in the text I am entering in the editbox.

Thanks for any possible help.

Adrian Fox

LarryMc

I could have helped a little faster if you had posted your entire code.
I had to reconstruct the missing mode so I could run it and see exactly what was happening.

Run the attached code and see if it does what you want.
Each time you click a date it reads whatever is currently in the edit control and adds the new modified date string to that.

If this isn't exactly what you want, post a text string of what you want the edit control to look like after clicking 3 different dates.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

January 05, 2014, 01:44:54 AM #2 Last Edit: January 05, 2014, 10:28:38 AM by AdrianFox
UPDATE:  Thanks for your help Larry and I now have everything working as intended.   

If you have time to explain or clarify (and it's possible to explain fairly easily) I would be grateful if you help me understand the following:

1.   I know that the MCN_SELECT constant you use is a Windows notification code sent by a month calendar control.

2.  I don't understand the use of the initial constant MCN_FIRST  set to -750 prior to the MCN_SELECT constant being set.  And why is this changed to (MCN_FIRST +4)?  As the program progresses what is actually happening when the CalendarControl is clicked?

3. Above all, why does the control responding  to  MCN_SELECT actually work properly while my simple @NOTIFYCODE did  not?  I have looked in the Control Pak guide and the IWBasic guide and cannot find any reference to MCN_SELECT. So should there be a way of doing what I was trying to do without recourse to this constant?

4. Something which may or may not be relevant was I discovered that with the DATETIMEPICKER I tried to use

       IF @NOTIFYCODE = @DTN_DATETIMECHANGE  etc.

that this worked fine except  the date selected was pasted TWICE into the edit box. 

5.  Finally, I was intrigued to find that while using my original (flawed) CalendarControl code  that the text I entered in the editbox,   disappeared completely as I typed at what seemed like random intervals.  I thought at first I was hitting a particular key, but it must have been the program trying to respond in an inappropriate way  due to CalendarControl code I used.    I noticed that as soon as I 'remarked' out the code, the problem disappeared.   This has not occurred of course with the code changes you supplied me with.

Thanks again.  No hurry over any reply of course, just if you feel like explaining things to those of us wandering around in the darkness!!   :D










Thanks very much Larry, and my apologies for not posting the whole code, especially as I know you are incredibly busy.  I will make sure I do that in future.

I tried using a DateTimePicker last night instead which worked ok, but I prefer the calendar control and will try out your code this morning.

Thanks again

:)
Adrian Fox

LarryMc

Quote from: AdrianFox on January 05, 2014, 01:44:54 AM
1.   I know that the MCN_SELECT constant you use is a Windows notification code sent by a month calendar control.
correct

Quote from: AdrianFox on January 05, 2014, 01:44:54 AM
2.  I don't understand the use of the initial constant MCN_FIRST  set to -750 prior to the MCN_SELECT constant being set.  And why is this changed to (MCN_FIRST +4)?  As the program progresses what is actually happening when the CalendarControl is clicked?
Notification messages for controls fall into 2 general categories.  Those that are specific to a particular type of control and those that are sort of generic and apply to multiple controls.  A particular type of control may or may not use some of the generic messages.

In order to key the two types of notification messages from conflicting the generics are numbered in one range and the control specifics are in a separate range.
An often used way of numbering messages is to have a constant to identify where the range starts and then number all associated messages relative to that starting point.
That means that this:
CONST MCN_FIRST = (-750)
CONST MCN_SELECT = (MCN_FIRST + 4)
CONST MCN_SELCHANGE = (MCN_FIRST + 1)

could have been written like this:
CONST MCN_SELECT = -746
CONST MCN_SELCHANGE = -749

A question you might ask is why the negative number.  In signed integers the most significant bit is used to indicate whether the number is positive or negative and the messages use all the bits like an unsigned integer.

Quote from: AdrianFox on January 05, 2014, 01:44:54 AM
3. Above all, why does the control responding  to  MCN_SELECT actually work properly while my simple @NOTIFYCODE did  not?  I have looked in the Control Pak guide and the IWBasic guide and cannot find any reference to MCN_SELECT. So should there be a way of doing what I was trying to do without recourse to this constant?
Most events in windows trigger multiple messages of various sorts.
In your case the following messages were being sent every time you clicked a date in the calendar:
MCN_SELECT
NM_RELEASEDCAPTURE

Since you weren't selecting which to respond to with @NOTIFYCODE you were responding to both therefore you were adding the date twice.
Actually, if the date you selected was different than the currently selected date you would also get the MCN_SELCHANGE message and the date added 3 times.
There was no way to do what you wanted to do without using the MCN_SELECT message.
The controlpak was an addon library and that would have been the proper place to document notification messages.  However, the help documentation only documents some of the most common notification messages for windows and controls.  The help file was never intended to replace the Windows SDK manual.  In my updating of the help file I'm trying to add more of the notification messages but I'm making no attempt to add them all...way too many.  That's why I keep a link to the SDK on my desktop.


Quote from: AdrianFox on January 05, 2014, 01:44:54 AM
4. Something which may or may not be relevant was I discovered that with the DATETIMEPICKER I tried to use

       IF @NOTIFYCODE = @DTN_DATETIMECHANGE  etc.

that this worked fine except  the date selected was pasted TWICE into the edit box. 
Can't say why.

Quote from: AdrianFox on January 05, 2014, 01:44:54 AM
5.  Finally, I was intrigued to find that while using my original (flawed) CalendarControl code  that the text I entered in the editbox,   disappeared completely as I typed at what seemed like random intervals.  I thought at first I was hitting a particular key, but it must have been the program trying to respond in an inappropriate way  due to CalendarControl code I used.    I noticed that as soon as I 'remarked' out the code, the problem disappeared.   This has not occurred of course with the code changes you supplied me with.
Can't explain why.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Thanks Larry.  That's amazing!  It gives me a much clearer understanding of what is happening when you use a control, as opposed to my very simplistic view that Windows somehow just 'knows' what is intended.  You explain things extremely clearly.

I know you have said it is purgatory for you when to have to write manuals but you do it exceptionally well.  I look forward to seeing the revised documentation when the new version of IWB is complete.

Thanks again for taking your time to clarify things.  My winter reading really must be to read more about the rudiments of Windows programming and SDK.  Trouble is at 67 I am finding it harder to learn new things!  But we must all keep trying.   ;)
Adrian Fox

LarryMc

I'll be 69 this year so you can kind of understand why manuals are so tough for me.
The "new" beta help file that comes with the beta of IWB 2.5 has 269 more pages than the one with the current release of IWB.
The last part I have to do is all the controls (plus the debugger when LarryS gives me one to incorporate).

If you want to do some reading that may help you understand windows and controls better you might try reading my tutorial on creating custom controls (before trying to start with the windows SDK).  The first portions cover a lot of the basics.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Thanks Larry.  I started reading your tutorial last night on my Kindle (there's a useful web program called 'Send to Kindle').   Looks like it will be very helpful to me in understanding the essentials for the first time.  Up to now it's just been a case of copying and using code not really knowing what it is doing and how.

I don't know how I missed your tutorial when you first posted it back in 2011, though I think I was still very busy restoring buildings here at that time and not looking at the Forum very often.

Best wishes,

:)
Adrian Fox