home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 June / VPR0106A.BIN / OLS / TCL228 / TCL228.lzh / EXESRC.lzh / deskcal.c < prev    next >
C/C++ Source or Header  |  1999-09-18  |  5KB  |  187 lines

  1. /*-------------------------------------------
  2.   deskcal.c
  3.     Update Desktop Calendar automatically
  4.     KAZUBON 1997-1999
  5. ---------------------------------------------*/
  6.  
  7. #include "tclock.h"
  8.  
  9. BOOL ScreenSaverExist(void);
  10. static HANDLE hProcessDeskcal = NULL;
  11.  
  12. /*------------------------------------------------
  13.   Execute Deskcal.exe
  14. --------------------------------------------------*/
  15. BOOL ExecDeskcal(HWND hwnd)
  16. {
  17.     char s[1024];
  18.     char fname[MAX_PATH], option[MAX_PATH];
  19.     STARTUPINFO si;
  20.     PROCESS_INFORMATION pi;
  21.     
  22.     if(GetMyRegLong("", "Deskcal", FALSE) == FALSE) return TRUE;
  23.     
  24.     if(hProcessDeskcal)
  25.     {
  26.         DWORD dwExitCode;
  27.         if(GetExitCodeProcess(hProcessDeskcal, &dwExitCode) &&
  28.             dwExitCode == STILL_ACTIVE)
  29.         {
  30.             return TRUE;
  31.         }
  32.     }
  33.     
  34.     if(FindWindow("TDeskcalForm", NULL)) return TRUE;
  35.     
  36.     if(ScreenSaverExist()) return FALSE;
  37.     
  38.     if(GetRegStr(HKEY_CURRENT_USER, "Software\\Shinonon\\Deskcal",
  39.         "ExeFileName", s, 1024, "") == 0)
  40.     {
  41.         if(GetMyRegStr("", "DeskcalCommand", s, 1024, "") == 0)
  42.             return TRUE;
  43.     }
  44.     
  45.     if(s[0] != '\"')
  46.     {
  47.         GetFileAndOption(s, fname, option);
  48.         s[0] = '\"'; strcpy(s + 1, fname);
  49.         strcat(s, "\" "); strcat(s, option);
  50.     }
  51.     
  52.     memset(&si, 0, sizeof(si));
  53.     si.cb = sizeof(si);
  54.     
  55.     hProcessDeskcal = NULL;
  56.     if(!CreateProcess(NULL, s, NULL, NULL, FALSE, 0,
  57.         NULL, NULL, &si, &pi))
  58.     {
  59.         return TRUE;
  60.     }
  61.     hProcessDeskcal = pi.hProcess;
  62.     
  63.     InitWatchWallpaper();
  64.     
  65.     return TRUE;
  66. }
  67.  
  68. /*------------------------------------------------
  69.   If screensaver is running
  70. --------------------------------------------------*/
  71. BOOL ScreenSaverExist(void)
  72. {
  73.     HWND hwnd;
  74.     RECT rc;
  75.     char s[80];
  76.     
  77.     hwnd = GetForegroundWindow();
  78.     if(!hwnd) return FALSE;
  79.  
  80.     GetWindowRect(hwnd, &rc);
  81.     if(rc.left <= 0 && rc.top <= 0 &&
  82.         rc.right >= GetSystemMetrics(SM_CXSCREEN) &&
  83.         rc.bottom >= GetSystemMetrics(SM_CYSCREEN))
  84.     {
  85.         GetClassName(hwnd, s, 80);
  86.         if(strcmp(s, "Progman") != 0 &&
  87.             strcmp(s, "DeskSaysNoPeekingItsASurprise") != 0)
  88.             return TRUE;
  89.     }
  90.     return FALSE;
  91. }
  92.  
  93. /*----------------------------------------
  94.    Watch the wallpaper file
  95. ----------------------------------------*/
  96.  
  97. static BOOL bWatchWallpaper = FALSE;
  98. static char* wallpapername = NULL;
  99. static int tilewallpaper, wallpaperstyle;
  100. static WIN32_FIND_DATA fd_wallpaper;
  101. static int hourLast = -1, minuteLast = -1;
  102. static DWORD colorbackground;
  103.  
  104. void InitWatchWallpaper(void)
  105. {
  106.     char s[30];
  107.     char section[] = "Control Panel\\desktop";
  108.     HANDLE hfind;
  109.     
  110.     EndWatchWallpaper();
  111.     
  112.     bWatchWallpaper = GetMyRegLong(NULL, "WatchWallpaper", FALSE);
  113.     if(!bWatchWallpaper) return;
  114.     
  115.     wallpapername = (char*)malloc(MAX_PATH);
  116.     GetRegStr(HKEY_CURRENT_USER, section, "Wallpaper",
  117.         wallpapername, MAX_PATH, "");
  118.     
  119.     GetRegStr(HKEY_CURRENT_USER, section, "TileWallpaper", s, 30, "0");
  120.     tilewallpaper = atoi(s);
  121.     GetRegStr(HKEY_CURRENT_USER, section, "WallpaperStyle", s, 30, "0");
  122.     wallpaperstyle = atoi(s);
  123.     
  124.     colorbackground = GetSysColor(COLOR_BACKGROUND);
  125.     
  126.     if(wallpapername[0])
  127.     {
  128.         hfind = FindFirstFile(wallpapername, &fd_wallpaper);
  129.         if(hfind != INVALID_HANDLE_VALUE)
  130.             FindClose(hfind);
  131.     }
  132. }
  133.  
  134. void EndWatchWallpaper(void)
  135. {
  136.     if(wallpapername) free(wallpapername);
  137.     wallpapername = NULL;
  138. }
  139.  
  140. void CheckWallpaper(HWND hwnd, SYSTEMTIME* pt)
  141. {
  142.     char section[] = "Control Panel\\desktop";
  143.     char s[30], fname[MAX_PATH];
  144.     WIN32_FIND_DATA fd;
  145.     HANDLE hfind;
  146.     BOOL b;
  147.     
  148.     if(!bWatchWallpaper || !wallpapername) return;
  149.     
  150.     if(hourLast == (int)pt->wHour &&
  151.         minuteLast == (int)pt->wMinute) return;
  152.     hourLast = pt->wHour; minuteLast = pt->wMinute;
  153.     
  154.     if(FindWindow("TDeskcalForm", NULL)) return;
  155.     
  156.     b = FALSE;
  157.     GetRegStr(HKEY_CURRENT_USER, section, "Wallpaper", fname, MAX_PATH, "");
  158.     if(strcmp(fname, wallpapername) != 0) b = TRUE;
  159.     GetRegStr(HKEY_CURRENT_USER, section, "TileWallpaper", s, 30, "0");
  160.     if(tilewallpaper != atoi(s)) b = TRUE;
  161.     GetRegStr(HKEY_CURRENT_USER, section, "WallpaperStyle", s, 30, "0");
  162.     if(wallpaperstyle != atoi(s)) b = TRUE;
  163.     
  164.     if(colorbackground != GetSysColor(COLOR_BACKGROUND))
  165.         b = TRUE;
  166.     
  167.     if(!b && fname[0])
  168.     {
  169.         hfind = FindFirstFile(wallpapername, &fd);
  170.         if(hfind != INVALID_HANDLE_VALUE)
  171.         {
  172.             FindClose(hfind);
  173.             if(fd.nFileSizeLow != fd_wallpaper.nFileSizeLow ||
  174.                 *(DWORDLONG*)&(fd.ftCreationTime) != 
  175.                     *(DWORDLONG*)&(fd_wallpaper.ftCreationTime) ||
  176.                 *(DWORDLONG*)&(fd.ftLastWriteTime) != 
  177.                     *(DWORDLONG*)&(fd_wallpaper.ftLastWriteTime) )
  178.             {
  179.                 b = TRUE;
  180.             }
  181.         }
  182.     }
  183.     
  184.     if(b) ExecDeskcal(hwnd);
  185. }
  186.  
  187.