Sunday 19 November 2017

Hwnd, my friend now.

I just spent a whole day trying to do two things, and failing at one. Both seem spectacularly simple at first, but they aren't. Oh, they are not.

Firstly, I tried to program an 'auto complete' function for drop-down boxes, as those provided by AHK don't do it for some reason. Simple enough to work around, I thought - just store the list of entries, compare what you type with those entries, inject back into the control and everybody will be happy. But that isn't the way things work. Selecting something in any way obliterates what you have typed, so there's no option to type two or three letters. Grrrr...

I found some clever code that did pretty much as I wanted, but there was a catch - no obvious way to get the text out of the control (which made it bloody pointless, but I digress). So I could program a hotkey to grab the text when I selected it and then... HOLD ON! I just made this so much more complicated. It wasn't worth the effort.

About 4 hours after I started, I found out that typing a letter or two then hitting the down arrow auto-selected the first match in the list. I'd like to say "I could have wept", but by this time the whole shebang had eaten my soul and I was an empty, lifeless husk wishing it was acceptable to get hammered drunk on a Sunday afternoon and go and shout at random people in the street.

I had a spot of lunch instead. How grown up of me :)

Later in the day I was trying to get a ctrl-J hotkey working as I wanted - to select, manipulate and replace text in whichever control was active. I wasted a lot of time building this to operate on the control under the mouse pointer before realising that I was an idiot. Elegant solution, but the wrong solution. Eventually I got to grips with finding a control's Hwnd and using it, and the whole thing fell into place.

The moral to this story? I wish I'd taken up knitting or something.
Ach well, there's always tomorrow. I'll write more stuff than I did today...


No comments:

Post a Comment