/*-------------------------------------- ; http://www.setsuki.com/ ;--------------------------------------- ; 使用例)拡張ダイアログ #include "dialog.as" extdialog "画像の更新を保存しますか?", MB_YESNOCANCEL, "タイトル" if( stat == 2 ): dialog "「キャンセル」が押されました" if( stat == 6 ): dialog "「はい」が押されました" if( stat == 7 ): dialog "「いいえ」が押されました" ;-------------------------------------- ; 使用例)ファイル選択ダイアログ filt = "ICOファイル(*.ico)|*.ico|" filt += "EXEファイル(*.exe;*.dll)|*.exe;*.dll|" filt += "すべてのファイル|*.*" ; ファイル選択ダイアログ opendialog filt,"", 2 : if( stat == -1 ) : end index = stat : file = refstr ;-------------------------------------- ; 使用例)アイコン選択ダイアログ file = dir_sys+"\\SHELL32.DLL" ; アイコン選択ダイアログ icondialog file : if( stat = -1 ) : end index = stat dialog getpath(file,8)+" の "+index+" 番目のアイコンを選択しました。" ;-------------------------------------- ; 使用例)フォント選択ダイアログ font "MS ゴシック", 15 mes "AaBbYyZz Aaあぁアァ亜宇" ; フォント選択ダイアログ fontdialog : if( stat = -1 ) : end mes "AaBbYyZz Aaあぁアァ亜宇" ;-------------------------------------- ; 使用例)フォルダ選択ダイアログ dirdialog "フォルダを選択してください", dir_exe : if( stat == -1 ) : end dialog ""+refstr+" が選択されました。" -------------------------------------*/ ; [[[ サイズ減少用 ]]] 使用しないダイアログは、0 を指定 #define global extdialog_flag 1 ;拡張ダイアログ #define global filedialog_flag 1 ;ファイル選択ダイアログ #define global icondialog_flag 1 ;アイコン選択ダイアログ #define global fontdialog_flag 1 ;フォント選択ダイアログ #define global dirdialog_flag 1 ;フォルダ選択ダイアログ ; [[[ 注意事項 ]]] ; フォルダ選択ダイアログのコールバック変数の著作は さくらさん にあります。 ; http://www.silkroad.ne.jp/sakura/ #ifdef __hsp30__ #ifndef __COMDLG32__ #define global __COMDLG32__ #uselib "COMDLG32.DLL" #func global GetOpenFileName "GetOpenFileNameA" sptr #func global GetSaveFileName "GetSaveFileNameA" sptr #func global ChooseFont "ChooseFontA" sptr #endif #ifndef __KERNEL32__ #define global __KERNEL32__ #uselib "KERNEL32.DLL" #func global GetProcAddress "GetProcAddress" sptr,sptr #func global LoadLibrary "LoadLibraryA" sptr #func global GetVersionEx "GetVersionExA" sptr #func global VirtualProtect "VirtualProtect" sptr,sptr,sptr,sptr #func global FreeLibrary "FreeLibrary" sptr #endif #ifndef __USER32__ #define global __USER32__ #uselib "USER32.DLL" #func global SendMessage "SendMessageA" sptr,sptr,sptr,sptr #func global MessageBox "MessageBoxA" sptr,sptr,sptr,sptr #endif #if dirdialog_flag #ifndef __SHELL32__ #define global __SHELL32__ #uselib "SHELL32.DLL" #func global SHBrowseForFolder "SHBrowseForFolderA" sptr #func global SHGetPathFromIDList "SHGetPathFromIDListA" sptr,sptr #endif #ifndef __OLE32__ #define global __OLE32__ #uselib "ole32.dll" #func global CoTaskMemFree "CoTaskMemFree" sptr #endif #endif #endif ;-------------------------------------- ; 拡張ダイアログ用変数 ;-------------------------------------- #define global MB_OK $00000000 ;[OK] #define global MB_OKCANCEL $00000001 ;[OK] [キャンセル] #define global MB_ABORTRETRYIGNORE $00000002 ;[中止] [再試行] [無視] #define global MB_YESNOCANCEL $00000003 ;[はい] [いいえ] [キャンセル] #define global MB_YESNO $00000004 ;[はい] [いいえ] #define global MB_RETRYCANCEL $00000005 ;[再試行] [キャンセル] #define global MB_CANCELTRYCONTINUE $00000006 ;[キャンセル] [もう一度] [継続](Winodws2000/XPのみ有効) #define global MB_HELP $00004000 ;[ヘルプ](Windows 9x/NT4.0 以降) #define global MB_ICONSTOP $00000010 ;停止のアイコン #define global MB_ICONERROR $00000010 #define global MB_ICONHAND $00000010 #define global MB_ICONQUESTION $00000020 ;疑問符のアイコン #define global MB_ICONEXCLAMATION $00000030 ;感嘆符のアイコン #define global MB_ICONWARNING $00000030 #define global MB_ICONINFORMATION $00000040 #define global MB_ICONASTERISK $00000040 ;吹き出しに「i」のアイコン #define global MB_DEFBUTTON1 $00000000 ;最初のボタンをデフォルトにする #define global MB_DEFBUTTON2 $00000100 ;2番目のボタンをデフォルトにする #define global MB_DEFBUTTON3 $00000200 ;3番目のボタンをデフォルトにする #define global MB_DEFBUTTON4 $00000300 ;4番目のボタンをデフォルトにする #define global MB_SETFOREGROUND $00010000 ;フォアグラウンドにする #define global MB_TOPMOST $00040000 ;最前面ウィンドウ(他のウィンドウに隠れない)にする ;-------------------------------------- ; ファイル選択ダイアログ ;-------------------------------------- #define global OFN_OVERWRITEPROMPT $00000002 ;上書きの確認をする #define global OFN_ALLOWMULTISELECT $00000200 ;複数選択可 #define global OFN_FILEMUSTEXIST $00001000 ;存在するファイルしか選べない ;-------------------------------------- ; フォント選択ダイアログ用変数 ;-------------------------------------- #define global CF_APPLY $00000200 ;適応ボタン表示 #define global CF_TTONLY $00040000 ;TrueTypeのみ #define global CF_EFFECTS $00000100 ;色や修飾を有効にする #define global CF_FIXEDPITCHONLY $00004000 ;固定ピッチフォントのみ #define global CF_FORCEFONTEXIST $00010000 ;存在しないフォントを選択した時にエラー #define global CF_INITTOLOGFONTSTRUCT $00000040 ;LOGFONT構造体の内容でダイアログを初期化する #define global CF_LIMITSIZE $00002000 ;フォントサイズの制限を有効にする #define global CF_NOOEMFONTS $00000800 ;ベクターフォント無効 #define global CF_NOVECTORFONTS CF_NOOEMFONTS ;同上 #define global CF_NOFACESEL $00080000 ;初期設定でフォントを選択しない #define global CF_NOSCRIPTSEL $00800000 ;書体の種類を無効 #define global CF_NOSIZESEL $00200000 ;初期設定でサイズを選択しない #define global CF_NOSIMULATIONS $00001000 ;フォントシミュレーションしない #define global CF_NOVERTFONTS $01000000 ;水平方向フォントのみ #define global CF_PRINTERFONTS $00000002 ;プリンタのフォントのみ #define global CF_SCALABLEONLY $00020000 ;スケーリング可能フォントのみ #define global CF_SCREENFONTS $00000001 ;スクリーンフォントのみ #define global CF_SELECTSCRIPT $00400000 ;LOGFONT構造体で指定したキャラクタセットを持つフォントのみ #define global CF_SHOWHELP $00000004 ;ヘルプボタン表示 #define global CF_USESTYLE $00000080 ;スタイルを初期化 #define global CF_WYSIWYG $00008000 ;スクリーンフォントとプリンタフォントの両方に対応するフォント #define global CF_BOTH CF_SCREENFONTS | CF_PRINTERFONTS ;スクリーンフォントとプリンタフォント #const global CF_DEFAULT ( CF_EFFECTS | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT ) ;-------------------------------------- ; フォルダ選択用変数 ;-------------------------------------- #define BIF_RETURNONLYFSDIRS $0001 ;コントロールパネル、プリンタ、ブリーフケース内は選択不可 #define BIF_DONTGOBELOWDOMAIN $0002 ;ネットワークコンピュータ内のリソースを非表示 #define BIF_STATUSTEXT $0004 ;テキスト文字列を表示(設定はコールバック関数で行なう) #define BIF_RETURNFSANCESTORS $0008 ;ネットワークコンピュータ内のリソースのみ選択可 #define BIF_EDITBOX $0010 ;フォルダ名を編集するテキストBoxを表示 #define BIF_VALIDATE $0020 #define BIF_USENEWUI $0040 ;(Winodws2000のみ有効) #define BIF_BROWSEFORCOMPUTER $1000 ;ネットワークコンピュータ内のリソースのみ選択可 #define BIF_BROWSEFORPRINTER $2000 ;ネットワークプリンタのみ選択可 #define BIF_BROWSEINCLUDEFILES $4000 ;フォルダ内のファイル名も表示(Windows98以降) #const global BIF_DEFAULT ( BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN ) #module dialogs ;-------------------------------------- ; メモリサイズの減少用 ;-------------------------------------- #define cdir fstr #define file_uni fstr #define fname fstr #define OSVERSIONINFO prm2 #define logfont prm2 ;-------------------------------------- ; 拡張ダイアログ ;-------------------------------------- #ifdef extdialog_flag #deffunc extdialog str msg, int style, str capt fstr = msg : prm2 = capt MessageBox hwnd, varptr(fstr), varptr(prm2), style return #endif #if filedialog_flag ;-------------------------------------- ; ファイルオープン・ダイアログ ;-------------------------------------- #deffunc opendialog var filt, str file, int index, int flags mref stt, 64 mref ref, 65 DefExt="" : gosub *@f GetOpenFileName varptr(prm) if( stat == 1 ) : ref=path : stt=prm.6 : else : stt=-1 return ;-------------------------------------- ; ファイルセーブ・ダイアログ ;-------------------------------------- #deffunc savedialog var filt, str file, int index, int flags mref stt, 64 mref ref, 65 DefExt="bmp" : gosub *@f GetSaveFileName varptr(prm) if( stat == 1 ) : ref=path : stt=prm.6 : else : stt=-1 return ;-------------------------------------- *@ sdim path, 260 : path = getpath(file, 8) ;初期ファイル名 sdim cdir, 260 : cdir = getpath(file,32) ;初期ディレクトリ if( strlen(cdir) < 1 ) : cdir = dir_cur ;フィルタをダイアログ用に変換 repeat strlen(filt) if( peek(filt,cnt) == '|' ) : poke filt,cnt,0 loop ; OPENFILENAME 構造体 dim prm,19 prm. 0 = 76, hwnd, hinstance, varptr(filt) prm. 6 = index, varptr(path), 260 prm.11 = varptr(cdir), 0, flags, 0, varptr(DefExt) ;prm.0=76 ;構造体のサイズ(固定) ;prm.1=hwnd ;親Windowのハンドル ;prm.2=hinstance ;親Windowのインスタンス ;prm.3=varptr(filt) ;フィルタ ;prm.4=0 ;カスタムフィルタ ;prm.5=0 ;カスタムフィルタのバッファサイズ ;prm.6=index ;フィルタのインデックス ;prm.7=varptr(path) ;ファイル名を格納するバッファ ;prm.8=260 ;そのサイズ ;prm.9=0 ;ファイルのフルパスを格納するバッファ ;prm.10=260 ;そのサイズ ;prm.11=varptr(cdir) ;初期ディレクトリ ;prm.12=0 ;ダイアログボックスの表示タイトル ;prm.13=flags ;拡張フラグ ;prm.14=0 ;フルパスのファイル名,拡張子までのオフセット ;prm.15=varptr(DefExt) ;デフォルト拡張子 ;prm.16=0 ;??? ;prm.17=0 ;フック関数へのポインタ ;prm.18=0 ;ダイアログのタイトル名 return #endif #if icondialog_flag ;-------------------------------------- ; アイコン・ダイアログ ;-------------------------------------- #deffunc icondialog str file mref stt,64 ;「SHPickIconDialog」関数のポインタ取得 LoadLibrary "shell32.dll" : pdll = stat GetProcAddress pdll, 62 : proc = stat ; バッファの確保 sdim path,1024 : path = file : icon_index = 0 dim OSVERSIONINFO,148 : OSVERSIONINFO = 148 prm = hwnd, varptr(path), 0, varptr(icon_index) ; OSの種類&バージョン取得 GetVersionEx varptr(OSVERSIONINFO) ; NT系の場合はユニコード文字を使用 if( OSVERSIONINFO.4 == 2 ){ sdim file_uni, 260 : cnvstow file_uni, path prm.1 = varptr(file_uni) } ;「SHPickIconDialog」関数実行 stt = callfunc( prm, proc, 4 ) if( stt == 1 ) : prm = icon_index : else : prm = -1 ; 読み込んだDLLを開放 FreeLibrary pdll : stt = prm return #endif #if filedialog_flag ;-------------------------------------- ; フォント選択ダイアログ ;-------------------------------------- #deffunc fontdialog int style mref bm ,67 mref stt,64 mref ref,65 ; LOGFONT構造体 (bm.49以降をコピー) dim logfont,15 memcpy logfont, bm, 60, 0, 196 ; CHOOSEFONT構造体 dim prm, 15 prm = 60, hwnd, 0, varptr(logfont), 12, style if( style == 0 ) : prm.5 = CF_DEFAULT ; フォント選択ダイアログを呼び出し ChooseFont varptr(prm) if( stat == 0 ) : stt = -1 : return ;LOGFONTからフォント名取得 sdim fname,32 memcpy fname, logfont, 32, 0, 28 ; フォントのスタイルを取得 logfont.1=0 if( prm.5 & CF_EFFECTS ){ ; 色を設定 color prm.6&0xFF, (prm.6>>8)&0xFF, (prm.6>>16)&0xFF ; CFE_UNDERLINEを加える(下線) if (logfont.5 & 0x0000FF00) : logfont.1 |= 0x0004 ; CFE_STRIKEOUTを加える(打ち消し線) if (logfont.5 & 0x00FF0000) : logfont.1 |= 0x0008 } ; CFE_BOLDを加える(太字) if (prm.12 & 0x0100) : logfont.1 |= 0x0001 ; CFE_ITALICを加える(イタリック体) if (prm.12 & 0x0200) : logfont.1 |= 0x0002 ; フォントを設定 font fname, abs(logfont), logfont.1 stt = prm.4/10 : ref = fname return ;-------------------------------------- ; 取得したフォントを現在のウィンドウに設定 ;-------------------------------------- #deffunc logfont_set if length(logfont) == 15 { ;LOGFONTからフォント名取得 sdim fname,32 memcpy fname, logfont, 32, 0, 28 ; フォントを設定 font fname, abs(logfont), logfont.1 } return #endif #if dirdialog_flag ;-------------------------------------- ; フォルダ選択ダイアログ ;-------------------------------------- #deffunc dirdialog str tit, str file mref stt,64 mref ref,65 ; コールバック変数の初期化 (著作:さくらさん) ; http://www.silkroad.ne.jp/sakura/ if( length(fncode) == 1 ){ dim fncode,9 : prm=0 : VirtualProtect varptr(fncode),36,$40,prm fncode=$08247C83,$90177501,$102474FF,$6668016A,$FF000004,$B8102474,varptr(SendMessage),$C031D0FF,$000010C2 } ; データを変数に格納 DefExt = tit : fname = file ; BROWSEINFO構造体 prm = hwnd, 0, varptr(retfldr), varptr(DefExt), BIF_DEFAULT, varptr(fncode), varptr(fname), 0 ; フォルダ選択ダイアログを表示 SHBrowseForFolder varptr(prm) : prm = stat if( prm != 0 ){ ; パスを取得 SHGetPathFromIDList prm, varptr(DefExt) : prm2 = 1 } else { prm2 = -1 } ; 変数を開放 CoTaskMemFree prm stt = prm2 : ref = DefExt return #endif ;-------------------------------------- #global