Jump to content

How To trap the WM_KEYDOWN in inputs?


Recommended Posts

I have an input control, and I need this:

When the user press a key and it's have the focus, show a messagebox and don't pass the pressed key into it.

When I click a button to set the text in the input (GuiCtrlSetData), don't show the messagebox.

I've tried WM_COMMAND, but the button click to set data and the keypress returns the same message code.

Global Const $WM_COMMAND = 0x0111
Local $hWnd = GUICreate("Test", 225, 100)
    Local $hInput = GUICtrlCreateInput("", 10, 25)
    Local $hButton = GUICtrlCreateButton("Change", 10, 60)
    GUIRegisterMsg($WM_COMMAND, "MyCommand")
GUISetState(@SW_SHOWNORMAL, $hWnd)

While WinExists($hWnd)
    Switch GUIGetMsg()
        case -3
        Exit
    case $hButton
        GUICtrlSetData($hInput, GUICtrlRead($hInput) & Random(1, 10, 1))
        EndSwitch
WEnd

Func MyCommand($hWnd, $Msg, $wParam, $lParam)
    if $lParam = GUICtrlGetHandle($hInput) then ConsoleWrite($wParam & @CRLF & $lParam & @CRLF & $Msg & @CRLF & @CRLF)
EndFunc

Thanks in advance.

Link to comment
Share on other sites

I have an input control, and I need this:

When the user press a key and it's have the focus, show a messagebox and don't pass the pressed key into it.

When I click a button to set the text in the input (GuiCtrlSetData), don't show the messagebox.

I've tried WM_COMMAND, but the button click to set data and the keypress returns the same message code.

Global Const $WM_COMMAND = 0x0111
Local $hWnd = GUICreate("Test", 225, 100)
    Local $hInput = GUICtrlCreateInput("", 10, 25)
    Local $hButton = GUICtrlCreateButton("Change", 10, 60)
    GUIRegisterMsg($WM_COMMAND, "MyCommand")
GUISetState(@SW_SHOWNORMAL, $hWnd)

While WinExists($hWnd)
    Switch GUIGetMsg()
        case -3
        Exit
    case $hButton
        GUICtrlSetData($hInput, GUICtrlRead($hInput) & Random(1, 10, 1))
        EndSwitch
WEnd

Func MyCommand($hWnd, $Msg, $wParam, $lParam)
    if $lParam = GUICtrlGetHandle($hInput) then ConsoleWrite($wParam & @CRLF & $lParam & @CRLF & $Msg & @CRLF & @CRLF)
EndFunc

Thanks in advance.

WM_COMMAND Message

http://msdn.microsoft.com/en-us/library/ms647591%28v=vs.85%29.aspx

#Include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


Local $hWnd = GUICreate("Test", 225, 100)
    Local $hInput = GUICtrlCreateInput("", 10, 25)
    Local $hButton = GUICtrlCreateButton("Change", 10, 60)
    GUIRegisterMsg($WM_COMMAND, "MyCommand")
GUISetState(@SW_SHOWNORMAL, $hWnd)

While WinExists($hWnd)
    Switch GUIGetMsg()
        case -3
        Exit
    case $hButton
        GUICtrlSetData($hInput, GUICtrlRead($hInput) & Random(1, 10, 1))
        EndSwitch
WEnd

Func MyCommand($hWnd, $Msg, $wParam, $lParam)
$HiWord = _WinAPI_HiWord($wParam)
$LoWord = _WinAPI_LoWord($wParam)
Switch $HiWord
Case 0
ConsoleWrite("Menu identifier ==> " & $LoWord & @CRLF)
Case 1
ConsoleWrite("Accelerator identifier ==> "  & $LoWord & @CRLF)
Case Else
if $lParam = GUICtrlGetHandle($hInput) then ConsoleWrite("Input control ==> $hInput" & @CRLF)
ConsoleWrite("Control identifier ==> " & $LoWord & @CRLF)
ConsoleWrite("notification code ==> " & $HiWord & @CRLF )
ConsoleWrite("Handle to the control window ==> " & $lParam & @CRLF )
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc

صرح السماء كان هنا

 

Link to comment
Share on other sites

Edit Control Notifications

http://msdn.microsoft.com/en-us/library/ff485924%28v=VS.85%29.aspx

#Include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Const $EN_UPDATE = 0x400 , $EN_CHANGE = 0x300 , $EN_SETFOCUS = 0x100
Global $Test = 0 , $Data = ""
Local $hWnd = GUICreate("Test", 225, 100)
    Local $hInput = GUICtrlCreateInput("", 10, 25)
    Local $hButton = GUICtrlCreateButton("Change", 10, 60)
    GUIRegisterMsg($WM_COMMAND, "MyCommand")
GUISetState(@SW_SHOWNORMAL, $hWnd)
$Data = GUICtrlRead($hInput)
While WinExists($hWnd)
    Switch GUIGetMsg()
        case -3
        Exit
    case $hButton
        $Test = 1
        GUICtrlSetData($hInput, GUICtrlRead($hInput) & Random(1, 10, 1))
        $Test = 0
        EndSwitch
WEnd

Func MyCommand($hWnd, $Msg, $wParam, $lParam)
$HiWord = _WinAPI_HiWord($wParam)
$LoWord = _WinAPI_LoWord($wParam)
Switch $HiWord
Case 0
ConsoleWrite("Menu identifier ==> " & $LoWord & @CRLF)
Case 1
ConsoleWrite("Accelerator identifier ==> "  & $LoWord & @CRLF)
Case Else
if $LoWord = $hInput And $HiWord = $EN_UPDATE Then
if ($Test) Then
$Data = GUICtrlRead($hInput)
Return $GUI_RUNDEFMSG
Else
GUICtrlSetData($hInput,$Data)
MsgBox(0,"Msg","Test")
Return $GUI_RUNDEFMSG
EndIf
EndIf
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...