forked from nakkag/CLCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFrame.c
129 lines (108 loc) · 2.79 KB
/
Frame.c
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
/*
* CLCL
*
* Frame.c
*
* Copyright (C) 1996-2019 by Ohno Tomoaki. All rights reserved.
* https://www.nakka.com/
*/
/* Include Files */
#define _INC_OLE
#include <windows.h>
#undef _INC_OLE
#include "Memory.h"
#include "Frame.h"
#include "dpi.h"
/* Define */
#define NOMOVESIZE Scale(6) // フレームの移動制限値
/* Global Variables */
static RECT *frame_rect; // フレームの位置情報
/* ocal Function Prototypes */
/*
* frame_initialize - フレーム描画用構造体の初期化
*/
BOOL frame_initialize(const HWND hWnd)
{
if (frame_rect == NULL) {
frame_rect = (RECT *)mem_calloc(sizeof(RECT) * FRAME_CNT);
if (frame_rect == NULL) {
return FALSE;
}
}
SetCapture(hWnd);
return TRUE;
}
/*
* frame_free - フレーム描画用構造体の解放
*/
void frame_free(void)
{
if (frame_rect != NULL) {
mem_free(&frame_rect);
}
ReleaseCapture();
}
/*
* frame_draw - フレームの描画
*/
int frame_draw(const HWND hWnd, const HWND hTreeView)
{
RECT window_rect, treeview_rect;
POINT apos;
HDC hdc;
int draw_cnt;
GetCursorPos((LPPOINT)&apos);
GetWindowRect(hWnd, (LPRECT)&window_rect);
GetWindowRect(hTreeView, (LPRECT)&treeview_rect);
// フレームの移動制限
if (apos.x <= (window_rect.left + NOMOVESIZE + GetSystemMetrics(SM_CXFRAME))) {
apos.x = window_rect.left + NOMOVESIZE + GetSystemMetrics(SM_CXFRAME);
} else if (apos.x >= (window_rect.right - (NOMOVESIZE + (FRAME_CNT * 2)) - GetSystemMetrics(SM_CXFRAME))) {
apos.x = window_rect.right - (NOMOVESIZE + (FRAME_CNT * 2)) - GetSystemMetrics(SM_CXFRAME);
}
// 前回の位置と比較
if (apos.x == frame_rect[0].left) {
return 1;
}
hdc = GetWindowDC(hWnd);
// 前回描画分を消去
for (draw_cnt = 0;draw_cnt < FRAME_CNT;draw_cnt++) {
DrawFocusRect(hdc, (LPRECT)&frame_rect[draw_cnt]);
}
// フレームの描画
for (draw_cnt = 0;draw_cnt < FRAME_CNT;draw_cnt++) {
(frame_rect + draw_cnt)->left = apos.x + draw_cnt - window_rect.left;
(frame_rect + draw_cnt)->right = (frame_rect + draw_cnt)->left + FRAME_CNT + 1;
(frame_rect + draw_cnt)->top = treeview_rect.top - window_rect.top;
(frame_rect + draw_cnt)->bottom = treeview_rect.bottom - window_rect.top;
DrawFocusRect(hdc, (LPRECT)(frame_rect + draw_cnt));
}
ReleaseDC(hWnd, hdc);
return 0;
}
/*
* frame_draw_end - フレームの描画終了、フレームの最終位置を返す
*/
int frame_draw_end(const HWND hWnd)
{
HDC hdc;
int draw_cnt;
int ret;
if (frame_rect[0].left == 0 && frame_rect[0].right == 0 &&
frame_rect[0].top == 0 && frame_rect[0].bottom == 0) {
frame_free();
return -1;
}
// 前回描画分を消去
hdc = GetWindowDC(hWnd);
for (draw_cnt = 0;draw_cnt < FRAME_CNT;draw_cnt++) {
DrawFocusRect(hdc, (LPRECT)&frame_rect[draw_cnt]);
}
ReleaseDC(hWnd, hdc);
// 境界位置の取得
ret = frame_rect[0].left - GetSystemMetrics(SM_CXFRAME);
frame_free();
return ret;
}
/* End of source */