no message

This commit is contained in:
ATTIOT\zhengcy 2021-09-15 17:37:26 +08:00
parent eadae2021d
commit dca8b90bc0
39 changed files with 1708 additions and 1027 deletions

View File

@ -130,13 +130,14 @@
<ProjectGuid>{8D9A6595-717A-41C8-B468-0011A72BE3D1}</ProjectGuid> <ProjectGuid>{8D9A6595-717A-41C8-B468-0011A72BE3D1}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>base</RootNamespace> <RootNamespace>base</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
@ -149,7 +150,7 @@
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
@ -204,7 +205,7 @@
</PrecompiledHeader> </PrecompiledHeader>
<WarningLevel>Level4</WarningLevel> <WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;NOMINMAX;WITH_ENCRYPT;CURL_STATICLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;NOMINMAX;CURL_STATICLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>false</TreatWarningAsError> <TreatWarningAsError>false</TreatWarningAsError>
<AdditionalIncludeDirectories>.\;..\</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\;..\</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4100;4127;4244;4245;4310;4355;4505;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4127;4244;4245;4310;4355;4505;%(DisableSpecificWarnings)</DisableSpecificWarnings>
@ -250,7 +251,7 @@
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;NOMINMAX;WITH_ENCRYPT;CURL_STATICLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;NOMINMAX;CURL_STATICLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>false</TreatWarningAsError> <TreatWarningAsError>false</TreatWarningAsError>
<AdditionalIncludeDirectories>.\;..\</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\;..\</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4100;4127;4189;4244;4245;4310;4355;4505;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4127;4189;4244;4245;4310;4355;4505;%(DisableSpecificWarnings)</DisableSpecificWarnings>

View File

@ -70,7 +70,7 @@ private:
// The lock that protects access to target_message_loop_. // The lock that protects access to target_message_loop_.
mutable NLock message_loop_lock_; mutable NLock message_loop_lock_;
MessageLoop* target_message_loop_; nbase::MessageLoop* target_message_loop_;
private: private:
// This relay class remembers the MessageLoop that it was created on, and // This relay class remembers the MessageLoop that it was created on, and

View File

