admin
8 天以前 6cd92a169cbc0db35042f243a09d976fd3e1445c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// 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;
}