-
Notifications
You must be signed in to change notification settings - Fork 8
/
QQDeskTimer.cpp
166 lines (150 loc) · 4.2 KB
/
QQDeskTimer.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
#pragma comment(lib, "Ole32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "comctl32.Lib")
#pragma comment(lib, "gdi32.Lib")
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define TIMER_REBAR 4001
HINSTANCE g_hInst;
HBITMAP g_hbmBall = NULL;
RECT g_rcTrayWnd;
RECT g_rcRebar;
HWND g_trayWnd;
HWND g_rebar;
LRESULT CALLBACK WindowFunc(HWND,UINT,WPARAM,LPARAM);
TCHAR szWinName[] = TEXT("MyWin");
int WINAPI WinMain(HINSTANCE hThisInst,HINSTANCE hPrevInst,LPSTR lpszArgs,int nWinMode)
{
HRESULT hRes = ::CoInitialize(NULL);
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
HWND hwnd;
MSG msg;
WNDCLASSEX wcl;
INITCOMMONCONTROLSEX ic;
BOOL ret;
g_hInst = hThisInst;
ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
ic.dwICC = 0x00004000;//ICC_STANDARD_CLASSES|ICC_BAR_CLASSES;
ret = InitCommonControlsEx(&ic);
wcl.cbSize = sizeof(WNDCLASSEX);
wcl.hInstance = hThisInst;
wcl.lpszClassName = szWinName;
wcl.lpfnWndProc = WindowFunc;
wcl.style = CS_DBLCLKS;//CS_HREDRAW|CS_VREDRAW
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wcl.hIconSm = NULL;
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
wcl.lpszMenuName = NULL;
wcl.cbClsExtra = 0;
wcl.cbWndExtra = 0;
wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&wcl)) return 0;
g_trayWnd = ::FindWindow("Shell_TrayWnd", NULL);
GetWindowRect(g_trayWnd, &g_rcTrayWnd);
hwnd = CreateWindowEx(
0x00080080,
szWinName,
TEXT("Window Title"),
0x16080000,
CW_USEDEFAULT,
CW_USEDEFAULT,
120,
150,
HWND_DESKTOP,//HWND_DESKTOP
NULL,
hThisInst,
NULL
);
::SetLayeredWindowAttributes( hwnd, RGB(0,0,255), 200, ULW_ALPHA|ULW_COLORKEY);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
g_rebar = ::FindWindowEx(g_trayWnd, NULL, "ReBarWindow32", NULL);
GetWindowRect(g_rebar, &g_rcRebar);
::SetWindowPos(g_rebar, NULL, g_rcTrayWnd.left+112, 0,
g_rcRebar.right - g_rcTrayWnd.left-112, g_rcRebar.bottom - g_rcRebar.top,
SWP_NOZORDER|SWP_NOACTIVATE);
SetTimer(hwnd,TIMER_REBAR,50,(TIMERPROC)NULL);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
::CoUninitialize();
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM
wParam,LPARAM lParam)
{
static UINT s_uTaskbarRestart;
HDC hdc;
PAINTSTRUCT ps;
switch(message){
case WM_CREATE:
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
g_hbmBall = (HBITMAP)LoadImage(0,"back.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
return 0;
case WM_SIZE:
return 0;
case WM_ERASEBKGND:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
{
//BITMAP bm;
//HDC hdcMem = CreateCompatibleDC(hdc);
//HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall);
Graphics g( hdc );
Image img(L"µ×ͼ.png");
g.DrawImage( &img, 0, 0);
//GetObject(g_hbmBall, sizeof(bm), &bm);
//BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
//SelectObject(hdcMem, hbmOld);
//DeleteDC(hdcMem);
}
EndPaint(hwnd, &ps);
return 0;
case WM_MOUSELEAVE:
return FALSE;
case WM_MOUSEMOVE:
return FALSE;
case WM_TIMER:
{
RECT rc;
GetWindowRect(g_rebar, &rc);
if (rc.left != g_rcTrayWnd.left+112)
{
::SetWindowPos(g_rebar, NULL, g_rcTrayWnd.left+112, 0,
rc.right - g_rcTrayWnd.left-112, rc.bottom - rc.top,
SWP_NOZORDER|SWP_NOACTIVATE);
}
}
return FALSE;
case WM_DESTROY:
KillTimer(hwnd,TIMER_REBAR);
PostQuitMessage(0);
return 0;
default:
if(message == s_uTaskbarRestart)
{
RECT rc;
GetWindowRect(g_rebar, &rc);
if (rc.left != g_rcTrayWnd.left+112)
{
::SetWindowPos(g_rebar, NULL, g_rcTrayWnd.left+112, 0,
rc.right - g_rcTrayWnd.left-112, rc.bottom - rc.top,
SWP_NOZORDER|SWP_NOACTIVATE);
}
}
}
return DefWindowProc(hwnd,message,wParam,lParam);
}