|
Take a look to:
FileTimeToSystemTime and related API's. Maybe are helpful.
|
|
|
|
|
It is not recommended that you add and subtract values from the SYSTEMTIME structure to obtain relative times.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
SYSTEMTIME structure is far less useful for calculating timespans than FILETIME. At SYSTEMTIME, the help pages even recommend converting it to FILETIME and then to LARGE_INTEGER structures before comparing (exactly what I was trying to do), but as I wrote above, I'll try to use a different timestamp item on the file to see if that corresponds with the real file date. Maybe simply the files were not recognized as one week old because they were moved in between...
|
|
|
|
|
Both of you have reason.
That stated, the following code works pretty well:
#include "stdafx.h"
#include <windows.h>
int main(int argc, char* argv[])
{
OFSTRUCT ofs;
if (argc <2) return -1;
HFILE hFile;
hFile = OpenFile(argv[1], &ofs, OF_READ);
FILETIME ct, lat, lwt[2];
SYSTEMTIME locTime;
GetLocalTime(& locTime);
BOOL bSuccess= SystemTimeToFileTime( &locTime, &lwt[0]);
bSuccess= GetFileTime( (HANDLE)hFile, &ct, &lat, &lwt[1]);
LARGE_INTEGER li[2], liresult;
li[0].LowPart = lwt[0].dwLowDateTime;
li[0].HighPart = lwt[0].dwHighDateTime;
li[1].LowPart = lwt[1].dwLowDateTime;
li[1].HighPart = lwt[1].dwHighDateTime;
liresult.QuadPart=li[0].QuadPart-li[1].QuadPart;
if (liresult.QuadPart> 6048000000000L)
{
printf("more than a week\n");
}
CloseHandle((HANDLE)hFile);
getchar();
return 0;
}
The program compare the file given as its argument with the current system
time. I tested it.
What about your code? Maybe you're considering the wrong attribute (I don't believe you're modifying the files...)
|
|
|
|
|
It's exactly that: The files were copied to their location shortly before I took that debug attempt and so the "creation" time was just a few hours ago and I had too look for the "modification" time. After I changed the code to ftLastWriteTime (from the WIN32_FIND_DATA structure) I could identify the files older than a week without problems.
Thanks for your help
Martin Dietz
|
|
|
|
|
|
Hi all
I have a CObList which stores list of objects of type CMyClass. CMyClass has a CString member say m_str . This list is populated with members coming from a dll which is compiled in ANSI mode whereas the application is compiled in Unicode mode . So in the list , if i expand the member m_str of CMyClass , I can see in debug auto windows m_str->ATL::CSimpleStringT (unsigned short ,1)
if the object is Unicode . And if the object is from dll (ie ANSI)
It appears m_str->ATL::CSimpleStringT (char,0). My problem is how to retreive this difference programmatically to distinguish between ANSI objects and Unicode objects ?
I tried IsTextUnicode() but could not succeed ..may be due to wrong usage .
Could any one help me pls ?
-- modified at 5:32 Tuesday 21st November, 2006
-- modified at 5:33 Tuesday 21st November, 2006
-- modified at 5:34 Tuesday 21st November, 2006
redindian
|
|
|
|
|
Maybe this can help you:
#ifdef UNICODE
. . .
#else
. . .
#endif
|
|
|
|
|
Hi Viorel
Thanks . But my problem is to find out if a CString variable is ANSI one or Unicode one .
redindian
|
|
|
|
|
Use the IsTextUnicode() function. But see this function is not foolproof. Read what the documentation[^] says.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Not sure if it is possible, but is there a way to evaluate the String's XCHAR type at runtime? Conceptually, something like:
if( sizeof( m_str::XCHAR ) == sizeof( wchar_t ) ) { Unicode };
if( sizeof( m_str::XCHAR ) == sizeof( char ) ) { ANSI }; But I am not that familiar with the new CString classes to be able to help further.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Hi all,
First of all, I would like apologize for creating a new thread, but I'm getting desperate.
This is the scenario:
I have this structure:
<br />
static struct<br />
{<br />
int ConnectSock;
int ConnectState;
ULONG BytesTrans;
ULONG FileLength;
ULONG TimeMark;
char Request[STRING_SIZE];
char FileName[STRING_SIZE];
char PathName[STRING_SIZE];
char PCName[STRING_SIZE];
ULONG BytesRec;
} gConnectData[MAX_CONNECT];<br />
Before I populate the PCName variale, I do the following, get an open slot for the next connection:
<br />
int FindFreeSlot(void)<br />
{<br />
int i, s;<br />
for(i=0;i<MAX_CONNECT;i++)<br />
{<br />
s = gConnectData[i].ConnectSock;<br />
if(s==-1)<br />
return i;<br />
}<br />
return -1;<br />
}<br />
main()<br />
{<br />
...<br />
while(1)<br />
{<br />
i = FindFreeSlot();<br />
...<br />
}<br />
}<br />
I when populate the PCName variable of the structure with data:
Please note that the for loop is part of the while loop.
<br />
for(i=0;i<MAX_CONNECT;i++)<br />
{<br />
...<br />
strcpy((char*)gConnectData[i].PCName,(char*)strDest);<br />
...<br />
}<br />
Ok, I'll try an explain this the best I can:
The thing is that the variable i does not move in a sequence (because of the server having to know which connection it's communicating with), for instance if I print the following the output would be:
<br />
strcpy((char*)gConnectData[i].PCName,(char*)strDest);<br />
printf("\n### Connection Sock -> %d Int Value -> %2d PC NAME VALUE -> %s\n",Sock,i,(char*)gConnectData[i].PCName);<br />
Connection Sock -> 0 Int Value -> 0 PC NAME VALUE -> PCOne
next cycle
Connection Sock -> 1 Int Value -> 1 PC NAME VALUE -> PCTwo
next cycle
Connection Sock -> 1 Int Value -> 1 PC NAME VALUE -> PCOne
Does it make sense
Can anyone help??
Many thanx in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Never mind .... I got it working ....
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
anyway, keep thinking to use the <pre></pre> tags to post code samples
|
|
|
|
|
Hi!
I´m using the Windows Forms Template and found some, in my oppinion, odd behaviour. Whenever I add something like an event to a component it´s added in the header file.
Aren´t those header files just supposed to hold declarations of methods etc?
The following is a snippet of the generated code in Form1.h:
#pragma endregion<br />
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {<br />
}<br />
private: System::Void dateTimePicker1_ValueChanged(System::Object^ sender, System::EventArgs^ e) {<br />
mopped->Text = dateTimePicker1->Value.ToLongDateString();<br />
}<br />
private: System::Void dateTimePicker1_Enter(System::Object^ sender, System::EventArgs^ e) {<br />
MessageBox::Show("Das ist ein Test");<br />
}
This code doesn´t really do anything and is just an attempt to fiddle out how things work in VS Express C++.
Well I hope someone is able to understand what I mean (in respect to my germanish english) .
Thanks,
Michael
|
|
|
|
|
C++/CLI tends to put it all in the .h, which is valid C++. I believe you can move it without problem to the .cpp.
Christian Graus - C++ MVP
|
|
|
|
|
Hi all, i have a tree control in which i want to show the
popup menu when someone right clicks on item.
so that i hadled the NM_RCLICK message but the pop up menu comes
somewhere near start button!!
the code is as follows
void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
NM_TREEVIEW* pNmTreeVew = NULL;
pNmTreeVew =(NM_TREEVIEW*) pNMHDR;
if(pNmTreeVew)
{
CPoint point;
point.x = pNmTreeVew->ptDrag.x;
point.y = pNmTreeVew->ptDrag.y;/*
HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1));
if(hMenu)
{
TrackPopupMenu(hMenu,0,point.x,point.y,0,pTreeCtrl->m_hWnd,NULL);
}
}
}
What can be the problem with this code?
actually when i debugged the code it point.y shows some big value
so please tell what is the problem
Thanks and regards
Harshal
|
|
|
|
|
Hi,
it retrieves you coordinates for the screen and you need convert it to client. Use ScreenToClient method of treectrl:
void ScreenToClient(
LPPOINT lpPoint
) const;
-----------
Mila
|
|
|
|
|
I have done it this way but still it shows the menu
at same position.
|
|
|
|
|
Try GetMessagePos():
...
point = (CPoint) GetMessagePos();
tree->ScreenToClient(&point);
In my case works fine.
-----------
Mila
|
|
|
|
|
void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
CPoint ptMouse;
DWORD dwPos;
UINT nFlags;
CTreeCtrl *pTreeCtrl;
pTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE1);
{
dwPos = ::GetMessagePos();
ptMouse.x = LOWORD (dwPos);
ptMouse.y = HIWORD (dwPos);
CPoint ptAction = ptMouse;
// convert coordinates
pTreeCtrl->ScreenToClient(&ptAction);
// determine if click is on tree item
HTREEITEM hItemRClick = pTreeCtrl->HitTest(ptAction, &nFlags);
// if click is on tree item,
if (hItemRClick != NULL)
{
// set selection to right+clicked item
pTreeCtrl->SelectItem(hItemRClick);
HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1));
if(hMenu)
{
hMenu = GetSubMenu(hMenu,1);
if(hMenu)
{
TrackPopupMenu(hMenu,0,ptMouse.x,ptMouse.y,0,pTreeCtrl->m_hWnd,NULL);
}
}
}
}
*pResult = 0;
}
i have done something like this
Noe the pop up menu is poping up
but whenever i click on something it does not go to respective
handler!!
Thanks and regards
Harshal
|
|
|
|
|
I think the pNMHDR argument of your handler actually does not point to NMTREEVIEW structure. (See the documentation of NM_RCLICK in case of tree controls). But you can obtain the current cursor position using GetCursorPos function:
CPoint point;
GetCursorPosition(&point);
I hope this helps.
|
|
|
|
|
2 questions
(1)how to get difference when user loads a file from "Open file" and "Recent fil" - or, how to know if user clicks a "Recent file" rather than "Open file"?
In my app, I used a setteing (or check register) to record "recent files", I think it is not a good way.
(2)how to change maximum allowed count of "recent files"?
|
|
|
|
|
1 => the function AddToRecentFileList of the application is automatically called by the document to complete the MRU (Most Recent Files) file list
when the application open a MRU file, the function OnOpenRecentFile is called by the application class
2 => in your class application::InitInstance there's the fuction LoadStdProfileSettings(5) which is called. This define the number of MRU
|
|
|
|
|
Hi,
I have a requirement to keep an application alive even after an user logs off. i.e When the second user logs in, the applications that are opened by the first user should remain open. Is there any way to do this? As our appication would take more time to shutdown and startup we dont want to close it while log off.
Can anybody help me out in resolving this...
An another thing i dont want run my application as a service ...
Is it possible to hibernate the application and wake up when the next user logs in?
Can anybody tell me the concept of Identity Switching? Can this be employed to solve this issue?
What happens when the Switch user is being called in Windows XP? Is there any API to accomplish this task?
Platform : Windows
Thanks,
Selva
-- modified at 4:25 Tuesday 21st November, 2006
~ Selva
|
|
|
|