[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: GUI Toolkit for Win32
- From: CHU Run-min <churunmin@...>
- Date: Thu, 5 Jan 2006 10:50:11 +0800
See the draft code
---------------------------
lua_State *L;
static void *luaL_checkptr(lua_State *L, int narg)
{
if (!lua_islightuserdata(L, narg))
{
luaL_typerror(L, narg, lua_typename(L, LUA_TLIGHTUSERDATA));
}
return lua_touserdata(L, narg);
}
BOOL OnWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam, LRESULT *pResult)
{
/* translate some message to Lua */
return FALSE;
}
static LRESULT SubclassProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
LRESULT result;
if (OnWindowMessage(hwnd, message, wParam, lParam, &result)) {
return result;
}
return CallWindowProc((WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA),
hwnd, message, wParam, lParam);
}
static int winapi_CreateWindow(lua_State *L)
{
HWND hwnd;
LPCTSTR className = (LPCTSTR)luaL_checkstring(L, 1);
DWORD style = (DWORD)luaL_checkptr(L, 2);
DWORD exStyle = (DWORD)luaL_checkptr(L, 3);
hwnd = CreateWindowEx(exStyle,
className,
TEXT(""),
style,
100,
100,
100,
100,
NULL,
NULL,
NULL,
NULL);
assert(hwnd);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)SubclassWindow(hwnd,
SubclassProc));
lua_pushlightuserdata(L, hwnd);
return 1;
}
static int winapi_SetWindowParent(lua_State *L)
{
HWND hwnd = (HWND)luaL_checkptr(L, 1);
HWND hwndNewParent = (HWND)luaL_checkptr(L, 2);
ShowWindow(hwnd, SW_HIDE);
SetParent(hwnd, hwndNewParent);
SetWindowStyle(hwnd, GetWindowStyle(hwnd) | WS_CHILD);
return 0;
}