@ -14,396 +14,392 @@
namespace nbase namespace nbase
{ {
static const wchar_t kWndClass[] = L"NeteaseMessagePumpWindow";
static const unsigned int kMsgHaveWork = WM_USER + 1;
static const int kUserTimerMinmum = 10;
static const wchar_t kWndClass[] = L"NeteaseMessagePumpWindow"; WinUIMessagePump::WinUIMessagePump()
static const unsigned int kMsgHaveWork = WM_USER + 1;
static const int kUserTimerMinmum = 10;
WinUIMessagePump::WinUIMessagePump()
{
InitMessageWnd();
}
WinUIMessagePump::~WinUIMessagePump()
{
::DestroyWindow(message_hwnd_);
::UnregisterClassW(kWndClass, ::GetModuleHandle(NULL));
}
void WinUIMessagePump::ScheduleWork()
{
if (::InterlockedExchange(&have_work_, 1))
return; // Pump已经开始
// 通知MessagePump有新任务到达如果MessagePump处于睡眠状态这将唤醒它
::PostMessageW(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0);
}
void WinUIMessagePump::ScheduleDelayedWork(const TimeTicks& delayed_work_time)
{
//
// We would *like* to provide high resolution timers. Windows timers using
// SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup
// mechanism because the application can enter modal windows loops where it
// is not running our MessageLoop; the only way to have our timers fire in
// these cases is to post messages there.
//
// To provide sub-10ms timers, we process timers directly from our run loop.
// For the common case, timers will be processed there as the run loop does
// its normal work. However, we *also* set the system timer so that WM_TIMER
// events fire. This mops up the case of timers not being able to work in
// modal message loops. It is possible for the SetTimer to pop and have no
// pending timers, because they could have already been processed by the
// run loop itself.
//
// We use a single SetTimer corresponding to the timer that will expire
// soonest. As new timers are created and destroyed, we update SetTimer.
// Getting a spurrious SetTimer event firing is benign, as we'll just be
// processing an empty timer queue.
//
delayed_work_time_ = delayed_work_time;
DWORD wait_time;
int64_t delay_msec = GetCurrentDelay();
if (delay_msec < kUserTimerMinmum)
wait_time = kUserTimerMinmum;
else if (delay_msec < 0)
wait_time = INFINITE;
else if (delay_msec > 0xfffffffe)
wait_time = 0xfffffffe;
else
wait_time = static_cast<DWORD>(delay_msec);
// Create a WM_TIMER event that will wake us up to check for any pending
// timers (in case we are running within a nested, external sub-pump).
::SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), wait_time, NULL);
}
void WinUIMessagePump::PumpOutPendingPaintMessages()
{
// If we are being called outside of the context of Run, then don't try to do
// any work.
if (!state_)
return;
// Create a mini-message-pump to force immediate processing of only Windows
// WM_PAINT messages. Don't provide an infinite loop, but do enough peeking
// to get the job done. Actual common max is 4 peeks, but we'll be a little
// safe here.
const int kMaxPeekCount = 20;
int peek_count;
for (peek_count = 0; peek_count < kMaxPeekCount; ++peek_count)
{ {
MSG msg; InitMessageWnd();
if (!::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_PAINT))
break;
ProcessMessageHelper(msg);
if (state_->should_quit) // Handle WM_QUIT.
break;
} }
}
void WinUIMessagePump::InitMessageWnd() WinUIMessagePump::~WinUIMessagePump()
{
HINSTANCE hinst = ::GetModuleHandle(NULL);
WNDCLASSEXW wc = {0};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = WndProcThunk;
wc.hInstance = hinst;
wc.lpszClassName = kWndClass;
::RegisterClassExW(&wc);
message_hwnd_ = ::CreateWindowW(kWndClass, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0);
}
LRESULT CALLBACK WinUIMessagePump::WndProcThunk(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message)
{ {
case kMsgHaveWork: ::DestroyWindow(message_hwnd_);
reinterpret_cast<WinUIMessagePump*>(wparam)->HandleWorkMessage(); ::UnregisterClassW(kWndClass, ::GetModuleHandle(NULL));
break;
case WM_TIMER:
reinterpret_cast<WinUIMessagePump*>(wparam)->HandleTimerMessage();
break;
} }
return ::DefWindowProcW(hwnd, message, wparam, lparam);
}
void WinUIMessagePump::DoRunLoop() void WinUIMessagePump::ScheduleWork()
{
// IF this was just a simple ::PeekMessageW() loop (servicing all possible work
// queues), then Windows would try to achieve the following order according
// to MSDN documentation about ::PeekMessageW with no filter):
// * Sent messages
// * Posted messages
// * Sent messages (again)
// * WM_PAINT messages
// * WM_TIMER messages
//
// Summary: none of the above classes is starved, and sent messages has twice
// the chance of being processed (i.e., reduced service time).
for (;;)
{ {
// If we do any work, we may create more messages etc., and more work may if (::InterlockedExchange(&have_work_, 1))
// possibly be waiting in another task group. When we (for example) return; // Pump已经开始
// ProcessNextWindowsMessage(), there is a good chance there are still more
// messages waiting. On the other hand, when any of these methods return
// having done no work, then it is pretty unlikely that calling them again
// quickly will find any work to do. Finally, if they all say they had no
// work, then it is a good time to consider sleeping (waiting) for more
// work.
bool more_work_is_plausible = ProcessNextWindowsMessage(); // 通知MessagePump有新任务到达如果MessagePump处于睡眠状态这将唤醒它
if (state_->should_quit) ::PostMessageW(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0);
break;
more_work_is_plausible |= state_->delegate->DoWork();
if (state_->should_quit)
break;
more_work_is_plausible |=
state_->delegate->DoDelayedWork(&delayed_work_time_);
// If we did not process any delayed work, then we can assume that our
// existing WM_TIMER if any will fire when delayed work should run. We
// don't want to disturb that timer if it is already in flight. However,
// if we did do all remaining delayed work, then lets kill the WM_TIMER.
if (more_work_is_plausible && delayed_work_time_.is_null())
KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
if (state_->should_quit)
break;
if (more_work_is_plausible)
continue;
more_work_is_plausible = state_->delegate->DoIdleWork();
if (state_->should_quit)
break;
if (more_work_is_plausible)
continue;
WaitForWork(); // Wait (sleep) until we have work to do again.
} }
}
void WinUIMessagePump::WaitForWork() void WinUIMessagePump::ScheduleDelayedWork(const TimeTicks& delayed_work_time)
{
// Wait until a message is available, up to the time needed by the timer
// manager to fire the next set of timers.
int64_t delay = GetCurrentDelay();
DWORD wait_time;
if (delay < 0) // Negative value means no timers waiting.
wait_time = INFINITE;
else if (delay > 0xfffffffe)
wait_time = 0xfffffffe;
else
wait_time = static_cast<DWORD>(delay);
DWORD result = ::MsgWaitForMultipleObjectsEx(0, NULL, wait_time, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
if (WAIT_OBJECT_0 == result)
{ {
// A WM_* message is available. //
// If a parent child relationship exists between windows across threads // We would *like* to provide high resolution timers. Windows timers using
// then their thread inputs are implicitly attached. // SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup
// This causes the MsgWaitForMultipleObjectsEx API to return indicating // mechanism because the application can enter modal windows loops where it
// that messages are ready for processing (specifically mouse messages // is not running our MessageLoop; the only way to have our timers fire in
// intended for the child window. Occurs if the child window has capture) // these cases is to post messages there.
// The subsequent PeekMessages call fails to return any messages thus //
// causing us to enter a tight loop at times. // To provide sub-10ms timers, we process timers directly from our run loop.
// The WaitMessage call below is a workaround to give the child window // For the common case, timers will be processed there as the run loop does
// sometime to process its input messages. // its normal work. However, we *also* set the system timer so that WM_TIMER
MSG msg = {0}; // events fire. This mops up the case of timers not being able to work in
DWORD queue_status = ::GetQueueStatus(QS_MOUSE); // modal message loops. It is possible for the SetTimer to pop and have no
if (HIWORD(queue_status) & QS_MOUSE && !::PeekMessageW(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE)) // pending timers, because they could have already been processed by the
// run loop itself.
//
// We use a single SetTimer corresponding to the timer that will expire
// soonest. As new timers are created and destroyed, we update SetTimer.
// Getting a spurrious SetTimer event firing is benign, as we'll just be
// processing an empty timer queue.
//
delayed_work_time_ = delayed_work_time;
DWORD wait_time;
int64_t delay_msec = GetCurrentDelay();
if (delay_msec < kUserTimerMinmum)
wait_time = kUserTimerMinmum;
else if (delay_msec < 0)
wait_time = INFINITE;
else if (delay_msec > 0xfffffffe)
wait_time = 0xfffffffe;
else
wait_time = static_cast<DWORD>(delay_msec);
// Create a WM_TIMER event that will wake us up to check for any pending
// timers (in case we are running within a nested, external sub-pump).
::SetTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this), wait_time, NULL);
}
void WinUIMessagePump::PumpOutPendingPaintMessages()
{
// If we are being called outside of the context of Run, then don't try to do
// any work.
if (!state_)
return;
// Create a mini-message-pump to force immediate processing of only Windows
// WM_PAINT messages. Don't provide an infinite loop, but do enough peeking
// to get the job done. Actual common max is 4 peeks, but we'll be a little
// safe here.
const int kMaxPeekCount = 20;
int peek_count;
for (peek_count = 0; peek_count < kMaxPeekCount; ++peek_count)
{ {
WaitMessage(); MSG msg;
if (!::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE | PM_QS_PAINT))
break;
ProcessMessageHelper(msg);
if (state_->should_quit) // Handle WM_QUIT.
break;
} }
return;
}
}
void WinUIMessagePump::HandleWorkMessage()
{
// If we are being called outside of the context of Run, then don't try to do
// any work. This could correspond to a MessageBox call or something of that
// sort.
if (!state_)
{
// Since we handled a kMsgHaveWork message, we must still update this flag.
::InterlockedExchange(&have_work_, 0);
return;
} }
// Let whatever would have run had we not been putting messages in the queue void WinUIMessagePump::InitMessageWnd()
// run now. This is an attempt to make our dummy message not starve other
// messages that may be in the Windows message queue.
ProcessPumpReplacementMessage();
// Now give the delegate a chance to do some work. He'll let us know if he
// needs to do more work.
if (state_->delegate->DoWork())
ScheduleWork();
}
void WinUIMessagePump::HandleTimerMessage()
{
::KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
// If we are being called outside of the context of Run, then don't do
// anything. This could correspond to a MessageBox call or something of
// that sort.
if (!state_)
return;
state_->delegate->DoDelayedWork(&delayed_work_time_);
if (!delayed_work_time_.is_null())
{ {
// A bit gratuitous to set delayed_work_time_ again, but oh well. HINSTANCE hinst = ::GetModuleHandle(NULL);
ScheduleDelayedWork(delayed_work_time_);
}
}
bool WinUIMessagePump::ProcessNextWindowsMessage() WNDCLASSEXW wc = { 0 };
{ wc.cbSize = sizeof(wc);
// If there are sent messages in the queue then PeekMessage internally wc.lpfnWndProc = WndProcThunk;
// dispatches the message and returns false. We return true in this wc.hInstance = hinst;
// case to ensure that the message loop peeks again instead of calling wc.lpszClassName = kWndClass;
// MsgWaitForMultipleObjectsEx again. ::RegisterClassExW(&wc);
bool sent_messages_in_queue = false;
DWORD queue_status = ::GetQueueStatus(QS_SENDMESSAGE);
if (HIWORD(queue_status) & QS_SENDMESSAGE)
sent_messages_in_queue = true;
MSG msg; message_hwnd_ = ::CreateWindowW(kWndClass, 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, 0);
if (::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
return ProcessMessageHelper(msg);
return sent_messages_in_queue;
}
bool WinUIMessagePump::ProcessMessageHelper(const MSG& msg)
{
if (WM_QUIT == msg.message)
{
// Repost the QUIT message so that it will be retrieved by the primary
// GetMessage() loop.
state_->should_quit = true;
::PostQuitMessage(static_cast<int>(msg.wParam));
return false;
} }
// While running our main message pump, we discard kMsgHaveWork messages. LRESULT CALLBACK WinUIMessagePump::WndProcThunk(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_)
return ProcessPumpReplacementMessage();
if (::CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode))
return true;
PreProcessMessage(msg);
if (state_->dispatcher)
{ {
if (!state_->dispatcher->Dispatch(msg)) switch (message)
{
case kMsgHaveWork:
reinterpret_cast<WinUIMessagePump*>(wparam)->HandleWorkMessage();
break;
case WM_TIMER:
reinterpret_cast<WinUIMessagePump*>(wparam)->HandleTimerMessage();
break;
}
return ::DefWindowProcW(hwnd, message, wparam, lparam);
}
void WinUIMessagePump::DoRunLoop()
{
// IF this was just a simple ::PeekMessageW() loop (servicing all possible work
// queues), then Windows would try to achieve the following order according
// to MSDN documentation about ::PeekMessageW with no filter):
// * Sent messages
// * Posted messages
// * Sent messages (again)
// * WM_PAINT messages
// * WM_TIMER messages
//
// Summary: none of the above classes is starved, and sent messages has twice
// the chance of being processed (i.e., reduced service time).
for (;;)
{
// If we do any work, we may create more messages etc., and more work may
// possibly be waiting in another task group. When we (for example)
// ProcessNextWindowsMessage(), there is a good chance there are still more
// messages waiting. On the other hand, when any of these methods return
// having done no work, then it is pretty unlikely that calling them again
// quickly will find any work to do. Finally, if they all say they had no
// work, then it is a good time to consider sleeping (waiting) for more
// work.
bool more_work_is_plausible = ProcessNextWindowsMessage();
if (state_->should_quit)
break;
more_work_is_plausible |= state_->delegate->DoWork();
if (state_->should_quit)
break;
more_work_is_plausible |=
state_->delegate->DoDelayedWork(&delayed_work_time_);
// If we did not process any delayed work, then we can assume that our
// existing WM_TIMER if any will fire when delayed work should run. We
// don't want to disturb that timer if it is already in flight. However,
// if we did do all remaining delayed work, then lets kill the WM_TIMER.
if (more_work_is_plausible && delayed_work_time_.is_null())
KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
if (state_->should_quit)
break;
if (more_work_is_plausible)
continue;
more_work_is_plausible = state_->delegate->DoIdleWork();
if (state_->should_quit)
break;
if (more_work_is_plausible)
continue;
WaitForWork(); // Wait (sleep) until we have work to do again.
}
}
void WinUIMessagePump::WaitForWork()
{
// Wait until a message is available, up to the time needed by the timer
// manager to fire the next set of timers.
int64_t delay = GetCurrentDelay();
DWORD wait_time;
if (delay < 0) // Negative value means no timers waiting.
wait_time = INFINITE;
else if (delay > 0xfffffffe)
wait_time = 0xfffffffe;
else
wait_time = static_cast<DWORD>(delay);
DWORD result = ::MsgWaitForMultipleObjectsEx(0, NULL, wait_time, QS_ALLINPUT, MWMO_INPUTAVAILABLE);
if (WAIT_OBJECT_0 == result)
{
// A WM_* message is available.
// If a parent child relationship exists between windows across threads
// then their thread inputs are implicitly attached.
// This causes the MsgWaitForMultipleObjectsEx API to return indicating
// that messages are ready for processing (specifically mouse messages
// intended for the child window. Occurs if the child window has capture)
// The subsequent PeekMessages call fails to return any messages thus
// causing us to enter a tight loop at times.
// The WaitMessage call below is a workaround to give the child window
// sometime to process its input messages.
MSG msg = { 0 };
DWORD queue_status = ::GetQueueStatus(QS_MOUSE);
if (HIWORD(queue_status) & QS_MOUSE && !::PeekMessageW(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE))
{
WaitMessage();
}
return;
}
}
void WinUIMessagePump::HandleWorkMessage()
{
// If we are being called outside of the context of Run, then don't try to do
// any work. This could correspond to a MessageBox call or something of that
// sort.
if (!state_)
{
// Since we handled a kMsgHaveWork message, we must still update this flag.
::InterlockedExchange(&have_work_, 0);
return;
}
// Let whatever would have run had we not been putting messages in the queue
// run now. This is an attempt to make our dummy message not starve other
// messages that may be in the Windows message queue.
ProcessPumpReplacementMessage();
// Now give the delegate a chance to do some work. He'll let us know if he
// needs to do more work.
if (state_->delegate->DoWork())
ScheduleWork();
}
void WinUIMessagePump::HandleTimerMessage()
{
::KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
// If we are being called outside of the context of Run, then don't do
// anything. This could correspond to a MessageBox call or something of
// that sort.
if (!state_)
return;
state_->delegate->DoDelayedWork(&delayed_work_time_);
if (!delayed_work_time_.is_null())
{
// A bit gratuitous to set delayed_work_time_ again, but oh well.
ScheduleDelayedWork(delayed_work_time_);
}
}
bool WinUIMessagePump::ProcessNextWindowsMessage()
{
// If there are sent messages in the queue then PeekMessage internally
// dispatches the message and returns false. We return true in this
// case to ensure that the message loop peeks again instead of calling
// MsgWaitForMultipleObjectsEx again.
bool sent_messages_in_queue = false;
DWORD queue_status = ::GetQueueStatus(QS_SENDMESSAGE);
if (HIWORD(queue_status) & QS_SENDMESSAGE)
sent_messages_in_queue = true;
MSG msg;
if (::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
return ProcessMessageHelper(msg);
return sent_messages_in_queue;
}
bool WinUIMessagePump::ProcessMessageHelper(const MSG& msg)
{
if (WM_QUIT == msg.message)
{
// Repost the QUIT message so that it will be retrieved by the primary
// GetMessage() loop.
state_->should_quit = true; state_->should_quit = true;
::PostQuitMessage(static_cast<int>(msg.wParam));
return false;
}
// While running our main message pump, we discard kMsgHaveWork messages.
if (msg.message == kMsgHaveWork && msg.hwnd == message_hwnd_)
return ProcessPumpReplacementMessage();
if (::CallMsgFilter(const_cast<MSG*>(&msg), kMessageFilterCode))
return true;
PreProcessMessage(msg);
if (state_->dispatcher)
{
if (!state_->dispatcher->Dispatch(msg))
state_->should_quit = true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
PostProcessMessage(msg);
return true;
} }
else
bool WinUIMessagePump::ProcessPumpReplacementMessage()
{ {
TranslateMessage(&msg); // When we encounter a kMsgHaveWork message, this method is called to peek
DispatchMessage(&msg); // and process a replacement message, such as a WM_PAINT or WM_TIMER. The
// goal is to make the kMsgHaveWork as non-intrusive as possible, even though
// a continuous stream of such messages are posted. This method carefully
// peeks a message while there is no chance for a kMsgHaveWork to be pending,
// then resets the have_work_ flag (allowing a replacement kMsgHaveWork to
// possibly be posted), and finally dispatches that peeked replacement. Note
// that the re-post of kMsgHaveWork may be asynchronous to this thread!!
bool have_message = false;
MSG msg;
// We should not process all window messages if we are in the context of an
// OS modal loop, i.e. in the context of a windows API call like MessageBox.
// This is to ensure that these messages are peeked out by the OS modal loop.
if (MessageLoop::current()->os_modal_loop())
{
// We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above.
have_message = ::PeekMessageW(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ||
::PeekMessageW(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
}
else
{
have_message = (0 != ::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE));
}
// Since we discarded a kMsgHaveWork message, we must update the flag.
::InterlockedExchange(&have_work_, 0);
// We don't need a special time slice if we didn't have_message to process.
if (!have_message)
return false;
// Guarantee we'll get another time slice in the case where we go into native
// windows code. This ScheduleWork() may hurt performance a tiny bit when
// tasks appear very infrequently, but when the event queue is busy, the
// kMsgHaveWork events get (percentage wise) rarer and rarer.
ScheduleWork();
return ProcessMessageHelper(msg);
} }
PostProcessMessage(msg); void WinUIMessagePump::AddObserver(UIObserver* observer)
return true;
}
bool WinUIMessagePump::ProcessPumpReplacementMessage()
{
// When we encounter a kMsgHaveWork message, this method is called to peek
// and process a replacement message, such as a WM_PAINT or WM_TIMER. The
// goal is to make the kMsgHaveWork as non-intrusive as possible, even though
// a continuous stream of such messages are posted. This method carefully
// peeks a message while there is no chance for a kMsgHaveWork to be pending,
// then resets the have_work_ flag (allowing a replacement kMsgHaveWork to
// possibly be posted), and finally dispatches that peeked replacement. Note
// that the re-post of kMsgHaveWork may be asynchronous to this thread!!
bool have_message = false;
MSG msg;
// We should not process all window messages if we are in the context of an
// OS modal loop, i.e. in the context of a windows API call like MessageBox.
// This is to ensure that these messages are peeked out by the OS modal loop.
if (MessageLoop::current()->os_modal_loop())
{ {
// We only peek out WM_PAINT and WM_TIMER here for reasons mentioned above. observers_.AddObserver(observer);
have_message = ::PeekMessageW(&msg, NULL, WM_PAINT, WM_PAINT, PM_REMOVE) ||
::PeekMessageW(&msg, NULL, WM_TIMER, WM_TIMER, PM_REMOVE);
} }
else
void WinUIMessagePump::RemoveObserver(UIObserver* observer)
{ {
have_message = (0 != ::PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)); observers_.RemoveObserver(observer);
} }
// Since we discarded a kMsgHaveWork message, we must update the flag. void WinUIMessagePump::PreProcessMessage(const MSG& msg)
::InterlockedExchange(&have_work_, 0);
// We don't need a special time slice if we didn't have_message to process.
if (!have_message)
return false;
// Guarantee we'll get another time slice in the case where we go into native
// windows code. This ScheduleWork() may hurt performance a tiny bit when
// tasks appear very infrequently, but when the event queue is busy, the
// kMsgHaveWork events get (percentage wise) rarer and rarer.
ScheduleWork();
return ProcessMessageHelper(msg);
}
void WinUIMessagePump::AddObserver(UIObserver *observer)
{
observers_.AddObserver(observer);
}
void WinUIMessagePump::RemoveObserver(UIObserver *observer)
{
observers_.RemoveObserver(observer);
}
void WinUIMessagePump::PreProcessMessage(const MSG& msg)
{
AutoLazyEraser lazy_eraser(&observers_);
size_t index = 0;
UIObserver* observer;
while (index < observers_.GetObserverCount())
{ {
observer = observers_.GetObserver(index++); AutoLazyEraser lazy_eraser(&observers_);
if (observer == NULL) size_t index = 0;
continue; UIObserver* observer;
observer->PreProcessMessage(msg); while (index < observers_.GetObserverCount())
{
observer = observers_.GetObserver(index++);
if (observer == NULL)
continue;
observer->PreProcessMessage(msg);
}
} }
}
void WinUIMessagePump::PostProcessMessage(const MSG& msg) void WinUIMessagePump::PostProcessMessage(const MSG& msg)
{
AutoLazyEraser lazy_eraser(&observers_);
size_t index = 0;
UIObserver* observer;
while (index < observers_.GetObserverCount())
{ {
observer = observers_.GetObserver(index++); AutoLazyEraser lazy_eraser(&observers_);
if (observer == NULL) size_t index = 0;
continue; UIObserver* observer;
observer->PostProcessMessage(msg); while (index < observers_.GetObserverCount())
{
observer = observers_.GetObserver(index++);
if (observer == NULL)
continue;
observer->PostProcessMessage(msg);
}
} }
}
} // namespace nbase } // namespace nbase
#endif // OS_WIN #endif // OS_WIN

View File

@ -12,7 +12,7 @@
</HBox> </HBox>
<Box> <Box>
<VBox margin="0,0,0,0" valign="center" halign="center" width="auto" height="auto"> <VBox margin="0,0,0,0" valign="center" halign="center" width="auto" height="auto">
<Label name="tooltip" text="一个简单窗口,带有标题栏和常规按钮。"/> <Label name="tooltip" text="dfasdfasd"/>
</VBox> </VBox>
</Box> </Box>
</VBox> </VBox>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Window> <Window caption="0,0,180,30" roundcorner="5,5" sizebox="10,10,10,10" mininfo="280,70" maxinfo="300,700">
<ListContainerElement class="listitem" height="auto"> <ListContainerElement class="listitem" height="auto">
<HBox height="auto" mouse="false" padding="10,5,10,5"> <HBox height="auto" mouse="false" padding="10,5,10,5">
<Control name="control_img" width="auto" height="auto" margin="0,0,10" mouse="false"/> <Control name="control_img" width="auto" height="auto" margin="0,0,10" mouse="false"/>

View File

@ -1,88 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0"?>
<Window size="1200,800" caption="0,0,0,35"> <Window size="1200,800" caption="0,0,0,35">
<VBox bkcolor="bk_wnd_darkcolor"> <VBox bkcolor="bk_wnd_darkcolor">
<HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor"> <HBox width="stretch" height="35" bkcolor="bk_wnd_lightcolor">
<Label text="TileBox数据懒加载实现" font="system_14" valign="center" margin="8"/> <Label text="TileBox数据懒加载实现" font="system_14" valign="center" margin="8" />
<Control /> <Control />
<Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0"/> <Button class="btn_wnd_min" name="minbtn" margin="4,6,0,0" />
<Box width="21" margin="4,6,0,0"> <Box width="21" margin="4,6,0,0">
<Button class="btn_wnd_max" name="maxbtn"/> <Button class="btn_wnd_max" name="maxbtn" />
<Button class="btn_wnd_restore" name="restorebtn" visible="false"/> <Button class="btn_wnd_restore" name="restorebtn" visible="false" />
</Box> </Box>
<Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0"/> <Button class="btn_wnd_close" name="closebtn" margin="4,6,8,0" />
</HBox> </HBox>
<HBox childmargin="5" bkcolor="white" padding="5,5,5,10"> <HBox childmargin="5" bkcolor="white" padding="5,5,5,10">
<VBox width="300" bordersize="1" bordercolor="splitline_level2" padding="5,10,5,10" childmargin="10"> <VBox width="300" bordersize="1" bordercolor="splitline_level2" padding="5,10,5,10" childmargin="10">
<HBox height="30" childmargin="10"> <HBox height="30" childmargin="10">
<Label font="system_bold_14" text="列设置:" width="auto" height="auto" valign="center" /> <Label font="system_bold_14" text="列设置:" width="auto" height="auto" valign="center" />
<Option class="circle_option_2" name="option_column_auto" group="option_group" text="自动计算" margin="0,5,0,10" selected="true"/> <Option class="circle_option_2" name="option_column_auto" group="option_group" text="自动计算" margin="0,5,0,10" selected="true" />
<Option class="circle_option_2" name="option_column_fix" group="option_group" text="固定列数" margin="0,5,0,10"> <Option class="circle_option_2" name="option_column_fix" group="option_group" text="固定列数" margin="0,5,0,10">
<Event type="select" receiver="box_column_op" applyattribute="visible=&quot;true&quot;" /> <Event type="select" receiver="box_column_op" applyattribute="visible=&quot;true&quot;" />
<Event type="unselect" receiver="box_column_op" applyattribute="visible=&quot;false&quot;" /> <Event type="unselect" receiver="box_column_op" applyattribute="visible=&quot;false&quot;" />
</Option> </Option>
</HBox> </HBox>
<HBox name="box_column_op" height="30" childmargin="10" visible="false">
<HBox name="box_column_op" height="30" childmargin="10" visible="false"> <Control width="45" />
<Control width="45" /> <Box bordersize="1" bordercolor="splitline_level1" width="80" height="26">
<Box bordersize="1" bordercolor="splitline_level1" width="80" height="26"> <RichEdit name="edit_column" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="列数" align="vcenter,hcenter" text="3" promptcolor="splitline_level1" autohscroll="true" />
<RichEdit name="edit_column" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="列数" align="vcenter,hcenter" text="3" promptcolor="splitline_level1" autohscroll="true" /> </Box>
</Box> <CheckBox class="checkbox_font12" name="checkbox_item_center" text="列表居中" margin="0,5,0,10" selected="true" />
<CheckBox class="checkbox_font12" name="checkbox_item_center" text="列表居中" margin="0,5,0,10" selected="true" /> </HBox>
</HBox> <Control height="1" bkcolor="splitline_level2" />
<Control height="1" bkcolor="splitline_level2" /> <HBox height="30" childmargin="10">
<HBox height="30" childmargin="10"> <Label font="system_bold_14" text="子项间隙:" width="auto" height="auto" valign="center" />
<Label font="system_bold_14" text="子项间隙:" width="auto" height="auto" valign="center" /> <Box bordersize="1" bordercolor="splitline_level1" width="80" height="26">
<Box bordersize="1" bordercolor="splitline_level1" width="80" height="26"> <RichEdit name="edit_child_margin" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="子项间隙" align="vcenter,hcenter" text="" promptcolor="splitline_level1" autohscroll="true" />
<RichEdit name="edit_child_margin" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="子项间隙" align="vcenter,hcenter" text="" promptcolor="splitline_level1" autohscroll="true" /> </Box>
</Box> </HBox>
</HBox> <HBox height="30" childmargin="10">
<HBox height="30" childmargin="10"> <Label font="system_bold_14" text="总数据:" width="auto" height="auto" valign="center" />
<Label font="system_bold_14" text="总数据:" width="auto" height="auto" valign="center" /> <Box bordersize="1" bordercolor="splitline_level1" width="180">
<Box bordersize="1" bordercolor="splitline_level1" width="180" > <RichEdit name="edit_total" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="总数据" promptcolor="splitline_level1" autohscroll="true" />
<RichEdit name="edit_total" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="总数据" promptcolor="splitline_level1" autohscroll="true" /> </Box>
</Box> </HBox>
<Box height="30" childmargin="10" width="stretch">
</HBox> <Button class="btn_global_blue_80x30" halign="center" valign="center" name="btn_set_total" text="更改/设置" />
</Box>
<Box height="30" childmargin="10" width="stretch"> <Control height="1" bkcolor="splitline_level2" />
<Button class="btn_global_blue_80x30" halign="center" valign="center" name="btn_set_total" text="更改/设置" /> <HBox height="30" childmargin="10">
</Box> <Label font="system_bold_14" text="改变数据:" width="auto" height="auto" valign="center" />
<Box bordersize="1" bordercolor="splitline_level1" height="26">
<Control height="1" bkcolor="splitline_level2" /> <RichEdit name="edit_update" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="序号(下标1)" promptcolor="splitline_level1" autohscroll="true" align="vcenter,hcenter" />
</Box>
<HBox height="30" childmargin="10"> <Box bordersize="1" bordercolor="splitline_level1" height="26">
<Label font="system_bold_14" text="改变数据:" width="auto" height="auto" valign="center" /> <RichEdit name="edit_task_name" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="新的任务名称" promptcolor="splitline_level1" autohscroll="true" />
<Box bordersize="1" bordercolor="splitline_level1" height="26"> </Box>
<RichEdit name="edit_update" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="序号(下标1)" promptcolor="splitline_level1" autohscroll="true" align="vcenter,hcenter" /> </HBox>
</Box> <Box height="30" childmargin="10" width="stretch">
<Box bordersize="1" bordercolor="splitline_level1" height="26"> <Button class="btn_global_blue_80x30" halign="center" valign="center" name="btn_update" text="更新数据" />
<RichEdit name="edit_task_name" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="新的任务名称" promptcolor="splitline_level1" autohscroll="true" /> </Box>
</Box> <Control height="1" bkcolor="splitline_level2" />
</HBox> <HBox height="30" childmargin="10">
<Label font="system_bold_14" text="删除数据:" width="auto" height="auto" valign="center" />
<Box bordersize="1" bordercolor="splitline_level1">
<Box height="30" childmargin="10" width="stretch"> <RichEdit name="edit_delete" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" promptmode="true" prompttext="序号(下标1)" promptcolor="splitline_level1" autohscroll="true" align="vcenter,hcenter" />
<Button class="btn_global_blue_80x30" halign="center" valign="center" name="btn_update" text="更新数据" /> </Box>
</Box> <Button class="btn_global_red_80x30" halign="center" valign="center" name="btn_delete" text="删除数据" />
</HBox>
<Control height="1" bkcolor="splitline_level2" /> </VBox>
<!--column="3" width="auto" halign="center" childmargin="10" -->
<HBox height="30" childmargin="10"> <Box>
<Label font="system_bold_14" text="删除数据:" width="auto" height="auto" valign="center" /> <VirtualTileBox class="list" name="list" vscrollunit="70" itemsize="220,60" bordersize="1" bordercolor="splitline_level2" padding="1,1,1,1" />
<Box bordersize="1" bordercolor="splitline_level1" > </Box>
<RichEdit name="edit_delete" margin="10,0,10,0" font="system_14" width="stretch" height="auto" valign="center" normaltextcolor="black" multiline="false" promptmode="true" prompttext="序号(下标1)" promptcolor="splitline_level1" autohscroll="true" align="vcenter,hcenter" /> </HBox>
</Box> </VBox>
<Button class="btn_global_red_80x30" halign="center" valign="center" name="btn_delete" text="删除数据" /> </Window>
</HBox>
</VBox>
<!--column="3" width="auto" halign="center" childmargin="10" -->
<Box>
<VirtualTileBox class="list" name="list" vscrollunit="70" itemsize="220,60" bordersize="1" bordercolor="splitline_level2" padding="1,1,1,1">
</VirtualTileBox>
</Box>
</HBox>
</VBox>
</Window>

View File

@ -2,488 +2,481 @@
namespace ui namespace ui
{ {
WindowImplBase::WindowImplBase()
WindowImplBase::WindowImplBase()
{
}
WindowImplBase::~WindowImplBase()
{
}
void WindowImplBase::OnFinalMessage( HWND hWnd )
{
__super::OnFinalMessage(hWnd);
ReapObjects(GetRoot());
delete this;
}
LONG WindowImplBase::GetStyle()
{
LONG styleValue = ::GetWindowLong(GetHWND(), GWL_STYLE);
styleValue &= ~WS_CAPTION;
return styleValue;
}
UINT WindowImplBase::GetClassStyle() const
{
return CS_DBLCLKS;
}
std::wstring WindowImplBase::GetResourceID() const
{
return _T("");
}
Control* WindowImplBase::CreateControl(const std::wstring& pstrClass)
{
return NULL;
}
LRESULT WindowImplBase::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return FALSE;
}
LRESULT WindowImplBase::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if( ::IsIconic(GetHWND()) ) bHandled = FALSE;
return (wParam == 0) ? TRUE : FALSE;
}
LRESULT WindowImplBase::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT WindowImplBase::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
if (IsZoomed(m_hWnd))
{ {
LPWINDOWPOS lpPos = (LPWINDOWPOS)lParam; }
if (lpPos->flags & SWP_FRAMECHANGED) // 第一次最大化而不是最大化之后所触发的WINDOWPOSCHANGE
WindowImplBase::~WindowImplBase()
{
}
void WindowImplBase::OnFinalMessage(HWND hWnd)
{
__super::OnFinalMessage(hWnd);
ReapObjects(GetRoot());
delete this;
}
LONG WindowImplBase::GetStyle()
{
LONG styleValue = ::GetWindowLong(GetHWND(), GWL_STYLE);
styleValue &= ~WS_CAPTION;
return styleValue;
}
UINT WindowImplBase::GetClassStyle() const
{
return CS_DBLCLKS;
}
std::wstring WindowImplBase::GetResourceID() const
{
return _T("");
}
Control* WindowImplBase::CreateControl(const std::wstring& pstrClass)
{
return NULL;
}
LRESULT WindowImplBase::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return FALSE;
}
LRESULT WindowImplBase::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (::IsIconic(GetHWND())) bHandled = FALSE;
return (wParam == 0) ? TRUE : FALSE;
}
LRESULT WindowImplBase::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT WindowImplBase::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
if (IsZoomed(m_hWnd))
{ {
POINT pt = { 0, 0 }; LPWINDOWPOS lpPos = (LPWINDOWPOS)lParam;
HMONITOR hMontorPrimary = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY); if (lpPos->flags & SWP_FRAMECHANGED) // 第一次最大化而不是最大化之后所触发的WINDOWPOSCHANGE
HMONITOR hMonitorTo = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
if (hMonitorTo != hMontorPrimary)
{ {
// 解决无边框窗口在双屏下面(副屏分辨率大于主屏)时,最大化不正确的问题 POINT pt = { 0, 0 };
MONITORINFO miTo = { sizeof(miTo), 0 }; HMONITOR hMontorPrimary = MonitorFromPoint(pt, MONITOR_DEFAULTTOPRIMARY);
GetMonitorInfo(hMonitorTo, &miTo); HMONITOR hMonitorTo = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST);
lpPos->x = miTo.rcWork.left; if (hMonitorTo != hMontorPrimary)
lpPos->y = miTo.rcWork.top; {
lpPos->cx = miTo.rcWork.right - miTo.rcWork.left; // 解决无边框窗口在双屏下面(副屏分辨率大于主屏)时,最大化不正确的问题
lpPos->cy = miTo.rcWork.bottom - miTo.rcWork.top; MONITORINFO miTo = { sizeof(miTo), 0 };
GetMonitorInfo(hMonitorTo, &miTo);
lpPos->x = miTo.rcWork.left;
lpPos->y = miTo.rcWork.top;
lpPos->cx = miTo.rcWork.right - miTo.rcWork.left;
lpPos->cy = miTo.rcWork.bottom - miTo.rcWork.top;
}
} }
} }
return 0;
} }
return 0;
}
LRESULT WindowImplBase::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT WindowImplBase::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return 0;
}
LRESULT WindowImplBase::OnNcLButtonDbClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
/*if (!::IsZoomed(GetHWND()))
{ {
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); return 0;
} }
else
LRESULT WindowImplBase::OnNcLButtonDbClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); /*if (!::IsZoomed(GetHWND()))
}*/ {
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
return 0;
}
LRESULT WindowImplBase::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
::ScreenToClient(GetHWND(), &pt);
UiRect rcClient;
::GetClientRect(GetHWND(), &rcClient);
rcClient.Deflate(m_shadow.GetShadowCorner());
if( !::IsZoomed(GetHWND()) ) {
UiRect rcSizeBox = GetSizeBox();
if( pt.y < rcClient.top + rcSizeBox.top ) {
if (pt.y >= rcClient.top) {
if (pt.x < (rcClient.left + rcSizeBox.left) && pt.x >= rcClient.left) return HTTOPLEFT;
else if (pt.x >(rcClient.right - rcSizeBox.right) && pt.x <= rcClient.right) return HTTOPRIGHT;
else return HTTOP;
}
else return HTCLIENT;
}
else if( pt.y > rcClient.bottom - rcSizeBox.bottom ) {
if (pt.y <= rcClient.bottom) {
if (pt.x < (rcClient.left + rcSizeBox.left) && pt.x >= rcClient.left) return HTBOTTOMLEFT;
else if (pt.x > (rcClient.right - rcSizeBox.right) && pt.x <= rcClient.right) return HTBOTTOMRIGHT;
else return HTBOTTOM;
}
else return HTCLIENT;
} }
else
{
SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
}*/
if (pt.x < rcClient.left + rcSizeBox.left) { return 0;
if (pt.x >= rcClient.left) return HTLEFT;
else return HTCLIENT;
}
if (pt.x > rcClient.right - rcSizeBox.right) {
if (pt.x <= rcClient.right) return HTRIGHT;
else return HTCLIENT;
}
} }
UiRect rcCaption = GetCaptionRect(); LRESULT WindowImplBase::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
if( pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \ {
&& pt.y >= rcClient.top + rcCaption.top && pt.y < rcClient.top + rcCaption.bottom ) { POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
::ScreenToClient(GetHWND(), &pt);
UiRect rcClient;
::GetClientRect(GetHWND(), &rcClient);
rcClient.Deflate(m_shadow.GetShadowCorner());
if (!::IsZoomed(GetHWND())) {
UiRect rcSizeBox = GetSizeBox();
if (pt.y < rcClient.top + rcSizeBox.top) {
if (pt.y >= rcClient.top) {
if (pt.x < (rcClient.left + rcSizeBox.left) && pt.x >= rcClient.left) return HTTOPLEFT;
else if (pt.x > (rcClient.right - rcSizeBox.right) && pt.x <= rcClient.right) return HTTOPRIGHT;
else return HTTOP;
}
else return HTCLIENT;
}
else if (pt.y > rcClient.bottom - rcSizeBox.bottom) {
if (pt.y <= rcClient.bottom) {
if (pt.x < (rcClient.left + rcSizeBox.left) && pt.x >= rcClient.left) return HTBOTTOMLEFT;
else if (pt.x > (rcClient.right - rcSizeBox.right) && pt.x <= rcClient.right) return HTBOTTOMRIGHT;
else return HTBOTTOM;
}
else return HTCLIENT;
}
if (pt.x < rcClient.left + rcSizeBox.left) {
if (pt.x >= rcClient.left) return HTLEFT;
else return HTCLIENT;
}
if (pt.x > rcClient.right - rcSizeBox.right) {
if (pt.x <= rcClient.right) return HTRIGHT;
else return HTCLIENT;
}
}
UiRect rcCaption = GetCaptionRect();
if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
&& pt.y >= rcClient.top + rcCaption.top && pt.y < rcClient.top + rcCaption.bottom) {
Control* pControl = FindControl(pt); Control* pControl = FindControl(pt);
if( pControl ) { if (pControl) {
if (dynamic_cast<Button*>(pControl) || dynamic_cast<ButtonBox*>(pControl) || dynamic_cast<RichEdit*>(pControl)) if (dynamic_cast<Button*>(pControl) || dynamic_cast<ButtonBox*>(pControl) || dynamic_cast<RichEdit*>(pControl))
return HTCLIENT; return HTCLIENT;
else else
return HTCAPTION; return HTCAPTION;
} }
}
return HTCLIENT;
} }
return HTCLIENT; LRESULT WindowImplBase::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
} {
LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
MONITORINFO oMonitor = {};
oMonitor.cbSize = sizeof(oMonitor);
::GetMonitorInfo(::MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTONEAREST), &oMonitor);
UiRect rcWork = oMonitor.rcWork;
UiRect rcMonitor = oMonitor.rcMonitor;
rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
LRESULT WindowImplBase::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) UiRect rcMaximize = GetMaximizeInfo();
{ if (rcMaximize.GetWidth() > 0 && rcMaximize.GetHeight() > 0) {
LPMINMAXINFO lpMMI = (LPMINMAXINFO) lParam; lpMMI->ptMaxPosition.x = rcWork.left + rcMaximize.left;
MONITORINFO oMonitor = {}; lpMMI->ptMaxPosition.y = rcWork.top + rcMaximize.top;
oMonitor.cbSize = sizeof(oMonitor); lpMMI->ptMaxSize.x = rcMaximize.GetWidth();
::GetMonitorInfo(::MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTONEAREST), &oMonitor); lpMMI->ptMaxSize.y = rcMaximize.GetHeight();
UiRect rcWork = oMonitor.rcWork; }
UiRect rcMonitor = oMonitor.rcMonitor; else {
rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top); // 计算最大化时,正确的原点坐标
lpMMI->ptMaxPosition.x = rcWork.left;
lpMMI->ptMaxPosition.y = rcWork.top;
lpMMI->ptMaxSize.x = rcWork.GetWidth();
lpMMI->ptMaxSize.y = rcWork.GetHeight();
}
UiRect rcMaximize = GetMaximizeInfo(); if (GetMaxInfo().cx != 0) {
if (rcMaximize.GetWidth() > 0 && rcMaximize.GetHeight() > 0) { lpMMI->ptMaxTrackSize.x = GetMaxInfo(true).cx;
lpMMI->ptMaxPosition.x = rcWork.left + rcMaximize.left; }
lpMMI->ptMaxPosition.y = rcWork.top + rcMaximize.top; if (GetMaxInfo().cy != 0) {
lpMMI->ptMaxSize.x = rcMaximize.GetWidth(); lpMMI->ptMaxTrackSize.y = GetMaxInfo(true).cy;
lpMMI->ptMaxSize.y = rcMaximize.GetHeight(); }
} if (GetMinInfo().cx != 0) {
else { lpMMI->ptMinTrackSize.x = GetMinInfo(true).cx;
// 计算最大化时,正确的原点坐标 }
lpMMI->ptMaxPosition.x = rcWork.left; if (GetMinInfo().cy != 0) {
lpMMI->ptMaxPosition.y = rcWork.top; lpMMI->ptMinTrackSize.y = GetMinInfo(true).cy;
lpMMI->ptMaxSize.x = rcWork.GetWidth(); }
lpMMI->ptMaxSize.y = rcWork.GetHeight();
}
if (GetMaxInfo().cx != 0) { bHandled = FALSE;
lpMMI->ptMaxTrackSize.x = GetMaxInfo(true).cx;
}
if (GetMaxInfo().cy != 0) {
lpMMI->ptMaxTrackSize.y = GetMaxInfo(true).cy;
}
if (GetMinInfo().cx != 0) {
lpMMI->ptMinTrackSize.x = GetMinInfo(true).cx;
}
if (GetMinInfo().cy != 0) {
lpMMI->ptMinTrackSize.y = GetMinInfo(true).cy;
}
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnDpiChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
// 重置全局 DPI 设定
DpiManager::GetInstance()->SetScale(LOWORD(wParam));
// 重置阴影范围
m_shadow.ResetShadowBox();
// TODO 对窗口大小进行进行改变,让所有控件重新根据 DPI 计算大小
return 0;
}
LRESULT WindowImplBase::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CSize szRoundCorner = GetRoundCorner();
if( !::IsIconic(GetHWND()) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0) ) {
UiRect rcWnd;
::GetWindowRect(GetHWND(), &rcWnd);
rcWnd.Offset(-rcWnd.left, -rcWnd.top);
rcWnd.right++; rcWnd.bottom++;
HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
::SetWindowRgn(GetHWND(), hRgn, TRUE);
::DeleteObject(hRgn);
}
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (wParam == SC_CLOSE) {
bHandled = TRUE;
SendMessage(WM_CLOSE);
return 0; return 0;
} }
BOOL bZoomed = ::IsZoomed(GetHWND()); LRESULT WindowImplBase::OnMouseWheel(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
LRESULT lRes = Window::HandleMessage(uMsg, wParam, lParam);
if( ::IsZoomed(GetHWND()) != bZoomed )
{ {
bHandled = FALSE;
return 0;
} }
return lRes; LRESULT WindowImplBase::OnMouseHover(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
}
LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
::SetWindowLong(this->GetHWND(), GWL_STYLE, GetStyle());
Init(m_hWnd);
SetWindowResourcePath(GetSkinFolder());
WindowBuilder builder;
std::wstring strSkinFile = GetWindowResourcePath() + GetSkinFile();
auto callback = nbase::Bind(&WindowImplBase::CreateControl, this, std::placeholders::_1);
auto pRoot = (Box*)builder.Create(strSkinFile.c_str(), callback, this);
ASSERT(pRoot && L"Faield to load xml file.");
if (pRoot == NULL) {
TCHAR szErrMsg[MAX_PATH] = { 0 };
_stprintf_s(szErrMsg, L"Failed to load xml file %s", strSkinFile.c_str());
MessageBox(NULL, szErrMsg, _T("Duilib"), MB_OK | MB_ICONERROR);
return -1;
}
pRoot = m_shadow.AttachShadow(pRoot);
AttachDialog(pRoot);
InitWindow();
if (pRoot->GetFixedWidth() == DUI_LENGTH_AUTO || pRoot->GetFixedHeight() == DUI_LENGTH_AUTO) {
CSize maxSize(99999, 99999);
CSize needSize = pRoot->EstimateSize(maxSize);
if( needSize.cx < pRoot->GetMinWidth() ) needSize.cx = pRoot->GetMinWidth();
if( pRoot->GetMaxWidth() >= 0 && needSize.cx > pRoot->GetMaxWidth() ) needSize.cx = pRoot->GetMaxWidth();
if( needSize.cy < pRoot->GetMinHeight() ) needSize.cy = pRoot->GetMinHeight();
if( needSize.cy > pRoot->GetMaxHeight() ) needSize.cy = pRoot->GetMaxHeight();
::MoveWindow(m_hWnd, 0, 0, needSize.cx, needSize.cy, FALSE);
}
Control *pControl = (Control*)FindControl(L"closebtn");
if (pControl) {
Button *pCloseBtn = dynamic_cast<Button*>(pControl);
ASSERT(pCloseBtn);
pCloseBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"minbtn");
if (pControl) {
Button* pMinBtn = dynamic_cast<Button*>(pControl);
ASSERT(pMinBtn);
pMinBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"maxbtn");
if (pControl) {
Button* pMaxBtn = dynamic_cast<Button*>(pControl);
ASSERT(pMaxBtn);
pMaxBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"restorebtn");
if (pControl) {
Button* pRestoreBtn = dynamic_cast<Button*>(pControl);
ASSERT(pRestoreBtn);
pRestoreBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
return 0;
}
LRESULT WindowImplBase::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;
BOOL bHandled = TRUE;
switch (uMsg)
{ {
case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break; bHandled = FALSE;
case WM_CLOSE: lRes = OnClose(uMsg, wParam, lParam, bHandled); break; return 0;
case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break;
case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
case WM_WINDOWPOSCHANGING: lRes = OnWindowPosChanging(uMsg, wParam, lParam, bHandled); break;
case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
case WM_NCLBUTTONDBLCLK:lRes = OnNcLButtonDbClick(uMsg, wParam, lParam, bHandled); break;
case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
case WM_GETMINMAXINFO: lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEWHEEL: lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break;
case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
case WM_CHAR: lRes = OnChar(uMsg, wParam, lParam, bHandled); break;
case WM_SYSCOMMAND: lRes = OnSysCommand(uMsg, wParam, lParam, bHandled); break;
case WM_KEYDOWN: lRes = OnKeyDown(uMsg, wParam, lParam, bHandled); break;
case WM_KILLFOCUS: lRes = OnKillFocus(uMsg, wParam, lParam, bHandled); break;
case WM_SETFOCUS: lRes = OnSetFocus(uMsg, wParam, lParam, bHandled); break;
case WM_LBUTTONUP: lRes = OnLButtonUp(uMsg, wParam, lParam, bHandled); break;
case WM_LBUTTONDOWN: lRes = OnLButtonDown(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEMOVE: lRes = OnMouseMove(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEHOVER: lRes = OnMouseHover(uMsg, wParam, lParam, bHandled); break;
case WM_DPICHANGED: lRes = OnDpiChanged(uMsg, wParam, lParam, bHandled); break;
default: bHandled = FALSE; break;
} }
if (bHandled) return lRes; LRESULT WindowImplBase::OnDpiChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return Window::HandleMessage(uMsg, wParam, lParam); // 重置全局 DPI 设定
} DpiManager::GetInstance()->SetScale(LOWORD(wParam));
bool WindowImplBase::OnButtonClick(EventArgs* msg) // 重置阴影范围
{ m_shadow.ResetShadowBox();
std::wstring sCtrlName = msg->pSender->GetName();
if( sCtrlName == _T("closebtn") ) { // TODO 对窗口大小进行进行改变,让所有控件重新根据 DPI 计算大小
Close();
return 0;
} }
else if( sCtrlName == _T("minbtn")) {
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); LRESULT WindowImplBase::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
} {
else if( sCtrlName == _T("maxbtn")) { CSize szRoundCorner = GetRoundCorner();
Control* pMaxButton = (Control*)FindControl(L"maxbtn"); if (!::IsIconic(GetHWND()) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) {
Control* pRestoreButton = (Control*)FindControl(L"restorebtn"); UiRect rcWnd;
if (pMaxButton && pRestoreButton) { ::GetWindowRect(GetHWND(), &rcWnd);
pMaxButton->SetVisible(false); rcWnd.Offset(-rcWnd.left, -rcWnd.top);
pRestoreButton->SetVisible(true); rcWnd.right++; rcWnd.bottom++;
HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
::SetWindowRgn(GetHWND(), hRgn, TRUE);
::DeleteObject(hRgn);
} }
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
} bHandled = FALSE;
else if( sCtrlName == _T("restorebtn")) { return 0;
Control* pMaxButton = (Control*)FindControl(L"maxbtn");
Control* pRestoreButton = (Control*)FindControl(L"restorebtn");
if (pMaxButton && pRestoreButton) {
pMaxButton->SetVisible(true);
pRestoreButton->SetVisible(false);
}
SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
} }
return true; LRESULT WindowImplBase::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
}
void WindowImplBase::ActiveWindow()
{
if (::IsWindow(m_hWnd))
{ {
if (::IsIconic(m_hWnd)) bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
if (wParam == SC_CLOSE) {
bHandled = TRUE;
SendMessage(WM_CLOSE);
return 0;
}
BOOL bZoomed = ::IsZoomed(GetHWND());
LRESULT lRes = Window::HandleMessage(uMsg, wParam, lParam);
if (::IsZoomed(GetHWND()) != bZoomed)
{ {
::ShowWindow(m_hWnd, SW_RESTORE);
}
else
{
if (!::IsWindowVisible(m_hWnd))
::ShowWindow(m_hWnd, SW_SHOW);
::SetForegroundWindow(m_hWnd);
} }
return lRes;
} }
}
void WindowImplBase::SetTaskbarTitle(const std::wstring &title) LRESULT WindowImplBase::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
::SetWindowTextW(m_hWnd, title.c_str());
}
void WindowImplBase::ToTopMost(bool forever)
{
ASSERT(::IsWindow(m_hWnd));
::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
if (!forever)
{ {
::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); ::SetWindowLong(this->GetHWND(), GWL_STYLE, GetStyle());
Init(m_hWnd);
SetWindowResourcePath(GetSkinFolder());
WindowBuilder builder;
std::wstring strSkinFile = GetWindowResourcePath() + GetSkinFile();
auto callback = nbase::Bind(&WindowImplBase::CreateControl, this, std::placeholders::_1);
auto pRoot = (Box*)builder.Create(strSkinFile.c_str(), callback, this);
ASSERT(pRoot && L"Faield to load xml file.");
if (pRoot == NULL) {
TCHAR szErrMsg[MAX_PATH] = { 0 };
_stprintf_s(szErrMsg, L"Failed to load xml file %s", strSkinFile.c_str());
MessageBox(NULL, szErrMsg, _T("Duilib"), MB_OK | MB_ICONERROR);
return -1;
}
pRoot = m_shadow.AttachShadow(pRoot);
AttachDialog(pRoot);
InitWindow();
if (pRoot->GetFixedWidth() == DUI_LENGTH_AUTO || pRoot->GetFixedHeight() == DUI_LENGTH_AUTO) {
CSize maxSize(99999, 99999);
CSize needSize = pRoot->EstimateSize(maxSize);
if (needSize.cx < pRoot->GetMinWidth()) needSize.cx = pRoot->GetMinWidth();
if (pRoot->GetMaxWidth() >= 0 && needSize.cx > pRoot->GetMaxWidth()) needSize.cx = pRoot->GetMaxWidth();
if (needSize.cy < pRoot->GetMinHeight()) needSize.cy = pRoot->GetMinHeight();
if (needSize.cy > pRoot->GetMaxHeight()) needSize.cy = pRoot->GetMaxHeight();
::MoveWindow(m_hWnd, 0, 0, needSize.cx, needSize.cy, FALSE);
}
Control* pControl = (Control*)FindControl(L"closebtn");
if (pControl) {
Button* pCloseBtn = dynamic_cast<Button*>(pControl);
ASSERT(pCloseBtn);
pCloseBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"minbtn");
if (pControl) {
Button* pMinBtn = dynamic_cast<Button*>(pControl);
ASSERT(pMinBtn);
pMinBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"maxbtn");
if (pControl) {
Button* pMaxBtn = dynamic_cast<Button*>(pControl);
ASSERT(pMaxBtn);
pMaxBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
pControl = (Control*)FindControl(L"restorebtn");
if (pControl) {
Button* pRestoreBtn = dynamic_cast<Button*>(pControl);
ASSERT(pRestoreBtn);
pRestoreBtn->AttachClick(nbase::Bind(&WindowImplBase::OnButtonClick, this, std::placeholders::_1));
}
return 0;
}
LRESULT WindowImplBase::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnLButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
bHandled = FALSE;
return 0;
}
LRESULT WindowImplBase::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lRes = 0;
BOOL bHandled = TRUE;
switch (uMsg)
{
case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
case WM_CLOSE: lRes = OnClose(uMsg, wParam, lParam, bHandled); break;
case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break;
case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
case WM_WINDOWPOSCHANGING: lRes = OnWindowPosChanging(uMsg, wParam, lParam, bHandled); break;
case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
case WM_NCLBUTTONDBLCLK:lRes = OnNcLButtonDbClick(uMsg, wParam, lParam, bHandled); break;
case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
case WM_GETMINMAXINFO: lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEWHEEL: lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break;
case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
case WM_CHAR: lRes = OnChar(uMsg, wParam, lParam, bHandled); break;
case WM_SYSCOMMAND: lRes = OnSysCommand(uMsg, wParam, lParam, bHandled); break;
case WM_KEYDOWN: lRes = OnKeyDown(uMsg, wParam, lParam, bHandled); break;
case WM_KILLFOCUS: lRes = OnKillFocus(uMsg, wParam, lParam, bHandled); break;
case WM_SETFOCUS: lRes = OnSetFocus(uMsg, wParam, lParam, bHandled); break;
case WM_LBUTTONUP: lRes = OnLButtonUp(uMsg, wParam, lParam, bHandled); break;
case WM_LBUTTONDOWN: lRes = OnLButtonDown(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEMOVE: lRes = OnMouseMove(uMsg, wParam, lParam, bHandled); break;
case WM_MOUSEHOVER: lRes = OnMouseHover(uMsg, wParam, lParam, bHandled); break;
case WM_DPICHANGED: lRes = OnDpiChanged(uMsg, wParam, lParam, bHandled); break;
default: bHandled = FALSE; break;
}
if (bHandled) return lRes;
return Window::HandleMessage(uMsg, wParam, lParam);
}
bool WindowImplBase::OnButtonClick(EventArgs* msg)
{
std::wstring sCtrlName = msg->pSender->GetName();
if (sCtrlName == _T("closebtn")) {
Close();
}
else if (sCtrlName == _T("minbtn")) {
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
else if (sCtrlName == _T("maxbtn")) {
Control* pMaxButton = (Control*)FindControl(L"maxbtn");
Control* pRestoreButton = (Control*)FindControl(L"restorebtn");
if (pMaxButton && pRestoreButton) {
pMaxButton->SetVisible(false);
pRestoreButton->SetVisible(true);
}
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
else if (sCtrlName == _T("restorebtn")) {
Control* pMaxButton = (Control*)FindControl(L"maxbtn");
Control* pRestoreButton = (Control*)FindControl(L"restorebtn");
if (pMaxButton && pRestoreButton) {
pMaxButton->SetVisible(true);
pRestoreButton->SetVisible(false);
}
SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
}
return true;
}
void WindowImplBase::ActiveWindow()
{
if (::IsWindow(m_hWnd))
{
if (::IsIconic(m_hWnd))
{
::ShowWindow(m_hWnd, SW_RESTORE);
}
else
{
if (!::IsWindowVisible(m_hWnd))
::ShowWindow(m_hWnd, SW_SHOW);
::SetForegroundWindow(m_hWnd);
}
}
}
void WindowImplBase::SetTaskbarTitle(const std::wstring& title)
{
::SetWindowTextW(m_hWnd, title.c_str());
}
void WindowImplBase::ToTopMost(bool forever)
{
ASSERT(::IsWindow(m_hWnd));
::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
if (!forever)
{
::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
} }
}
} }

