tags:

views:

51

answers:

1

I have a win32 API application in visual c++ in which I want to save recently viewed or opened folder to a log file. I have a code which stores the current window open to a log file. The code for current window opened is as following. Can this code be manipulated to create log file for recently viewed folder.

static TCHAR wndText[100];
    TCHAR tempWndText[100];
    TCHAR timestamp[255];
    DWORD written;
    time_t t=time(0);
    ctime_s(timestamp,sizeof(timestamp),&t); 
    SetFilePointer(_Wfile,0,NULL,FILE_END);
    TCHAR buf[255];
    wsprintf(buf,"\r\n-->%s\r\n",timestamp);
WriteFile(_Wfile,buf,(DWORD)lstrlen(buf)*sizeof(TCHAR),&written,NULL);

while(1)
{
 Sleep(5);  
 flush();
 hWndCurWnd=GetForegroundWindow();
 GetWindowText(hWndCurWnd,tempWndText,100);
 if(_Wfile==INVALID_HANDLE_VALUE)
 {
  return;
 }

 if(lstrcmp(tempWndText,wndText)!=0)
 {
  lstrcpyn(wndText,tempWndText,255);
  wsprintf(buf,"\r[%s]\r\n",wndText);
  WriteFile(_Wfile,buf,(DWORD)lstrlen(buf)*sizeof(TCHAR),&written,NULL);
 }

}
+1  A: 

Raymon Chen covers how to decide:

  1. Whether a window is an Explorer window, and if so

  2. What folder it is viewing?

in his blog here:

http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx

atomice