// TipDlg.cpp: 实现文件
|
//
|
|
#include "common/pch.h"
|
#include "FloatTrade.h"
|
#include "../common/Win32Util.h"
|
#include "TipDlg.h"
|
#include "afxdialogex.h"
|
#include <thread>
|
|
|
// TipDlg 对话框
|
|
IMPLEMENT_DYNAMIC(TipDlg, CDialogEx)
|
|
TipDlg::TipDlg(int delayMs, int position, CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_TIPS, pParent)
|
{
|
this->delayMs = delayMs;
|
this->position = position;
|
}
|
|
TipDlg::~TipDlg()
|
{
|
}
|
|
void TipDlg::DoDataExchange(CDataExchange* pDX)
|
{
|
DDX_Control(pDX, IDC_STATIC_MSG, labelMsg);
|
|
CDialogEx::DoDataExchange(pDX);
|
}
|
|
|
BEGIN_MESSAGE_MAP(TipDlg, CDialogEx)
|
ON_WM_TIMER()
|
ON_WM_CTLCOLOR()
|
END_MESSAGE_MAP()
|
|
|
// TipDlg 消息处理程序
|
|
|
BOOL TipDlg::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
CRect windowRect;
|
GetWindowRect(&windowRect);
|
int x = screenWidth - windowRect.Width();
|
int y = screenHeight - windowRect.Height();
|
list<HWND> hwnds = Win32Util::searchWindow("悬浮盯盘");
|
if (hwnds.size() > 0&& position == POSITION_NORMAL) {
|
CRect rect;
|
GetWindowRect(&rect);
|
Win32Util::getWindowRect(*(hwnds.begin()),&rect);
|
x = rect.left;
|
y = rect.top - windowRect.Height();
|
}
|
|
SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
std::thread t1(closeTip, this, this->delayMs);
|
t1.detach();
|
|
CFont middleFont;
|
|
middleFont.CreateFont(24, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, 0, 0, 0, 0, L"微软雅黑");
|
|
// 设置透明度(0透明,255完全不透明)
|
ModifyStyleEx(0, WS_EX_LAYERED);
|
BYTE opacity = 230; // 透明度值取值范围为0~255
|
SetLayeredWindowAttributes(RGB(0, 0, 0), opacity, LWA_ALPHA);
|
|
//设置字体
|
labelMsg.SetFont(&middleFont, FALSE);
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
|
void TipDlg::OnTimer(UINT_PTR nIDEvent)
|
{
|
|
CDialogEx::OnTimer(nIDEvent);
|
}
|
|
void TipDlg::setMsg(CString text, COLORREF textColor)
|
{
|
msgColor = textColor;
|
labelMsg.SetWindowTextW(text);
|
labelMsg.Invalidate();
|
}
|
|
void TipDlg::closeTip(TipDlg* context,int delayMs){
|
Sleep(delayMs);
|
if (context != nullptr) {
|
context->EndDialog(IDOK);
|
}
|
}
|
|
|
HBRUSH TipDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
{
|
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
|
if (nCtlColor == CTLCOLOR_STATIC) {
|
int nID = pWnd->GetDlgCtrlID();
|
switch (nID) {
|
case IDC_STATIC_MSG:
|
pDC->SetTextColor(msgColor);
|
break;
|
}
|
}
|
return hbr;
|
}
|