the TRANSPARENT style of kero's code

Тема в разделе "WASM.ENGLISH", создана пользователем dcskm4200, 30 янв 2008.

  1. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    Код (Text):
    1. ; Moveable WS_EX_TRANSPARENT-Static
    2. .386
    3. .model flat,stdcall
    4. option casemap:none
    5.  
    6. include \masm32\include\windows.inc
    7. include \masm32\include\kernel32.inc
    8. include \masm32\include\user32.inc
    9. include \masm32\include\gdi32.inc
    10. include \masm32\include\ole32.inc
    11. include \masm32\include\oleaut32.inc
    12. include \masm32\include\Comctl32.inc
    13. include \masm32\include\masm32.inc
    14. include \masm32\include\debug.inc
    15.  
    16. includelib \masm32\lib\kernel32.lib
    17. includelib \masm32\lib\user32.lib
    18. includelib \masm32\lib\gdi32.lib
    19. includelib \masm32\lib\ole32.lib
    20.  includelib \masm32\lib\oleaut32.lib
    21. includelib \masm32\lib\Comctl32.lib
    22. includelib \masm32\lib\masm32.lib
    23. includelib \masm32\lib\debug.lib
    24.  
    25. include \masm32\macros\macros.asm
    26.  
    27. .data
    28.     _class       db "just_parent_window",0
    29.     _static      db "Static",0
    30.     _edit        db "Edit",0
    31.     _button      db "Button",0
    32.     _button_text db "Send  text  from  Edit  to  Static !",0
    33.     _edit_text   db "It's very easy to work with WS_EX_TRANSPARENT :-)",0
    34.     _static_text db "  Moveable  WS_EX_TRANSPARENT - Static",0
    35.     _about       db "by kero <geocities.com/xmemor>, v.2006-09-19",0
    36.  
    37. .data?
    38.     hInstance    HINSTANCE ?
    39.     hw_static    HWND ?
    40.     hw_edit      HWND ?
    41.     hbrush       HBRUSH ?
    42.     oldwndproc   dd ?
    43.     flag         dd ?
    44.     xhBitmap     dd ?
    45.     tValue       SDWORD ?
    46.     hMain        dd ?
    47.  
    48. .code
    49.  
    50. SetWinTransparence proc hWin:HWND,ValueTransparence:dword
    51.    
    52.     invoke  GetWindowLong,hWin,GWL_EXSTYLE
    53.     or  eax, WS_EX_LAYERED or WS_EX_TRANSPARENT
    54.     invoke  SetWindowLong,hWin,GWL_EXSTYLE,eax
    55.     invoke  SetLayeredWindowAttributes,hWin,0,ValueTransparence,LWA_ALPHA or LMA_COLORKEY
    56.     ret
    57.  
    58. SetWinTransparence endp
    59.  
    60. ResumeWin proc hWin:HWND
    61.    
    62.     invoke  SetWindowLong,hWin,GWL_EXSTYLE,WS_EX_LEFT
    63.     invoke  InvalidateRect,hWin,NULL,NULL
    64.     invoke  UpdateWindow,hWin
    65.     ret
    66.  
    67. ResumeWin endp
    68.  
    69. NewWndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    70.     Local ps:PAINTSTRUCT
    71.     Local hdc:HDC
    72.     Local mdc:HDC
    73.     Local xRc:RECT
    74.  
    75.     .if uMsg==WM_SETTEXT || uMsg==WM_GETICON
    76.         invoke CallWindowProc,oldwndproc,hWnd,uMsg,wParam,lParam
    77. @@:
    78.         invoke SetWindowPos,hWnd,0,0,0,0,0,SWP_NOMOVE OR SWP_NOSIZE OR SWP_NOSENDCHANGING OR SWP_FRAMECHANGED OR SWP_NOZORDER
    79.     .elseif (uMsg==WM_MOVE && flag==0) || (uMsg==WM_WINDOWPOSCHANGING && flag!=0)
    80.         jmp @b
    81.     .elseif uMsg == WM_TIMER
    82. PrintDec tValue
    83.         sub tValue,2
    84.         .if tValue <= 0
    85.             invoke  ResumeWin,hWnd
    86.             mov tValue,255
    87.         .else
    88.             invoke  SetWinTransparence,hWnd,tValue
    89.         .endif
    90.     .elseif uMsg == WM_PAINT
    91.         invoke  BeginPaint, hWnd,addr ps
    92.         mov hdc, eax
    93.         invoke  CreateCompatibleDC, eax
    94.         mov mdc, eax
    95.         invoke  SelectObject, mdc, xhBitmap
    96.         invoke  GetClientRect,hWnd,addr xRc
    97.         invoke  BitBlt,hdc,0,0,xRc.right,xRc.bottom,mdc,0,0,SRCCOPY
    98.         invoke  DeleteDC, mdc
    99.         invoke  EndPaint, hWnd, addr ps
    100.     .elseif uMsg == WM_DESTROY
    101.         invoke  PostQuitMessage,NULL
    102.     .elseif uMsg==WM_LBUTTONDBLCLK
    103.         xor flag,1
    104.         invoke  KillTimer, hWnd, 505
    105.     .elseif uMsg==WM_LBUTTONDOWN
    106.         mov tValue,255
    107.         invoke  SetTimer, hWnd, 505, 100, 0
    108.         invoke  SetWindowPos,hWnd,0,0,0,0,0,SWP_NOMOVE OR SWP_NOSIZE OR SWP_NOSENDCHANGING OR SWP_FRAMECHANGED OR SWP_NOZORDER
    109.         invoke  DefWindowProc,hWnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam
    110.     .else
    111.         invoke  CallWindowProc,oldwndproc,hWnd,uMsg,wParam,lParam
    112.         ret
    113.     .endif
    114.     xor eax,eax
    115.     ret
    116. NewWndProc endp
    117.  
    118. WndProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    119.     local buf[MAX_PATH+1]:BYTE
    120.  
    121.     .if uMsg==WM_DESTROY
    122.         invoke DeleteObject,hbrush
    123.         invoke PostQuitMessage,0
    124.     .elseif uMsg==WM_CREATE
    125.         m2m hMain,hWnd
    126.         invoke CreateWindowEx,NULL,offset _static,\
    127.             NULL,WS_CHILD or WS_VISIBLE or \
    128.             WS_CLIPSIBLINGS or WS_BORDER or SS_NOTIFY,\
    129.             90,50,100,75,hWnd,2000,hInstance,0
    130.         mov hw_static,eax
    131.         invoke  SetWindowLong,hw_static,GWL_WNDPROC,addr NewWndProc
    132.         mov oldwndproc,eax
    133.        
    134.         invoke  BitmapFromResource,hInstance,601
    135.         mov xhBitmap,eax
    136.     .elseif uMsg==WM_LBUTTONDOWN
    137.         invoke DefWindowProc,hWnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam
    138.  
    139.     .elseif uMsg==WM_ACTIVATE
    140.         invoke SetWindowPos,hw_static,HWND_TOP,0,0,0,0,\
    141.             SWP_NOMOVE OR SWP_NOSIZE OR SWP_NOSENDCHANGING OR SWP_FRAMECHANGED
    142.     .else
    143.         invoke DefWindowProc,hWnd,uMsg,wParam,lParam       
    144.         ret
    145.     .endif
    146.     xor eax,eax
    147.     ret
    148. WndProc endp
    149.  
    150. WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    151.     local wc:WNDCLASSEX
    152.     local msg:MSG
    153.     local hwnd:HWND
    154.     local hBitmap:HBITMAP
    155.  
    156.     mov wc.cbSize,sizeof WNDCLASSEX
    157.     mov wc.style,CS_DBLCLKS
    158.     mov wc.lpfnWndProc,offset WndProc
    159.     mov wc.cbClsExtra,0
    160.     mov wc.cbWndExtra,0
    161.     m2m wc.hInstance,hInst
    162.  
    163.     invoke  BitmapFromResource,hInstance,600
    164.     mov hBitmap,eax
    165.     invoke  CreatePatternBrush,eax
    166.     mov hbrush,eax
    167.     mov wc.hbrBackground,eax
    168.     invoke  DeleteObject,hBitmap
    169.  
    170.     mov wc.lpszMenuName,0
    171.     mov wc.lpszClassName,offset _class
    172. ;   invoke  LoadIcon,0,IDI_APPLICATION
    173.     mov wc.hIcon,0
    174.     mov wc.hIconSm,0
    175.     invoke  LoadCursor,0,IDC_ARROW
    176.     mov wc.hCursor,eax
    177.     invoke  RegisterClassEx,addr wc
    178.     invoke  CreateWindowEx,WS_EX_TOPMOST or WS_EX_TOOLWINDOW,\
    179.         offset _class,offset _static_text,WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,\
    180.         100,100,300,225,0,0,hInst,0
    181.  
    182.     mov hwnd,eax
    183.     invoke  ShowWindow,hwnd,SW_SHOWNORMAL
    184.     invoke  UpdateWindow,hwnd
    185.  
    186.     .while TRUE
    187.         invoke GetMessage,addr msg,0,0,0
    188.         .break .if (!eax)
    189.         invoke TranslateMessage,addr msg
    190.         invoke DispatchMessage,addr msg
    191.     .endw
    192.     mov eax,msg.wParam
    193.     ret
    194. WinMain endp
    195.  
    196. start:
    197.     invoke  GetModuleHandle,0
    198.     mov hInstance,eax
    199.     invoke  WinMain,eax,0,0,SW_SHOWDEFAULT
    200.     invoke  ExitProcess,eax
    201.  
    202. end start
    Код (Text):
    1. #include "\masm32\include\resource.h"
    2.  
    3. 600 IMAGE DISCARDABLE "1.jpg"
    4. 601 IMAGE DISCARDABLE "7.jpg"
    hello, all
    why hasn't the Static been changed into TRANSPARENT style?
    or
    how can i achieve the result which the filial window is transparenting from the paternal window?


    the attachment is exe
     
  2. kero

    kero Модератор SOURCES & 2LZ Команда форума

    Публикаций:
    0
    Регистрация:
    4 апр 2006
    Сообщения:
    1.074
    Адрес:
    Москва
    dcskm4200

    1) ?? This isn't kero's code. kero's code is in attachment.

    2) My code is about WS_EX_TRANSPARENT, but in your code i see also WS_EX_LAYERED+SetLayeredWindowAttributes.
    BTW, the window with WS_EX_LAYERED+WS_EX_TRANSPARENT is absolutely hole for mouse, so - can't be "moveable" :)

    3)
    Because Static is system's predefined control (= child), read MSDN about layered windows (must be top-level).

    But! -
    4)
    You can find experimental "partly workable" layered controls here: http://www.wasm.ru/forum/viewtopic.php?id=21495.
     
  3. dcskm4200

    dcskm4200 New Member

    Публикаций:
    0
    Регистрация:
    12 окт 2004
    Сообщения:
    173
    Адрес:
    China
    Hello,kero
    Thank you very much.
    i'v got the right result.
     
  4. kero

    kero Модератор SOURCES & 2LZ Команда форума

    Публикаций:
    0
    Регистрация:
    4 апр 2006
    Сообщения:
    1.074
    Адрес:
    Москва
    I'm glad :)