News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Set/GetWindowLongPtr

Started by Slugsnack, July 05, 2009, 10:44:53 AM

Previous topic - Next topic

Slugsnack

I have this code within the initdialog case for my dialogproc :

invoke GetWindowLongPtr, hwndDlg, GWL_EXSTYLE
mov eax, eax OR WS_EX_LAYERED
invoke SetWindowLongPtr, hwndDlg, GWL_EXSTYLE, eax
invoke SetLayeredWindowAttributes, hwndDlg, NULL, 200, LWA_ALPHA


first of all the assembler fails to recognise either get/setwindowlongptr as an API, basically an unrecognised symbol. so i tried changing it to getwindowlong instead but then it gives an error saying the setwindowlong line 'constant expected'. so i'm guessing it's not liking the eax there. how else would i go about doing this ?

in case it's unclear, i'm trying to set some transparency for my dialog

jj2007

mov eax, eax OR WS_EX_LAYERED = or eax, WS_EX_LAYERED

Slugsnack

of course ! works good now. do you know why i can't use the 64 bit compatible versions of the APIs though ? they're not even exported as symbols from user32.dll which they are supposed to be..

ramguru

I agree this is strange. There is a problem with this API.
It doesn't appear in windows 7 64bit system dll export list.
When I compile I have an old user32.dll from windows xp 64bit
in the same directory, then it's fine. But fasm doesn't complain about that API
only some other assemblers do...

xandaz

   i know that this is an old thread but i was wondering if Get/SetWindowLong(Ptr) can be used to retrieve the pointer to the cbWndExtra bytes reffered  in WNDCLASSEX?
   Thanks.

MichaelW

AFAIK you cannot retrieve a pointer, but you can address the extra memory by index.

;==============================================================================
; Build as a console app.
;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================

printf MACRO format:REQ, args:VARARG
    IFNB <args>
        invoke crt_printf, cfm$(format), args
    ELSE
        invoke crt_printf, cfm$(format)
    ENDIF
    EXITM <>
ENDM

;==============================================================================
    .data
      hInst       dd          0
      hWnd        dd          0
      _x          dd          0
      _y          dd          0
      wc          WNDCLASSEX  <>
      msg         MSG         <>
      className   db          "test_class",0
    .code
;==============================================================================

WndProc proc hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

    SWITCH uMsg

        CASE WM_CREATE

            push ebx

            xor ebx, ebx
            .WHILE ebx < 40
                invoke SetWindowLong, hwnd, ebx , ebx
                add ebx, 4
            .ENDW

            xor ebx, ebx
            .WHILE ebx < 40
                invoke SetClassLong, hwnd, ebx , ebx
                add ebx, 4
            .ENDW

            pop ebx

        CASE WM_LBUTTONUP

            push ebx

            xor ebx, ebx
            .WHILE ebx < 40
                invoke GetWindowLong, hwnd, ebx
                printf( "%d\n", eax )
                add ebx, 4
            .ENDW

            xor ebx, ebx
            .WHILE ebx < 40
                invoke GetClassLong, hwnd, ebx
                printf( "%d\n", eax )
                add ebx, 4
            .ENDW

            pop ebx

        CASE WM_CLOSE

            invoke DestroyWindow, hwnd

        CASE WM_DESTROY

            invoke PostQuitMessage, NULL

        DEFAULT

            invoke DefWindowProc, hwnd, uMsg, wParam, lParam

    ENDSW

    ret

WndProc endp

;==============================================================================
start:
;==============================================================================

    mov hInst, rv(GetModuleHandle, NULL)
    mov wc.cbSize,        sizeof WNDCLASSEX
    mov wc.style,         CS_BYTEALIGNWINDOW
    mov wc.lpfnWndProc,   OFFSET WndProc
    mov wc.cbClsExtra,    40
    mov wc.cbWndExtra,    40
    m2m wc.hInstance,     hInst
    mov wc.hbrBackground, rv(GetStockObject, BLACK_BRUSH)
    mov wc.lpszMenuName,  NULL
    mov wc.lpszClassName, OFFSET className
    mov wc.hIcon,         rv(LoadIcon, NULL, IDI_APPLICATION)
    mov wc.hCursor,       rv(LoadCursor, NULL, IDC_ARROW)
    mov wc.hIconSm,       0
    invoke RegisterClassEx, ADDR wc

    W = 400
    H = 300
    invoke GetSystemMetrics, SM_CXSCREEN
    shr eax, 1
    sub eax, W / 2
    mov _x, eax
    invoke GetSystemMetrics, SM_CYSCREEN
    shr eax, 1
    sub eax, H / 2
    mov _y, eax

    invoke CreateWindowEx, WS_EX_OVERLAPPEDWINDOW,
                           ADDR className,
                           chr$("Test"),
                           WS_OVERLAPPED or WS_SYSMENU,
                           _x, _y, W, H,
                           NULL, NULL,
                           hInst, NULL
    mov hWnd, eax

    invoke ShowWindow, hWnd, SW_SHOWNORMAL
    invoke UpdateWindow, hWnd

  msgLoop:

    invoke GetMessage, ADDR msg, NULL, 0, 0
    .IF eax != 0
        invoke TranslateMessage, ADDR msg
        invoke DispatchMessage, ADDR msg
        jmp   msgLoop
    .ENDIF

    exit msg.wParam

;==============================================================================

end start

eschew obfuscation