Sign in to follow this  
Followers 0
Syrin

tagNMLVKEYDOWN oddity

5 posts in this topic

#1 ·  Posted (edited)

I'm going about setting up a "delete" hotkey for a listview in my GUI, and so I decide to search it up. I see a bunch of examples of the form DllStructCreate($tagNMLVKEYDOWN,$ilParam), and I was confused as I had never seen the global $tagNMLVKEYDOWN before. So, I tracked it down to StructureConstants.au3, examined it, accepted it, and went back to debugging what the hell was going wrong.

See, in the WM_NOTIFY function I have set up, it wasn't detecting DllStructGetData($thestruct,"VKey") as the Delete key - in fact, it wasn't doing anything. So I output it to a quickly crafted text box, and it seems like no matter what, the value of "VKey" is 0 - except when I press two keys at the same time, then it's 65535. So, okay, weird. What should be the code of the pressed key is in fact either 0x0 or 0xFFFF. And then I tried the "Flag" portion of the DllStruct instead. In that case, it was jumping all over the place - but it never seemed to correspond to the key pressed either.

So, since I have no prior experience with Dlls or any of this stuff, I had to go look up the functions, and find out that the "align" keyword in the StructureConstants.au3 definition of tagNMLVKEYDOWN might be out of place, who knows. So I give it a shot, and take it out, and use this:

DllStructCreate("hwnd hWndFrom;uint_ptr IDFrom;INT Code;word VKey;uint Flags",$ilParam)

VKey is still wrong! Augh. So, I decide to try Flags instead and - for some reason - it works.

DllStructGetData(DllStructCreate("hwnd hWndFrom;uint_ptr IDFrom;INT Code;word VKey;uint Flags",$ilParam),"Flags") returns what SHOULD be held in the "VKey" spot.

Is the structureconstants.au3 definition just, wrong? or something?

Or is the pointer being passed to WM_NOTIFY messed up on my machine?

Actually, on that note, is there some documentation somewhere on the expected values stored at the location pointed to by $ilParam (and, of equal importance, what the values mean/indicate)?

Some quick example code to show what I mean

#include <GUIListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode",1)
$main = GUICreate("Test",500,300,-1,-1,$WS_TILEDWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE,"Terminate")
$list = GUICtrlCreateListView(" ",-1,-1,100,280,BitOR($LVS_SHOWSELALWAYS,$LVS_NOCOLUMNHEADER,$LVS_SINGLESEL))
GUICtrlSetResizing(-1,$GUI_DOCKWIDTH)
For $i = 1 to 5
    GUICtrlCreateListViewItem("Item " & $i,$list)
Next
_GUICtrlListView_SetColumnWidth(GUICtrlGetHandle($list),0,95)
$edit = GUICtrlCreateEdit("",100,-1,400,280)
GUICtrlSetResizing(-1,BitOR($GUI_DOCKRIGHT,$GUI_DOCKLEFT))
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY,"WM_NOTIFY")

While 1
    Sleep(1000)
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $tInfo,$hWndListView
    $hWndListView = GUICtrlGetHandle($list)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    If (HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hWndListView) And (DllStructGetData($tNMHDR, "Code") = $LVN_KEYDOWN) Then
        #cs
        The original version (which DOESN'T work) is:
        $tInfo = DllStructCreate($tagNMLVKEYDOWN, $ilParam)
        If BitAND (DllStructGetData ($tInfo, "VKey"), 0xFFFF) = 46 Then
        #ce
        $tInfo = DllStructCreate("hwnd hWndFrom;uint_ptr IDFrom;INT Code;word VKey;uint Flags", $ilParam)
        If BitAND (DllStructGetData ($tInfo, "Flags"), 0xFFFF) = 46 Then GUICtrlSetData($edit,_GUICtrlListView_GetSelectedIndices($hWndListView)+1)
    EndIf
EndFunc

Func Terminate()
    Exit 0
EndFunc
Edited by Syrin

Share this post


Link to post
Share on other sites



Syrin,

I will leave the structure stuff to those who understand it better. :)

But if all you want a HotKey, why not use HotKeySet rather than writing your own handler? :)

One line and an associated function and you are all done. And if you want the action key limited to just your GUI , then GUISetAcclerators is another good option. :P

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Because the accelerator functionality isn't sufficient to do what I desire. I only want the hotkey to work while the listview has focus, and one of the items is selected.

And the code that I have now does that - it's just weird because I had to do some unintuitive things to fix what was wrong, so I'm curious if it's a problem with my machine, or if what "should be correct" is not, in fact, what is correct (i.e, the given documentation about the structure of the $ilParam DllStruct for an $LVN_KEYDOWN event is, in fact, completely 100% wrong)

Edit: Ah! There is, apparently, documentation, and it's on the microsoft website! I guess I was just googling the wrong things.

According to the microsoft website, the StructureConstants.au3 definition is correct (except maybe that align 1 thing? I have no idea what that does), so I guess my laptop is just fucked, I dunno. Can anybody at least run that example code and corroborate that pressing the "Delete" key while one of the items is selected will place the selection's number into the edit box? Because then at least it won't just be me.

Edited by Syrin

Share this post


Link to post
Share on other sites

Syrin,

Because the accelerator functionality isn't sufficient to do what I desire. I only want the hotkey to work while the listview has focus, and one of the items is selected

So put those checks into the HotKey function and Return if they are not met. Good functions to look at would be _WinAPI_GetFocus and _GUICtrlListView_GetSelectedIndices. :)

Are you running an x64 system? There are alignment problems in x64 systems with some of the standard structures (all based on x86) - they should be resolved in the next release. But again you will need to wait for someone who understands these things better than I do to explain in detail.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

So put those checks into the HotKey function and Return if they are not met. Good functions to look at would be _WinAPI_GetFocus and _GUICtrlListView_GetSelectedIndices. :)

But that's gross, I don't want the key-capturing functionality of HotKeySet() :/

Are you running an x64 system?

This is the key I needed, thanks. Completely forgot about it, but that would cause precisely the problems I'm having.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0