View File

@ -21,13 +21,14 @@
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{E106ACD7-4E53-4AEE-942B-D0DD426DB34E}</ProjectGuid> <ProjectGuid>{E106ACD7-4E53-4AEE-942B-D0DD426DB34E}</ProjectGuid>
<RootNamespace>duilib</RootNamespace> <RootNamespace>duilib</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
@ -39,13 +40,13 @@
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings"> <ImportGroup Label="ExtensionSettings">
@ -232,6 +233,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<DisableSpecificWarnings>4100;4121;4127;4244;4310;4355;4481;4505;4512;4702;%(DisableSpecificWarnings)</DisableSpecificWarnings> <DisableSpecificWarnings>4100;4121;4127;4244;4310;4355;4481;4505;4512;4702;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<LanguageStandard>stdcpp14</LanguageStandard>
</ClCompile> </ClCompile>
<ResourceCompile> <ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>

View File

@ -23,13 +23,13 @@
<ProjectGuid>{F1A9371F-9A34-45A0-98EB-83FF371F067F}</ProjectGuid> <ProjectGuid>{F1A9371F-9A34-45A0-98EB-83FF371F067F}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>basic</RootNamespace> <RootNamespace>basic</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -42,7 +42,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
@ -107,7 +107,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>

View File

@ -7,7 +7,6 @@ BasicForm::BasicForm()
{ {
} }
BasicForm::~BasicForm() BasicForm::~BasicForm()
{ {
} }
@ -27,13 +26,17 @@ std::wstring BasicForm::GetWindowClassName() const
return kClassName; return kClassName;
} }
LRESULT BasicForm::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
return WindowImplBase::OnNcHitTest(uMsg, wParam, lParam, bHandled);
}
void BasicForm::InitWindow() void BasicForm::InitWindow()
{ {
} }
LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{ {
PostQuitMessage(0L); PostQuitMessage(0L);
return __super::OnClose(uMsg, wParam, lParam, bHandled); return __super::OnClose(uMsg, wParam, lParam, bHandled);
} }

