これでどうでしょうか.
ウインドウの幅を小さくするとスクロールバーが現れるようになっています.
項目の変更にも対応できます.
分からない関数やメッセージがあったらmsdnで調べてみてください.
#include "user32.as"
#include "gdi32.as"
#define WM_SIZE 0x0005
#define WM_COMMAND 0x0111
#define LBN_DBLCLK 2
#define GWL_STYLE -16
#define GWL_EXSTYLE -20
#define GWL_HWNDPARENT -8
#define WS_OVERLAPPED 0x00000000
#define WS_CAPTION 0x00C00000
#define WS_SYSMENU 0x00080000
#define WS_THICKFRAME 0x00040000
#define WS_MINIMIZEBOX 0x00020000
#define WS_MAXIMIZEBOX 0x00010000
#define WS_VSCROLL 0x00200000
#define WS_HSCROLL 0x00100000
#define WS_CHILD 0x40000000
#define WS_VISIBLE 0x10000000
#define WS_EX_CLIENTEDGE 0x00000200
#define WS_OVERLAPPEDWINDOW WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
#define SWP_FRAMECHANGED 0x0020
#define SWP_NOSIZE 0x0001
#define SWP_NOMOVE 0x0002
#define SWP_NOZORDER 0x0004
#define LB_GETHORIZONTALEXTENT 0x0193
#define LB_SETHORIZONTALEXTENT 0x0194
#define LB_ADDSTRING 0x0180
#define LB_GETCURSEL 0x0188
#define LB_GETTEXT 0x0189
#define LBS_NOTIFY 0x0001
#define LBS_NOINTEGRALHEIGHT 0x0100
#define WM_SETFONT 0x0030
#define DEFAULT_GUI_FONT 17
#define SIZE_RESTORED 0
#define TRUE 1
#define FALSE 0
#define NULL 0
// 上位ワードと下位ワード
#define ctype LOWORD(%1) (%1 & $FFFF)
#define ctype HIWORD(%1) ((%1 >> 16) & $FFFF)
#define ctype MAKELPARAM(%1, %2) (%1 & 0xFFFF) | (%2 << 16)
#define ctype MAKEWPARAM(%1, %2) (%1 & 0xFFFF) | (%2 << 16)
screen 0, ginfo(20), ginfo(21), 2, 0, 0
cls
title "ListBox"
MainWindowWidth = 640 :MainWindowHeight = 480
// ウインドウのハンドルを格納(後で使う)
hMainWindow = 0 :hMainWindow = hWnd
// ウインドウスタイルを設定
GetWindowLong hMainWindow, GWL_STYLE
MainWindowStyle = stat | WS_OVERLAPPEDWINDOW
SetWindowLong hMainWindow, GWL_STYLE, MainWindowStyle
SetWindowPos hMainWindow, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER
dim tagRECT, 4
dim tagSIZE, 2
MaxSize = 0
// ウインドウの大きさ(クライアント領域)を設定
SetRect varptr(tagRECT), 0, 0, MainWindowWidth, MainWindowHeight
AdjustWindowRectEx varptr(tagRECT), MainWindowStyle, FALSE, 0
SetWindowPos hMainWindow, NULL, 50, 50, tagRECT(2) - tagRECT(0), tagRECT(3) - tagRECT(1), SWP_NOZORDER
gsel 0, 1
oncmd gosub *OnCommand, WM_COMMAND
oncmd gosub *OnSize, WM_SIZE
// リストボックスの作成
SelectedIndex = 0
ItemString = ""
ListString = "Windows 3.1", "Microsoft Visual Studio 2010 Professional Service Pack 1", "Hot Soup Processor Version 3.4 Beta 2", "Windows XP Professional Service Pack 3", "Microsoft Visual Studio Team Foundation Server Express 2012 with Update 3"
winobj "listbox", "", WS_EX_CLIENTEDGE, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT, MainWindowWidth, MainWindowHeight, 100, 0
hListBox = objinfo(stat, 2)
// リストボックスのフォント指定
GetStockObject DEFAULT_GUI_FONT
hFont = 0 :hFont = stat
sendmsg hListbox, WM_SETFONT, hFont
repeat 5
sendmsg hListBox, LB_ADDSTRING, 0, ListString(cnt)
// 文字列の横幅(ピクセル単位)を取得
SelectObject hdc, hFont
GetTextExtentPoint32 hdc, ListString(cnt), strlen(ListString(cnt)), varptr(tagSIZE)
if (tagSIZE(0) > MaxSize) {
sendmsg hListBox, LB_SETHORIZONTALEXTENT, tagSIZE(0), 0
MaxSize = tagSIZE(0)
}
loop
stop
*OnSize
MoveWindow hListBox, 0, 0, LOWORD(lParam), HIWORD(lParam), FALSE
return
*OnCommand
if (lParam == hListBox) {
if (HIWORD(wParam) == LBN_DBLCLK) {
sendmsg hListBox, LB_GETCURSEL, 0, 0
SelectedIndex = stat
dialog "" + SelectedIndex + "番目の項目が選択されました"
sendmsg hListBox, LB_GETTEXT, SelectedIndex, varptr(ItemString)
dialog ItemString
if (ItemString == "Windows 3.1") {
gosub *Index0
} else : if (ItemString == "Microsoft Visual Studio 2010 Professional Service Pack 1") {
gosub *Index1
} else : if (ItemString == "Hot Soup Processor Version 3.4 Beta 2") {
gosub *Index2
} else : if (ItemString == "Windows XP Professional Service Pack 3") {
gosub *Index3
} else : if (ItemString == "Microsoft Visual Studio Team Foundation Server Express 2012 with Update 3") {
gosub *Index4
} else : if (ItemString == "Windows Vista") {
gosub *Index5
}
return
}
}
return
*Index0
dialog "Windows 3.1が選択されました", 0, "ラベルIndex0"
return
*Index1
dialog "Microsoft Visual Studio 2010 Professional Service Pack 1が選択されました", 0, "ラベルIndex1"
return
*Index2
dialog "Hot Soup Processor Version 3.4 Beta 2が選択されました", 0, "ラベルIndex2"
return
*Index3
dialog "Windows XP Professional Service Pack 3が選択されました", 0, "ラベルIndex3"
return
*Index4
dialog "Microsoft Visual Studio Team Foundation Server Express 2012 with Update 3が選択されました", 0, "ラベルIndex4"
return
*Index5
dialog "Windows Vistaが選択されました", 0, "ラベルIndex5 : 項目の変化に対応"
return