'L_MnuChg.mac / キー設定ファイルを読込む / by Kabuneko 99/08/11

proc main
    dim file$, a$, l$, s$, sel, count, done, i, n,
    dim item$[20], item[10], check[10]
'現在開いているファイルが INI なら、このファイルを読込むかたずねる
    if @hwnd > 0 then
        if right$(@Filename$, 3) = "ini" or \
            right$(@Filename$, 3) = "INI" then
                item$[1] = "この設定ファイルを読込む"
                item$[2] = "ファイルを指定する"
                sel = popupmenu(item$)
                if sel = 1 then file$ = @Pathname$
                if sel < 1 or sel > 2 then exit proc
        end if
    end if
'INIファイルを探すフォルダとマスクを指定
    if file$ = "" then file$ = \
        GetFileName$(@@QXDirectory$, "*.ini", "ファイル選択")
    if file$ = "" then exit proc
'指定されたファイルの内容項目チェック
    open file$ for input as #1
    do until eof(1)
        lineinput #1, l$
        if left$(l$, 1) = "[" then
            if instr(lcase$(l$), "[key]") then item[3] = 1
            if instr(lcase$(l$), "[menubar]") then item[4] = 1
            if instr(lcase$(l$), "[popupmenu]") then item[5] = 1
            if instr(lcase$(l$), "[keymenu]") then item[6] = 1
            if instr(lcase$(l$), "[toolbar]") then item[7] = 1
            if instr(lcase$(l$), "[statusbar]") then item[7] = 1
        end if
    loop
'ポップアップメニューの項目初期化
    i = 1
    item$[i++] = file$ + " 読込む項目?"
    item$[i++] = chr$(1) + "-"
    a$ = "" : if item[i] = 0 then a$ = chr$(1)
    item$[i++] = a$ + "キー設定"
    a$ = "" : if item[i] = 0 then a$ = chr$(1)
    item$[i++] = a$ + "メニューバー"
    a$ = "" : if item[i] = 0 then a$ = chr$(1)
    item$[i++] = a$ + "右クリックメニュー"
    a$ = "" : if item[i] = 0 then a$ = chr$(1)
    item$[i++] = a$ + "キーメニュー"
    a$ = "" : if item[i] = 0 then a$ = chr$(1)
    item$[i++] = a$ + "ツールバー・ステータスバー"
    item$[i++] = chr$(1) + "-"
    item$[i++] = chr$(1) + "・決定・"
    item$[i++] = chr$(1) + "-"
    item$[i++] = "ぜんぶ"
    item$[i++] = chr$(1) + "-"
    item$[i++] = "やめる"
'ポップアップメニューを表示
    do until done = 1
        sel = popupmenu(item$,200,100)
        if sel > 2 and sel < 8 then
            if check[sel] = 0 then
                check[sel] = 1
                item$[sel] = chr$(2) + item$[sel]
                count++
            else
                check[sel] = 0
                item$[sel] = mid$(item$[sel], 2)
                count--
            end if
        else
            done = 1
        end if
        '「決定」を選択可能に
        if count > 0 then
            item$[9] = "・決定・"
        else
            item$[9] = chr$(1) + "・決定・"
        end if
    loop
'選択項目にしたがって実行
    if sel > 11 or sel < 3 then
        call msgbox("キー・メニュー切替 --- 中止しました")
        exit proc
    end if
    if sel = 11 then
        for i = 3 to 7
            check[i] = item[i]
        next
    end if
    for i = 3 to 7
        if check[i] > 0 then
            if instr(item$[i],chr$(2)) then item$[i] = mid$(item$[i],2)
            s$ = s$ + chr$(10) + "・ " + item$[i]
        end if
    next
    sel = msgbox("キー・メニュー切替 --- 以下を切替えます" + \
        chr$(10) + s$, MB_OKCANCEL)
    if sel = IDCANCEL then exit proc
    n = check[3] + check[4]*2 + check[5]*4 + check[6]*8 + check[7]*16
    @@InitKeyFile file$,n
    call msgbox("キー・メニュー切替 --- Done !!!")
end proc