Re: Subclassing crash

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Fri, 24 Jan 2003 16:07:33 -0500, Matt Lewis wrote:

>It looks like you simply pass the callback to ControlProc, where you =
should
>be passing the pointer to the default procedure for that control.

Sorry, I was wrong in previous  post.

SubControl=3Dc_func(SetWindowLong,{ hControl, GWL_WNDPROC,
                                call_back(routine_id("ControlProc"))})


Check it out

--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D

without warning

include msgbox.e

constant
user32=3Dopen_dll("user32.dll"),

CallWindowProc=3Ddefine_c_func(user32,"CallWindowProcA",{C_ULONG,C_ULONG,=
C_ULONG,C_ULONG,C_ULONG},C_INT),
CreateWindowEx=3Ddefine_c_func(user32,"CreateWindowExA",{C_ULONG,C_ULONG,=
C_ULONG,C_ULONG,C_ULONG,C_ULONG,C_ULONG,C_ULONG,C_ULONG,C_ULONG,C_ULONG,C=
_ULONG},C_INT),
SetWindowLong=3Ddefine_c_func(user32,"SetWindowLongA",{C_ULONG,C_ULONG,C_=
ULONG},C_INT),
PostQuitMessage=3Ddefine_c_func(user32,"PostQuitMessage",{C_ULONG},C_INT)=
,
DefWindowProc=3Ddefine_c_func(user32,"DefWindowProcA",{C_ULONG,C_ULONG,C_=
ULONG,C_ULONG},C_INT),
LoadIcon=3Ddefine_c_func(user32,"LoadIconA",{C_ULONG,C_ULONG},C_INT),
LoadCursor=3Ddefine_c_func(user32,"LoadCursorA",{C_ULONG,C_ULONG},C_INT),
RegisterClass=3Ddefine_c_func(user32,"RegisterClassA",{C_ULONG},C_INT),
ShowWindow=3Ddefine_c_func(user32,"ShowWindow",{C_ULONG,C_ULONG},C_INT),
UpdateWindow=3Ddefine_c_func(user32,"UpdateWindow",{C_ULONG},C_INT),
GetMessage=3Ddefine_c_func(user32,"GetMessageA",{C_ULONG,C_ULONG,C_ULONG,=
C_ULONG},C_INT),
TranslateMessage=3Ddefine_c_func(user32,"TranslateMessage",{C_ULONG},C_IN=
T),
DispatchMessage=3Ddefine_c_func(user32,"DispatchMessageA",{C_ULONG},C_INT=
),

WS_CHILD=3D#40000000,
WS_VISIBLE=3D#10000000,
GWL_WNDPROC=3D#FFFFFFFC,
WM_CREATE=3D#1,
WM_DESTROY=3D#2,
sizeofMSG=3D28,
sizeofWNDCLASS=3D40,
WNDCLASS_style=3D0,
CS_HREDRAW=3D#2,
CS_VREDRAW=3D#1,
WNDCLASS_lpfnWndProc=3D4,
WNDCLASS_cbClsExtra=3D8,
WNDCLASS_cbWndExtra=3D12,
WNDCLASS_hInstance=3D16,
WNDCLASS_hbrBackground=3D28,
COLOR_WINDOW=3D#5,
WNDCLASS_lpszMenuName=3D32,
WNDCLASS_lpszClassName=3D36,
IDI_WINLOGO=3D#7F05,
WNDCLASS_hIcon=3D20,
IDC_ARROW=3D#7F00,
WNDCLASS_hCursor=3D24,
WS_OVERLAPPEDWINDOW=3D#CF0000,
WS_MAXIMIZEBOX=3D#10000,
SW_SHOWNORMAL=3D#1


object ret
atom hButton
atom SubControl


function ControlButtProc(atom hWnd,atom wMsg,atom wParam,atom lParam)

integer c

c=3D1

   ret=3Dc_func(CallWindowProc,{ SubControl, hWnd, wMsg, wParam,
lParam})

   if c then end if            ------>  COMMENT/UNCOMMENT THIS LINE=20

   return ret

end function


function Button(atom hParent,sequence Name,integer x,integer y,integer
w,integer h,integer id)

atom szName
atom szClassName
atom hButt

   szName=3Dallocate_string(Name)
   szClassName=3Dallocate_string("BUTTON")

   hButt=3Dc_func(CreateWindowEx,{ NULL, szClassName, szName,
                             WS_CHILD + WS_VISIBLE,
                             x, y, w, h, hParent, id, instance(), 0 })


   free(szName)
   free(szClassName)

SubControl=3Dc_func(SetWindowLong,{ hButt, GWL_WNDPROC,
call_back(routine_id("ControlButtProc"))})

   return hButt

end function


function WndProc(atom hWnd,atom wMsg,atom wParam,atom lParam)

   if wMsg =3D WM_CREATE then
       hButton=3DButton( hWnd,"My Button", 25, 25, 80, 25, 10)
       return 0

   elsif wMsg =3D WM_DESTROY then
       ret=3Dc_func(PostQuitMessage,{NULL})
       return 0=20
=20
   end if

   return c_func(DefWindowProc,{hWnd,wMsg,wParam,lParam})

end function


procedure WinMain()

atom wc
atom msg
atom hMainWnd
atom szDisplayName
atom szClassName

    msg=3Dallocate(sizeofMSG)
    szDisplayName=3Dallocate_string("My Win")
    szClassName=3Dallocate_string("My_Win_Class")
    wc=3Dallocate(sizeofWNDCLASS)

    poke4(wc+WNDCLASS_style,CS_HREDRAW+CS_VREDRAW)
    poke4(wc+WNDCLASS_lpfnWndProc,call_back(routine_id("WndProc")))
    poke4(wc+WNDCLASS_cbClsExtra,NULL)
    poke4(wc+WNDCLASS_cbWndExtra,NULL)
    poke4(wc+WNDCLASS_hInstance,instance())
    poke4(wc+WNDCLASS_hbrBackground,COLOR_WINDOW)
    poke4(wc+WNDCLASS_lpszMenuName,NULL)
    poke4(wc+WNDCLASS_lpszClassName,szClassName)
         ret=3Dc_func(LoadIcon,{NULL,IDI_WINLOGO})
    poke4(wc+WNDCLASS_hIcon,ret)
         ret=3Dc_func(LoadCursor,{NULL,IDC_ARROW})
    poke4(wc+WNDCLASS_hCursor,ret)

    ret=3Dc_func(RegisterClass,{wc})

    free(wc)

    hMainWnd=3Dc_func(CreateWindowEx,{NULL,
                        szClassName,
                        szDisplayName,
                        xor_bits(WS_OVERLAPPEDWINDOW,WS_MAXIMIZEBOX),
                        0,0,340,200,
                        NULL,NULL,
                        instance(),NULL})
       =20
    free(szDisplayName)
    free(szClassName)

    ret=3Dc_func(ShowWindow,{hMainWnd,SW_SHOWNORMAL})
    ret=3Dc_func(UpdateWindow,{hMainWnd})

    while c_func(GetMessage,{msg, NULL, 0, 0}) do
        ret=3Dc_func(TranslateMessage,{msg})
        ret=3Dc_func(DispatchMessage,{msg})
    end while

    free(msg)

end procedure

WinMain()


--=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

-George-

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu