home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2003 August / VPR0308.ISO / OLS / TAR32_1-20001226-140023 / tar32_1-20001226-140023.lzh / tar32_1 / Src / SRC / DLGCONF.C < prev    next >
C/C++ Source or Header  |  2000-12-26  |  6KB  |  168 lines

  1. /* dlgconf.c */
  2. /* 設定ダイアログ関係 */
  3. #include "defconf.h"
  4. #include "main.h"
  5. #include "resource.h"
  6. #include "version.h"
  7. #include "gzip.h"
  8. #include "tar32.h"
  9.  
  10. #include <windows.h>
  11. #include <commctrl.h>
  12.  
  13. extern HWND api_hwnd;
  14.  
  15. static HKEY *tar32_registry_root=HKEY_CURRENT_USER;
  16. static char *tar32_registry_key_name="Software\\ArchiverDLL\\TAR32";
  17.  
  18.  
  19. /* レジストリ情報の取得(HKEY_CURRENT_USER\Software\ArchiverDLL\TAR32) */
  20. int load_registry_info(void)
  21. {
  22.     HKEY hKey;
  23.     DWORD dwData;
  24.     DWORD size;
  25.  
  26.     if(RegOpenKey(tar32_registry_root,tar32_registry_key_name,&hKey)!=0){return -1;}
  27.     
  28.     
  29.     if(RegQueryValueEx(hKey,"GzipLevel",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
  30.         DefaultGzipLevel = dwData;
  31.     }
  32.     if(RegQueryValueEx(hKey,"BzipLevel",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
  33.         DefaultBzipLevel = dwData;
  34.     }
  35.     if(RegQueryValueEx(hKey,"CompressAttributeType",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
  36.         attri_flag=dwData;
  37.     }
  38.     if(RegQueryValueEx(hKey,"GnuHeader",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
  39.         Gflag=(bool)dwData;
  40.     }
  41.     if(RegQueryValueEx(hKey,"DisplayDialog",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
  42.         OPTION_display_dialog=(bool)dwData;
  43.     }
  44.  
  45.     RegQueryValueEx(hKey,"NkfSetFilenameConversion",NULL,NULL,(BYTE *)OPTION_nkf_set_filename_conversion,(size=20,&size));
  46.     RegQueryValueEx(hKey,"NkfGetFilenameConversion",NULL,NULL,(BYTE *)OPTION_nkf_get_filename_conversion,(size=20,&size));
  47.     
  48.     RegCloseKey(hKey);
  49.     return 0;
  50. }
  51. int save_registry_info(void)
  52. {
  53.     HKEY hKey;
  54.     DWORD dwData;
  55.     int version=TarGetVersion();
  56.  
  57.     if(RegCreateKey(tar32_registry_root,tar32_registry_key_name,&hKey)!=0){return -1;}
  58.  
  59.     if(RegSetValueEx(hKey,"Version",0,REG_DWORD,(BYTE *)&version,sizeof(DWORD))!=0){return -1;}
  60.  
  61.     if(RegSetValueEx(hKey,"GzipLevel",0,REG_DWORD,(BYTE *)&DefaultGzipLevel,sizeof(DWORD))!=0){return -1;}
  62.     if(RegSetValueEx(hKey,"BzipLevel",0,REG_DWORD,(BYTE *)&DefaultBzipLevel,sizeof(DWORD))!=0){return -1;}
  63.     if(RegSetValueEx(hKey,"CompressAttributeType",0,REG_DWORD,(BYTE *)&attri_flag,sizeof(DWORD))!=0){return -1;}
  64.     dwData=Gflag;    // Gflagはbool型(=char)なので、とりあえずDWORD(=int)に変換する
  65.     if(RegSetValueEx(hKey,"GnuHeader",0,REG_DWORD,(BYTE *)&dwData,sizeof(DWORD))!=0){return -1;}
  66.     dwData=OPTION_display_dialog;
  67.     if(RegSetValueEx(hKey,"DisplayDialog",0,REG_DWORD,(BYTE *)&dwData,sizeof(DWORD))!=0){return -1;}
  68.  
  69.     if(RegSetValueEx(hKey,"NkfSetFilenameConversion",0,REG_SZ,OPTION_nkf_set_filename_conversion,0)!=0){return -1;}
  70.     if(RegSetValueEx(hKey,"NkfGetFilenameConversion",0,REG_SZ,OPTION_nkf_get_filename_conversion,0)!=0){return -1;}
  71.  
  72.  
  73.     RegCloseKey(hKey);
  74.     return 0;
  75. }
  76.  
  77.  
  78. static void get_config_dialog(HWND hwnd)
  79. {
  80.     int attr=0;
  81.  
  82.     DefaultGzipLevel=SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_GETPOS,0,0);
  83.     DefaultBzipLevel=SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_GETPOS,0,0);
  84.  
  85.     attr |=  SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_HIDDEN,BM_GETCHECK,0,0) ? FILE_ATTRIBUTE_HIDDEN : 0 ;
  86.     attr |=  SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_SYSTEM,BM_GETCHECK,0,0) ? FILE_ATTRIBUTE_SYSTEM : 0 ;
  87.     attri_flag=attr;
  88.     Gflag=(bool)SendDlgItemMessage(hwnd,IDC_CHECK_GNUHEADER,BM_GETCHECK,0,0);
  89.     OPTION_display_dialog=(bool)SendDlgItemMessage(hwnd,IDC_CHECK_DISPLAY_DIALOG,BM_GETCHECK,0,0);
  90.     
  91.     GetDlgItemText(hwnd,IDC_EDIT_NKF_SET_FILENAME_CONVERSION,OPTION_nkf_set_filename_conversion,20);
  92.     GetDlgItemText(hwnd,IDC_EDIT_NKF_GET_FILENAME_CONVERSION,OPTION_nkf_get_filename_conversion,20);
  93. }
  94. static void set_config_dialog(HWND hwnd)
  95. {
  96.     char verstr[100];
  97.     int ver;
  98.  
  99.  
  100.     ver = TarGetVersion();
  101.     sprintf(verstr,"%d.%02d",ver/100,ver%100);
  102.     SetDlgItemText(hwnd,IDC_EDIT_VERSION,verstr);
  103.     
  104.     SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_SETRANGE,0,MAKELONG(1,9));
  105.     SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_SETPOS,1,DefaultGzipLevel);
  106.     SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_SETRANGE,0,MAKELONG(1,9));
  107.     SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_SETPOS,1,DefaultBzipLevel);
  108.  
  109.     SetDlgItemInt(hwnd,IDC_EDIT_GZIP_LEVEL,level,1);
  110.     SetDlgItemInt(hwnd,IDC_EDIT_BZIP_LEVEL,DefaultBzipLevel,1);
  111.  
  112.     SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_HIDDEN,BM_SETCHECK,(attri_flag & FILE_ATTRIBUTE_HIDDEN)>0,0);
  113.     SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_SYSTEM,BM_SETCHECK,(attri_flag & FILE_ATTRIBUTE_SYSTEM)>0,0);
  114.  
  115.     SendDlgItemMessage(hwnd,IDC_CHECK_GNUHEADER,BM_SETCHECK,Gflag,0);
  116.     SendDlgItemMessage(hwnd,IDC_CHECK_DISPLAY_DIALOG,BM_SETCHECK,OPTION_display_dialog,0);
  117.  
  118.     SetDlgItemText(hwnd,IDC_EDIT_NKF_SET_FILENAME_CONVERSION,OPTION_nkf_set_filename_conversion);
  119.     SetDlgItemText(hwnd,IDC_EDIT_NKF_GET_FILENAME_CONVERSION,OPTION_nkf_get_filename_conversion);
  120. }
  121. static BOOL CALLBACK config_dialog_func(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
  122. {
  123.     switch(message){
  124.     case WM_COMMAND:
  125.         switch(LOWORD(wParam)){
  126.         case IDOK:
  127.             get_config_dialog(hwnd);
  128.             if(save_registry_info()==-1){
  129.                 MessageBox(api_hwnd,"エラー:レジストリの保存ができませんでした。", "TAR32.DLL",0);
  130.             }
  131.             EndDialog(hwnd,0);
  132.             break;
  133.         case IDCANCEL:
  134.             EndDialog(hwnd,0);
  135.             break;
  136.         }
  137.         break;
  138.     case WM_HSCROLL:
  139.         if((HWND)lParam==GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL)){
  140.             SetDlgItemInt(hwnd,IDC_EDIT_GZIP_LEVEL,SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_GETPOS,0,0),1);
  141.         }
  142.         if((HWND)lParam==GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL)){
  143.             SetDlgItemInt(hwnd,IDC_EDIT_BZIP_LEVEL,SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_GETPOS,0,0),1);
  144.         }
  145.         break;
  146.     case WM_DESTROY:
  147.         EndDialog(hwnd,0);
  148.         return 1;
  149.         break;
  150.     case WM_INITDIALOG:
  151.         set_config_dialog(hwnd);
  152.         break;
  153.     }
  154.     return 0;
  155. }
  156. int config_dialog(const HWND hwnd, LPSTR lpszComBuffer,const int iMode)
  157. {
  158.     int ret;
  159.     extern HINSTANCE application_instance;
  160.  
  161.     ret=DialogBox(application_instance,MAKEINTRESOURCE(IDD_DIALOG_CONFIG),api_hwnd,(DLGPROC)config_dialog_func);
  162.     if(ret==-1){
  163.         MessageBox(api_hwnd,"Can't Display DialogBox", "TAR32.DLL",0);
  164.         return 0;
  165.     }
  166.     return 1;
  167. }
  168.