View File

@ -15,6 +15,7 @@ public:
virtual std::wstring GetSkinFolder() override; virtual std::wstring GetSkinFolder() override;
virtual std::wstring GetSkinFile() override; virtual std::wstring GetSkinFile() override;
virtual std::wstring GetWindowClassName() const override; virtual std::wstring GetWindowClassName() const override;
virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
/** /**
* WM_CREATE * WM_CREATE
@ -28,4 +29,3 @@ public:
static const std::wstring kClassName; static const std::wstring kClassName;
}; };

View File

@ -11,10 +11,13 @@ enum ThreadId
}; };
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine, _In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) _In_ int nCmdShow)
{ {
AllocConsole();
freopen("CONOUT$", "w", stdout);
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);
@ -40,12 +43,13 @@ void MainThread::Init()
// 如需修改请指定 Startup 最后两个参数 // 如需修改请指定 Startup 最后两个参数
ui::GlobalManager::Startup(theme_dir + L"resources\\", ui::CreateControlCallback(), false); ui::GlobalManager::Startup(theme_dir + L"resources\\", ui::CreateControlCallback(), false);
#else #else
// Release 模式下使用资源中的压缩包作为资源 // Release 模式下使用资源中的压缩包作为资源
// 资源被导入到资源列表分类为 THEME资源名称为 IDR_THEME // 资源被导入到资源列表分类为 THEME资源名称为 IDR_THEME
// 如果资源使用的是本地的 zip 文件而非资源中的 zip 压缩包 // 如果资源使用的是本地的 zip 文件而非资源中的 zip 压缩包
// 可以使用 OpenResZip 另一个重载函数打开本地的资源压缩包 // 可以使用 OpenResZip 另一个重载函数打开本地的资源压缩包
ui::GlobalManager::OpenResZip(MAKEINTRESOURCE(IDR_THEME), L"THEME", ""); //ui::GlobalManager::OpenResZip(MAKEINTRESOURCE(IDR_THEME), L"THEME", "");
// ui::GlobalManager::OpenResZip(L"resources.zip", ""); ui::GlobalManager::OpenResZip(L"resources.zip", "");
ui::GlobalManager::Startup(L"resources\\", ui::CreateControlCallback(), false); ui::GlobalManager::Startup(L"resources\\", ui::CreateControlCallback(), false);
#endif #endif
@ -61,4 +65,4 @@ void MainThread::Cleanup()
ui::GlobalManager::Shutdown(); ui::GlobalManager::Shutdown();
SetThreadWasQuitProperly(true); SetThreadWasQuitProperly(true);
nbase::ThreadManager::UnregisterThread(); nbase::ThreadManager::UnregisterThread();
} }

View File

@ -23,13 +23,13 @@
<ProjectGuid>{B8588C07-9CE2-456C-83B1-86E4B65D4108}</ProjectGuid> <ProjectGuid>{B8588C07-9CE2-456C-83B1-86E4B65D4108}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>cef</RootNamespace> <RootNamespace>cef</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -23,19 +23,19 @@
<ProjectGuid>{8BD95440-9000-4745-8011-27DD553EF06F}</ProjectGuid> <ProjectGuid>{8BD95440-9000-4745-8011-27DD553EF06F}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>controls</RootNamespace> <RootNamespace>controls</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
@ -75,7 +75,7 @@
<IntDir>$(ProjectDir)..\..\tmp\$(PlatformName)\$(ProjectName)\$(Configuration)\</IntDir> <IntDir>$(ProjectDir)..\..\tmp\$(PlatformName)\$(ProjectName)\$(Configuration)\</IntDir>
<TargetName>$(ProjectName)_d</TargetName> <TargetName>$(ProjectName)_d</TargetName>
<OutDir>..\..\bin\</OutDir> <OutDir>..\..\bin\</OutDir>
<IncludePath>..\..\;$(IncludePath)</IncludePath> <IncludePath>..\..\;$(ProjectDir)..\..\duilib;$(IncludePath)</IncludePath>
<LibraryPath>$(LibraryPath)</LibraryPath> <LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -107,7 +107,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile> </ClCompile>

View File

@ -1,5 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "controls_form.h" #include "controls_form.h"
#include "Utils\DpiManager.h"
#include <fstream> #include <fstream>
@ -9,7 +10,6 @@ ControlForm::ControlForm()
{ {
} }
ControlForm::~ControlForm() ControlForm::~ControlForm()
{ {
} }
@ -29,6 +29,16 @@ std::wstring ControlForm::GetWindowClassName() const
return kClassName; return kClassName;
} }
bool ComboChange(ui::EventArgs* ev) {
if (nullptr != ev) {
printf("%d\r\n", ev->Type);
auto p = static_cast<ui::Combo*>(ev->pSender);
auto text = p->GetText();
wprintf(L"%s\r\n", text.c_str());
}
return true;
}
void ControlForm::InitWindow() void ControlForm::InitWindow()
{ {
/** /**
@ -37,7 +47,7 @@ void ControlForm::InitWindow()
* 使 FindControl * 使 FindControl
*/ */
/* Initialize ListBox data */ /* Initialize ListBox data */
ui::ListBox* list = dynamic_cast<ui::ListBox*>(FindControl(L"list")); ui::ListBox* list = dynamic_cast<ui::ListBox*>(FindControl(L"list"));
for (auto i = 0; i < 30; i++) for (auto i = 0; i < 30; i++)
{ {
@ -82,7 +92,7 @@ void ControlForm::InitWindow()
element->SetText(nbase::StringPrintf(L"Combo element %d", i)); element->SetText(nbase::StringPrintf(L"Combo element %d", i));
combo->Add(element); combo->Add(element);
} }
combo->AttachAllEvents(ComboChange);
/* Load xml file content in global misc thread, and post update RichEdit task to UI thread */ /* Load xml file content in global misc thread, and post update RichEdit task to UI thread */
StdClosure closure = [this]() { StdClosure closure = [this]() {
std::streamoff length = 0; std::streamoff length = 0;
@ -103,7 +113,9 @@ void ControlForm::InitWindow()
} }
// Post task to UI thread // Post task to UI thread
nbase::ThreadManager::PostTask(kThreadUI, nbase::Bind(&ControlForm::OnLoadedResourceFile, this, xml)); // or Post2UI(nbase::Bind(&ControlForm::OnLoadedResourceFile, this, xml)); nbase::ThreadManager::PostTask(kThreadUI,
nbase::Bind(&ControlForm::OnLoadedResourceFile, this, xml));
// or Post2UI(nbase::Bind(&ControlForm::OnLoadedResourceFile, this, xml));
}; };
// Using ToWeakCallback to protect closure when if [ControlForm] was destoryed // Using ToWeakCallback to protect closure when if [ControlForm] was destoryed
nbase::ThreadManager::PostTask(kThreadGlobalMisc, ToWeakCallback(closure)); // or Post2GlobalMisc(ToWeakCallback(closure)); nbase::ThreadManager::PostTask(kThreadGlobalMisc, ToWeakCallback(closure)); // or Post2GlobalMisc(ToWeakCallback(closure));
@ -111,9 +123,11 @@ void ControlForm::InitWindow()
/* Post repeat task to update progress value 200 milliseconds once */ /* Post repeat task to update progress value 200 milliseconds once */
StdClosure repeat_task = [this]() { StdClosure repeat_task = [this]() {
nbase::TimeDelta time_delta = nbase::TimeDelta::FromMicroseconds(nbase::Time::Now().ToInternalValue()); nbase::TimeDelta time_delta = nbase::TimeDelta::FromMicroseconds(nbase::Time::Now().ToInternalValue());
nbase::ThreadManager::PostTask(kThreadUI, nbase::Bind(&ControlForm::OnProgressValueChagned, this, time_delta.ToMilliseconds() % 100)); nbase::ThreadManager::PostTask(kThreadUI,
nbase::Bind(&ControlForm::OnProgressValueChagned, this, time_delta.ToMilliseconds() % 100));
}; };
nbase::ThreadManager::PostRepeatedTask(kThreadGlobalMisc, ToWeakCallback(repeat_task), nbase::TimeDelta::FromMilliseconds(200)); nbase::ThreadManager::PostRepeatedTask(kThreadGlobalMisc,
ToWeakCallback(repeat_task), nbase::TimeDelta::FromMilliseconds(200));
/* Show settings menu */ /* Show settings menu */
ui::Button* settings = dynamic_cast<ui::Button*>(FindControl(L"settings")); ui::Button* settings = dynamic_cast<ui::Button*>(FindControl(L"settings"));
@ -128,7 +142,7 @@ void ControlForm::InitWindow()
ui::STRINGorID xml(L"settings_menu.xml"); ui::STRINGorID xml(L"settings_menu.xml");
pMenu->Init(xml, _T("xml"), point); pMenu->Init(xml, _T("xml"), point);
return true; return true;
}); });
} }
LRESULT ControlForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT ControlForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@ -154,7 +168,7 @@ void ControlForm::OnProgressValueChagned(float value)
progress->SetValue(value); progress->SetValue(value);
auto circleprogress = dynamic_cast<ui::Progress*>(FindControl(L"circleprogress")); auto circleprogress = dynamic_cast<ui::Progress*>(FindControl(L"circleprogress"));
circleprogress->SetValue(value); circleprogress->SetValue(value);
TCHAR szBuffer[32] = {0}; TCHAR szBuffer[32] = { 0 };
swprintf_s(szBuffer, _T("%.0f%%"), value); swprintf_s(szBuffer, _T("%.0f%%"), value);
circleprogress->SetText(szBuffer); circleprogress->SetText(szBuffer);
} }

