|
Hi all,
I need to get the yesterday's day using any MFC classes like CTime, ColeDateTime. I.e by using ColeDateTime::GetDay i am able to get the day of the week.Is thr any member function or any way to get the yesterdays day
For example if the current day is 1 the previous day should be 31.
If any one have some code patch please let me know
Thanks
- Parthan
|
|
|
|
|
This function might work (pass it the current day, it returns the int for yesterday):
int YourClass::GetYesterday(int nCurrentDay)
{
if(nCurrentDay < 1) || (nCurrentDay > 31))
return 0;
if(nCurrentDay == 1)
{
int month = COleDateTime::GetMonth();
int lastmonth = month - 1;
if(!lastmonth)
lastmonth = 12;
switch(lastmonth)
{
case 4 :
case 6 :
case 10 :
case 11 : return(30);
break;
case 1 :
case 3 :
case 5 :
case 7 :
case 8 :
case 9 :
case 12 : return(31);
break;
case 2 :
if((!COleDateTime::GetYear()%4) && ((COleDateTime::GetYear()%100) || (!COleDateTime::GetYear()% 400)))
return(29);
else
return(28);
}
}
else
return(nCurrentDay--);
}
See http://resurscentrum.nu/members/english/exercises/writing/leap_years.asp[^] for an explanation of the leap year algorithm - I probably wrote it wrong - I didn't check this code
|
|
|
|
|
COleDateTime dt = COleDateTime::GetCurrentTime();
int today = dt.GetDay();
COleDateTimeSpan span(1.0f);
dt -= span;
int yesterday = dt.GetDay();
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
That is cool! I didn't realize that the built-in functionality handles all of the leap-year stuff.
For simple things, I am stuck in the stone-ages I just code them myself and never learn what the members are actually capable of. I keep saying "One of these days...." but it never seems to happen....
|
|
|
|
|
Yeah, it's amazing what a guy can do when he RTFM;P
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks Mr. Terry O'Nolley & Mr.PJ Arends for the Help
|
|
|
|
|
hi,
try to look at much simpler code :
void CMyDlg::GetYesterday()
{
SYSTEMTIME st;
GetLocalTime(&st);
FILETIME ft;
SystemTimeToFileTime(&st,&ft);
__int64 longTime;
memcpy(&longTime,&ft,sizeof(longTime));
longTime -= (__int64)10000000*60*60*24;
memcpy(&ft,&longTime,sizeof(ft));
FileTimeToSystemTime(&ft,&st);
}
hope this helps you
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Hi,
I'm trying to add a tabcontrol to a treeview the followig way: But I don't see any tab in the treeview, just the tree control is there.
Where am I wrong?
Please advise.
void CTreeTestView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
CTreeCtrl& tree = GetTreeCtrl();
CRect rct = CRect(1, 10, 100, 0);
cMyTabCtrl.Create(TCS_TABS | TCS_FIXEDWIDTH | WS_CHILD | WS_VISIBLE,
rct, this, 0x1098);
TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT;
PSTR pszTabItems = "hello";
tcItem.pszText = pszTabItems;
tcItem.cchTextMax = strlen(pszTabItems);
cMyTabCtrl.InsertItem(0,&tcItem);
cMyTabCtrl.SetCurSel(0);
tree.DeleteAllItems();
if (!bXMLTreeCreated)
{
m_ImageList.Create(IDB_BITMAP1, 13, 4, RGB( 255, 255, 255 ));
tree.SetImageList( &m_ImageList, TVSIL_NORMAL );
bXMLTreeCreated = true;
}
hierarchy newNode = hierarchy("Root", "", "", "$Root$", "", false, false, "", 0 );
m_pFormView->cSharedData.HNode [iHierarchyNodeCount++] = newNode;
HTREEITEM hItem = tree.InsertItem( "Root", 4,5,TVI_ROOT );
tree.SelectItem (hItem);
tree.SetItemState(hItem, TVIS_BOLD, TVIS_BOLD );
for (int iCount = 0 ; iCount <15 ; iCount++)
OnPopupInserta();
// TODO: You may populate your TreeView with items by directly accessing
// its tree control through a call to GetTreeCtrl().
}
|
|
|
|
|
Hi,
The follwoing code adds the tab control. but, how can i position it so that it is always at the bottom of the tree view and how can set size of tree control in the tree view so that it doesn't overlap with tab control?
static bool bXMLTreeCreated = false; //this bool is used to make sure image list is added only once
iAttributeNodeCount = 0; //Count of Attribute Nodes, even if deleted not decreased
iHierarchyNodeCount = 0; //Count of Hierarchy Nodes, even if deleted not decreased, not changed if Hierarchy appears twice
uniqueHierarchyCount = 0;
m_pFormView->mapsCount = 0;
m_pFormView->domNodeCount = 0;
lastSelectedItem = NULL;
CTreeView::OnInitialUpdate();
CRect rct = CRect(20,390,280,430);
cMyTabCtrl.Create(TCS_TABS | WS_CHILD | WS_VISIBLE, rct, this, 0x1098);
TC_ITEM tcItem [2];
PSTR pszTabItems [2] = {"Hierarchy", "Device Groups"};
for (int iCount =0 ; iCount <2 ; iCount++)
{
tcItem[iCount].mask = TCIF_TEXT;
tcItem[iCount].pszText = pszTabItems[iCount];
tcItem[iCount].cchTextMax = strlen(pszTabItems[iCount]);
cMyTabCtrl.InsertItem(0,&tcItem[iCount]);
}
cMyTabCtrl.SetCurSel(0);
|
|
|
|
|
hi, I trying to optimize the following subroutine. I was advised that statements like: "sum += (j*16 +1);" should be done using shift and bitwise OR... just exactly how?
I do understand bit flag/masking. But what does multiplication/addition has to do with it? Why'd it optimize code? Can someone show me how to multiply two numbers using bitwise SHIFT/AND/OR...etc?
Thanks.
norm
|
|
|
|
|
Well, first off you shouldn't use shifting for math if you care about code readability. The compiler will optimize your expressions for you, optimizing by hand is largely futile unless you're already writing assembly.
Anyhoo, shifting and multiplying/dividing by powers of 2 are equivalent:
x * 2 == x << 1<br />
x * 4 == x << 2<br />
x * 8 == x << 3
and so on. Similarly,
x / 2 == x >> 1<br />
x / 8 == x >> 3
Since a bit shift instruction can be executed in fewer clock cycles then the corresponding integer math instruction, using shift gives you (theoretically) faster code, although with CPUs these days it's not something a human would ever notice.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Ericahist updated Aug 30!
|
|
|
|
|
Just adding to Michael's answer, the compiler is most likely to do this kind of replacing itself (it is smart enough to know that multiplying by 16 is equivalent to shifting), so your speed gain is most probably 0. To outsmart the compiler in this type of expressions, you should be knowing something that the compiler cannot possibly find out. For instance, suppose you've got an expression like:
sum+=j*i+1; and you know that i is always a power of 2. Then you can actually have some speedup by replacing i with its log2 in the code and doing the shifting.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
hum... i don't quite get it. In my example, i=16 (always)..
so, i do:
sum = sum | j<<4 | 3;
norm
|
|
|
|
|
You may not need to do your hand optimization. Most modern compilers will optimize multiplication and division of certain integer constants (2,3,4,5,any power of 2, and so on), into the appropriate set of shifts.
Software Zen: delete this;
|
|
|
|
|
Hi. How can we launch program from resources using C++.net?
|
|
|
|
|
I want to have my app look at another app running on my computer, and tell me whether the pixel at a certain location is black or white. Can that be done? How do I refer to the other apps coordinates?
|
|
|
|
|
Hi, I need to compute duration of a method call in millisecond, how can I do that? I'm using _ftime to retrieve time. It has millisecond resolution, according to MSDN:
millitm field of __timeb64 is: "Fraction of a second in milliseconds."
--> Now, from when to when in millisecond?
--> Does operating system actually do millisecond? Assuming MS Windows.
--> difftime( ) precision up to second. Anything for millisec?
Thanks!
************************************************
Anyway, Here's the code:
_ftime64( &timebuffer );
timeline = _ctime64( & ( timebuffer.time ) );
printf( "Start: %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
//Time consuming method call:
obj->SomeMethod(..);
_ftime64( &timebuffer );
timeline = _ctime64( & ( timebuffer.time ) );
printf( "Finish: %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
norm
|
|
|
|
|
Have a look at QueryPerformanceCounter and QueryPerformanceFrequency
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I remember having to do this exact same thing when I was in school. This might help out.
#include <time.h>
clock_t Clock1 = clock();
obj->SomeMethod(..);
clock_t Clock2 = clock();
printf( "%.3f seconds", ((float)(Clock2-Clock1))/CLOCKS_PER_SEC );
I didn't look these functions up, but I believe the clock() function returns the number of clock ticks since the program (or maybe the current thread) has begun. You have to cast Clock2-Clock1 to a double or a float or you'll just be performing integer division, which won't give you the answer you are looking for. I suspect you are wrapping the clock calls around sorting algorithms or something of that nature...good luck!
Douglas A. Wright
dawrigh3@kent.edu
|
|
|
|
|
These functions have millisecond precision, but not millisecond accuracy. In other words, while the result may be expressed as +/- 0.001 second, it may actually only be good to +/- 0.010 second (the Windows 'quantum'), for example. The difference is due to the fact that this clock is based on Windows timekeeping, which may not be updated often enough.
As someone else mentioned, use QueryPerformanceCounter and QueryPerformanceFrequency instead. These functions use a hardware timer that is not dependent on Windows.
Software Zen: delete this;
|
|
|
|
|
|
In winamp,the 3 dialog can attach to each other.When the main dialog moves.the child dialog move according to the main dialog.When there is only one child dialog,this is easy to do so.But if we have multi child dialog,when
moving,that is very complicated.Is there any good ideas? thanx!
|
|
|
|
|
that's an interesting question
norm
|
|
|
|
|
Hi,
I have this little part of code:
<br />
char* echoReply = new char[1024];<br />
int nRet;<br />
int nAddrLen = sizeof(struct sockaddr_in);<br />
sockaddr_in lpsaFrom;<br />
lpsaFrom.sin_family = AF_INET;<br />
lpsaFrom.sin_port = 0;<br />
<br />
nRet = recvfrom(s,<br />
(char*) &echoReply,<br />
1024,<br />
0,<br />
(sockaddr*) &lpsaFrom,<br />
&nAddrLen);<br />
<br />
if (nRet == SOCKET_ERROR)<br />
<br />
int error = WSAGetLastError();<br />
nRet (the return value of recvfrom) is 0xffffffff (SOCKET_ERROR)
but WSAGetLastError returns 0 (no error).
how can this be?
I don't think this is possible.
can anybody help me, please?
Thx
CND
|
|
|
|
|
I have a word file, with some text being bold, some
italic, etc., etc. Is their any way to open the
file and see the code behind the file? In latex, I
would see
\begin{bold}Bold text here\end{bold}
but I would like to see the code behind a ms word
doc file.
Please, any response any one can give me will be
greatly appreciated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|