More ... | GetLastErrorのエラーコードメッセージを取得GetLastErrorのエラーコードメッセージを取得
;---------------------------------------------------------------------
; GetLastError エラーコード→文字列 変換ソフト
;
; HISTORY
; Shark++
; 2005-06-26 サンプルとして公開
;---------------------------------------------------------------------
#packopt type 0
#packopt name "gle"
#packopt hide 1
;---------------------------------------------------------------------
#uselib "user32.dll"
#func GetWindowLong "GetWindowLongA" int, int
#func SetWindowLong "SetWindowLongA" int, int, int
#define GWL_STYLE (-16)
#define WS_MAXIMIZEBOX $10000
#define WS_MINIMIZEBOX $20000
#func SetWindowPos "SetWindowPos" int, int, int, int, int, int, int
#define SWP_DRAWFRAME 32
#define SWP_NOMOVE 2
#define SWP_NOSIZE 1
#define SWP_NOZORDER 4
#define VK_RETURN 13
#define EM_SETSEL 177
#define BM_SETSTYLE 244
#define BM_SETCHECK 241
#define RedrawFrame(%1) SetWindowPos %1, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_DRAWFRAME
#define ctype MAKELONG(%1,%2) ( ((%1) & $FFFF) | (((%2) & $FFFF) << 16) )
#define BS_AUTOCHECKBOX 3
#define BST_CHECKED 1
#define SetWndCenter width , , (ginfo(20) - ginfo(10)) / 2, (ginfo(21) - ginfo(11)) / 2
;---------------------------------------------------------------------
#define ID_ERRCODE 0
#define ID_MSGGET 1
#define ID_ERRMSG 2
#define ID_SETTOP 3
; キー割り込み
onkey goto *KeyChar
; 変数の確保
sdim num, 64
sdim msg, 1024
dim id, 4
dim topmost,1
goto *init
*GetLastError
; GetLastErrorのエラー文字列を取得
; エラーコード
n = int(num)
; 他はどうでも良くてココが一番重要
#uselib "kernel32.dll"
#func FormatMessage "FormatMessageA" int, int, int, int, var, int, int
#define FORMAT_MESSAGE_FROM_SYSTEM $1000
FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, 0, n, 0, msg, 1023, 0
; 画面上にセット
objprm id.ID_ERRMSG, msg
stop
*KeyChar
; 改行キー(ENTER)
if VK_RETURN = wParam {
sendmsg objinfo(id.ID_ERRCODE, 2), EM_SETSEL, 0, -1
goto *GetLastError
}
stop
*SetTopMost
topmost = topmost ^ 1
gsel 0, 1 + topmost
stop
*init
; ウインドウの初期化
width 200, 100
SetWndCenter
title "GetLastError"
; タイトルバーのボタンを[X]だけにする
GetWindowLong hwnd, GWL_STYLE
SetWindowLong hwnd, GWL_STYLE, stat & (-1 ^ (WS_MAXIMIZEBOX | WS_MINIMIZEBOX))
RedrawFrame hwnd
; デフォルトGUIフォントを使用
objmode 1
; エラーコードの入力オブジェクト
pos 20, 0
input num, 130, 20, 10
id.ID_ERRCODE = stat
; 取得ボタン
objsize 50, 20
pos 150, 0
button "取得", *GetLastError
id.ID_MSGGET = stat
; 取得したエラーコードを表示
pos 0, 20
mesbox msg, 200, 80, 0
id.ID_ERRMSG = stat
objsize 20, 20
pos 0, 0
button "", *SetTopMost
id.ID_SETTOP = stat
sendmsg objinfo(id.ID_SETTOP, 2), BM_SETSTYLE, MAKELONG(BS_AUTOCHECKBOX, 0), MAKELONG(1, 0)
; ウインドウを表示
gsel 0, 1
sendmsg objinfo(id.ID_SETTOP, 2), BM_SETCHECK, BST_CHECKED, 0
goto *SetTopMost
stop
|