View File

@ -4,12 +4,21 @@
#include "stdafx.h" #include "stdafx.h"
#include "main.h" #include "main.h"
#include "controls_form.h" #include "controls_form.h"
#include "Utils\DpiManager.h"
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine, _In_ LPWSTR lpCmdLine,
_In_ int nCmdShow) _In_ int nCmdShow)
{ {
AllocConsole();
freopen("CONOUT$", "w", stdout);
auto dpiManager = ui::DpiManager::GetInstance();
dpiManager->SetAdaptDPI(); // 设置适配自动dpi
printf("dpi is %d\r\n",dpiManager->GetDPIFromRegistry());
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);

View File

@ -10,7 +10,7 @@
class MiscThread : public nbase::FrameworkThread class MiscThread : public nbase::FrameworkThread
{ {
public: public:
MiscThread(enum ThreadId thread_id, const char *name) MiscThread(enum ThreadId thread_id, const char* name)
: FrameworkThread(name) : FrameworkThread(name)
, thread_id_(thread_id) {} , thread_id_(thread_id) {}

View File

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013 # Visual Studio Version 16
VisualStudioVersion = 12.0.40629.0 VisualStudioVersion = 16.0.31229.75
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{B2087994-3DF6-4A57-B8C6-6F744520D7FA}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{B2087994-3DF6-4A57-B8C6-6F744520D7FA}"
EndProject EndProject
@ -29,6 +29,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "duilib", "..\duilib\duilib.
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui_components", "..\ui_components\ui_components.vcxproj", "{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ui_components", "..\ui_components\ui_components.vcxproj", "{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proto_debuger", "proto_debuger\proto_debuger.vcxproj", "{6D78D8B7-1617-4ED4-B155-94369FC3E73C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catch_test", "catch_test\catch_test.vcxproj", "{91850193-0E5E-4983-9D11-F9875805D91E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
@ -123,6 +127,22 @@ Global
{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|Win32.Build.0 = Release|Win32 {0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|Win32.Build.0 = Release|Win32
{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|x64.ActiveCfg = Release|x64 {0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|x64.ActiveCfg = Release|x64
{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|x64.Build.0 = Release|x64 {0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}.Release|x64.Build.0 = Release|x64
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Debug|Win32.ActiveCfg = Debug|Win32
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Debug|Win32.Build.0 = Debug|Win32
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Debug|x64.ActiveCfg = Debug|x64
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Debug|x64.Build.0 = Debug|x64
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|Win32.ActiveCfg = Release|Win32
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|Win32.Build.0 = Release|Win32
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|x64.ActiveCfg = Release|x64
{6D78D8B7-1617-4ED4-B155-94369FC3E73C}.Release|x64.Build.0 = Release|x64
{91850193-0E5E-4983-9D11-F9875805D91E}.Debug|Win32.ActiveCfg = Debug|Win32
{91850193-0E5E-4983-9D11-F9875805D91E}.Debug|Win32.Build.0 = Debug|Win32
{91850193-0E5E-4983-9D11-F9875805D91E}.Debug|x64.ActiveCfg = Debug|x64
{91850193-0E5E-4983-9D11-F9875805D91E}.Debug|x64.Build.0 = Debug|x64
{91850193-0E5E-4983-9D11-F9875805D91E}.Release|Win32.ActiveCfg = Release|Win32
{91850193-0E5E-4983-9D11-F9875805D91E}.Release|Win32.Build.0 = Release|Win32
{91850193-0E5E-4983-9D11-F9875805D91E}.Release|x64.ActiveCfg = Release|x64
{91850193-0E5E-4983-9D11-F9875805D91E}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -136,6 +156,7 @@ Global
{A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {1DA0A8E2-5832-42FC-83F7-2CDCAD379C90} {A9D6DC71-C0DC-4549-AEA0-3B15B44E86A9} = {1DA0A8E2-5832-42FC-83F7-2CDCAD379C90}
{8BD95440-9000-4745-8011-27DD553EF06F} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA} {8BD95440-9000-4745-8011-27DD553EF06F} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA}
{E35589C6-9509-4116-996F-1D045C2DACAE} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA} {E35589C6-9509-4116-996F-1D045C2DACAE} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA}
{91850193-0E5E-4983-9D11-F9875805D91E} = {B2087994-3DF6-4A57-B8C6-6F744520D7FA}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {68CA0970-4242-4E4F-94D2-C19760FCA05D} SolutionGuid = {68CA0970-4242-4E4F-94D2-C19760FCA05D}

View File

@ -23,13 +23,13 @@
<ProjectGuid>{2BFFA1EE-039D-479E-9BCC-2D12F8AEDD16}</ProjectGuid> <ProjectGuid>{2BFFA1EE-039D-479E-9BCC-2D12F8AEDD16}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>layouts</RootNamespace> <RootNamespace>layouts</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -22,12 +22,13 @@
<ProjectGuid>{FDB5539F-1060-4975-B603-B66454C8C897}</ProjectGuid> <ProjectGuid>{FDB5539F-1060-4975-B603-B66454C8C897}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>multi_browser</RootNamespace> <RootNamespace>multi_browser</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -0,0 +1,86 @@
#include "base_form.h"
#include "new_monitor_form.h"
const std::wstring BasicForm::kClassName = L"Basic";
#define WM_USER_POS_CHANGED (WM_USER + 2)
BasicForm::BasicForm()
{
}
BasicForm::~BasicForm()
{
}
std::wstring BasicForm::GetSkinFolder()
{
return L"basic";
}
std::wstring BasicForm::GetSkinFile()
{
return L"basic.xml";
}
std::wstring BasicForm::GetWindowClassName() const
{
return kClassName;
}
LRESULT BasicForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_USER_POS_CHANGED) {
NewMonitorForm* window = new NewMonitorForm();
window->Create(NULL, NewMonitorForm::kClassName.c_str(), WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & WS_SIZEBOX, 0);
window->CenterWindow();
window->ShowModalFake(this->m_hWnd);
nim_comp::Toast::ShowToast(L"×Ô¶¨ÒåÏûÏ¢±»µ÷ÓÃ", 1000, this->GetHWND());
}
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
}
void BasicForm::InitWindow()
{
/* Show settings menu */
ui::Button* settings = dynamic_cast<ui::Button*>(FindControl(L"test_customize"));
if (nullptr != settings) {
settings->AttachClick([this](ui::EventArgs* args) {
printf("%d\r\n", ::PostMessage(this->GetHWND(), WM_USER_POS_CHANGED, 0, 0));
return true;
});
}
ui::TreeView* tree = dynamic_cast<ui::TreeView*>(FindControl(L"tree"));
if (nullptr != tree) {
ui::TreeNode* parent_node = nullptr;
for (auto j = 0; j < 8; j++)
{
ui::TreeNode* node = new ui::TreeNode;
node->SetClass(L"listitem");
node->SetFixedHeight(20);
if (parent_node)
{
node->SetText(nbase::StringPrintf(L"Child node %d", j));
node->SetMargin({ 10, 0, 0, 0 });
parent_node->AddChildNode(node);
}
else
{
node->SetText(nbase::StringPrintf(L"Parent node", j));
tree->GetRootNode()->AddChildNode(node);
parent_node = node;
parent_node->AttachClick([this](ui::EventArgs* args) {
printf("%d\r\n", ::PostMessage(this->GetHWND(), WM_USER_POS_CHANGED, 0, 0));
return true;
});
}
}
}
}
LRESULT BasicForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0L);
return __super::OnClose(uMsg, wParam, lParam, bHandled);
}

View File

@ -0,0 +1,46 @@
#pragma once
// C runtime header
#ifdef __cplusplus
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#endif
// base header
#include "base/base.h"
// duilib
#include "duilib/UIlib.h"
#include "ui_components/ui_components.h"
class BasicForm : public ui::WindowImplBase
{
public:
BasicForm();
~BasicForm();
/**
*
* GetSkinFolder
* GetSkinFile xml
* GetWindowClassName
*/
virtual std::wstring GetSkinFolder() override;
virtual std::wstring GetSkinFile() override;
virtual std::wstring GetWindowClassName() const override;
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
/**
* WM_CREATE
*/
void InitWindow() override;
/**
* WM_CLOSE
*/
virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
static const std::wstring kClassName;
};

View File

@ -0,0 +1,67 @@
// basic.cpp : 定义应用程序的入口点。
//
#include "main.h"
#include "base_form.h"
#include"resource1.h"
#include <math.h>
enum ThreadId
{
kThreadUI
};
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
AllocConsole();
freopen("CONOUT$", "w", stdout);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// 创建主线程
MainThread thread;
// 执行主线程循环
thread.RunOnCurrentThreadWithLoop(nbase::MessageLoop::kUIMessageLoop);
return 0;
}
void MainThread::Init()
{
nbase::ThreadManager::RegisterThread(kThreadUI);
// 获取资源路径,初始化全局参数
std::wstring theme_dir = nbase::win32::GetCurrentModuleDirectory();
wprintf(L"%s\r\n", theme_dir);
#if 1
// Debug 模式下使用本地文件夹作为资源
// 默认皮肤使用 resources\\themes\\default
// 默认语言使用 resources\\lang\\zh_CN
// 如需修改请指定 Startup 最后两个参数
ui::GlobalManager::Startup(theme_dir + L"resources\\", ui::CreateControlCallback(), false);
#else
// Release 模式下使用资源中的压缩包作为资源
// 资源被导入到资源列表分类为 THEME资源名称为 IDR_THEME
// 如果资源使用的是本地的 zip 文件而非资源中的 zip 压缩包
// 可以使用 OpenResZip 另一个重载函数打开本地的资源压缩包
ui::GlobalManager::OpenResZip(MAKEINTRESOURCE(IDR_THEME2), L"THEME", "");
//ui::GlobalManager::OpenResZip(L"resources.zip", "");
ui::GlobalManager::Startup(L"resources\\", ui::CreateControlCallback(), false);
#endif
// 创建一个默认带有阴影的居中窗口
BasicForm* window = new BasicForm();
window->Create(NULL, BasicForm::kClassName.c_str(), WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & WS_SIZEBOX, 0);
window->CenterWindow();
window->ShowWindow();
}
void MainThread::Cleanup()
{
ui::GlobalManager::Shutdown();
SetThreadWasQuitProperly(true);
nbase::ThreadManager::UnregisterThread();
}

View File

@ -0,0 +1,40 @@
#pragma once
// C runtime header
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
// base header
#include "base/base.h"
// duilib
#include "duilib/UIlib.h"
/** @class MainThread
* @brief 线UI线程 nbase::FrameworkThread
* @copyright (c) 2015, NetEase Inc. All rights reserved
* @author towik
* @date 2015/1/1
*/
class MainThread : public nbase::FrameworkThread
{
public:
MainThread() : nbase::FrameworkThread("MainThread") {}
virtual ~MainThread() {}
private:
/**
* 线
* @return void
*/
virtual void Init() override;
/**
* 线退
* @return void
*/
virtual void Cleanup() override;
};

View File

@ -0,0 +1,41 @@
#include "new_monitor_form.h"
const std::wstring NewMonitorForm::kClassName = L"Basic";
NewMonitorForm::NewMonitorForm()
{
}
NewMonitorForm::~NewMonitorForm()
{
}
std::wstring NewMonitorForm::GetSkinFolder()
{
return L"basic";
}
std::wstring NewMonitorForm::GetSkinFile()
{
return L"newmonitor.xml";
}
std::wstring NewMonitorForm::GetWindowClassName() const
{
return kClassName;
}
LRESULT NewMonitorForm::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return WindowImplBase::HandleMessage(uMsg, wParam, lParam);
}
void NewMonitorForm::InitWindow()
{
}
LRESULT NewMonitorForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0L);
return __super::OnClose(uMsg, wParam, lParam, bHandled);
}

View File

@ -0,0 +1,46 @@
#pragma once
// C runtime header
#ifdef __cplusplus
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#endif
// base header
#include "base/base.h"
// duilib
#include "duilib/UIlib.h"
#include "ui_components/ui_components.h"
class NewMonitorForm : public ui::WindowImplBase
{
public:
NewMonitorForm();
~NewMonitorForm();
/**
*
* GetSkinFolder
* GetSkinFile xml
* GetWindowClassName
*/
virtual std::wstring GetSkinFolder() override;
virtual std::wstring GetSkinFile() override;
virtual std::wstring GetWindowClassName() const override;
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override;
/**
* WM_CREATE
*/
void InitWindow() override;
/**
* WM_CLOSE
*/
virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
static const std::wstring kClassName;
};

View File

@ -0,0 +1,76 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource1.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// 中文(简体,中国) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource1.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//
/////////////////////////////////////////////////////////////////////////////
//
// THEME
//
IDR_THEME2 THEME "E:\\NIM_Duilib_Framework\\examples\\proto_debuger\\Release\\resources.zip"
#endif // 中文(简体,中国) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,181 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{6d78d8b7-1617-4ed4-b155-94369fc3e73c}</ProjectGuid>
<RootNamespace>protodebuger</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<ReferencePath>$(VC_ReferencesPath_x86);</ReferencePath>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);..\..\;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>../../;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ShowProgress>LinkVerbose</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\..\base\base.vcxproj">
<Project>{8d9a6595-717a-41c8-b468-0011a72be3d1}</Project>
</ProjectReference>
<ProjectReference Include="..\..\duilib\duilib.vcxproj">
<Project>{e106acd7-4e53-4aee-942b-d0dd426db34e}</Project>
</ProjectReference>
<ProjectReference Include="..\..\ui_components\ui_components.vcxproj">
<Project>{0149ba6e-3c0a-426d-aa0a-0b9ec7742f19}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="base_form.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="new_monitor_form.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="base_form.h" />
<ClInclude Include="main.h" />
<ClInclude Include="new_monitor_form.h" />
<ClInclude Include="resource1.h" />
</ItemGroup>
<ItemGroup>
<Xml Include="..\Debug\resources\themes\default\global.xml" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="proto_debuger.rc" />
</ItemGroup>
<ItemGroup>
<None Include="..\Release\resources.zip" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="base_form.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="new_monitor_form.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="main.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="base_form.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="resource1.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="new_monitor_form.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Xml Include="..\Debug\resources\themes\default\global.xml">
<Filter>资源文件</Filter>
</Xml>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="proto_debuger.rc">
<Filter>资源文件</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\Release\resources.zip" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,17 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 proto_debuger.rc 使用
//
#define IDR_ACCELERATOR1 101
#define IDR_THEME2 103
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -23,13 +23,13 @@
<ProjectGuid>{878F5BF0-652A-4FDB-992B-BB7F26D62F0D}</ProjectGuid> <ProjectGuid>{878F5BF0-652A-4FDB-992B-BB7F26D62F0D}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>richlist</RootNamespace> <RootNamespace>richlist</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -43,7 +43,7 @@ void MainThread::Init()
// 获取资源路径,初始化全局参数 // 获取资源路径,初始化全局参数
std::wstring theme_dir = nbase::win32::GetCurrentModuleDirectory(); std::wstring theme_dir = nbase::win32::GetCurrentModuleDirectory();
ui::GlobalManager::Startup(theme_dir + L"resources\\", MyCreateControlCallback, false); ui::GlobalManager::Startup(theme_dir + L"resources\\", MyCreateControlCallback, true);
// 创建一个默认带有阴影的居中窗口 // 创建一个默认带有阴影的居中窗口
MainForm* window = new MainForm(); MainForm* window = new MainForm();

