AutoHotkey Community

It is currently May 27th, 2012, 5:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: September 1st, 2010, 3:04 pm 
Offline

Joined: November 20th, 2008, 6:00 pm
Posts: 72
Location: Thionville, France
Hi,

I have a GUI with an edit control which I need to detect many windows messages. Subclassing seems to be the right way to do it (I tried OnMessage too, but some messages I need are not detected).
Now, I need to hide some messages from the system, especially WM_KEYDOWN and WM_KEYUP.
I thought subclassing would allow me to process then pass or discard any message before the system could process it, but it seems it doesn't do that, as, for example, a WM_KEYDOWN always generates a WM_CHAR, whatever I return for WM_KEYDOWN message.

Am I doing something wrong?

Here is a sample code in which I am trying to discard WM_KEYDOWN/UP messages received by a subclassed edit control
Code:
Gui, 1:Add, Edit, w100 hwndE1, Some text
Gui, 1:Show
If !Subclass(E1, "WinMsg")
   msgbox Subclassing failed.
Return

guiclose:
guiescape:
exitapp


WinMsg(hwnd, uMsg, wParam, lParam)
{
   critical
    if ((uMsg = 0x100) || (uMsg = 0x101)) ; wm_keydown/up messages
   {
      ; Return 0
      Return 1
      ; Hex2Bin("51", w2Param)                  ;Mimics Q key vk code
      ; Hex2Bin("3078313030303031", l2Param)      ;Mimics Q key (on US kbd layout)
      ; VarSetCapacity(Name, 100)
      ; DllCall( "GetKeyNameText", "int", l2param, "str", Name, "int", 100 )      ;Returns Q (or else, depending on the layout)
      ; Tooltip % Name
      ; return DllCall("CallWindowProcA", "UInt", A_EventInfo, "UInt", hwnd, "UInt", uMsg, "UInt", w2Param, "UInt", l2Param)
   }
   return DllCall("CallWindowProcA", "UInt", A_EventInfo, "UInt", hwnd, "UInt", uMsg, "UInt", wParam, "UInt", lParam)
}


;-------------------------------------------------------------------------------------
; Function: Subclass
;         Helper function to subclass control
;
; Parameters:
;         hCtrl   - handle to control
;         func   - window procedure
;         cbOpt   - callback options, by default ""
;
Subclass(hCtrl, func, cbOpt="") {
   oldProc := DllCall("GetWindowLong", "uint", hCtrl, "uint", -4)
   ifEqual, oldProc, 0, return 0
     
   WndProc := RegisterCallback(func, cbOpt, 4, oldProc)
   ifEqual, WndProc, , return 0
     
    return DllCall("SetWindowLong", "UInt", hCtrl, "Int", -4, "Int", WndProc, "UInt")
}


Hex2Bin(hex, ByRef bin, len="")
{
   If (len="")
      len:=(StrLen(hex)+1)//2
   VarSetCapacity(bin,len)
    Loop % len
      NumPut("0x" SubStr(hex,2*A_Index-1,2), bin, A_Index-1, "Char")
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 1st, 2010, 6:21 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
It should be
Code:
WinMsg(wParam, lParam, hwnd, uMsg)

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2010, 7:05 pm 
Offline

Joined: November 20th, 2008, 6:00 pm
Posts: 72
Location: Thionville, France
I couldn't find a solution for this yet. Just to let others know, order of parameters seems right in my code.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, migz99, mrhobbeys, rbrtryn, sjc1000 and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group