Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[function] Subclass - helper function to subclass control


  • Please log in to reply
5 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
This is just something I find useful, so you don't have to think about internal details of subclassing. A_EventInfo contains pointer to old WndProc.


;-------------------------------------------------------------------------------------
; 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") 
}
Example:
if !SubClass(hwndList, "MyWindowProc")
     MsgBox, Subclassing failed.
...
MyWindowProc(hwnd, uMsg, wParam, lParam){ 

 	if (uMsg = .....)  ; my message handling here

	return DllCall("CallWindowProcA", "UInt", [color=blue]A_EventInfo[/color], "UInt", hwnd, "UInt", uMsg, "UInt", wParam, "UInt", lParam) 
}


Posted Image

jmalone68
  • Members
  • 4 posts
  • Last active: Feb 07 2008 03:10 PM
  • Joined: 23 Jan 2008
Could you please post a full example of how you do this?

I'm trying to detect when a user selects an item from a combo box and this looks like one way of doing it, but I can't seem to make it work. I'm not getting useful data back from the
DllCall("GetWindowLong"...
function call.

Any hints, clues, advice or full script examples would be greatly appreciated.

Cheers,
John

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
You don't need this function for that.

jmalone68
  • Members
  • 4 posts
  • Last active: Feb 07 2008 03:10 PM
  • Joined: 23 Jan 2008
You are right.
I managed to solve it using a timer poll loop.
ref http://www.autohotke...7881&highlight=

I would have much preferred to use a callback rather than a poll loop, because I'd rather react to events instead of taking up the computer time to loop continually on something that isn't going to be there very often, but that's more of a philosophical preference than it is of any practical concern.

Cheers all,
John

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
I don't have time to explain it, but it can be done with callback. I use it in some my scripts. I remember it was problem, but I figure out it somehow. Wait until I release MRS script if you want to see it.

Experiment a bit with combobox regular AHK API.

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006

Wait until I release MRS script if you want to see it.

What is MRS?
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