View File

@ -46,8 +46,6 @@ void MainForm::InitWindow()
m_DataProvider = new Provider; m_DataProvider = new Provider;
m_pTileList->SetDataProvider(m_DataProvider); m_pTileList->SetDataProvider(m_DataProvider);
} }
LRESULT MainForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT MainForm::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@ -72,7 +70,7 @@ bool MainForm::OnClicked(ui::EventArgs* args)
if (m_CheckBoxItemCenter->IsSelected()) if (m_CheckBoxItemCenter->IsSelected())
{ {
m_pTileList->SetAttribute(L"width", L"auto"); m_pTileList->SetAttribute(L"width", L"auto");
m_pTileList->SetAttribute(L"halign", L"center"); m_pTileList->SetAttribute(L"halign", L"left");
} }
else { else {
m_pTileList->SetAttribute(L"width", L"stretch"); m_pTileList->SetAttribute(L"width", L"stretch");
@ -93,7 +91,7 @@ bool MainForm::OnClicked(ui::EventArgs* args)
} }
else if (sName == L"btn_update") else if (sName == L"btn_update")
{ {
m_DataProvider->ChangeTaskName(_ttoi(m_EditUpdate->GetText().c_str())-1, m_DataProvider->ChangeTaskName(_ttoi(m_EditUpdate->GetText().c_str()) - 1,
m_EditTaskName->GetText()); m_EditTaskName->GetText());
} }
else if (sName == L"btn_delete") else if (sName == L"btn_delete")

