root/lang/objective-cplusplus/i3/trunk/tmp/dwmedit/dwmtest.cpp @ 38388

Revision 38388, 22.7 kB (checked in by saturday06, 4 years ago)

aaaaaaaaaaaa

  • Property svn:executable set to *
Line 
1#include <windows.h>
2#include <windowsx.h>
3#include <tchar.h>
4#include <assert.h>
5#include <richedit.h>
6#include <stdio.h>
7#include <windows.h>
8#include <windowsx.h>
9#include <tchar.h>
10#include <tlhelp32.h>
11#include <dbghelp.h>
12
13#pragma comment(lib, "dbghelp.lib")
14
15// �ЂƂ‚̃��W���[���ɑ΂���PI�t�b�N����֐�
16void ReplaceIATEntryInOneMod(
17    const char* pszModuleName,
18    PROC pfnCurrent,
19    PROC pfnNew,
20    HMODULE hmodCaller)
21{
22    ULONG ulSize = 0;
23    IMAGE_IMPORT_DESCRIPTOR* pImportDesc = NULL;
24    pImportDesc = (IMAGE_IMPORT_DESCRIPTOR*)ImageDirectoryEntryToData(
25                      hmodCaller, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ulSize);
26
27    if (pImportDesc == NULL) {
28        return;
29    }
30
31    while(pImportDesc->Name) {
32        char* pszModName = (char*)((BYTE*)hmodCaller + pImportDesc->Name);
33        if (lstrcmpiA(pszModName, pszModuleName) == 0) {
34            break;
35        }
36        pImportDesc++;
37    }
38
39    if (!pImportDesc->Name) {
40        return;
41    }
42
43    IMAGE_THUNK_DATA* pThunk = (IMAGE_THUNK_DATA*)((BYTE*)hmodCaller + pImportDesc->FirstThunk);
44
45    while(pThunk->u1.Function) {
46        PROC* ppfn = (PROC*)&pThunk->u1.Function;
47        bool fFound = (*ppfn == pfnCurrent);
48        if (fFound) {
49            DWORD dwDummy;
50            VirtualProtect(ppfn, sizeof(ppfn), PAGE_EXECUTE_READWRITE, &dwDummy);
51            WriteProcessMemory(GetCurrentProcess(), ppfn, &pfnNew, sizeof(pfnNew), NULL);
52            return;
53        }
54        pThunk++;
55    }
56    return;
57}
58
59// ���ׂẴ��W���[���ɑ΂���PI�t�b�N����֐�
60void ReplaceIATEntryInAllMods(
61    const char* pszModuleName,
62    PROC pfnCurrent,
63    PROC pfnNew)
64{
65    // ���W���[�����X�g���
66    HANDLE hModuleSnap = CreateToolhelp32Snapshot(
67                             TH32CS_SNAPMODULE, GetCurrentProcessId());
68    if(hModuleSnap == INVALID_HANDLE_VALUE) {
69        return;
70    }
71
72    MODULEENTRY32 me = {};
73    me.dwSize = sizeof(me);
74    BOOL bModuleResult = Module32First(hModuleSnap, &me);
75    // ���ꂼ�����W���[���ɑ΂���eplaceIATEntryInOneMod��s
76    while (bModuleResult) {
77        ReplaceIATEntryInOneMod(pszModuleName, pfnCurrent, pfnNew, me.hModule);
78        bModuleResult = Module32Next(hModuleSnap, &me);
79    }
80    CloseHandle(hModuleSnap);
81}
82
83struct api_ {
84    typedef int (WINAPI *PFNMESSAGEBOXW)(HWND, const wchar_t*, const wchar_t*, unsigned int);
85    typedef BOOL (WINAPI *fp_TextOutW)(HDC, int, int, const wchar_t*, int);
86    typedef BOOL (WINAPI *fp_ExtTextOutW)(
87        HDC hdc,          // �f�o�C�X�R���e�L�X�g�̃n���h��
88        int X,            // �J�n�ʒu�i��_�j��x ��W
89        int Y,            // �J�n�ʒu�i��_�j��y ��W
90        UINT fuOptions,   // �������g�����v�V����
91        CONST RECT *lprc, // ��������\���̂ւ̃|�C���^
92        LPCTSTR lpString, // ������       UINT cbCount,     // ������
93        CONST INT *lpDx   // �����Ԋu�̓�z��   );
94    typedef int (WINAPI *fp_DrawTextExW)(
95        HDC hdc,                     // �f�o�C�X�R���e�L�X�g�̃n���h��
96        LPTSTR lpchText,             // �`�悷���L�X�g
97        int cchText,                 // �`�悷���L�X�g�̒���
98        LPRECT lprc,                 // �e�L�X�g��悷�钷������W
99        UINT dwDTFormat,             // ���`�I�v�V����
100        LPDRAWTEXTPARAMS lpDTParams  // ���̑��̐��`�I�v�V����
101    );
102    typedef int (WINAPI *fp_DrawTextW)(
103        HDC hDC,          // �f�o�C�X�R���e�L�X�g�̃n���h��
104        LPCTSTR lpString, // �`�悷���L�X�g
105        int nCount,       // �e�L�X�g�̒���
106        LPRECT lpRect,    // �e�L�X�g��悷�钷����        UINT uFormat      // �e�L�X�g�`���v�V����
107    );
108    typedef BOOL (WINAPI *fp_PolyTextOutW)(
109        HDC hdc,                // �f�o�C�X�R���e�L�X�g�̃n���h��
110        CONST POLYTEXT *pptxt,  // ��������ʂ������̂�
111        // �z��̃|�C���^
112        int cStrings            // �z��̍\���̂̐�
113    );
114
115    api_();
116};
117
118
119
120
121// �t�b�N�������̃v���g�^�C�v��`
122int WINAPI Hook_MessageBoxW(HWND hWnd, const wchar_t* pszText, const wchar_t* pszCaption, unsigned int uType) {
123    PROC pfnOrig = GetProcAddress(GetModuleHandleA("user32.dll"), "MessageBoxW");
124    int nResult = ((api_::PFNMESSAGEBOXW) pfnOrig)(hWnd, pszText, L"I am Hook_MessageBoxW", uType);
125    return nResult;
126}
127
128BOOL WINAPI hook_TextOutW(HDC hdc, int nXStart, int nYStart, const wchar_t* lpString, int cbString) {
129    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "TextOutW");
130    wprintf(L"TextOutW\n");
131    return ((api_::fp_TextOutW)pfnOrig)(hdc, nXStart, nYStart, lpString, cbString);
132}
133
134struct ExtTextOutHook_ {
135        LONG cancel_count; // thread guard
136        DWORD thread_id; // raw
137        int done; // raw
138        api_::fp_ExtTextOutW original;
139} ExtTextOutHook = {};
140
141BOOL WINAPI hook_ExtTextOutW(
142    HDC hdc, int X, int Y, UINT fuOptions, CONST RECT *lprc,
143    LPCTSTR lpString, UINT cbCount, CONST INT *lpDx) {
144
145        LONG ea = InterlockedExchangeAdd(&ExtTextOutHook.cancel_count, 0);
146    if (!ea || ExtTextOutHook.thread_id != GetCurrentThreadId()) {
147            //printf("x, ea=%d, %x != %x ", ea, ExtTextOutHook.thread_id, GetCurrentThreadId());
148                //fflush(stdout);
149                return ExtTextOutHook.original(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
150    }
151
152        ExtTextOutHook.done = 1;
153    //printf("c, ea=%d ", ea);
154        //fflush(stdout);
155
156    //wprintf(L"ExtTextOutW: dc=0x%x\n", hdc);
157    return TRUE;
158}
159
160int WINAPI hook_DrawTextExW(
161    HDC hdc,                     // �f�o�C�X�R���e�L�X�g�̃n���h��
162    LPTSTR lpchText,             // �`�悷���L�X�g
163    int cchText,                 // �`�悷���L�X�g�̒���
164    LPRECT lprc,                 // �e�L�X�g��悷�钷������W
165    UINT dwDTFormat,             // ���`�I�v�V����
166    LPDRAWTEXTPARAMS lpDTParams  // ���̑��̐��`�I�v�V����
167) {
168    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "DrawTextExW");
169    wprintf(L"DrawTextExW\n");
170    return ((api_::fp_DrawTextExW)pfnOrig)(hdc, lpchText, cchText, lprc, dwDTFormat, lpDTParams);
171}
172int WINAPI hook_DrawTextW(
173    HDC hDC,          // �f�o�C�X�R���e�L�X�g�̃n���h��
174    LPCTSTR lpString, // �`�悷���L�X�g
175    int nCount,       // �e�L�X�g�̒���
176    LPRECT lpRect,    // �e�L�X�g��悷�钷����    UINT uFormat      // �e�L�X�g�`���v�V����
177) {
178    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "DrawTextW");
179    wprintf(L"DrawTextW\n");
180    return ((api_::fp_DrawTextW)pfnOrig)(hDC, lpString, nCount, lpRect, uFormat);
181}
182BOOL WINAPI hook_PolyTextOutW(
183    HDC hdc,                // �f�o�C�X�R���e�L�X�g�̃n���h��
184    CONST POLYTEXT *pptxt,  // ��������ʂ������̂�
185    // �z��̃|�C���^
186    int cStrings            // �z��̍\���̂̐�
187) {
188    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "PolyTextOutW");
189    wprintf(L"PolyTextOutW\n");
190    return ((api_::fp_PolyTextOutW)pfnOrig)(hdc, pptxt, cStrings);
191}
192
193
194api_::api_() {
195    // check api prototypes
196    static_cast<PFNMESSAGEBOXW>(Hook_MessageBoxW);
197    static_cast<PFNMESSAGEBOXW>(MessageBoxW);
198    fp_TextOutW check1_TextOutW = TextOutW;
199    fp_ExtTextOutW check1_ExtTextOutW = ExtTextOutW;
200    fp_DrawTextExW check1_DrawTextExW = DrawTextExW;
201    fp_DrawTextW check1_DrawTextW = DrawTextW;
202    fp_PolyTextOutW check1_PolyTextOutW = PolyTextOutW;
203    fp_TextOutW check2_TextOutW = hook_TextOutW;
204    fp_ExtTextOutW check2_ExtTextOutW = hook_ExtTextOutW;
205    fp_DrawTextExW check2_DrawTextExW = hook_DrawTextExW;
206    fp_DrawTextW check2_DrawTextW = hook_DrawTextW;
207    fp_PolyTextOutW check2_PolyTextOutW = hook_PolyTextOutW;
208}
209
210
211//#define HAVE_DWM 1
212
213#ifdef HAVE_DWM
214
215#include <uxtheme.h>
216#include <dwmapi.h>
217#pragma comment(lib, "dwmapi.lib")
218#pragma comment(lib, "uxtheme.lib")
219
220#else
221
222typedef struct _MARGINS {
223    int cxLeftWidth;      // width of left border that retains its size
224    int cxRightWidth;     // width of right border that retains its size
225    int cyTopHeight;      // height of top border that retains its size
226    int cyBottomHeight;   // height of bottom border that retains its size
227} MARGINS;
228typedef MARGINS* PMARGINS;
229
230typedef struct _BP_PAINTPARAMS {
231    DWORD cbSize;
232    DWORD dwFlags;
233    const RECT *prcExclude;
234    const BLENDFUNCTION *pBlendFunction;
235} BP_PAINTPARAMS, *PBP_PAINTPARAMS;
236typedef HANDLE HPAINTBUFFER;
237typedef enum _BP_BUFFERFORMAT {
238    BPBF_COMPATIBLEBITMAP,
239    BPBF_DIB,
240    BPBF_TOPDOWNDIB,
241    BPBF_TOPDOWNMONODIB
242} BP_BUFFERFORMAT;
243#define BPPF_ERASE               0x0001 // Empty the buffer during BeginBufferedPaint()
244#define BPPF_NOCLIP              0x0002 // Don't apply the target DC's clip region to the double buffer
245#define BPPF_NONCLIENT           0x0004 // Using a non-client DC
246#define ULW_EX_NORESIZE         0x00000008
247
248typedef enum _DWMWINDOWATTRIBUTE {
249    DWMWA_NCRENDERING_ENABLED = 1,
250    DWMWA_NCRENDERING_POLICY,
251    DWMWA_TRANSITIONS_FORCEDISABLED,
252    DWMWA_ALLOW_NCPAINT,
253    DWMWA_CAPTION_BUTTON_BOUNDS,
254    DWMWA_NONCLIENT_RTL_LAYOUT,
255    DWMWA_FORCE_ICONIC_REPRESENTATION,
256    DWMWA_FLIP3D_POLICY,
257    DWMWA_EXTENDED_FRAME_BOUNDS,
258    DWMWA_HAS_ICONIC_BITMAP,
259    DWMWA_DISALLOW_PEEK,
260    DWMWA_EXCLUDED_FROM_PEEK,
261    DWMWA_LAST
262} DWMWINDOWATTRIBUTE;
263// Blur behind data structures
264#define DWM_BB_ENABLE                 0x00000001  // fEnable has been specified
265#define DWM_BB_BLURREGION             0x00000002  // hRgnBlur has been specified
266#define DWM_BB_TRANSITIONONMAXIMIZED  0x00000004  // fTransitionOnMaximized has been specified
267typedef struct _DWM_BLURBEHIND {
268    DWORD dwFlags;
269    BOOL fEnable;
270    HRGN hRgnBlur;
271    BOOL fTransitionOnMaximized;
272} DWM_BLURBEHIND, *PDWM_BLURBEHIND;
273
274#endif
275
276struct Dll {
277    HRESULT (WINAPI *DwmExtendFrameIntoClientArea)(HWND, const MARGINS*);
278    HRESULT (WINAPI *DwmIsCompositionEnabled)(BOOL*);
279    HRESULT (WINAPI *DwmEnableBlurBehindWindow)(HWND, const DWM_BLURBEHIND*);
280    HRESULT (WINAPI *DwmGetColorizationColor)(DWORD*, BOOL*);
281    HRESULT (WINAPI *DwmGetWindowAttribute)(HWND, DWORD, void*,DWORD);
282    HPAINTBUFFER (WINAPI *BeginBufferedPaint)(HDC, const RECT*, BP_BUFFERFORMAT, BP_PAINTPARAMS*, HDC*);
283    HRESULT (WINAPI *BufferedPaintInit)(void);
284    HRESULT (WINAPI *BufferedPaintUnInit)(void);
285    HRESULT (WINAPI *EndBufferedPaint)(HPAINTBUFFER, BOOL);
286    HRESULT (WINAPI *BufferedPaintSetAlpha)(HPAINTBUFFER, const RECT*, BYTE);
287} dll = {};
288
289struct BlurStatus {
290    BlurStatus() :
291        capture(false),
292        focus(false),
293        dc_width_max(0),
294        dc_width(0),
295        dc_height_max(0),
296        dc_height(0),
297        dc_changed(false),
298        dc1(NULL),
299        dc2(NULL)
300    {
301        black_brush = (HBRUSH)GetStockObject(BLACK_BRUSH);
302
303        blend_function.BlendOp = AC_SRC_OVER;
304        blend_function.BlendFlags = 0;
305        blend_function.AlphaFormat = 0; //AC_SRC_ALPHA
306        blend_function.SourceConstantAlpha = 255;
307
308        bp_paintparams.cbSize = sizeof(bp_paintparams);
309        bp_paintparams.dwFlags = 0;
310        bp_paintparams.prcExclude = NULL;
311        bp_paintparams.pBlendFunction = &blend_function;
312    }
313    WNDPROC DefaultWindowProceduer;
314    bool capture;
315    bool focus;
316    HBRUSH black_brush;
317    int dc_width_max;
318    int dc_height_max;
319    int dc_width;
320    int dc_height;
321    bool dc_changed;
322    HDC dc1;
323    HDC dc2;
324    BLENDFUNCTION blend_function;
325    BP_PAINTPARAMS bp_paintparams;
326    HRGN rgn;
327} blur;
328
329LRESULT CALLBACK BlurEditWndProc(
330    HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
331
332        //printf("{");
333        //fflush(stdout);
334
335    WNDPROC wp = BlurEditWndProc;
336    (void)wp;
337    bool redraw = false;
338
339    if (message == WM_PAINT && dll.BeginBufferedPaint) {
340                //printf("<");
341                //fflush(stdout);
342        BYTE alpha = 0;
343        if (blur.focus) {
344            alpha = 0xff;
345        } else if (blur.capture) {
346            alpha = 0xbb;
347        } else {
348            alpha = 0x88;
349        }
350
351        PAINTSTRUCT ps = {};
352        HDC hdc = BeginPaint(hWnd, &ps);
353        HDC mem_dc1 = NULL;
354        HPAINTBUFFER paint_buffer1 = dll.BeginBufferedPaint(hdc, &ps.rcPaint, BPBF_TOPDOWNDIB, NULL, &mem_dc1);
355        if (paint_buffer1 == 0) {
356            EndPaint(hWnd, &ps);
357            return CallWindowProc(blur.DefaultWindowProceduer, hWnd, message, wParam, lParam);
358        }
359
360        if (alpha == 255) {
361            // �s�����̏ꍇ
362                LONG ex = InterlockedExchange(&ExtTextOutHook.cancel_count, 0);
363            CallWindowProc(blur.DefaultWindowProceduer, hWnd, WM_PRINTCLIENT, (WPARAM)mem_dc1, PRF_CLIENT);
364                        InterlockedExchange(&ExtTextOutHook.cancel_count, ex);
365
366            dll.BufferedPaintSetAlpha(paint_buffer1, 0, 255);
367        } else {
368            // �����̏ꍇ�A�������f�o�C�X�R���e�L�X�g��������ăA���t�@�u�����h����            blur.blend_function.SourceConstantAlpha = alpha;
369
370            HDC mem_dc2 = 0;
371            HPAINTBUFFER paint_buffer2 = dll.BeginBufferedPaint(mem_dc1, &ps.rcPaint, BPBF_TOPDOWNDIB, &blur.bp_paintparams, &mem_dc2);
372            if (paint_buffer2 == 0) {
373                dll.EndBufferedPaint(paint_buffer1, FALSE);
374                EndPaint(hWnd, &ps);
375                return CallWindowProc(blur.DefaultWindowProceduer, hWnd, message, wParam, lParam);
376            }
377
378                        LONG ex = InterlockedExchange(&ExtTextOutHook.cancel_count, 0);
379            CallWindowProc(blur.DefaultWindowProceduer, hWnd, WM_PRINTCLIENT, (WPARAM)mem_dc2, PRF_CLIENT);
380                        InterlockedExchange(&ExtTextOutHook.cancel_count, ex);
381
382
383            dll.BufferedPaintSetAlpha(paint_buffer2, 0, 255);
384            FillRect(mem_dc1, &ps.rcPaint, blur.black_brush);
385            dll.EndBufferedPaint(paint_buffer2, TRUE);
386        }
387
388        dll.EndBufferedPaint(paint_buffer1, TRUE);
389        EndPaint(hWnd, &ps);
390                //printf(">");
391                //fflush(stdout);
392        return 0;
393    }
394
395
396
397    // TODO: �}�E�X�h���b�O���ɁA�I��͂�������
398    //       �����AWM_ERASEBKGND�Ƃ��A������M_PAINT����ɏ����ĕ`�悵�₪��    //       �f�o�C�X�R���e�L�X�g���w�������������ǂ���������
399
400    if (message == WM_SETFOCUS) {
401        blur.focus = true;
402        redraw = true;
403    }
404
405    if (message == WM_KILLFOCUS) {
406        blur.focus = false;
407        redraw = true;
408    }
409
410    //if (message == WM_LBUTTONDOWN) {
411    //    redraw = true;
412    //}
413
414    //if (message == WM_LBUTTONDBLCLK) {
415    //    redraw = true;
416    //}
417
418    if (message == WM_CAPTURECHANGED) {
419        if ((HWND)lParam != hWnd && blur.capture) {
420            ReleaseCapture();
421            blur.capture = false;
422            redraw = true;
423        }
424    }
425
426    //if (message == WM_SIZE) {
427    //    blur.dc_width = LOWORD(lParam);
428    //    blur.dc_height = HIWORD(lParam);
429    //    blur.dc_changed = true;
430    //}
431
432    //if (message == WM_WINDOWPOSCHANGED || message == WM_WINDOWPOSCHANGING) {
433    //    const WINDOWPOS* pos = (WINDOWPOS*)lParam;
434    //    if (!(pos->flags & SWP_NOSIZE)) {
435    //        blur.dc_width = pos->cx;
436    //        blur.dc_height = pos->cy;
437    //        blur.dc_changed = true;
438    //    }
439    //}
440
441    if (message == WM_MOUSEMOVE) {
442        // �}�E�X���E�B���h�E�����݂��邩�`�F�b�N
443        RECT rect = {};
444        POINT p = {};
445        p.x = GET_X_LPARAM(lParam);
446        p.y = GET_Y_LPARAM(lParam);
447        if (!(wParam & MK_LBUTTON) &&
448                (p.x < 0 ||
449                 p.y < 0 ||
450                 !GetWindowRect(hWnd, &rect) ||
451                 p.x >= (rect.right - rect.left) ||
452                 p.y >= (rect.bottom - rect.top)
453                )) {
454            // �f�[�^�擾���s���A�J�[�\�����E�B���h�E�O�ɂ���            if (blur.capture) {
455                ReleaseCapture();
456                blur.capture = false;
457                redraw = true;
458            }
459        } else {
460            // �J�[�\�����E�B���h�E������            if (!blur.capture) {
461                SetCapture(hWnd);
462                blur.capture = true;
463                redraw = true;
464            }
465        }
466
467        if (wParam & MK_LBUTTON) {
468            redraw = true;
469        }
470    }
471
472    InterlockedExchangeAdd(&ExtTextOutHook.cancel_count, 1);
473    LRESULT l = CallWindowProc(blur.DefaultWindowProceduer, hWnd, message, wParam, lParam);
474    InterlockedExchangeAdd(&ExtTextOutHook.cancel_count, -1);
475
476        if (ExtTextOutHook.done) {
477        InvalidateRect(hWnd, NULL, FALSE);
478            BlurEditWndProc(hWnd, WM_PAINT, 0, 0);
479                ExtTextOutHook.done = 0;
480        } else if (redraw) {
481                InvalidateRect(hWnd, NULL, FALSE);
482        }
483        //puts("}");
484    return l;
485}
486
487LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
488    WNDPROC wp = WndProc;
489    (void)wp;
490
491    if (message == WM_COMMAND) {
492        int wID = LOWORD(wParam);
493        int wNotifyCode = HIWORD(wParam);
494        HWND hwndControl =  (HWND)lParam;
495        if (hwndControl == (HWND)GetProp(hWnd, _T("my editbox"))) {
496            if (wNotifyCode == EN_UPDATE) {
497                //InvalidateRect(hwndControl, 0, FALSE);
498            }
499        }
500    }
501
502    if (message == WM_DESTROY) {
503        PostQuitMessage(0);
504        return 0;
505    }
506
507    return DefWindowProc(hWnd, message, wParam, lParam);
508}
509
510#ifdef HAVE_DWM
511#define CHECK(name) {dll.name = name;}
512#else
513#define CHECK(name)
514#endif
515
516#define SET_DLL_ADDRESS(module, name)                                   \
517    {                                                                   \
518        uintptr_t pointer = (uintptr_t)&dll.name;                       \
519        uintptr_t* pointer2 = (uintptr_t*)pointer;                      \
520        *pointer2 = (uintptr_t)GetProcAddress(module, #name);           \
521    }
522
523/*
524int APIENTRY _tWinMain(HINSTANCE hInstance,
525                       HINSTANCE hPrevInstance,
526                       LPTSTR    lpCmdLine,
527                       int       nCmdShow) {
528    UNREFERENCED_PARAMETER(hPrevInstance);
529    UNREFERENCED_PARAMETER(lpCmdLine);
530*/
531int main() {
532    ExtTextOutHook.thread_id = GetCurrentThreadId();
533        ExtTextOutHook.original = (api_::fp_ExtTextOutW)GetProcAddress(GetModuleHandleA("gdi32.dll"), "ExtTextOutW");
534        assert(ExtTextOutHook.original);
535
536    HINSTANCE hInstance = GetModuleHandle(NULL);
537
538    assert(LoadLibrary(_T("msftedit.dll")));
539    assert(LoadLibrary(_T("riched20.dll")));
540    assert(LoadLibrary(_T("riched32.dll")));
541
542    HMODULE dwmapi_dll = LoadLibrary(_T("dwmapi.dll"));
543    if (dwmapi_dll) {
544        SET_DLL_ADDRESS(dwmapi_dll, DwmExtendFrameIntoClientArea);
545        SET_DLL_ADDRESS(dwmapi_dll, DwmIsCompositionEnabled);
546        SET_DLL_ADDRESS(dwmapi_dll, DwmEnableBlurBehindWindow);
547        SET_DLL_ADDRESS(dwmapi_dll, DwmGetColorizationColor);
548        SET_DLL_ADDRESS(dwmapi_dll, DwmGetWindowAttribute);
549    }
550
551    HMODULE uxtheme_dll = LoadLibrary(_T("uxtheme.dll"));
552    if (uxtheme_dll) {
553        SET_DLL_ADDRESS(uxtheme_dll, BeginBufferedPaint);
554        SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintInit);
555        SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintUnInit);
556        SET_DLL_ADDRESS(uxtheme_dll, EndBufferedPaint);
557        SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintSetAlpha);
558    }
559
560    PROC pfnOrig;
561    //pfnOrig = GetProcAddress(GetModuleHandleA("user32.dll"), "MessageBoxA");
562    //ReplaceIATEntryInAllMods("user32.dll", pfnOrig, (PROC)Hook_MessageBoxA);
563
564    //pfnOrig = GetProcAddress(GetModuleHandleA("user32.dll"), "MessageBoxW");
565    //ReplaceIATEntryInAllMods("user32.dll", pfnOrig, (PROC)Hook_MessageBoxW);
566
567    //MessageBox(NULL, _T("���b�Z�[�W�{�b�N�X�\���̃e�X�g"), _T("�e�X�g"), MB_OK);
568
569    pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "TextOutW");
570    ReplaceIATEntryInAllMods("gdi32.dll", pfnOrig, (PROC)hook_TextOutW);
571
572    pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "ExtTextOutW");
573    ReplaceIATEntryInAllMods("gdi32.dll", pfnOrig, (PROC)hook_ExtTextOutW);
574
575    pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "DrawTextExW");
576    ReplaceIATEntryInAllMods("gdi32.dll", pfnOrig, (PROC)hook_DrawTextExW);
577
578    pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "DrawTextW");
579    ReplaceIATEntryInAllMods("gdi32.dll", pfnOrig, (PROC)hook_DrawTextW);
580
581    pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "PolyTextOutW");
582    ReplaceIATEntryInAllMods("gdi32.dll", pfnOrig, (PROC)hook_PolyTextOutW);
583
584
585    const TCHAR szWindowClass[] = _T("hoge");
586
587    WNDCLASS wc = {};
588    wc.style            = CS_HREDRAW | CS_VREDRAW;
589    wc.lpfnWndProc      = WndProc;
590    wc.cbClsExtra       = 0;
591    wc.cbWndExtra       = 0;
592    wc.hInstance        = hInstance;
593    wc.hIcon            = NULL;
594    wc.hCursor          = LoadCursor(NULL, IDC_ARROW);
595    wc.hbrBackground    = (HBRUSH)GetStockObject(BLACK_BRUSH);
596    wc.lpszMenuName     = NULL;
597    wc.lpszClassName    = szWindowClass;
598
599    assert(RegisterClass(&wc));
600
601    TCHAR szTitle[] = _T("hige");
602    DWORD style = WS_OVERLAPPEDWINDOW;
603
604    RECT r;
605    r.top = 0;
606    r.left = 0;
607    r.right = 600;
608    r.bottom = 200;
609    assert(AdjustWindowRectEx(&r, style, FALSE, 0));
610
611    HWND hWnd = CreateWindow(
612                    szWindowClass, szTitle, style,
613                                        r.top, r.bottom, r.right - r.left, r.bottom - r.top,
614                    NULL, NULL, hInstance, NULL);
615    assert(hWnd);
616
617    HWND hEdit = CreateWindow(
618                     _T("EDIT"),
619                     _T("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"),
620                     WS_CHILD | WS_VISIBLE /*| WS_BORDER */,
621                     50,
622                     50,
623                     500,
624                     100,
625                     hWnd,
626                     NULL,
627                     hInstance,
628                     NULL);
629
630    assert(hEdit);
631    assert(SetProp(hWnd, _T("my editbox"), (HANDLE)hEdit) != 0);
632
633    if (dwmapi_dll && uxtheme_dll) {
634        assert(dll.BufferedPaintInit() == S_OK);
635
636        DWM_BLURBEHIND bb  = {};
637        bb.dwFlags = DWM_BB_ENABLE;
638        bb.fEnable = TRUE;
639        assert(dll.DwmEnableBlurBehindWindow(hWnd, &bb) == S_OK);
640
641        MARGINS margins = {};
642                margins.cxLeftWidth = 50;
643        margins.cxRightWidth = 50;
644        margins.cyBottomHeight = 50;
645                margins.cyTopHeight = 50;
646
647        assert(dll.DwmExtendFrameIntoClientArea(hWnd, &margins) == S_OK);
648    }
649    blur.DefaultWindowProceduer = (WNDPROC)GetWindowLongPtr(hEdit, GWLP_WNDPROC);
650    SetWindowLongPtr(hEdit, GWLP_WNDPROC, (LONG_PTR)BlurEditWndProc);
651
652    ShowWindow(hWnd, SW_SHOW);
653    UpdateWindow(hWnd);
654
655    MSG msg = {};
656    for (;;) {
657        BOOL b = GetMessage(&msg, NULL, 0, 0);
658        if (!b) {
659            break;
660        }
661        if (b < 0) {
662            break;
663        }
664        TranslateMessage(&msg);
665        DispatchMessage(&msg);
666    }
667
668    return (int) msg.wParam;
669}
670
671
Note: See TracBrowser for help on using the browser.