回答編集履歴

2

DT_EDITCONTROL を追加

2020/03/01 08:54

投稿

KOZ6.0
KOZ6.0

スコア2626

test CHANGED
@@ -76,7 +76,7 @@
76
76
 
77
77
  SendMessage(hWnd, EM_GETRECT, NULL, (LPARAM)&rc);
78
78
 
79
- DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
79
+ DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_EDITCONTROL);
80
80
 
81
81
  free(text);
82
82
 

1

オーナードローのサンプルを追記

2020/03/01 08:54

投稿

KOZ6.0
KOZ6.0

スコア2626

test CHANGED
@@ -17,3 +17,91 @@
17
17
  コンテナとなる親ウインドウを作成し、その子ウインドウとして EDIT を作成します。
18
18
 
19
19
  親ウインドウを無効化することで入力を受け付けなくなりますが、EDIT そのものは有効な状態なので文字色を変更することができます。
20
+
21
+
22
+
23
+ #追記
24
+
25
+ オーナードローのサンプルです。
26
+
27
+ EDIT をサブクラス化し、無効状態なら自前で描画します。
28
+
29
+ ```C
30
+
31
+ LRESULT CALLBACK EditWndProc(HWND hWnd, UINT message, WPARAM wp, LPARAM lp)
32
+
33
+ {
34
+
35
+ switch (message)
36
+
37
+ {
38
+
39
+ case WM_PAINT:
40
+
41
+ {
42
+
43
+ if (!IsWindowEnabled(hWnd))
44
+
45
+ {
46
+
47
+ HDC hdc;
48
+
49
+ PAINTSTRUCT ps;
50
+
51
+ int textLen;
52
+
53
+ LPWSTR text;
54
+
55
+ RECT rc;
56
+
57
+ hdc = BeginPaint(hWnd, &ps);
58
+
59
+ GetClientRect(hWnd, &rc);
60
+
61
+ FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
62
+
63
+ textLen = GetWindowTextLength(hWnd);
64
+
65
+ if (textLen > 0)
66
+
67
+ {
68
+
69
+ textLen = (textLen + 1) * 2;
70
+
71
+ text = (LPWSTR)malloc(textLen);
72
+
73
+ GetWindowText(hWnd, text, textLen);
74
+
75
+ SetTextColor(hdc, RGB(0, 0, 255));
76
+
77
+ SendMessage(hWnd, EM_GETRECT, NULL, (LPARAM)&rc);
78
+
79
+ DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
80
+
81
+ free(text);
82
+
83
+ }
84
+
85
+ EndPaint(hWnd, &ps);
86
+
87
+ return 0;
88
+
89
+ }
90
+
91
+ else {
92
+
93
+ return CallWindowProc(prevEditWndProc, hWnd, message, wp, lp);
94
+
95
+ }
96
+
97
+ }
98
+
99
+ default:
100
+
101
+ return CallWindowProc(prevEditWndProc, hWnd, message, wp, lp);
102
+
103
+ }
104
+
105
+ }
106
+
107
+ ```