View File

@ -15,12 +15,13 @@
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>VirtualBox</RootNamespace> <RootNamespace>VirtualBox</RootNamespace>
<ProjectName>virtualbox</ProjectName> <ProjectName>virtualbox</ProjectName>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

View File

@ -23,13 +23,14 @@
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<Platform>Win32</Platform> <Platform>Win32</Platform>
<ProjectName>libcef_dll_wrapper</ProjectName> <ProjectName>libcef_dll_wrapper</ProjectName>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
@ -41,7 +42,7 @@
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseOfMfc>false</UseOfMfc> <UseOfMfc>false</UseOfMfc>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>

View File

@ -35,10 +35,12 @@ public:
// the ownership of the dialog // the ownership of the dialog
bool DoModal(ModalWndBase *dlg); bool DoModal(ModalWndBase *dlg);
void CancelModalThenExit(); void CancelModalThenExit();
template<class _Ty>
friend class Ref_count_obj;
private: private:
template<class _Ty>
friend class std::_Ref_count_obj;
friend class AsyncModalRunnerManager; friend class AsyncModalRunnerManager;
friend class std::shared_ptr<AsyncModalRunner>; friend class std::shared_ptr<AsyncModalRunner>;

View File

@ -23,19 +23,19 @@
<ProjectGuid>{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}</ProjectGuid> <ProjectGuid>{0149BA6E-3C0A-426D-AA0A-0B9EC7742F19}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>uicomponents</RootNamespace> <RootNamespace>uicomponents</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType> <ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
@ -100,6 +100,7 @@
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>.\;..\;..\third_party\cef_wrapper\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>.\;..\;..\third_party\cef_wrapper\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile> </ClCompile>
<Link> <Link>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -200,7 +201,6 @@
<ClInclude Include="cef_control\util\util.h" /> <ClInclude Include="cef_control\util\util.h" />
<ClInclude Include="menu\ui_menu.h" /> <ClInclude Include="menu\ui_menu.h" />
<ClInclude Include="modal_wnd\async_do_modal.h" /> <ClInclude Include="modal_wnd\async_do_modal.h" />
<ClInclude Include="modal_wnd\async_modal_runner.h" />
<ClInclude Include="modal_wnd\file_dialog_ex.h" /> <ClInclude Include="modal_wnd\file_dialog_ex.h" />
<ClInclude Include="modal_wnd\modal_wnd_base.h" /> <ClInclude Include="modal_wnd\modal_wnd_base.h" />
<ClInclude Include="msgbox\msgbox.h" /> <ClInclude Include="msgbox\msgbox.h" />
@ -228,7 +228,6 @@
<ClCompile Include="cef_control\util\memory_dc.cpp" /> <ClCompile Include="cef_control\util\memory_dc.cpp" />
<ClCompile Include="menu\ui_menu.cpp" /> <ClCompile Include="menu\ui_menu.cpp" />
<ClCompile Include="modal_wnd\async_do_modal.cpp" /> <ClCompile Include="modal_wnd\async_do_modal.cpp" />
<ClCompile Include="modal_wnd\async_modal_runner.cpp" />
<ClCompile Include="modal_wnd\file_dialog_ex.cpp" /> <ClCompile Include="modal_wnd\file_dialog_ex.cpp" />
<ClCompile Include="msgbox\msgbox.cpp" /> <ClCompile Include="msgbox\msgbox.cpp" />
<ClCompile Include="shadow_wnd\shadow_wnd.cpp" /> <ClCompile Include="shadow_wnd\shadow_wnd.cpp" />

