NO

Author Topic: DelKey Produces date  (Read 5155 times)

gromit

  • Guest
DelKey Produces date
« on: July 14, 2012, 12:33:25 PM »

Hi folks Is this prob weird or what

This is my get todays date routine

Does what it says on the tin
wchar_t  *ReturnTodaysDateString()
{
SYSTEMTIME st;
GetSystemTime(&st);
wchar_t *xstr=L"";
wchar_t daystr[10];   
wchar_t mnthstr[10];
wchar_t yrstr[10];
if (st.wDay<10)
swprintf(daystr, L"0%d/",st.wDay);
else
swprintf(daystr, L"%d/",st.wDay);

if (st.wMonth<10)
swprintf(mnthstr, L"0%d/",st.wMonth);
else
swprintf(mnthstr, L"%d/",st.wMonth);

swprintf(yrstr, L"%d",st.wYear);
wcscpy(xstr,daystr);
wcscat(xstr,mnthstr);
wcscat(xstr,yrstr);

return xstr;

}

This is a  sip delete button handler used it for years no problem
// It is my own alphanumertic sip ( slightly larger than the one that the pda uses by default)

// Handle Delete____________________________________________________________
// g_editfocus is the edit control i am deleteing in
if(idctrltapped==IDC_DELKEY)
{
   SendMessage(GetDlgItem(h, g_editfocus),EM_GETSEL ,(WPARAM)&start,(LPARAM)&end);
   if (end>start && end!=0)
      SendMessage(GetDlgItem(h, g_editfocus),EM_REPLACESEL ,(WPARAM)TRUE,PARAM)L"");
   if (end==start && end!=0)
   {
   SendMessage(GetDlgItem(h, g_editfocus),EM_SETSEL   ,(WPARAM)start-1,(LPARAM)end);
   SendMessage(GetDlgItem(h, g_editfocus),EM_REPLACESEL   ,(WPARAM)TRUE,(LPARAM)L"");
   }
   SetFocus(GetDlgItem(h, g_editfocus));

return 0;
}

Now for the problem

No matter what dialog i am using or what control every time i tap delete instead of deleteing a character it prints the date into the edit box ?????????????????
Del key works fine until i call the date function

I have never been able to get _wcsdate(wchar_t * dst) to work always get unresolved externals error


i have tried setting todays datestr to both global and local variables and still same problem

Any help woul be appreciated

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: DelKey Produces date
« Reply #1 on: July 14, 2012, 01:25:56 PM »
Try this:
Code: [Select]
wchar_t *ReturnTodaysDateString(void)
{
static wchar_t xstr[11];
SYSTEMTIME st;
GetSystemTime(&st);
swprintf(xstr, L"%04d-%02d-%02d",st.wYear,st.wMonth,st.wDay);
return xstr;
}
May the source be with you

gromit

  • Guest
Re: DelKey Produces date
« Reply #2 on: July 14, 2012, 05:03:56 PM »

Thanks timovjl 
:) :) :) :) :)
Whilst i am none the wiser as to why the bug occurred your code whacked it full on.
Now works perfectly.
Obviously a lot to be said for a better understanding of formatting text.

I Can only assume my wscpy ing of the various strings had some bearing on it

Once again big thanks have been struggling on that one for a couple of nights now :)