LRESULT CALLBACK CWindowWnd::__ControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CWindowWnd* pThis = NULL; if( uMsg == WM_NCCREATE ) { LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); pThis = static_cast<CWindowWnd*>(lpcs->lpCreateParams); ::SetProp(hWnd, _T("WndX"), (HANDLE) pThis); pThis->m_hWnd = hWnd; } else { pThis = reinterpret_cast<CWindowWnd*>(::GetProp(hWnd, _T("WndX"))); if( uMsg == WM_NCDESTROY && pThis != NULL ) { LRESULT lRes = ::CallWindowProc(pThis->m_OldWndProc, hWnd, uMsg, wParam, lParam); if( pThis->m_bSubclassed ) pThis->Unsubclass(); ::SetProp(hWnd, _T("WndX"), NULL); pThis->m_hWnd = NULL; pThis->OnFinalMessage(hWnd); return lRes; } } if( pThis != NULL ) { return pThis->HandleMessage(uMsg, wParam, lParam); } else { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } }
LRESULT CALLBACK CWindowWnd::__WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CWindowWnd* pThis = NULL; if( uMsg == WM_NCCREATE ) { LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam); pThis = static_cast<CWindowWnd*>(lpcs->lpCreateParams); pThis->m_hWnd = hWnd; ::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LPARAM>(pThis)); } else { pThis = reinterpret_cast<CWindowWnd*>(::GetWindowLongPtr(hWnd, GWLP_USERDATA)); if( uMsg == WM_NCDESTROY && pThis != NULL ) { LRESULT lRes = ::CallWindowProc(pThis->m_OldWndProc, hWnd, uMsg, wParam, lParam); ::SetWindowLongPtr(pThis->m_hWnd, GWLP_USERDATA, 0L); if( pThis->m_bSubclassed ) pThis->Unsubclass(); pThis->m_hWnd = NULL; pThis->OnFinalMessage(hWnd); //OnFinalMessage做最后处理 return lRes; } } if( pThis != NULL ) { return pThis->HandleMessage(uMsg, wParam, lParam); } else { return ::DefWindowProc(hWnd, uMsg, wParam, lParam); } }
IMPL_LUA_FUNC(LuaCWindowWnd, CreateDuiWindow) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); HWND hwndParent = NULL; if (lua_isuserdata(l, 2)) hwndParent = static_cast<HWND>(LuaStatic::CheckUserData(l, 2)); CDuiString pstrText; lua_op_t<CDuiString>::lua_to_value(l, 3, pstrText); DWORD dwStyle = 0; if(lua_isnumber(l,4)) dwStyle = (DWORD)lua_tonumber(l,4); DWORD dwStyleEx = 0; if(lua_isnumber(l,5)) dwStyleEx = (DWORD)lua_tonumber(l,5); HWND hWnd = self->CreateDuiWindow(hwndParent, pstrText, dwStyle, dwStyleEx); LuaStatic::AddObject2Lua(l, hWnd, "HWND"); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::CreateDuiWindow")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, PostMessage) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); UINT uMsg = (UINT)lua_tonumber(l,2); WPARAM wParam = 0; if (lua_isuserdata(l, 3)) wParam = (WPARAM)LuaStatic::CheckUserData(l, 3); else if (!lua_isnone(l, 4)) { dui_uint32 wp = 0; lua_op_t<dui_uint32>::get_ret_value(l, 3, wp); wParam = wp; } LPARAM lParam = 0; if (lua_isuserdata(l, 4)) lParam = (LPARAM)LuaStatic::CheckUserData(l, 4); else if (!lua_isnone(l, 4)) { dui_uint64 lp = 0; lua_op_t<dui_uint64>::get_ret_value(l, 4, lp); lParam = lp; } LRESULT ret = self->PostMessage(uMsg,wParam,lParam); lua_pushnumber(l,ret); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::PostMessage")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, Create) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); HWND hwndParent = NULL; if (lua_isuserdata(l,2)) hwndParent = static_cast<HWND>(LuaStatic::CheckUserData(l, 2)); CDuiString pstrText; lua_op_t<CDuiString>::lua_to_value(l, 3, pstrText); DWORD dwStyle = (DWORD)lua_tonumber(l,4); DWORD dwStyleEx = (DWORD)lua_tonumber(l,5); RECT rc = LuaStatic::ReadRectFromLua(l,6); HMENU hMenu = NULL; if(lua_isuserdata(l,7)) hMenu = static_cast<HMENU>(LuaStatic::CheckUserData(l, 7)); HWND hWnd = self->Create(hwndParent, pstrText, dwStyle, dwStyleEx, rc, hMenu); LuaStatic::AddObject2Lua(l, hWnd, "HWND"); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::Create")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, Delete) { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); LuaStatic::RemoveObjectInLua(l); if (::IsWindow(self->GetHWND()) ) SafeDelete(self); return 0; }
void CLoginPreWnd::Notify(TNotifyUI& msg) { if( msg.sType == _T("windowinit") ) { OnPrepare(msg); } else if( msg.sType == _T("click") ) { if( msg.pSender->GetName() == L"closebtn" ) { Close(); return; } else if( msg.pSender->GetName() == L"EverAccountLoginBtn" ) { Close(); // 强制弹出更新窗口进行升级 mainframe::MainFrame_GetWndService stGetWndService; login::g_LoginModule->GetModuleManager()->CallService(mainframe::SERVICE_VALUE_MAINFRAME_GET_MAINWND, (param)&stGetWndService); CWindowWnd* pMainFrameWnd = reinterpret_cast<CWindowWnd*>(stGetWndService.pBaseWnd); ASSERT(pMainFrameWnd != NULL); CLoginFrameWnd* pLoginFrame = new CLoginFrameWnd(); pLoginFrame->Create(pMainFrameWnd->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, UI_WNDSTYLE_EX_DIALOG, 0, 0, 0, 0, NULL); pLoginFrame->CenterWindow(); /* pMainFrameWnd->ShowModal(*pLoginFrame); */ return; } else if( msg.pSender->GetName() == L"EverAacountRegisterBtn" ) { } else if( msg.pSender->GetName() == L"QQLogin" ) { Close(); // 强制弹出更新窗口进行升级 mainframe::MainFrame_GetWndService stGetWndService; login::g_LoginModule->GetModuleManager()->CallService(mainframe::SERVICE_VALUE_MAINFRAME_GET_MAINWND, (param)&stGetWndService); CWindowWnd* pMainFrameWnd = reinterpret_cast<CWindowWnd*>(stGetWndService.pBaseWnd); ASSERT(pMainFrameWnd != NULL); COAuthLoginWnd* pLoginFrame = new COAuthLoginWnd(); pLoginFrame->Create(pMainFrameWnd->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, UI_WNDSTYLE_EX_DIALOG, 0, 0, 0, 0, NULL); pLoginFrame->CenterWindow(); } } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) { CWindowWnd* pFrame = new MyWindowWnd(hInstance); if (pFrame == NULL) return 0; pFrame->Create(NULL, _T("ListDemo"), UI_WNDSTYLE_FRAME, WS_EX_STATICEDGE | WS_EX_APPWINDOW, 0, 0, 600, 320); pFrame->CenterWindow(); pFrame->ShowModal(); return 0; }
IMPL_LUA_FUNC(LuaCWindowWnd, Unsubclass) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); self->Unsubclass(); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::Unsubclass")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, RegisterSuperclass) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); lua_pushboolean(l,self->RegisterSuperclass() ? 1 : 0); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::RegisterSuperclass")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, ShowModal) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); lua_pushnumber(l,self->ShowModal()); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::ShowModal")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, CenterWindow) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); self->CenterWindow(); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::CenterWindow")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, GetHWND) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); LuaStatic::AddObject2Lua(l, self->GetHWND(), "HWND"); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::GetHWND")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, SetIcon) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); UINT nRes = (UINT)lua_tonumber(l,2); self->SetIcon(nRes); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::SetIcon")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, Subclass) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); HWND hwndParent = static_cast<HWND>(LuaStatic::CheckUserData(l, 2)); HWND hWnd = self->Subclass(hwndParent); LuaStatic::AddObject2Lua(l, hWnd, "HWND"); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::Subclass")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, Close) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); UINT nRet = IDOK; if(lua_isnumber(l,2)) nRet = (UINT)lua_tonumber(l,2); self->Close(nRet); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::Close")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, ResizeClient) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); int cx = -1; if(!lua_isnumber(l,2)) cx = lua_tointeger(l,2); int cy = -1; if(!lua_isnumber(l,3)) cy = lua_tointeger(l,3); self->ResizeClient(cx,cy); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::PostMessage")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, ShowWindow) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); bool bShow = true; if(lua_isboolean(l,2)) bShow = lua_toboolean(l,2) != 0; bool bFocus = true; if(lua_isboolean(l,3)) bFocus = lua_toboolean(l,3) != 0; self->ShowWindow(bShow,bFocus); return 0; } catch(...) { DuiException(_T("LuaCWindowWnd::ShowWindow")); return 0; } }
IMPL_LUA_FUNC(LuaCWindowWnd, Create2) { try { CWindowWnd* self; self = static_cast<CWindowWnd*>(LuaStatic::CheckUserData(l, 1)); HWND hwndParent = NULL; if (lua_isuserdata(l, 2)) hwndParent = static_cast<HWND>(LuaStatic::CheckUserData(l, 2)); CDuiString pstrText; lua_op_t<CDuiString>::lua_to_value(l, 3, pstrText); DWORD dwStyle = (DWORD)lua_tonumber(l,4); DWORD dwStyleEx = (DWORD)lua_tonumber(l,5); int x = CW_USEDEFAULT; if(lua_isnumber(l,6)) x = lua_tointeger(l,6); int y = CW_USEDEFAULT; if(lua_isnumber(l,7)) y = lua_tointeger(l,7); int cx = CW_USEDEFAULT; if(lua_isnumber(l,8)) cx = lua_tointeger(l,8); int cy = CW_USEDEFAULT; if(lua_isnumber(l,9)) cy = lua_tointeger(l,9); HMENU hMenu = NULL; if(lua_isuserdata(l,10)) hMenu = static_cast<HMENU>(LuaStatic::CheckUserData(l, 10)); HWND hWnd = self->Create(hwndParent, pstrText, dwStyle, dwStyleEx, x, y, cx, cy, hMenu); LuaStatic::AddObject2Lua(l, hWnd, "HWND"); return 1; } catch(...) { DuiException(_T("LuaCWindowWnd::Create2")); return 0; } }
// HANDLE VwCreateWin( // VApiHandle hWndParent, int X, int Y, int nWidth, int nHeight, // WCHAR* wszRegName, WCHAR* wszNewName, BOOL bIsAlpha) SQInteger VwCreateWin(HSQUIRRELVM v) { SQInteger nargs = sq_gettop(v); SQInteger nWndParent = 0; HWND hWndParent = NULL; CUIImage* pImg = NULL; CScriptMgr* pMgr = NULL; CPaintManagerUI* pPM = NULL; int X = 0; int Y = 0; int nWidth = 0; int nHeight = 0; const SQChar* pwszRegName = NULL; const SQChar* pwszNewName = NULL; WCHAR wszNewName[60] = {0}; SQBool bIsAlphaWin = NULL; WinMgrItem* pWinMgrIt = NULL; HWND hWnd = NULL; CWindowWnd* pWinObj = NULL; SQInteger nRet = 0; CMarkupNode* pRootXm = NULL; if (!v || 8 + 1 != nargs) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 2)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 3)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 4)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 5)) {goto _Exit_;} if (OT_INTEGER != sq_gettype(v, 6)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 7)) {goto _Exit_;} if (OT_STRING != sq_gettype(v, 8)) {goto _Exit_;} if (OT_BOOL != sq_gettype(v, 9)) {goto _Exit_;} sq_getinteger(v, 2, &nWndParent); sq_getinteger(v, 3, &X); sq_getinteger(v, 4, &Y); sq_getinteger(v, 5, &nWidth); sq_getinteger(v, 6, &nHeight); sq_getstring(v, 7, &pwszRegName); //sq_getinteger(v, 8, &wszNewName); sq_getbool(v, 9, &bIsAlphaWin); swprintf_s(wszNewName, 60, L"%x", ::GetTickCount()); if (nWndParent) { hWndParent = QiHwHandleToWin(nWndParent)->pWinObj->GetHWND(); } pMgr = (CScriptMgr*)sq_getforeignptr(v); if (!pMgr) {goto _Exit_;} pPM = pMgr->GetManager(); if (!pPM || !pPM->GetWinMgr()) {goto _Exit_;} pWinMgrIt = pPM->GetWinMgr()->FindWinByName(pwszRegName); if (!pWinMgrIt) {goto _Exit_;} // 新建立个模板,因为需要可重复用以前的名字 pRootXm = new CMarkupNode(*pWinMgrIt->pWinXML); pWinObj = new CWindowTemplate(pWinMgrIt->pWinObj); pWinObj->GetPM()->SetWinMgr(pPM->GetWinMgr()); pWinObj->SetDefaultResource(pRootXm); pWinMgrIt = pPM->GetWinMgr()->AddOneWin(pWinObj, wszNewName, pRootXm, X, Y, nWidth, nHeight, pWinMgrIt->dwStyle, pWinMgrIt->dwExStyle, &pWinMgrIt->ExInfo); if (!bIsAlphaWin) { hWnd = pWinObj->Create(hWndParent, pwszNewName, pWinMgrIt->dwStyle, pWinMgrIt->dwExStyle, X, Y, nWidth, nHeight, 0); } else { hWnd = pWinObj->CreateAlphaWin(hWndParent, pwszNewName, pWinMgrIt->dwStyle | WS_EX_LAYERED, pWinMgrIt->dwExStyle, X, Y, nWidth, nHeight); } if (!hWnd) {goto _Exit_;} nRet = QiHwObjToHandle(pWinMgrIt); _Exit_: sq_pushinteger(v, nRet); return 1; }
static void framebuffer_size_callback(GLFWwindow* window, int width, int height) { CWindowWnd* pWnd = (CWindowWnd*)glfwGetWindowUserPointer(window); pWnd->HandleMessage(UI_WM_SIZE, width, height); glViewport(0, 0, width, height); }
static void window_refresh_callback(GLFWwindow* window) { CWindowWnd* pWnd = (CWindowWnd*)glfwGetWindowUserPointer(window); pWnd->HandleMessage(UI_WM_PAINT, 0, 0); }