home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2001 December (DVD) / VPR0112A.ISO / OLS / TCL230JA95 / tcl230ja95.lzh / source.lzh / exe / pagemisc.c < prev    next >
C/C++ Source or Header  |  2001-02-17  |  7KB  |  254 lines

  1. /*-------------------------------------------
  2.   pagemisc.c
  3.   「その他」プロパティページ
  4.   KAZUBON 1997-1998
  5. ---------------------------------------------*/
  6.  
  7. #include "tclock.h"
  8.  
  9. static void OnInit(HWND hDlg);
  10. static void OnApply(HWND hDlg);
  11. static void OnDeskcal(HWND hDlg);
  12. static void OnSanshoDeskcal(HWND hDlg, WORD id);
  13.  
  14. static void OnStartup(HWND hDlg);
  15. BOOL CreateLink(LPCSTR fname, LPCSTR dstpath, LPCSTR name);
  16.  
  17. #define SendPSChanged(hDlg) SendMessage(GetParent(hDlg),PSM_CHANGED,(WPARAM)(hDlg),0)
  18.  
  19. /*------------------------------------------------
  20.  「その他」ページ用ダイアログプロシージャ
  21. --------------------------------------------------*/
  22. BOOL CALLBACK PageMiscProc(HWND hDlg, UINT message,
  23.     WPARAM wParam, LPARAM lParam)
  24. {
  25.     switch(message)
  26.     {
  27.         case WM_INITDIALOG:
  28.             OnInit(hDlg);
  29.             return TRUE;
  30.         case WM_COMMAND:
  31.         {
  32.             WORD id, code;
  33.             id = LOWORD(wParam); code = HIWORD(wParam);
  34.             // 「時計を改造しない」
  35.             if(id == IDC_NOCLOCK)
  36.             {
  37.                 g_bApplyClock = TRUE;
  38.                 SendPSChanged(hDlg);
  39.             }
  40.             // 「デスクトップカレンダーの自動更新」
  41.             else if(id == IDC_DESKCAL)
  42.                 OnDeskcal(hDlg);
  43.             // チェックボックス
  44.             else if(id == IDC_MCIWAVE || id == IDC_ONLYDATECHANGED ||
  45.                     id == IDC_RESUMESUSPEND || id == IDC_TONIKAKU || 
  46.                     id == IDC_WATCHWALL)
  47.                 SendPSChanged(hDlg);
  48.             // 何秒後に開始
  49.             else if(id == IDC_DELAYSTART && code == EN_CHANGE)
  50.                 SendPSChanged(hDlg);
  51.             // 「...」 デスクトップカレンダーの参照
  52.             else if(id == IDC_SANSHODESKCAL)
  53.                 OnSanshoDeskcal(hDlg, id);
  54.             // 「スタートアップ」にショートカットをつくる
  55.             else if(id == IDC_STARTUP)
  56.                 OnStartup(hDlg);
  57.             return TRUE;
  58.         }
  59.         case WM_NOTIFY:
  60.             switch(((NMHDR *)lParam)->code)
  61.             {
  62.                 case PSN_APPLY: OnApply(hDlg); break;
  63.                 case PSN_HELP: MyHelp(GetParent(hDlg), 6); break;
  64.             }
  65.             return TRUE;
  66.     }
  67.     return FALSE;
  68. }
  69.  
  70. /*------------------------------------------------
  71.  ページの初期化
  72. --------------------------------------------------*/
  73. void OnInit(HWND hDlg)
  74. {
  75.     char s[1024];
  76.     HFONT hfont;
  77.     
  78.     hfont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  79.     if(hfont)
  80.         SendDlgItemMessage(hDlg, IDC_COMDESKCAL,
  81.             WM_SETFONT, (WPARAM)hfont, 0);
  82.     
  83.     CheckDlgButton(hDlg, IDC_NOCLOCK,
  84.         GetMyRegLong("", "NoClock", FALSE));
  85.     
  86.     CheckDlgButton(hDlg, IDC_MCIWAVE,
  87.         GetMyRegLong("", "MCIWave", FALSE));
  88.  
  89.     SendDlgItemMessage(hDlg, IDC_SPINDELAYSTART, UDM_SETRANGE, 0,
  90.         MAKELONG(600, 0));
  91.     SendDlgItemMessage(hDlg, IDC_SPINDELAYSTART, UDM_SETPOS, 0,
  92.         (int)(short)GetMyRegLong("", "DelayStart", 0));
  93.     
  94.     CheckDlgButton(hDlg, IDC_DESKCAL,
  95.         GetMyRegLong("", "Deskcal", FALSE));
  96.     
  97.     GetRegStr(HKEY_CURRENT_USER, "Software\\Shinonon\\Deskcal",
  98.         "ExeFileName", s, 1024, "");
  99.     if(s[0] == 0) GetMyRegStr("", "DeskcalCommand", s, 1024, "");
  100.     SetDlgItemText(hDlg, IDC_COMDESKCAL, s);
  101.     
  102.     CheckDlgButton(hDlg, IDC_ONLYDATECHANGED,
  103.         GetMyRegLong("", "DeskcalOnlyDate", FALSE));
  104.     CheckDlgButton(hDlg, IDC_RESUMESUSPEND,
  105.         GetMyRegLong("", "DeskcalResumeSuspend", FALSE));
  106.     CheckDlgButton(hDlg, IDC_TONIKAKU,
  107.         GetMyRegLong("", "DeskcalTonikaku", FALSE));
  108.     CheckDlgButton(hDlg, IDC_WATCHWALL,
  109.         GetMyRegLong("", "WatchWallpaper", FALSE));
  110.     
  111.     OnDeskcal(hDlg);
  112. }
  113.  
  114. /*------------------------------------------------
  115.  更新
  116. --------------------------------------------------*/
  117. void OnApply(HWND hDlg)
  118. {
  119.     char s[1024];
  120.  
  121.     SetMyRegLong("", "NoClock", IsDlgButtonChecked(hDlg, IDC_NOCLOCK));
  122.     
  123.     SetMyRegLong("", "MCIWave", IsDlgButtonChecked(hDlg, IDC_MCIWAVE));
  124.     
  125.     SetMyRegLong("", "DelayStart",
  126.         SendDlgItemMessage(hDlg, IDC_SPINDELAYSTART, UDM_GETPOS, 0, 0));
  127.     
  128.     SetMyRegLong("", "Deskcal", IsDlgButtonChecked(hDlg, IDC_DESKCAL));
  129.     
  130.     GetDlgItemText(hDlg, IDC_COMDESKCAL, s, 1024);
  131.     SetMyRegStr("", "DeskcalCommand", s);
  132.  
  133.     SetMyRegLong("", "DeskcalOnlyDate",
  134.         IsDlgButtonChecked(hDlg, IDC_ONLYDATECHANGED));
  135.  
  136.     SetMyRegLong("", "DeskcalResumeSuspend",
  137.         IsDlgButtonChecked(hDlg, IDC_RESUMESUSPEND));
  138.  
  139.     SetMyRegLong("", "DeskcalTonikaku",
  140.         IsDlgButtonChecked(hDlg, IDC_TONIKAKU));
  141.     SetMyRegLong("", "WatchWallpaper",
  142.         IsDlgButtonChecked(hDlg, IDC_WATCHWALL));
  143.     
  144.     InitWatchWallpaper(); // deskcal.c
  145. }
  146.  
  147. /*------------------------------------------------
  148.  「デスクトップカレンダー」の自動更新
  149. --------------------------------------------------*/
  150. void OnDeskcal(HWND hDlg)
  151. {
  152.     BOOL b;
  153.     int i;
  154.     
  155.     b = IsDlgButtonChecked(hDlg, IDC_DESKCAL);
  156.     for(i = IDC_LABDESKCAL; i <= IDC_WATCHWALL; i++)
  157.         EnableDlgItem(hDlg, i, b);
  158.     SendPSChanged(hDlg);
  159. }
  160.  
  161. /*------------------------------------------------
  162.  「...」 デスクトップカレンダーの参照
  163. --------------------------------------------------*/
  164. void OnSanshoDeskcal(HWND hDlg, WORD id)
  165. {
  166.     char filter[] = "Deskcal.exe\0Deskcal.exe\0";
  167.     char deffile[MAX_PATH], fname[MAX_PATH];
  168.     HFILE hf = HFILE_ERROR;
  169.     
  170.     GetDlgItemText(hDlg, id - 1, deffile, MAX_PATH);
  171.     if(strlen(deffile) > 10 && 
  172.         strcmp(deffile + (strlen(deffile) - 10), " -OnlyDraw") == 0)
  173.         deffile[strlen(deffile) - 10] = 0;
  174.     
  175.     if(!SelectMyFile(hDlg, filter, 0, deffile, fname)) // propsheet.c
  176.         return;
  177.     
  178.     strcat(fname, " -OnlyDraw");
  179.     SetDlgItemText(hDlg, id - 1, fname);
  180.     PostMessage(hDlg, WM_NEXTDLGCTL, 1, FALSE);
  181.     SendPSChanged(hDlg);
  182. }
  183.  
  184. /*------------------------------------------------
  185.  「スタートアップ」にショートカットをつくる
  186. --------------------------------------------------*/
  187. void OnStartup(HWND hDlg)
  188. {
  189.     LPITEMIDLIST pidl;
  190.     char dstpath[MAX_PATH], myexe[MAX_PATH];
  191.  
  192.     if(SHGetSpecialFolderLocation(hDlg, CSIDL_STARTUP, &pidl) == NOERROR &&
  193.         SHGetPathFromIDList(pidl, dstpath) == TRUE)
  194.         ;
  195.     else return;
  196.     
  197.     if(MyMessageBox(hDlg, MyString(IDS_STARTUPLINK),
  198.         "TClock", MB_YESNO, MB_ICONQUESTION) != IDYES) return;
  199.  
  200.     GetModuleFileName(g_hInst, myexe, MAX_PATH);
  201.     CreateLink(myexe, dstpath, "TClock");
  202. }
  203.  
  204. /*------------------------------------------------
  205.  ショートカットの作成
  206. --------------------------------------------------*/
  207. BOOL CreateLink(LPCSTR fname, LPCSTR dstpath, LPCSTR name) 
  208. {
  209.     HRESULT hres;
  210.     IShellLink* psl;
  211.     
  212.     CoInitialize(NULL);
  213.     
  214.     hres = CoCreateInstance(&CLSID_ShellLink, NULL, 
  215.         CLSCTX_INPROC_SERVER, &IID_IShellLink, &psl); 
  216.     if(SUCCEEDED(hres))
  217.     {
  218.         IPersistFile* ppf;
  219.         char path[MAX_PATH];
  220.         
  221. /*        path[0] = '\"';
  222.         strcpy(path+1, fname);
  223.         strcat(path, "\"");*/
  224.         psl->lpVtbl->SetPath(psl, fname);
  225.         psl->lpVtbl->SetDescription(psl, name);
  226.         strcpy(path, fname);
  227.         del_title(path);
  228.         psl->lpVtbl->SetWorkingDirectory(psl, path);
  229.         
  230.         hres = psl->lpVtbl->QueryInterface(psl, &IID_IPersistFile,
  231.             &ppf);
  232.         
  233.         if(SUCCEEDED(hres))
  234.         {
  235.             WORD wsz[MAX_PATH]; 
  236.             char lnkfile[MAX_PATH];
  237.             strcpy(lnkfile, dstpath);
  238.             add_title(lnkfile, (char*)name);
  239.             strcat(lnkfile, ".lnk");
  240.             
  241.             MultiByteToWideChar(CP_ACP, 0, lnkfile, -1,
  242.                 wsz, MAX_PATH);
  243.             
  244.             hres = ppf->lpVtbl->Save(ppf, wsz, TRUE);
  245.             ppf->lpVtbl->Release(ppf);
  246.         }
  247.         psl->lpVtbl->Release(psl);
  248.     }
  249.     CoUninitialize();
  250.     
  251.     if(SUCCEEDED(hres)) return TRUE;
  252.     else return FALSE;
  253. }
  254.