〜 オブジェクト 〜
ボタンキャプションの表示位置を変更 (要USER32.DLL)

ボタンのテキストは標準で中央に表示されていきます。
必ずしも、中央に表示して欲しいわけではなく、左寄せ・右寄せで表示したい場合もあることでしょう。
API関数SetWindowLongに、ボタンのオブジェクトハンドルと
左寄せを示す「BS_LEFT(=0x0100)」、または右寄せを示す「BS_RIGHT(=0x0200)」と
標準スタイルを示す「GWL_STYLE(=16)」パラメータを指定することで表示位置を変更できますが、
表示位置設定以外の基本スタイルを継承するには、API関数GetWindowLongで現在のスタイルを取得します。
尚、縦位置を上寄せにするには「BS_TOP(=0x0400)」、下寄せは「BS_BOTTOM(=0x0800)」を指定し、
標準の中央寄せは「BS_CENTER(=0x0300)」を、縦位置の中間は「BS_VCENTER(=0x0C00)」を使います。
さて、「オブジェクトのハンドルとは?」って説明はココでは省略するとして、
objinfo関数で取得できるHSP3はさておき、HSP2でどうやってハンドルを取得するかと言うと、
BMSCR構造体の要素41(hCld)から64要素分が各オブジェクトハンドルの保有領域となっているので
mref命令を使ってBMSCR構造体を取得し、該当オブジェクトのハンドル保有領域を取得すればOKです。 
インプットボックスなどのエディットボックス)の横位置を変更するにはパラメータが異なるだけなのですが、
当TIPSのBSパラメータ(BS_xxx)ではなくコチラに載せたESパラメータ(ES_xxx)をご利用ください。
	

setobjinfo オブジェクトID, 位置X, 位置Y, 横幅, 高さ, フラグ
オブジェクトID変更対象オブジェクトID指定する。
位置X変更後のX座標を指定する。尚、フラグに2を指定していると位置Xは無視される。
位置Y変更後のY座標を指定する。尚、フラグに2を指定していると位置Yは無視される。
横幅変更後の横幅を指定する。尚、フラグに1を指定していると横幅は無視される。
高さ変更後の高さを指定する。尚、フラグに1を指定していると高さは無視される。
フラグ動作フラグ(-1:スタイル変更時に使用 1:サイズ変更なし 2:位置変更なし)を指定する。

objgetstyle オブジェクトID, 拡張スタイルフラグ
オブジェクトIDスタイルの確認をするオブジェクトIDを指定する。
尚、1000以上だとオブジェクトハンドルとして拡張オブジェクトにも対応。
取得したスタイルはstatに代入する。
拡張スタイルフラグ0又は省略すると標準スタイル、
それ以外を指定すると拡張スタイル値を取得する。

objsetstyle オブジェクトID, 拡張スタイルフラグ, 追加スタイル, 削除スタイル
オブジェクトIDスタイルの変更をするオブジェクトIDを指定する。
尚、1000以上だとオブジェクトハンドルとして拡張オブジェクトにも対応。
拡張スタイルフラグ現在の操作対象ウィンドウのうち、0又は省略すると標準ウィンドウスタイル、
それ以外を指定すると拡張ウィンドウスタイル値を設定する。
追加スタイル現在のスタイルのほかに追加したいスタイル値を指定する。
削除スタイル現在のスタイルのうちで削除したいスタイル値を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	ll_libload user, "user32.dll"
	ll_getproc SetWindowPos, "SetWindowPos", user
	ll_getproc GetWindowLong, "GetWindowLongA", user
	ll_getproc SetWindowLong, "SetWindowLongA", user

#module
#deffunc setobjinfo int, int, int, int, int, int
	mref id, 0 : mref px, 1 : mref py, 2 : mref sx, 3 : mref sy, 4 : mref flg, 5
	mref bmscr, 67
	if id < 1000 : i = id + 41 : i = bmscr.i : else : i = id
	prm = i, 0, px, py, sx, sy, flg = -1 * 0x0027 + (flg ! -1 * flg)
	ll_callfunc prm, 7, SetWindowPos@
	return

