mirror of
https://github.com/duilib/duilib.git
synced 2026-10-18 06:46:58 +08:00
132 lines
4.8 KiB
C++
132 lines
4.8 KiB
C++
// App.cpp : Defines the entry point for the application.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
|
|
class CFrameWindowWnd : public CWindowWnd, public INotifyUI
|
|
{
|
|
public:
|
|
CFrameWindowWnd() { };
|
|
LPCTSTR GetWindowClassName() const { return _T("UIMainFrame"); };
|
|
UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; };
|
|
void OnFinalMessage(HWND /*hWnd*/) { delete this; };
|
|
|
|
void Init() { }
|
|
|
|
bool OnHChanged(void* param) {
|
|
TNotifyUI* pMsg = (TNotifyUI*)param;
|
|
if( pMsg->sType == _T("valuechanged") ) {
|
|
short H, S, L;
|
|
CPaintManagerUI::GetHSL(&H, &S, &L);
|
|
CPaintManagerUI::SetHSL(true, (static_cast<CSliderUI*>(pMsg->pSender))->GetValue(), S, L);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool OnSChanged(void* param) {
|
|
TNotifyUI* pMsg = (TNotifyUI*)param;
|
|
if( pMsg->sType == _T("valuechanged") ) {
|
|
short H, S, L;
|
|
CPaintManagerUI::GetHSL(&H, &S, &L);
|
|
CPaintManagerUI::SetHSL(true, H, (static_cast<CSliderUI*>(pMsg->pSender))->GetValue(), L);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool OnLChanged(void* param) {
|
|
TNotifyUI* pMsg = (TNotifyUI*)param;
|
|
if( pMsg->sType == _T("valuechanged") ) {
|
|
short H, S, L;
|
|
CPaintManagerUI::GetHSL(&H, &S, &L);
|
|
CPaintManagerUI::SetHSL(true, H, S, (static_cast<CSliderUI*>(pMsg->pSender))->GetValue());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool OnAlphaChanged(void* param) {
|
|
TNotifyUI* pMsg = (TNotifyUI*)param;
|
|
if( pMsg->sType == _T("valuechanged") ) {
|
|
m_pm.SetOpacity((static_cast<CSliderUI*>(pMsg->pSender))->GetValue());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void OnPrepare()
|
|
{
|
|
CSliderUI* pSilder = static_cast<CSliderUI*>(m_pm.FindControl(_T("alpha_controlor")));
|
|
if( pSilder ) pSilder->OnNotify += MakeDelegate(this, &CFrameWindowWnd::OnAlphaChanged);
|
|
pSilder = static_cast<CSliderUI*>(m_pm.FindControl(_T("h_controlor")));
|
|
if( pSilder ) pSilder->OnNotify += MakeDelegate(this, &CFrameWindowWnd::OnHChanged);
|
|
pSilder = static_cast<CSliderUI*>(m_pm.FindControl(_T("s_controlor")));
|
|
if( pSilder ) pSilder->OnNotify += MakeDelegate(this, &CFrameWindowWnd::OnSChanged);
|
|
pSilder = static_cast<CSliderUI*>(m_pm.FindControl(_T("l_controlor")));
|
|
if( pSilder ) pSilder->OnNotify += MakeDelegate(this, &CFrameWindowWnd::OnLChanged);
|
|
}
|
|
|
|
void Notify(TNotifyUI& msg)
|
|
{
|
|
if( msg.sType == _T("windowinit") ) OnPrepare();
|
|
else if( msg.sType == _T("click") ) {
|
|
if( msg.pSender->GetName() == _T("insertimagebtn") ) {
|
|
CRichEditUI* pRich = static_cast<CRichEditUI*>(m_pm.FindControl(_T("testrichedit")));
|
|
if( pRich ) {
|
|
pRich->RemoveAll();
|
|
}
|
|
}
|
|
else if( msg.pSender->GetName() == _T("changeskinbtn") ) {
|
|
if( CPaintManagerUI::GetResourcePath() == CPaintManagerUI::GetInstancePath() )
|
|
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath() + _T("skin\\FlashRes"));
|
|
else
|
|
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
|
|
CPaintManagerUI::ReloadSkin();
|
|
}
|
|
}
|
|
}
|
|
|
|
LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if( uMsg == WM_CREATE ) {
|
|
m_pm.Init(m_hWnd);
|
|
CDialogBuilder builder;
|
|
CControlUI* pRoot = builder.Create(_T("test1.xml"), (UINT)0, NULL, &m_pm);
|
|
ASSERT(pRoot && "Failed to parse XML");
|
|
m_pm.AttachDialog(pRoot);
|
|
m_pm.AddNotifier(this);
|
|
Init();
|
|
return 0;
|
|
}
|
|
else if( uMsg == WM_DESTROY ) {
|
|
::PostQuitMessage(0L);
|
|
}
|
|
else if( uMsg == WM_ERASEBKGND ) {
|
|
return 1;
|
|
}
|
|
LRESULT lRes = 0;
|
|
if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;
|
|
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
|
}
|
|
|
|
public:
|
|
CPaintManagerUI m_pm;
|
|
};
|
|
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow)
|
|
{
|
|
CPaintManagerUI::SetInstance(hInstance);
|
|
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
|
|
|
|
HRESULT Hr = ::CoInitialize(NULL);
|
|
if( FAILED(Hr) ) return 0;
|
|
|
|
CFrameWindowWnd* pFrame = new CFrameWindowWnd();
|
|
if( pFrame == NULL ) return 0;
|
|
pFrame->Create(NULL, _T("这是一个最简单的测试用exe,修改test1.xml就可以看到效果"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
|
|
pFrame->CenterWindow();
|
|
pFrame->ShowWindow(true);
|
|
CPaintManagerUI::MessageLoop();
|
|
|
|
::CoUninitialize();
|
|
return 0;
|
|
}
|