Changeset 37165

Show
Ignore:
Timestamp:
04/07/10 12:42:10 (3 years ago)
Author:
saturday06
Message:

moudamepo

Location:
lang/objective-cplusplus/i3/trunk/tmp
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/objective-cplusplus/i3/trunk/tmp/dwmtest.cpp

    r36861 r37165  
    2222LRESULT CALLBACK BlurEditWndProc( 
    2323    HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { 
    24 static bool blured = false; 
    2524 
    2625    WNDPROC wp = BlurEditWndProc; 
     
    2928        (WNDPROC)GetProp(hWnd, _T("my default wndproc")); 
    3029     
    31     if (message == WM_SETFOCUS) { 
     30        if (message == WM_SETFOCUS) { 
    3231        InvalidateRect(hWnd, 0, FALSE); 
    3332    } 
     
    8584        } 
    8685    } 
     86         
    8787 
    8888    if (message == WM_PAINT) { 
     
    148148    (void)wp; 
    149149 
    150         if (message = WM_SHOWWINDOW) { 
    151                 bool show = (bool)wParam; 
    152                 if (!show) { 
    153                         // before hide 
    154                         if (blured) { 
    155                                 blured = false; 
    156                                 DWM_BLURBEHIND bb  = {}; 
    157                                 bb.dwFlags = DWM_BB_ENABLE; 
    158                                 bb.fEnable = FALSE; 
    159                                 DwmEnableBlurBehindWindow(hWnd, &bb); 
    160                         } 
    161                 } 
    162         } 
    163  
    164         if (message == WM_COMMAND) { 
    165                 int wID = wParam & 0xFFFF; 
    166                 int wNotifyCode = (wParam >> 16) & 0xFFFF; 
    167                 HWND hwndControl =  (HWND)lParam; 
    168                 if (wNotifyCode == EN_UPDATE) { 
    169                         InvalidateRect(hwndControl, 0, FALSE); 
    170                 } else if (wNotifyCode == EN_KILLFOCUS) { 
    171                         focused = false; 
    172                         if (IsWindowVisible(hWnd) && !blured) { 
    173                                 blured = true; 
    174                                 DWM_BLURBEHIND bb  = {}; 
    175                                 bb.dwFlags = DWM_BB_ENABLE; 
    176                                 bb.fEnable = TRUE; 
    177                                 DwmEnableBlurBehindWindow(hWnd, &bb); 
    178                                 InvalidateRect(hwndControl, NULL, FALSE); 
    179                         } 
    180                 } else if (wNotifyCode == EN_SETFOCUS) { 
    181                         focused = true; 
    182                         if (blured) { 
    183                                 blured = false; 
    184                                 DWM_BLURBEHIND bb  = {}; 
    185                                 bb.dwFlags = DWM_BB_ENABLE; 
    186                                 bb.fEnable = FALSE; 
    187                                 DwmEnableBlurBehindWindow(hWnd, &bb); 
    188                                 InvalidateRect(hwndControl, NULL, FALSE); 
    189                         } 
    190                 } 
    191         } 
     150    if (message == WM_COMMAND) { 
     151        int wID = LOWORD(wParam); 
     152        int wNotifyCode = HIWORD(wParam); 
     153        HWND hwndControl =  (HWND)lParam; 
     154        if (hwndControl == (HWND)GetProp(hWnd, _T("my editbox"))) { 
     155            if (wNotifyCode == EN_UPDATE) { 
     156                InvalidateRect(hwndControl, 0, FALSE); 
     157            } 
     158        } 
     159    } 
    192160 
    193161    if (message == WM_DESTROY) { 
     
    199167} 
    200168 
    201 void ShowLastError() { 
    202         DWORD le = GetLastError(); 
    203         LPVOID lpMessageBuffer; 
    204         FormatMessage( 
    205         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    206         FORMAT_MESSAGE_FROM_SYSTEM, 
    207         NULL, 
    208         le, 
    209                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // �f�t�H���g ���[�U�[���� 
    210                 (LPTSTR)&lpMessageBuffer, 
    211         0, 
    212         NULL); 
    213    
    214         MessageBox(NULL, (LPTSTR)lpMessageBuffer, _T("GetLastError"), MB_OK); 
    215         LocalFree(lpMessageBuffer); 
    216         DebugBreak(); 
    217 } 
     169#define SET_DLL_ADDRESS(module, name)                                   \ 
     170    {                                                                   \ 
     171        dll.name = (decltype(&name))GetProcAddress(module, #name);      \ 
     172    } 
    218173 
    219174int APIENTRY _tWinMain(HINSTANCE hInstance, 
     
    224179    UNREFERENCED_PARAMETER(lpCmdLine); 
    225180 
    226         if (BufferedPaintInit() != S_OK) { 
    227                 ShowLastError(); 
    228                 return 1; 
    229         } 
     181    assert(LoadLibrary(_T("msftedit.dll"))); 
     182    assert(LoadLibrary(_T("riched20.dll"))); 
     183    assert(LoadLibrary(_T("riched32.dll"))); 
    230184 
    231185    HMODULE dwmapi_dll = LoadLibrary(_T("dwmapi.dll")); 
     
    238192    SET_DLL_ADDRESS(dwmapi_dll, DwmGetWindowAttribute); 
    239193 
    240         WNDCLASS wc; 
    241     wc.style                    = CS_HREDRAW | CS_VREDRAW; 
    242     wc.lpfnWndProc              = WndProc; 
    243     wc.cbClsExtra               = 0; 
    244     wc.cbWndExtra               = 0; 
    245     wc.hInstance                = hInstance; 
    246     wc.hIcon                    = NULL; 
    247     wc.hCursor                  = LoadCursor(NULL, IDC_ARROW); 
    248     wc.hbrBackground    = (HBRUSH)GetStockObject(BLACK_BRUSH); 
    249     wc.lpszMenuName             = NULL; 
    250     wc.lpszClassName    = szWindowClass; 
    251  
    252         if (!RegisterClass(&wc)) { 
    253                 ShowLastError(); 
    254                 return 1; 
    255         } 
    256  
    257         TCHAR szTitle[] = _T("hige"); 
    258     HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 
    259                         CW_USEDEFAULT, 0, 200, 200, NULL, NULL, hInstance, NULL); 
    260         if (!hWnd) { 
    261                 ShowLastError(); 
    262                 return 1; 
    263         } 
     194    HMODULE uxtheme_dll = LoadLibrary(_T("uxtheme.dll")); 
     195    assert(uxtheme_dll); 
     196    SET_DLL_ADDRESS(uxtheme_dll, BeginBufferedPaint); 
     197    SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintInit); 
     198    SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintUnInit); 
     199    SET_DLL_ADDRESS(uxtheme_dll, EndBufferedPaint); 
     200    SET_DLL_ADDRESS(uxtheme_dll, BufferedPaintSetAlpha); 
     201 
     202    assert(dll.BufferedPaintInit() == S_OK); 
    264203 
    265204    MSG msg = {}; 
     
    322261        NULL); 
    323262 
    324         if (!hEdit) { 
    325                 ShowLastError(); 
    326                 return 1; 
    327         } 
    328  
    329     EditDefaultWndProc = (WNDPROC)GetWindowLongPtr(hEdit, GWLP_WNDPROC); 
     263    assert(hEdit); 
     264    assert(SetProp(hWnd, _T("my editbox"), (HANDLE)hEdit) != 0); 
     265 
     266    HANDLE wp = (HANDLE)GetWindowLongPtr(hEdit, GWLP_WNDPROC); 
     267    assert(SetProp(hEdit, _T("my default wndproc"), wp) != 0); 
    330268    SetWindowLong(hEdit, GWLP_WNDPROC, (LONG_PTR)BlurEditWndProc); 
    331269     
  • lang/objective-cplusplus/i3/trunk/tmp/dwmtest.vcxproj

    r36619 r37165  
    4949      <PrecompiledHeader> 
    5050      </PrecompiledHeader> 
    51       <WarningLevel>Level3</WarningLevel> 
     51      <WarningLevel>Level4</WarningLevel> 
    5252      <MinimalRebuild>true</MinimalRebuild> 
    5353      <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 
  • lang/objective-cplusplus/i3/trunk/tmp/ex.cpp

    r37162 r37165  
    1  
    21///////////////////////////////////////////////////////////////////// 
    32// ex2.cpp 
     
    65///////////////////////////////////////////////////////////////////// 
    76 
    8 #define WIN32_LEAN_AND_MEAN 
    97#define STRICT 
    108 
     
    1412#include <tlhelp32.h> 
    1513#include <dbghelp.h> 
     14#include <windows.h> 
     15#include <windowsx.h> 
     16#include <tchar.h> 
     17#include <uxtheme.h> 
     18#include <dwmapi.h> 
     19#include <assert.h> 
     20#include <richedit.h> 
    1621 
    1722// ImageDirectoryEntryToData 
     
    2328    PROC pfnCurrent, 
    2429    PROC pfnNew, 
    25     HMODULE hmodCaller)  
     30    HMODULE hmodCaller) 
    2631{ 
    2732    ULONG ulSize; 
    2833    PIMAGE_IMPORT_DESCRIPTOR pImportDesc; 
    2934    pImportDesc = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToData( 
    30         hmodCaller, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ulSize); 
     35                      hmodCaller, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ulSize); 
    3136 
    3237    if (pImportDesc == NULL) { 
     
    3540 
    3641 
    37     while(pImportDesc->Name) { 
     42    while (pImportDesc->Name) { 
    3843        PSTR pszModName = (PSTR) ((PBYTE) hmodCaller + pImportDesc->Name); 
    3944        if (lstrcmpiA(pszModName, pszModuleName) == 0) { 
     
    4752    } 
    4853 
    49     PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)  
    50         ((PBYTE) hmodCaller + pImportDesc->FirstThunk); 
    51  
    52     while(pThunk->u1.Function) { 
     54    PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA) 
     55                               ((PBYTE) hmodCaller + pImportDesc->FirstThunk); 
     56 
     57    while (pThunk->u1.Function) { 
    5358        PROC *ppfn = (PROC*) &pThunk->u1.Function; 
    5459        BOOL fFound = (*ppfn == pfnCurrent); 
     
    6671// ���ׂẴ��W���[���ɑ΂���PI�t�b�N����֐� 
    6772void ReplaceIATEntryInAllMods( 
    68     PCSTR pszModuleName,  
    69     PROC pfnCurrent,  
    70     PROC pfnNew)  
     73    PCSTR pszModuleName, 
     74    PROC pfnCurrent, 
     75    PROC pfnNew) 
    7176{ 
    7277    // ���W���[�����X�g��� 
    7378    HANDLE hModuleSnap = CreateToolhelp32Snapshot( 
    74         TH32CS_SNAPMODULE, GetCurrentProcessId()); 
    75     if(hModuleSnap == INVALID_HANDLE_VALUE) { 
     79                             TH32CS_SNAPMODULE, GetCurrentProcessId()); 
     80    if (hModuleSnap == INVALID_HANDLE_VALUE) { 
    7681        return; 
    7782    } 
     
    8085    BOOL bModuleResult = Module32First(hModuleSnap, &me); 
    8186    // ���ꂼ�����W���[���ɑ΂���eplaceIATEntryInOneMod��s 
    82     while(bModuleResult) {         
     87    while (bModuleResult) { 
    8388        ReplaceIATEntryInOneMod(pszModuleName, pfnCurrent, pfnNew, me.hModule); 
    8489        bModuleResult = Module32Next(hModuleSnap, &me); 
     
    96101 
    97102int WINAPI Hook_TextOutW( 
    98 HDC hdc, int x, int y, LPCWSTR str, int count 
    99     ) { 
     103    HDC hdc, int x, int y, LPCWSTR str, int count 
     104) { 
    100105    OutputDebugString(_T("to")); 
    101106    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "TextOutW"); 
     
    104109 
    105110int WINAPI Hook_ExtTextOutW( 
    106 HDC hdc, int x, int y, UINT option, CONST RECT *rc, LPCWSTR str, UINT count, CONST INT *dx  
    107     ) { 
     111    HDC hdc, int x, int y, UINT option, CONST RECT *rc, LPCWSTR str, UINT count, CONST INT *dx 
     112) { 
    108113    OutputDebugString(_T("dw")); 
    109114    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "ExtTextOutW"); 
     
    112117 
    113118LONG WINAPI Hook_TabbedTextOutW( 
    114 HDC hdc, int x, int y, LPCWSTR str, int count, int ntabs, const INT* tabs, int origin     ) { 
     119    HDC hdc, int x, int y, LPCWSTR str, int count, int ntabs, const INT* tabs, int origin     ) { 
    115120    OutputDebugString(_T("dw")); 
    116121    PROC pfnOrig = GetProcAddress(GetModuleHandleA("gdi32.dll"), "TabbedTextOutW"); 
     
    144149 
    145150int WINAPI Hook_MessageBoxW( 
    146     HWND hWnd,  
    147     PCWSTR pszText,  
    148     PCWSTR pszCaption,  
     151    HWND hWnd, 
     152    PCWSTR pszText, 
     153    PCWSTR pszCaption, 
    149154    UINT uType) 
    150155{ 
     
    160165PFN_DrawTextW dt1 = DrawText; 
    161166PFN_DrawTextW dt2 = Hook_DrawTextW; 
    162  
    163167PFN_ExtTextOutW di1 = ExtTextOut; 
    164168PFN_ExtTextOutW di2 = Hook_ExtTextOutW; 
    165  
    166169PFN_TextOutW do1 = TextOut; 
    167170PFN_TextOutW do2 = Hook_TextOutW; 
    168  
    169171PFN_TabbedTextOutW dx1 = TabbedTextOut; 
    170172PFN_TabbedTextOutW dx2 = Hook_TabbedTextOutW; 
    171173 
    172 //int APIENTRY _tWinMain(HINSTANCE hInstance, 
    173 //                       HINSTANCE hPrevInstance, 
    174 //                       LPTSTR    lpCmdLine, 
    175 //                       int       nCmdShow) 
    176  
    177  
    178  
    179 #include <windows.h> 
    180 #include <windowsx.h> 
    181 #include <tchar.h> 
    182 #include <uxtheme.h> 
    183 #include <dwmapi.h> 
    184 #include <assert.h> 
    185 #include <richedit.h> 
    186174 
    187175void ShowLastError() { 
    188         DWORD le = GetLastError(); 
    189         LPVOID lpMessageBuffer; 
    190         FormatMessage( 
    191         FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    192         FORMAT_MESSAGE_FROM_SYSTEM, 
    193         NULL, 
    194         le, 
    195                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // �f�t�H���g ���[�U�[���� 
    196                 (LPTSTR)&lpMessageBuffer, 
    197         0, 
    198         NULL); 
    199    
    200         //MessageBox(NULL, (LPTSTR)lpMessageBuffer, _T("GetLastError"), MB_OK); 
     176    DWORD le = GetLastError(); 
     177    LPVOID lpMessageBuffer; 
     178    FormatMessage( 
     179        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
     180        FORMAT_MESSAGE_FROM_SYSTEM, 
     181        NULL, 
     182        le, 
     183        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // �f�t�H���g ���[�U�[����        (LPTSTR)&lpMessageBuffer, 
     184        0, 
     185        NULL); 
     186 
     187    //MessageBox(NULL, (LPTSTR)lpMessageBuffer, _T("GetLastError"), MB_OK); 
    201188    OutputDebugString((LPTSTR)lpMessageBuffer); 
    202         LocalFree(lpMessageBuffer); 
    203         DebugBreak(); 
     189    LocalFree(lpMessageBuffer); 
     190    DebugBreak(); 
    204191} 
    205192 
     
    212199 
    213200    if (message == WM_PAINT) { //�N���C�A���g�̈��ĕ`�揈�� 
    214          /* �f�o�C�X�R���e�L�X�g�̃n���h����� */ 
     201        /* �f�o�C�X�R���e�L�X�g�̃n���h����� */ 
    215202        PAINTSTRUCT ps; 
    216203        HDC hDC = BeginPaint(hWnd, &ps); 
     
    220207//        TextOut(hDC, 100, 170, _T("���������Ή������ׂ���, 22); 
    221208//        TextOut(hDC, 100, 200, _T("Hello World!"), 12); 
    222          
     209 
    223210        /* �����̐F�Ɣw�i�F����������̕`��/ 
    224211        SetTextColor(hDC, RGB(0,0,255));   //�����̐F��肷��        SetBkColor(hDC, RGB(255,255,0));   //�����̔w�i�F��肷��        _tcscpy(str, _T("abcde12345����������")); 
    225212//        TextOut(hDC, 100, 230, str, _tcslen(str)); 
    226          
     213 
    227214        /* �����/ 
    228215        MoveToEx(hDC, 100, 190, NULL);  //�P�{�ڂ̉���܂��u 
     
    230217        MoveToEx(hDC, 100, 220, NULL);  //�Q�{�ڂ̉���܂��u 
    231218        LineTo(hDC, 185, 220);          //�Q�{�ڂ̉�����ʒu 
    232          
     219 
    233220        /* �n���h���̉�*/ 
    234221        EndPaint(hWnd, &ps); 
     
    295282 
    296283    HWND hWnd = CreateWindow( 
    297         szWindowClass, szTitle, style, 
    298         50, 50, r.right - r.left, r.bottom - r.top, 
    299         NULL, NULL, hInstance, NULL); 
     284                    szWindowClass, szTitle, style, 
     285                    50, 50, r.right - r.left, r.bottom - r.top, 
     286                    NULL, NULL, hInstance, NULL); 
    300287    assert(hWnd); 
    301288 
    302     HWND hEdit = CreateWindow(  
    303         _T("EDIT"), 
    304         _T("hage"), 
    305         WS_CHILD | WS_VISIBLE /*| WS_BORDER */, 
    306         50, 
    307         100, 
    308         200, 
    309         100, 
    310         hWnd, 
    311         NULL, 
    312         hInstance, 
    313         NULL); 
    314  
    315         if (!hEdit) { 
    316                 ShowLastError(); 
    317                 return 1; 
    318         } 
    319      
     289    HWND hEdit = CreateWindow( 
     290                     _T("EDIT"), 
     291                     _T("hage"), 
     292                     WS_CHILD | WS_VISIBLE /*| WS_BORDER */, 
     293                     50, 
     294                     100, 
     295                     200, 
     296                     100, 
     297                     hWnd, 
     298                     NULL, 
     299                     hInstance, 
     300                     NULL); 
     301 
     302    if (!hEdit) { 
     303        ShowLastError(); 
     304        return 1; 
     305    } 
     306 
    320307    ShowWindow(hWnd, nCmdShow); 
    321308    UpdateWindow(hWnd);