root/lang/objective-cplusplus/i3/trunk/tmp/dwmedit/DWMEdit.cc @ 38647

Revision 38647, 5.5 kB (checked in by saturday06, 3 years ago)

wst

  • Property svn:executable set to *
Line 
1#include <windows.h>
2#include <windowsx.h>
3#include <richedit.h>
4#include <stdio.h>
5#include <tlhelp32.h>
6#include <commctrl.h>
7
8#include "WindowsVersionHelp.h"
9#include "BlurEditController.h"
10
11#ifdef _MSC_VER
12
13#ifdef UNICODE
14
15#if defined _M_X64
16#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
17#elif defined _M_IX86
18#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
19#elif defined _M_IA64
20#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
21#else
22#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
23#endif
24
25#endif
26
27#endif
28
29
30namespace windows_version_help {
31    extern WindowsVersionHelpDLL dll;
32}
33
34LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
35    WNDPROC wp = WndProc;
36    (void)wp;
37
38    if (message == WM_WINDOWPOSCHANGING) {
39        WINDOWPOS* window_pos = (WINDOWPOS*)lParam;
40        if (window_pos->flags | SWP_SHOWWINDOW && window_pos->flags | SWP_NOREDRAW) {
41            // First time ShowWindow() is special on Windows 7 (ignore SWP_NOREDRAW)
42            InvalidateRect(hWnd, NULL, FALSE);
43            WndProc(hWnd, WM_PAINT, 0, 0);
44        }
45    }
46   
47/*
48    if (message == WM_CTLCOLOREDIT) {
49        HDC hDC = (HDC)wParam;
50        HWND hCtrl = (HWND)lParam;
51        //SetBkMode(hDC, TRANSPARENT);  // �w�i�𓧉�
52        //SetTextColor(hDC, RGB(255,0,0));      // �e�L�X�g�̐F
53        //SetBkColor(hDC,RGB(192,192,192));     // �e�L�X�g�����������镔���̃e�L�X�g�̔w�i�̐F
54        return (LRESULT)GetStockObject(GRAY_BRUSH);     // �e�L�X�g�����������Ȃ������̔w�i�̐F
55    }
56*/
57   
58    if (message == WM_DESTROY) {
59        PostQuitMessage(0);
60        return 0;
61    }
62
63    return DefWindowProc(hWnd, message, wParam, lParam);
64}
65
66int main() {
67    BlurEditControllerInitialize();
68
69    InitCommonControls();
70
71    HINSTANCE hInstance = GetModuleHandle(NULL);
72
73    const TCHAR szWindowClass[] = _T("HOGE");
74
75    WNDCLASS wc = {};
76    wc.style            = CS_HREDRAW | CS_VREDRAW;
77    wc.lpfnWndProc      = WndProc;
78    wc.cbClsExtra       = 0;
79    wc.cbWndExtra       = 0;
80    wc.hInstance        = hInstance;
81    wc.hIcon            = NULL;
82    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
83    wc.hbrBackground    = (HBRUSH)GetStockObject(BLACK_BRUSH);
84    wc.lpszMenuName     = NULL;
85    wc.lpszClassName    = szWindowClass;
86
87    if (!RegisterClass(&wc)) {
88        return 1;
89    }
90
91    TCHAR szTitle[] = _T("HIGE");
92    DWORD style = WS_OVERLAPPEDWINDOW;
93
94    RECT r;
95    r.top = 0;
96    r.left = 0;
97    r.right = 600;
98    r.bottom = 200;
99    if (!AdjustWindowRectEx(&r, style, FALSE, 0)) {
100        abort();
101    }
102
103    HWND hWnd = CreateWindow(
104                    szWindowClass, szTitle, style,
105                    0, 0, r.right - r.left, r.bottom - r.top,
106                    NULL, NULL, hInstance, NULL);
107    if (!IsWindow(hWnd)) {
108        return 1;
109    }
110
111    HWND hEdit = CreateWindow(
112                    _T("EDIT"),
113                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
114                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
115                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
116                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
117                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
118                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
119                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
120                    _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"),
121                    WS_CHILD | WS_VISIBLE /*| WS_BORDER */,
122                    50,
123                    50,
124                    500,
125                    100,
126                    hWnd,
127                    NULL,
128                    hInstance,
129                    NULL);
130
131    if (!hEdit) {
132        abort();
133    }
134
135    if (dll.BufferedPaintInit) {
136        if (dll.BufferedPaintInit() != S_OK) {
137            abort();
138        }
139
140        DWM_BLURBEHIND bb  = {};
141        bb.dwFlags = DWM_BB_ENABLE;
142        bb.fEnable = TRUE;
143        if (dll.DwmEnableBlurBehindWindow(hWnd, &bb) != S_OK) {
144            abort();
145        }
146
147        MARGINS margins = {};
148        margins.cxLeftWidth = 50;
149        margins.cxRightWidth = 50;
150        margins.cyBottomHeight = 50;
151        margins.cyTopHeight = 50;
152
153        if (dll.DwmExtendFrameIntoClientArea(hWnd, &margins) != S_OK) {
154            abort();
155        }
156    }
157
158    ShowWindow(hWnd, SW_SHOW);
159    UpdateWindow(hWnd);
160    BlurEditControllerHook(hEdit);
161
162    //DWORD from = GetTickCount();
163    //bool once = false;
164
165    MSG msg = {};
166    for (;;) {
167        //if (from + 5000 < GetTickCount() && !once) {
168        //    once = true;
169        //}
170
171        BOOL b = GetMessage(&msg, NULL, 0, 0);
172        if (!b) {
173            break;
174        }
175        if (b < 0) {
176            break;
177        }
178        TranslateMessage(&msg);
179        DispatchMessage(&msg);
180    }
181
182    return (int) msg.wParam;
183}
184
185
Note: See TracBrowser for help on using the browser.