April 23, 2024, 11:34:34 AM

News:

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


Placing date from calendar control on to clipboard

Started by AdrianFox, August 25, 2012, 09:19:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

Is there a more 'direct' way to copy the selected date from a calendar control on to the clipboard?

What I'm currently doing, which seems inelegant to me,  is to create my date variable:
         ccGetCurSel d1,1,m,d,y
datenumber=str$(d)+str$(m)+str$(y)


and then display the variable datenumber in an edit box...so I can copy it with CONTROLCMD window | dialog, ID, @EDCOPY

I guess I'm asking if there is code which enables me to directly copy the calendar selection to the clipboard or a better way to do this.

Alternatively can I do it more easily using the DateTimePicker? 

Thanks,

:)
Adrian Fox

LarryMc

Did you look at the clipboard.iwb example that comes with IWB?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

How could I have missed that?   
I was so busy looking at the cp_demo.iwb example to see how to use the Datetimepicker and calendar control that I somehow didn't see the obvious in front of me!  The sun has been very hot today!    :-[

Thanks for pointing me in the right direction... even though I feel like someone standing at the end of the Champs Elysees and asking where the Eiffel Tower is!   ;)
Adrian Fox

LarryMc

I do it all the time.  I didn't pull that bit of info off the top of my head either.
1st, I looked at Fletchie's ctl library and there are two commands in there for reading/writing to the clipboard.
using those two commands I searched the old pyxia forum disk and found some examples and one mentioned that example.  That example has been around at least 7-8 years and I didn't remember it outright; and I use it in some of my programs!

I'm just glad I could stumble across it again and be of some help. ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

AdrianFox

Just a follow up... if you have time to answer it or point me in the right direction for further reading... if you are too busy and can't help I fully understand and this is just curiosity rather than a desperate need to know.

What do some of the following terms in this code indicate when responding to a message from the DateTimePicker, as I can't find any of the code in either the IWBasic help or the Control Pak help?

CASE IDDATEPICKER
IF @NOTIFYCODE = @DTN_DATETIMECHANGE
int day = *<NMDATETIMECHANGE>@lparam.st.wDay
int month = *<NMDATETIMECHANGE>@lparam.st.wMonth
int year = *<NMDATETIMECHANGE>@lparam.st.wYear


   I realise that the DTN_DATETIMECHANGE is a windows notification code, but I don't begin to understand what the
      *<NMDATETIMECHANGE>@lparam.st.wDay
is doing.  Why is there an asterisk before the <> brackets and what does that indicate?  What is the code NMDATETIMECHANGE... as the windows code seems to be (LPNMDATETIMECHANGE) lParam;?

Why is the message information in @lparam appended by .st. before the wDay or wMonth etc.?

I realise this can only be fully explained in the context of Windows programming, but where could I go to start finding answers for these things which are not covered in the IWBasic help?  Just looking up Windows notification codes on the MS website doesn't help too much.  Without understanding the code I cannot change it easily except by trial and error.

Thanks

Adrian Fox

LarryMc

I guess the best place to start is with the window handler and how messages are sent.

when you create a handler like
sub main_handler(),int
   select @MESSAGE
CASE @IDCREATE

CASE @IDCLOSEWINDOW

   endselect
   return 0
endsub

messages are being sent in the background with a function similar to this:
SENDMESSAGE(win as ANYTYPE, msg as UINT, wparam as UINT,lparam as ANYTYPE)
the value of msg is plugged into an IWB constant @MESSAGE
the value of wparam is plugged into an IWB constant @WPARAM
the value of lparam is plugged into an IWB constant @LPARAM

for some messages @WPARAM and @LPARAM are 0,0 (they aren't needed.)

messages coming from controls use the value of @MESSAGE to indicate it is coming from a control (@IDCONTROL)
the @WPARAM value is split into 2 parts
1 part tells us which control(@CONTROLID)
the other part is the msg being sent from it(@NOTIFYCODE)
That leaves us with @LPARAM to send any and all necessary information.

If it is something like a simple number there's no problem; the value is sent.
If it is a string the pointer to the string's location is sent.

But some times we need to send a lot of imformation and we have to send it in @LPARAM(which is really just a UINT).
We accomplish the task by creating a UDT (user Defined Type) and insert an element of the proper type for each piece of info that needs to be sent.

Since the @LPARAM is stupid and doesn't really know what is being sent we have to tell the handler what UDT to use to decode the info once it arrives.
As it states in the help file, UDTs are always sent BYREF just like strings.
By BYREF we mean it sends a UINT value that is a POINTER to a memory location.

So,let's look at where we are so far:

@MESSAGE is @IDCONTROL
@WPARAM is split into IDDATEPICKER and @DTN_DATETIMECHANGE

then we have

*<NMDATETIMECHANGE>@lparam.st.wDay
The * is telling us @lparam is a pointer
.st.wDay is an element in a structure
NMDATETIMECHANGE is telling us what structure(UDT) to use to decode the memory location

You mentioned
(LPNMDATETIMECHANGE)
LP just means Long Pointer

Looking in the controlpak.incc file in the dev\bin folder we find this:
type NMDATETIMECHANGE
NMHDR       nmhdr
UINT       dwFlags
SYSTEMTIME  st
ENDTYPE


SYSTEMTIME is an OS structure defined as
TYPE SYSTEMTIME
DEF wYear:WORD
DEF wMonth:WORD
DEF wDayOfWeek:WORD
DEF wDay:WORD
DEF wHour:WORD
DEF wMinute:WORD
DEF wSecond:WORD
DEF wMilliseconds:WORD
ENDTYPE
where WORD = INT

FYI:
This
int day = *<NMDATETIMECHANGE>@lparam.st.wDay
int month = *<NMDATETIMECHANGE>@lparam.st.wMonth
int year = *<NMDATETIMECHANGE>@lparam.st.wYear

could also be written like this
SETTYPE @lparam , NMDATETIMECHANGE
int day = *@lparam.st.wDay
int month = *@lparam.st.wMonth
int year = *@lparam.st.wYear

Also, the * can be replaced with a #


For additional information about windows and messages you might look at my tutorial starting here:
http://www.ionicwind.com/forums/index.php?topic=4659.0

and look in the IWB Help file under Language\Pointers and Typecasting

Hope this helps a little.
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 very much, Larry, that really is extremely helpful and you explain things very well.   

I didn't even know of the existence of the controlpak.incc file and glancing at it I can see it is the source of much of the information I needed about where particular pieces of code come from and what each definition 'means'.

Thanks also for the tutorial which looks to be just the kind of help I need.

Very much appreciate you giving up the time to give me such a helpful reply.   

:) :) :) :) :)
Adrian Fox