View File

@ -66,9 +66,6 @@
<ClInclude Include="modal_wnd\async_do_modal.h"> <ClInclude Include="modal_wnd\async_do_modal.h">
<Filter>modal_wnd</Filter> <Filter>modal_wnd</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="modal_wnd\async_modal_runner.h">
<Filter>modal_wnd</Filter>
</ClInclude>
<ClInclude Include="modal_wnd\file_dialog_ex.h"> <ClInclude Include="modal_wnd\file_dialog_ex.h">
<Filter>modal_wnd</Filter> <Filter>modal_wnd</Filter>
</ClInclude> </ClInclude>
@ -149,9 +146,6 @@
<ClCompile Include="modal_wnd\async_do_modal.cpp"> <ClCompile Include="modal_wnd\async_do_modal.cpp">
<Filter>modal_wnd</Filter> <Filter>modal_wnd</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="modal_wnd\async_modal_runner.cpp">
<Filter>modal_wnd</Filter>
</ClCompile>
<ClCompile Include="modal_wnd\file_dialog_ex.cpp"> <ClCompile Include="modal_wnd\file_dialog_ex.cpp">
<Filter>modal_wnd</Filter> <Filter>modal_wnd</Filter>
</ClCompile> </ClCompile>

View File

@ -3,86 +3,86 @@
namespace nim_comp namespace nim_comp
{ {
/** @class WindowEx /** @class WindowEx
* @brief * @brief
* @copyright (c) 2015, NetEase Inc. All rights reserved * @copyright (c) 2015, NetEase Inc. All rights reserved
* @date 2015/9/16 * @date 2015/9/16
*/ */
class WindowEx : public ui::WindowImplBase class WindowEx : public ui::WindowImplBase
{ {
public: public:
WindowEx(); WindowEx();
virtual ~WindowEx(); virtual ~WindowEx();
/**
*
* @param[in] hwndParent
* @param[in] pstrName
* @param[in] dwStyle
* @param[in] dwExStyle
* @param[in] isLayeredWindow
* @param[in] rc
* @return HWND
*/
virtual HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle,
bool isLayeredWindow = true, const ui::UiRect& rc = ui::UiRect(0, 0, 0, 0)) override;
/**
*
* @param[in] uMsg
* @param[in] wParam
* @param[in] lParam
* @param[out] b
d
* @return LRESULT
*/
virtual LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
/**
* ESC键单击的消息
* @param[out] bHandled
* @return void
*/
virtual void OnEsc(BOOL& bHandled);
/**
*
* @return wstring
*/
virtual std::wstring GetWindowClassName(void) const = 0;
/**
* id的接口
* @return wstring id
*/
virtual std::wstring GetWindowId(void) const = 0;
/**
*
* @param[in] uMsg
* @param[in] wParam
* @param[in] lParam
* @return LRESULT
*/
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
/**
* WindowManager中注册自己
* @return bool true false
*/
bool RegisterWnd();
/**
* WindowManager中反注册自己
* @return void
*/
void UnRegisterWnd();
};
/** /**
* *
* @param[in] hwndParent * @return POINT
* @param[in] pstrName */
* @param[in] dwStyle POINT GetPopupWindowPos(WindowEx* window);
* @param[in] dwExStyle
* @param[in] isLayeredWindow
* @param[in] rc
* @return HWND
*/
virtual HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle,
bool isLayeredWindow = true, const ui::UiRect& rc = ui::UiRect(0, 0, 0, 0)) override;
/**
*
* @param[in] uMsg
* @param[in] wParam
* @param[in] lParam
* @param[out] bHandled
* @return LRESULT
*/
virtual LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
/**
* ESC键单击的消息
* @param[out] bHandled
* @return void
*/
virtual void OnEsc(BOOL &bHandled);
/**
*
* @return wstring
*/
virtual std::wstring GetWindowClassName(void) const = 0;
/**
* id的接口
* @return wstring id
*/
virtual std::wstring GetWindowId(void) const = 0;
/**
*
* @param[in] uMsg
* @param[in] wParam
* @param[in] lParam
* @return LRESULT
*/
virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
/**
* WindowManager中注册自己
* @return bool true false
*/
bool RegisterWnd();
/**
* WindowManager中反注册自己
* @return void
*/
void UnRegisterWnd();
};
/**
*
* @return POINT
*/
POINT GetPopupWindowPos(WindowEx* window);
} }