home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 January (DVD) / VPR980100.ISO / OLS / WIN16 / ESAVER04 / ESAVER04.LZH / ESSRC04.LZH / ESRUNSET.FRM < prev    next >
Text File  |  1995-06-03  |  5KB  |  181 lines

  1. VERSION 2.00
  2. Begin Form ESRunSet 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  '固定(2重線)
  5.    Caption         =   "実行ファイルの設定"
  6.    Height          =   1980
  7.    Icon            =   ESRUNSET.FRX:0000
  8.    Left            =   2175
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   1620
  11.    ScaleWidth      =   5055
  12.    Top             =   3390
  13.    Width           =   5175
  14.    Begin CommandButton btnBrows 
  15.       Caption         =   "参照"
  16.       FontBold        =   0   'False
  17.       FontItalic      =   0   'False
  18.       FontName        =   "標準ゴシック"
  19.       FontSize        =   12
  20.       FontStrikethru  =   0   'False
  21.       FontUnderline   =   0   'False
  22.       Height          =   375
  23.       Left            =   3960
  24.       TabIndex        =   3
  25.       Top             =   1080
  26.       Width           =   975
  27.    End
  28.    Begin CommandButton btnCancel 
  29.       Caption         =   "取消"
  30.       FontBold        =   0   'False
  31.       FontItalic      =   0   'False
  32.       FontName        =   "標準ゴシック"
  33.       FontSize        =   12
  34.       FontStrikethru  =   0   'False
  35.       FontUnderline   =   0   'False
  36.       Height          =   375
  37.       Left            =   3960
  38.       TabIndex        =   2
  39.       Top             =   600
  40.       Width           =   975
  41.    End
  42.    Begin CommandButton chkReturn 
  43.       Caption         =   "了解"
  44.       FontBold        =   0   'False
  45.       FontItalic      =   0   'False
  46.       FontName        =   "標準ゴシック"
  47.       FontSize        =   12
  48.       FontStrikethru  =   0   'False
  49.       FontUnderline   =   0   'False
  50.       Height          =   375
  51.       Left            =   3960
  52.       TabIndex        =   1
  53.       Top             =   120
  54.       Width           =   975
  55.    End
  56.    Begin TextBox txtRunName 
  57.       FontBold        =   0   'False
  58.       FontItalic      =   0   'False
  59.       FontName        =   "標準ゴシック"
  60.       FontSize        =   10.5
  61.       FontStrikethru  =   0   'False
  62.       FontUnderline   =   0   'False
  63.       Height          =   300
  64.       Left            =   120
  65.       TabIndex        =   0
  66.       Top             =   240
  67.       Width           =   3735
  68.    End
  69. End
  70. Option Explicit
  71.  
  72. Sub btnBrows_Click ()
  73. Dim ofn As OPENFILENAME
  74. Dim RtnInt As Integer
  75. Dim StrFilter As String
  76. Dim StrFile As String
  77. Dim StrIniDir As String
  78. Dim StrTitle As String
  79. Dim StrDefExt As String
  80. Dim StringSize As Long
  81. Dim hMem As Integer
  82. Dim Address As Long
  83.  
  84.     RtnInt = -1
  85.     '表示などの、文字列変数の設定
  86.     StrFilter = "プログラム" & Chr$(0) & "*.exe" & Chr$(0) & Chr$(0)
  87.     StrFile = String$(256, 0)
  88.     StrIniDir = CurDir$ & Chr$(0)
  89.     StrTitle = "スクリーンセーバーにするファイルを選ぶ" & Chr$(0)
  90.  
  91.     '文字列変数の長さを調べるーLenBを使わないとAPIに渡したときアドレスがずれる
  92.     StringSize = LenB(StrFile) + LenB(StrFilter) + LenB(StrIniDir) + LenB(StrTitle)
  93.  
  94.     '文字列のサイズだけメモリーを割り当てる
  95.     hMem = GlobalAlloc(GHND, StringSize)
  96.     'もし返り値が0ならば、メモリー割当失敗
  97.     If hMem = 0 Then
  98.         MsgBox "メモリーの割り当てに失敗しました"
  99.         Exit Sub
  100.     End If
  101.  
  102.     '割り当てたメモリーをLockする
  103.     Address = GlobalLock(hMem)
  104.     'もし返り値が0ならメモリーのLock失敗
  105.     If Address = 0 Then
  106.         MsgBox "メモリーのロックに失敗しました"
  107.         Exit Sub
  108.     Else
  109.         'lockに成功したら文字列を割り当てたメモリーにコピー
  110.         Call hmemcpy(ByVal Address, ByVal (StrFile + StrFilter + StrIniDir + StrTitle), StringSize)
  111.     End If
  112.  
  113.     'OPENFILENAME構造体の設定
  114.     ofn.lStructSize = 72
  115.     ofn.hwndOwner = Me.hWnd
  116.     ofn.hInstance = 0
  117.     ofn.lpstrFile = Address  'StrFileのアドレス
  118.     ofn.lpstrFilter = ofn.lpstrFile + LenB(StrFile) '文字列はメモリー上で連続しているので文字列の長さ分アドレスがずれている
  119.     ofn.lpstrCustomfilter = 0
  120.     ofn.nMaxCustFilter = 0
  121.     ofn.nFilterIndex = 1
  122.     ofn.nMaxFile = 256
  123.     ofn.lpstrInitialDir = ofn.lpstrFilter + LenB(StrFilter)
  124.     ofn.lpstrTitle = ofn.lpstrInitialDir + LenB(StrIniDir)
  125.     ofn.Flags = OFN_HIDEREADONLY
  126.     ofn.nFileOffset = 0
  127.     ofn.nFileExtension = 0
  128.     ofn.lpstrDefExt = 0
  129.     ofn.lCustData = 0
  130.     ofn.lpfnHook = 0
  131.     ofn.lpTemplateName = 0
  132.  
  133.     RtnInt = GetOpenFileName(ofn)
  134.     If RtnInt <> 0 Then
  135.         '返り値が0以外ならダイアログオープン成功
  136.         '選択ファイル名は、StrFileのアドレスに返るので内容を文字列変数にコピー
  137.         Call hmemcpy(ByVal StrFile, ByVal Address, Len(StrFile))
  138.         '文字列変数の内容を取り出してテキストボックスに表示
  139.         txtRunName.Text = Left$(StrFile, InStr(StrFile, Chr$(0)) - 1)
  140.     End If
  141.  
  142.     'Lockしたメモリーをアンロック
  143.     RtnInt = GlobalUnlock(hMem)
  144.     '割り当てたメモリーを開放
  145.     RtnInt = GlobalFree(hMem)
  146.  
  147. End Sub
  148.  
  149. Sub btnCancel_Click ()
  150.     Unload Me
  151. End Sub
  152.  
  153. Sub chkReturn_Click ()
  154. Dim Rtn
  155.  
  156. 'ファイルが指定されていなかったら
  157.     If txtRunName.Text = "" Then
  158.         MsgBox "ファイルを指定してください"
  159.         Exit Sub
  160.     End If
  161. '実行ファイル?
  162.     Rtn = InStr(txtRunName.Text, ".")
  163.  
  164.     If Mid$(txtRunName.Text, Rtn + 1, 3) <> "EXE" Then
  165.         MsgBox "実行ファイルを指定してください"
  166.         Exit Sub
  167.     End If
  168.  
  169.     ESSetup.lstRunFileName.AddItem " " & txtRunName.Text
  170.     
  171.     Unload Me
  172.  
  173. End Sub
  174.  
  175. Sub Form_Load ()
  176. '画面中央に登場
  177.     ESRunSet.Left = (Screen.Width - ESRunSet.Width) / 2
  178.     ESRunSet.Top = (Screen.Height - ESRunSet.Height) / 2
  179. End Sub
  180.  
  181.