#deffunc objgetstyle int, int
	mref id, 0 : mref extflg, 1
	mref stt, 64
	mref bmscr, 67
	if id < 1000 : i = id + 41 : i = bmscr.i : else : i = id
	prm = i, -4 * (extflg ! 0) - 16
	ll_callfunc prm, 2, GetWindowLong@
	ll_ret i : stt = i
	return

#deffunc objsetstyle int, int, int, int
	mref id, 0 : mref extflg, 1 : mref aprm, 2 : mref dprm, 3
	mref bmscr, 67
	objgetstyle id, extflg
	if id < 1000 : i = id + 41 : i = bmscr.i : else : i = id
	prm = i, -4 * (extflg ! 0) - 16, stat | aprm & (stat | aprm ^ dprm)
	ll_callfunc prm, 3, SetWindowLong@
	setobjinfo id, , , , , -1 // 位置・サイズは変更せずにスタイルのみ変更
	return
#global

	sdim msg, 12, 6
	msg = "左寄せ", "右寄せ", "上寄せ", "下寄せ", "左上寄せ", "右下寄せ"
	prm = 0x100, 0x200, 0x400, 0x800, 0x500, 0xA00
	objsize 100, 100
	repeat 6
		pos cnt \ 3 * 150, cnt / 3 * 150 : button msg.cnt, *click
		objsetstyle cnt, , prm.cnt
	loop
	stop

*click
	dialog msg.stat + "で表示されたボタンを押しました"
	stop

取得スタイル = objgetstyle(オブジェクトID, 拡張スタイルフラグ)
取得スタイル取得したスタイル値の受取先を指定する。
オブジェクトIDスタイルの確認をするオブジェクトIDを指定する。
尚、1000以上だとオブジェクトハンドルとして拡張オブジェクトにも対応。
拡張スタイルフラグ0又は省略すると標準スタイル、
それ以外を指定すると拡張スタイル値を取得する。

objsetstyle オブジェクトID, 拡張スタイルフラグ, 追加スタイル, 削除スタイル
オブジェクトIDスタイルの変更をするオブジェクトIDを指定する。
尚、1000以上だとオブジェクトハンドルとして拡張オブジェクトにも対応。
拡張スタイルフラグ現在の操作対象ウィンドウのうち、0又は省略すると標準ウィンドウスタイル、
それ以外を指定すると拡張ウィンドウスタイル値を設定する。
追加スタイル現在のスタイルのほかに追加したいスタイル値を指定する。
削除スタイル現在のスタイルのうちで削除したいスタイル値を指定する。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#uselib "user32.dll"
#cfunc global GetWindowLong "GetWindowLongA" int, int
#func  global SetWindowLong "SetWindowLongA" int, int, int
#func  global SetWindowPos "SetWindowPos" int, int, int, int, int, int, int

#module
#defcfunc objgetstyle int id, int extflg, local i
	if id < 1000 : i = objinfo(id, 2) : else : i = id
	return GetWindowLong( i, -4 * (extflg ! 0) - 16 )

#deffunc objsetstyle int id, int extflg, int aprm, int dprm, local i
	if id < 1000 : i = objinfo(id, 2) : else : i = id
	SetWindowLong i, -4 * (extflg ! 0) - 16, objgetstyle(id, extflg) | aprm & (objgetstyle(id, extflg) | aprm ^ dprm)
	SetWindowPos i, , , , , , 0x0027 // SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED
	return
#global

	msg = "左寄せ", "右寄せ", "上寄せ", "下寄せ", "左上寄せ", "右下寄せ"
	prm = 0x100, 0x200, 0x400, 0x800, 0x500, 0xA00
	objsize 100, 100
	repeat length(msg)
		pos cnt \ 3 * 150, cnt / 3 * 150 : button gosub msg.cnt, *click
		objsetstyle cnt, , prm.cnt
	loop
	stop

*click
	dialog msg.stat + "で表示されたボタンを押しました"
	return