AutoHotkey Community

It is currently May 27th, 2012, 10:34 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: December 6th, 2007, 9:36 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.


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

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

   return DllCall("CallWindowProcA", "UInt", A_EventInfo, "UInt", hwnd, "UInt", uMsg, "UInt", wParam, "UInt", lParam)
}


_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: More information please
PostPosted: January 23rd, 2008, 10:54 pm 
Offline

Joined: January 23rd, 2008, 10:38 pm
Posts: 4
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2008, 10:43 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
You don't need this function for that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Solved a different way
PostPosted: January 24th, 2008, 9:28 pm 
Offline

Joined: January 23rd, 2008, 10:38 pm
Posts: 4
You are right.
I managed to solve it using a timer poll loop.
ref http://www.autohotkey.com/forum/viewtopic.php?t=27881&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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 24th, 2008, 11:31 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2008, 12:20 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
majkinetor wrote:
Wait until I release MRS script if you want to see it.

What is MRS?

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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