RegisterClassEx

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

RegisterClassEx

30 Jan 2014, 01:12

Code: Select all

 SetBatchlines,-1
        #Persistent
        ;~ OnMessage(0x200, "OnMOUSEMOVE")
        ;~ OnMessage(0x201, "OnLBUTTONDOWN")
        ;~ OnMessage(0x202, "OnLBUTTONUP")
        ;~ OnMessage(0x2A2, "OnLeave")
        ;~ OnMessage(0x2A3, "OnLeave")
        ;~ OnMessage(0x8, "OnLeave")



    Class GDIGUI {
    
    static Init:=0
    __new(x=0,y=0,w="",h="",Style=0x80CA0000,ExStyle=0)
    {
        If !GDIGUI.Init
        {
        Gdip_Startup()
        hInstance := DllCall("GetModuleHandle", "Ptr", 0, "Ptr")
        VarSetCapacity(wndclassex, 16+8*A_PtrSize, 0)
        NumPut(16+8*A_PtrSize, wndclassex, 0, "UInt") ;cbSize
        NumPut(0x23, wndclassex, 4, "UInt") ;style HERE
        NumPut(RegisterCallback("WindowProc"), wndclassex, 8, "Ptr") ;lpfnWndProc
        NumPut(hInstance, wndclassex, 16+A_PtrSize, "Ptr") ;hInstance
        NumPut(DllCall("LoadCursor", "Ptr", 0, "Ptr", 32512, "Ptr"), wndclassex, 16+3*A_PtrSize, "Ptr") ;hCursor
        NumPut(6, wndclassex, 16+4*A_PtrSize, "Ptr") ;hbrBackground
        lpClassname:="GDI-Window"
        NumPut(&lpClassName, wndclassex, 16+6*A_PtrSize, "Ptr") ;lpszClassName
        atom := DllCall("RegisterClassEx", "Ptr", &wndclassex, "UShort")
        GDIGUI.Init:=1
        }
        this.Width:=w?w:A_ScreenWidth
        this.Height:=h?h:A_ScreenHeight
        this.DrawBitmap:=Gdip_CreateBitmap(this.Width, this.Height)
        this.BkgndBitmap:=Gdip_CreateBitmap(this.Width, this.Height)
        this.DrawGraphics:=Gdip_GraphicsFromImage(this.DrawBitmap)
        this.GUIhwnd:=DllCall("User32.dll\CreateWindowEx", "Uint", ExStyle, "Str", "GDI-Window", "Str", "GDI-App", "UInt", Style, "Int", x , "Int", y , "Int", this.Width, "Int", this.Height, "Ptr", 0, "Ptr", 0, "Ptr", hInstance, "Ptr", 0, "Ptr")
        WindowProc(this.GUIHWND, 0, this, 0)
    }
    
    Show()
    {
        DllCall("ShowWindow", "ptr", this.GUIhwnd, "uint", 5)
        this.GUIHDC:=GetDC(this.GUIhwnd)
        this.GUIGraphics:=gdip_GraphicsfromHDC(this.GUIHDC)
        this.Redraw()
        this.MSG_15()
    }

    MSG_15()
    {
        static call:=0
        If !call
        {
        gdip_DrawImage(this.GUIGraphics,this.DrawBitmap)
        tooltip %  ((a:=GetDC(this.GUIhwnd))=this.GUIHDC) "`n" this.GUIHDC "`n" a
        return call:=0
        }
        return 0
    }
    
    Redraw()
    {
        Gdip_GraphicsClear(this.DrawGraphics,0xFF000000)
        gdip_DrawImage(this.DrawGraphics,this.BkgndBitmap)
        For each, GDIControl in this
            If (IsObject(GDIControl)&&IsFunc(GDIControl.Redraw))
            {
                Control.Redraw()
                gdip_DrawImage(this.DrawGraphics,GDIControl.DrawBitmap,GDIControl.X,GDIControl.Y)
            }
    }
    }

    
    
    
    


Frontier2400GUI:=new GDIGUI()
Brush:=Gdip_CreateLineBrushFromRect(0, 0, A_ScreenWidth, A_ScreenHeight, 0xFF35281B, 0xFF261C13, 1, 1)
Bkgnd:=Gdip_GraphicsFromImage(Frontier2400GUI.BkgndBitmap)
Gdip_FillRectangle(Bkgnd, Brush, 0, 0, A_ScreenWidth, A_ScreenHeight)
Frontier2400GUI.Show()






WindowProc(hWnd, msg, wParam, lParam)
{
   static callbacks:={}
Critical ;Sollte zeitliche Probleme beseitigen
If !msg
    callbacks[hwnd]:=wparam
If (callbacks.haskey(hwnd)&&IsFunc(callbacks[hwnd,"MSG_" . msg]))
    callbacks[hwnd,"MSG_" . msg].(wparam,lparam)
  return DllCall("DefWindowProc", "Ptr", hWnd, "UInt", msg, "Ptr", wParam, "Ptr", lParam, "Ptr") 
}
According to MSDN the class style 0x20 would give this Window a unique HWND but it doesnt stay the same at my PC.
I want to find out if its a Problem of the script or of this PC.
Simply run th Code and move the window around a bit.
Tell me if the tooltip changes.
Recommends AHK Studio
User avatar
LazyMan
Posts: 26
Joined: 14 Jan 2014, 00:22
Location: peering out from behind my favorite rock

Re: RegisterClassEx

30 Jan 2014, 01:42

I am methodically challenged. :mrgreen:
Spoiler
lexikos
Posts: 9635
Joined: 30 Sep 2013, 04:07
Contact:

Re: RegisterClassEx

30 Jan 2014, 06:52

You are passing the HWND to GetDC only once. On every subsequent call, you are passing a blank value. Although the tooltip doesn't show this.GUIhwnd, you should have noticed that the tooltip shows this.GUIHDC is blank.

Code: Select all

callbacks[hwnd,"MSG_" . msg].(wparam,lparam)
There is always a method name between the dot and open parenthesis. In this case, the method name is blank, and the target (this) of the method call is the GDIGUI.MSG_15 function object. When called this way, the function object executes the function, simply passing the parameters along, so the syntax object.(params) is essentially a function call, not a method call. In this case, the value wparam is assigned to the this parameter.

This is how you should call the method:

Code: Select all

callbacks[hwnd]["MSG_" . msg](wparam,lparam)
First, callbacks[hwnd] is retrieved. Then that object is used as the target of a method call, where the method name is "MSG_15" (assuming msg=15) - equivalent to callbacks[hwnd].MSG_15(wparam,lparam).
According to MSDN the class style 0x20 would give this Window a unique HWND
Nonsense. You probably mean that it gives each window a unique device context. HWND is a window handle, not a device context handle. Even if you meant HDC, you'd be wrong: MSDN doesn't say GetDC will return the same HDC each time. Two different handle values could plausibly refer to the same device context object.

Also, I recommend reading What does the CS_OWNDC class style do? - The Old New Thing
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: RegisterClassEx

30 Jan 2014, 09:50

WOW Thanks.
I was just about as far as finding out some pieces of it in 3 hours of work.
Recommends AHK Studio
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: RegisterClassEx

30 Jan 2014, 10:13

@LazyMan:
The gdip library is not a standard library on your PC.
You can download it here:
http://www.autohotkey.com/board/topic/2 ... 45-by-tic/
Recommends AHK Studio

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Leonardo_Portela, mikeyww, sachalamp and 200 guests