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 >
Wrap
C/C++ Source or Header
|
2000-12-26
|
6KB
|
168 lines
/* dlgconf.c */
/* 設定ダイアログ関係 */
#include "defconf.h"
#include "main.h"
#include "resource.h"
#include "version.h"
#include "gzip.h"
#include "tar32.h"
#include <windows.h>
#include <commctrl.h>
extern HWND api_hwnd;
static HKEY *tar32_registry_root=HKEY_CURRENT_USER;
static char *tar32_registry_key_name="Software\\ArchiverDLL\\TAR32";
/* レジストリ情報の取得(HKEY_CURRENT_USER\Software\ArchiverDLL\TAR32) */
int load_registry_info(void)
{
HKEY hKey;
DWORD dwData;
DWORD size;
if(RegOpenKey(tar32_registry_root,tar32_registry_key_name,&hKey)!=0){return -1;}
if(RegQueryValueEx(hKey,"GzipLevel",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
DefaultGzipLevel = dwData;
}
if(RegQueryValueEx(hKey,"BzipLevel",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
DefaultBzipLevel = dwData;
}
if(RegQueryValueEx(hKey,"CompressAttributeType",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
attri_flag=dwData;
}
if(RegQueryValueEx(hKey,"GnuHeader",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
Gflag=(bool)dwData;
}
if(RegQueryValueEx(hKey,"DisplayDialog",NULL,NULL,(BYTE *)&dwData,(size=sizeof(DWORD),&size))==0){
OPTION_display_dialog=(bool)dwData;
}
RegQueryValueEx(hKey,"NkfSetFilenameConversion",NULL,NULL,(BYTE *)OPTION_nkf_set_filename_conversion,(size=20,&size));
RegQueryValueEx(hKey,"NkfGetFilenameConversion",NULL,NULL,(BYTE *)OPTION_nkf_get_filename_conversion,(size=20,&size));
RegCloseKey(hKey);
return 0;
}
int save_registry_info(void)
{
HKEY hKey;
DWORD dwData;
int version=TarGetVersion();
if(RegCreateKey(tar32_registry_root,tar32_registry_key_name,&hKey)!=0){return -1;}
if(RegSetValueEx(hKey,"Version",0,REG_DWORD,(BYTE *)&version,sizeof(DWORD))!=0){return -1;}
if(RegSetValueEx(hKey,"GzipLevel",0,REG_DWORD,(BYTE *)&DefaultGzipLevel,sizeof(DWORD))!=0){return -1;}
if(RegSetValueEx(hKey,"BzipLevel",0,REG_DWORD,(BYTE *)&DefaultBzipLevel,sizeof(DWORD))!=0){return -1;}
if(RegSetValueEx(hKey,"CompressAttributeType",0,REG_DWORD,(BYTE *)&attri_flag,sizeof(DWORD))!=0){return -1;}
dwData=Gflag; // Gflagはbool型(=char)なので、とりあえずDWORD(=int)に変換する
if(RegSetValueEx(hKey,"GnuHeader",0,REG_DWORD,(BYTE *)&dwData,sizeof(DWORD))!=0){return -1;}
dwData=OPTION_display_dialog;
if(RegSetValueEx(hKey,"DisplayDialog",0,REG_DWORD,(BYTE *)&dwData,sizeof(DWORD))!=0){return -1;}
if(RegSetValueEx(hKey,"NkfSetFilenameConversion",0,REG_SZ,OPTION_nkf_set_filename_conversion,0)!=0){return -1;}
if(RegSetValueEx(hKey,"NkfGetFilenameConversion",0,REG_SZ,OPTION_nkf_get_filename_conversion,0)!=0){return -1;}
RegCloseKey(hKey);
return 0;
}
static void get_config_dialog(HWND hwnd)
{
int attr=0;
DefaultGzipLevel=SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_GETPOS,0,0);
DefaultBzipLevel=SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_GETPOS,0,0);
attr |= SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_HIDDEN,BM_GETCHECK,0,0) ? FILE_ATTRIBUTE_HIDDEN : 0 ;
attr |= SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_SYSTEM,BM_GETCHECK,0,0) ? FILE_ATTRIBUTE_SYSTEM : 0 ;
attri_flag=attr;
Gflag=(bool)SendDlgItemMessage(hwnd,IDC_CHECK_GNUHEADER,BM_GETCHECK,0,0);
OPTION_display_dialog=(bool)SendDlgItemMessage(hwnd,IDC_CHECK_DISPLAY_DIALOG,BM_GETCHECK,0,0);
GetDlgItemText(hwnd,IDC_EDIT_NKF_SET_FILENAME_CONVERSION,OPTION_nkf_set_filename_conversion,20);
GetDlgItemText(hwnd,IDC_EDIT_NKF_GET_FILENAME_CONVERSION,OPTION_nkf_get_filename_conversion,20);
}
static void set_config_dialog(HWND hwnd)
{
char verstr[100];
int ver;
ver = TarGetVersion();
sprintf(verstr,"%d.%02d",ver/100,ver%100);
SetDlgItemText(hwnd,IDC_EDIT_VERSION,verstr);
SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_SETRANGE,0,MAKELONG(1,9));
SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_SETPOS,1,DefaultGzipLevel);
SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_SETRANGE,0,MAKELONG(1,9));
SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_SETPOS,1,DefaultBzipLevel);
SetDlgItemInt(hwnd,IDC_EDIT_GZIP_LEVEL,level,1);
SetDlgItemInt(hwnd,IDC_EDIT_BZIP_LEVEL,DefaultBzipLevel,1);
SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_HIDDEN,BM_SETCHECK,(attri_flag & FILE_ATTRIBUTE_HIDDEN)>0,0);
SendDlgItemMessage(hwnd,IDC_CHECK_ATTRIBUTE_SYSTEM,BM_SETCHECK,(attri_flag & FILE_ATTRIBUTE_SYSTEM)>0,0);
SendDlgItemMessage(hwnd,IDC_CHECK_GNUHEADER,BM_SETCHECK,Gflag,0);
SendDlgItemMessage(hwnd,IDC_CHECK_DISPLAY_DIALOG,BM_SETCHECK,OPTION_display_dialog,0);
SetDlgItemText(hwnd,IDC_EDIT_NKF_SET_FILENAME_CONVERSION,OPTION_nkf_set_filename_conversion);
SetDlgItemText(hwnd,IDC_EDIT_NKF_GET_FILENAME_CONVERSION,OPTION_nkf_get_filename_conversion);
}
static BOOL CALLBACK config_dialog_func(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message){
case WM_COMMAND:
switch(LOWORD(wParam)){
case IDOK:
get_config_dialog(hwnd);
if(save_registry_info()==-1){
MessageBox(api_hwnd,"エラー:レジストリの保存ができませんでした。", "TAR32.DLL",0);
}
EndDialog(hwnd,0);
break;
case IDCANCEL:
EndDialog(hwnd,0);
break;
}
break;
case WM_HSCROLL:
if((HWND)lParam==GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL)){
SetDlgItemInt(hwnd,IDC_EDIT_GZIP_LEVEL,SendMessage(GetDlgItem(hwnd,IDC_SLIDER_GZIP_LEVEL),TBM_GETPOS,0,0),1);
}
if((HWND)lParam==GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL)){
SetDlgItemInt(hwnd,IDC_EDIT_BZIP_LEVEL,SendMessage(GetDlgItem(hwnd,IDC_SLIDER_BZIP_LEVEL),TBM_GETPOS,0,0),1);
}
break;
case WM_DESTROY:
EndDialog(hwnd,0);
return 1;
break;
case WM_INITDIALOG:
set_config_dialog(hwnd);
break;
}
return 0;
}
int config_dialog(const HWND hwnd, LPSTR lpszComBuffer,const int iMode)
{
int ret;
extern HINSTANCE application_instance;
ret=DialogBox(application_instance,MAKEINTRESOURCE(IDD_DIALOG_CONFIG),api_hwnd,(DLGPROC)config_dialog_func);
if(ret==-1){
MessageBox(api_hwnd,"Can't Display DialogBox", "TAR32.DLL",0);
return 0;
}
return 1;
}