質問するログイン新規登録

回答編集履歴

2

DT_EDITCONTROL を追加

2020/03/01 08:54

投稿

KOZ6.0
KOZ6.0

スコア2738

answer CHANGED
@@ -37,7 +37,7 @@
37
37
  GetWindowText(hWnd, text, textLen);
38
38
  SetTextColor(hdc, RGB(0, 0, 255));
39
39
  SendMessage(hWnd, EM_GETRECT, NULL, (LPARAM)&rc);
40
- DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
40
+ DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_EDITCONTROL);
41
41
  free(text);
42
42
  }
43
43
  EndPaint(hWnd, &ps);

1

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

2020/03/01 08:54

投稿

KOZ6.0
KOZ6.0

スコア2738

answer CHANGED
@@ -7,4 +7,48 @@
7
7
  (2) 疑似的に無効化状態にする
8
8
 
9
9
  コンテナとなる親ウインドウを作成し、その子ウインドウとして EDIT を作成します。
10
- 親ウインドウを無効化することで入力を受け付けなくなりますが、EDIT そのものは有効な状態なので文字色を変更することができます。
10
+ 親ウインドウを無効化することで入力を受け付けなくなりますが、EDIT そのものは有効な状態なので文字色を変更することができます。
11
+
12
+ #追記
13
+ オーナードローのサンプルです。
14
+ EDIT をサブクラス化し、無効状態なら自前で描画します。
15
+ ```C
16
+ LRESULT CALLBACK EditWndProc(HWND hWnd, UINT message, WPARAM wp, LPARAM lp)
17
+ {
18
+ switch (message)
19
+ {
20
+ case WM_PAINT:
21
+ {
22
+ if (!IsWindowEnabled(hWnd))
23
+ {
24
+ HDC hdc;
25
+ PAINTSTRUCT ps;
26
+ int textLen;
27
+ LPWSTR text;
28
+ RECT rc;
29
+ hdc = BeginPaint(hWnd, &ps);
30
+ GetClientRect(hWnd, &rc);
31
+ FillRect(hdc, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
32
+ textLen = GetWindowTextLength(hWnd);
33
+ if (textLen > 0)
34
+ {
35
+ textLen = (textLen + 1) * 2;
36
+ text = (LPWSTR)malloc(textLen);
37
+ GetWindowText(hWnd, text, textLen);
38
+ SetTextColor(hdc, RGB(0, 0, 255));
39
+ SendMessage(hWnd, EM_GETRECT, NULL, (LPARAM)&rc);
40
+ DrawText(hdc, text, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
41
+ free(text);
42
+ }
43
+ EndPaint(hWnd, &ps);
44
+ return 0;
45
+ }
46
+ else {
47
+ return CallWindowProc(prevEditWndProc, hWnd, message, wp, lp);
48
+ }
49
+ }
50
+ default:
51
+ return CallWindowProc(prevEditWndProc, hWnd, message, wp, lp);
52
+ }
53
+ }
54
+ ```