home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 December (DVD) / VPR0112A.ISO / OLS / TCL230JA95 / tcl230ja95.lzh / source.lzh / exe / deskcal.c < prev    next >
C/C++ Source or Header  |  2001-02-04  |  5KB  |  188 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.     GetRegStr(HKEY_CURRENT_USER, "Software\\Shinonon\\Deskcal",
  39.         "ExeFileName", s, 1024, "");
  40.     if(s[0] == 0)
  41.     {
  42.         GetMyRegStr("", "DeskcalCommand", s, 1024, "");
  43.         if(s[0] == 0) return TRUE;
  44.     }
  45.     
  46.     if(s[0] != '\"')
  47.     {
  48.         GetFileAndOption(s, fname, option);
  49.         s[0] = '\"'; strcpy(s + 1, fname);
  50.         strcat(s, "\" "); strcat(s, option);
  51.     }
  52.     
  53.     memset(&si, 0, sizeof(si));
  54.     si.cb = sizeof(si);
  55.     
  56.     hProcessDeskcal = NULL;
  57.     if(!CreateProcess(NULL, s, NULL, NULL, FALSE, 0,
  58.         NULL, NULL, &si, &pi))
  59.     {
  60.         return TRUE;
  61.     }
  62.     hProcessDeskcal = pi.hProcess;
  63.     
  64.     InitWatchWallpaper();
  65.     
  66.     return TRUE;
  67. }
  68.  
  69. /*------------------------------------------------
  70.   If screensaver is running
  71. --------------------------------------------------*/
  72. BOOL ScreenSaverExist(void)
  73. {
  74.     HWND hwnd;
  75.     RECT rc;
  76.     char s[80];
  77.     
  78.     hwnd = GetForegroundWindow();
  79.     if(!hwnd) return FALSE;
  80.  
  81.     GetWindowRect(hwnd, &rc);
  82.     if(rc.left <= 0 && rc.top <= 0 &&
  83.         rc.right >= GetSystemMetrics(SM_CXSCREEN) &&
  84.         rc.bottom >= GetSystemMetrics(SM_CYSCREEN))
  85.     {
  86.         GetClassName(hwnd, s, 80);
  87.         if(strcmp(s, "Progman") != 0 &&
  88.             strcmp(s, "DeskSaysNoPeekingItsASurprise") != 0)
  89.             return TRUE;
  90.     }
  91.     return FALSE;
  92. }
  93.  
  94. /*----------------------------------------
  95.    Watch the wallpaper file
  96. ----------------------------------------*/
  97.  
  98. static BOOL bWatchWallpaper = FALSE;
  99. static char* wallpapername = NULL;
  100. static int tilewallpaper, wallpaperstyle;
  101. static WIN32_FIND_DATA fd_wallpaper;
  102. static int hourLast = -1, minuteLast = -1;
  103. static DWORD colorbackground;
  104.  
  105. void InitWatchWallpaper(void)
  106. {
  107.     char s[30];
  108.     char section[] = "Control Panel\\desktop";
  109.     HANDLE hfind;
  110.     
  111.     EndWatchWallpaper();
  112.     
  113.     bWatchWallpaper = GetMyRegLong(NULL, "WatchWallpaper", FALSE);
  114.     if(!bWatchWallpaper) return;
  115.     
  116.     wallpapername = (char*)malloc(MAX_PATH);
  117.     GetRegStr(HKEY_CURRENT_USER, section, "Wallpaper",
  118.         wallpapername, MAX_PATH, "");
  119.     
  120.     GetRegStr(HKEY_CURRENT_USER, section, "TileWallpaper", s, 30, "0");
  121.     tilewallpaper = atoi(s);
  122.     GetRegStr(HKEY_CURRENT_USER, section, "WallpaperStyle", s, 30, "0");
  123.     wallpaperstyle = atoi(s);
  124.     
  125.     colorbackground = GetSysColor(COLOR_BACKGROUND);
  126.     
  127.     if(wallpapername[0])
  128.     {
  129.         hfind = FindFirstFile(wallpapername, &fd_wallpaper);
  130.         if(hfind != INVALID_HANDLE_VALUE)
  131.             FindClose(hfind);
  132.     }
  133. }
  134.  
  135. void EndWatchWallpaper(void)
  136. {
  137.     if(wallpapername) free(wallpapername);
  138.     wallpapername = NULL;
  139. }
  140.  
  141. void CheckWallpaper(HWND hwnd, SYSTEMTIME* pt)
  142. {
  143.     char section[] = "Control Panel\\desktop";
  144.     char s[30], fname[MAX_PATH];
  145.     WIN32_FIND_DATA fd;
  146.     HANDLE hfind;
  147.     BOOL b;
  148.     
  149.     if(!bWatchWallpaper || !wallpapername) return;
  150.     
  151.     if(hourLast == (int)pt->wHour &&
  152.         minuteLast == (int)pt->wMinute) return;
  153.     hourLast = pt->wHour; minuteLast = pt->wMinute;
  154.     
  155.     if(FindWindow("TDeskcalForm", NULL)) return;
  156.     
  157.     b = FALSE;
  158.     GetRegStr(HKEY_CURRENT_USER, section, "Wallpaper", fname, MAX_PATH, "");
  159.     if(strcmp(fname, wallpapername) != 0) b = TRUE;
  160.     GetRegStr(HKEY_CURRENT_USER, section, "TileWallpaper", s, 30, "0");
  161.     if(tilewallpaper != atoi(s)) b = TRUE;
  162.     GetRegStr(HKEY_CURRENT_USER, section, "WallpaperStyle", s, 30, "0");
  163.     if(wallpaperstyle != atoi(s)) b = TRUE;
  164.     
  165.     if(colorbackground != GetSysColor(COLOR_BACKGROUND))
  166.         b = TRUE;
  167.     
  168.     if(!b && fname[0])
  169.     {
  170.         hfind = FindFirstFile(wallpapername, &fd);
  171.         if(hfind != INVALID_HANDLE_VALUE)
  172.         {
  173.             FindClose(hfind);
  174.             if(fd.nFileSizeLow != fd_wallpaper.nFileSizeLow ||
  175.                 *(DWORDLONG*)&(fd.ftCreationTime) != 
  176.                     *(DWORDLONG*)&(fd_wallpaper.ftCreationTime) ||
  177.                 *(DWORDLONG*)&(fd.ftLastWriteTime) != 
  178.                     *(DWORDLONG*)&(fd_wallpaper.ftLastWriteTime) )
  179.             {
  180.                 b = TRUE;
  181.             }
  182.         }
  183.     }
  184.     
  185.     if(b) ExecDeskcal(hwnd);
  186. }
  187.  
  188.