amazing function behavior
Phil Deets
pjdeets2 at gmail.com
Tue Oct 20 10:05:28 PDT 2009
On Mon, 19 Oct 2009 02:39:57 -0500, Zarathustra
<adam.chrapkowski at gmail.com> wrote:
> Function is never called but why?
> look at: window.Window.wndProc : case WM.LBUTTONDOWN
> //______________________________________________
> module window;
>
> private import base;
> private import structs;
>
> private static import user32;
> private static import kernel32;
> private static import gdi32;
>
> private:
> extern (Windows) static dword wndProc(ptr o_hwnd, dword o_msg, dword
> o_wparam, dword o_lparam){
>
> alias user32.EWindowMessage WM;
> auto l_wnd = cast(Window*)user32.getWindowLong(o_hwnd, 0x00);
> if(o_msg == WM.NCCREATE){
> user32.setWindowLong(o_hwnd, 0x00, *(cast(dword*)o_lparam));
> }
> else if(l_wnd is null){
> return 0x00;
> }
> return (cast(Window*)user32.getWindowLong(o_hwnd,
> 0x00)).wndProc(o_hwnd, o_msg, o_wparam, o_lparam);
> }
>
> public:
> class Window{
> private const ptr handle;
>
> void onMouseDown(MouseEventArgs o_mea){
> user32.messageBox(null, cast(wstr)"Window", cast(wstr)"msg", 0x00);
> }
>
> this(){
> WINWndClassEx wndClass;
>
> wndClass.size = 0x00000030;
> wndClass.style = 0x00000003;
> wndClass.wndProc = cast(ptr)&.wndProc;
> wndClass.clsExtraBytes = 0x00000000;
> wndClass.wndExtraBytes = 0x00000004;
> wndClass.hInstance = kernel32.getModuleHandle(null);
> wndClass.hIcon = user32.loadIcon(null, 0x00007F00);
> wndClass.hCursor = user32.loadCursor(null, 0x00007F00);
> wndClass.hbrBackground = gdi32.getStockObject(0x00000000);
> wndClass.menuName = null;
> wndClass.className = cast(wstr)"clsname";
> wndClass.hIconSm = user32.loadIcon(null, 0x00007F00);
> if(!user32.registerClassEx(cast(ptr)&wndClass)){
> if(kernel32.getLastError() != 0x0582){
> user32.messageBox(null,
> user32.translateErrorCode(kernel32.getLastError()), cast(wstr)"error",
> 0x00000000);
> assert(false, "window class registering failed");
> }
> }
>
> handle = user32.createWindowEx(
> 0,
> wndClass.className,
> cast(wstr)"<applicationcaption>",
> 0x00CF0000,
> 0x00000000,
> 0x00000000,
> 0x00000280,
> 0x000001E0,
> null,
> null,
> kernel32.getModuleHandle(null),
> cast(ptr)&this
> );
> if(handle is null){
> user32.messageBox(null,
> user32.translateErrorCode(kernel32.getLastError()), cast(wstr)"error",
> 0x00000000);
> assert(false, "window creating failed");
> }
> }
>
> public void run(){
> WINMsg msg;
> user32.showWindow(handle, 0x0000000A);
> user32.updateWindow(handle);
>
> while(user32.getMessage(cast(ptr)&msg, null, 0, 0)){
> user32.translateMessage(cast(ptr)&msg);
> user32.dispatchMessage(cast(ptr)&msg);
> }
> }
>
> private dword wndProc(ptr o_hwnd, dword o_msg, dword o_wparam, dword
> o_lparam){
>
> alias user32.EWindowMessage WM;
> alias user32.EMouseKey WK;
>
> switch(o_msg){
>
> case WM.DESTROY:
> user32.postQuitMessage(0x00);
> break;
>
> case WM.LBUTTONDOWN:
> MouseEventArgs l_mea;
> l_mea.button = MouseButton.LEFT;
> l_mea.location.x = loword(o_lparam);
> l_mea.location.x = hiword(o_lparam);
> user32.messageBox(null, cast(wstr)"LBUTTONDOWN",
> cast(wstr)"msg", 0x00); // ok it is displayed
> this.onMouseDown(l_mea);
> // !!! it is never called
> break;
> default: return user32.defWindowProc(o_hwnd, o_msg, o_wparam,
> o_lparam);
> }
> return 0;
> }
>
> public Rect getBounds(){
> WINRect l_rc;
> user32.getWindowRect(this.handle, cast(ptr)&l_rc);
> with(l_rc) return Rect(left, top, right - left, bottom - top);
> }
> }
> //________________________________________________________
I don't know what the problem is, but I would try checking to see if the
pointer at window construction and the this pointer before calling
onMouseDown are the same. Maybe there is a problem with using the result
of getWindowLong as a pointer. For example, one value could be 32-bits and
the pointer could be 64-bits. I didn't run the code to test anything, I'm
just throwing out some ideas which may be way off.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the Digitalmars-d-learn
mailing list