Sign in to follow this  
Followers 0
Achilles

Problem deleting a control

17 posts in this topic

#1 ·  Posted (edited)

Here there is an input box created with a Dll, however it doesn't delete with the normal GuiCtrlDelete(). Any ideas?

#include <GUIConstants.au3>

Opt("WinTitleMatchMode", 4)

Global Const $HKM_SETHOTKEY = $WM_USER+1
Global Const $HKM_GETHOTKEY = $WM_USER+2
Global Const $HKM_SETRULES = $WM_USER+3
Global Const $HOTKEYF_SHIFT = 0x01
Global Const $HOTKEYF_CONTROL= 0x02
Global Const $HOTKEYF_ALT = 0x04

$gui_Main = GuiCreate('Get Hotkey', 300, 200)

$bt = GuiCtrlCreateButton('See Value', 10, 40, 100, 30);
    GUICtrlSetState(-1, $GUI_DEFBUTTON)

$a_HotKey = DllCall('user32', 'hwnd', 'CreateWindowEx', 'long', 0, 'str', 'msctls_hotkey32', 'str', '', 'int', _ 
BitOr($WS_CHILD, $WS_VISIBLE, $WS_TABSTOP), 'int', 10, 'int', 10, 'int', 200, 'int', 20, 'hwnd', _
$gui_Main, 'long', 0, 'hwnd', 0, 'ptr', 0)

GuiSetState()

While 1
    $gm = GuiGetMsg()
    If $gm = $GUI_EVENT_CLOSE Then ExitLoop

    If $gm = $bt Then
        $i_HotKey = SendMessage($a_HotKey[0], $HKM_GETHOTKEY, 0, 0)
        $n_Flag = BitShift($i_HotKey, 8)
        $sz_Flag = ""
        If BitAnd($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
        If BitAnd($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
        If BitAnd($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
        InputBox('HotKey control return:', $i_HotKey & @LF & 'Chr(' & $i_HotKey & ') = ', $sz_Flag & Chr($i_HotKey))
        GuiCtrlDelete($a_HotKey)
    EndIf
WEnd

Exit

Func SendMessage($hWnd, $Msg, $wParam = 0, $lParam = 0)
    $a_Ret = DllCall('user32.dll', 'int', 'SendMessage', _
    'hwnd', $hWnd, _
    'int', $Msg, _
    'int', $wParam, _
    'int', $lParam)
    Return $a_Ret[0]
EndFunc
Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites



If i had to guess (I have no clue if I'm right), I would say the reason you are encountering this problem would be that the .dll call you are using to create your input doesn't return a control id like those returned by the GUICtrlCreate* functions

Unfortunately, I could be totally wrong, but even if i'm right, I couldn't begin to tell you how to fix it. <_<

Share this post


Link to post
Share on other sites

If i had to guess (I have no clue if I'm right), I would say the reason you are encountering this problem would be that the .dll call you are using to create your input doesn't return a control id like those returned by the GUICtrlCreate* functions

Unfortunately, I could be totally wrong, but even if i'm right, I couldn't begin to tell you how to fix it. <_<

I think you are right... It doesn't seem to work with any of the GuiCtrl commands...

BTW, I like your personal statement (or whatever it's called)... That message used to annoy me every time I played with the Protoss


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

_WinAPI_DestroyWindow

also might want to look up _SendMessage in the help file

I don't want to destroy the whole window, just the hotkey input control.

I looked at _SendMessage and tried this:

_SendMessage($a_Hotkey[0], $WM_DELETEITEM)
Which I sincerely hoped would work, but it didn't.

Any specific message I should be sending? Or should I be creating the actual inputbox differently?


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

I don't want to destroy the whole window, just the hotkey input control.

I looked at _SendMessage and tried this:

_SendMessage($a_Hotkey[0], $WM_DELETEITEM)
Which I sincerely hoped would work, but it didn't.

Any specific message I should be sending? Or should I be creating the actual inputbox differently?

Think about it, the Input control is a window, use the _WinAPI_DestroyWindow($a_HotKey)

I was telling you about the _SendMessage because you had created the function which is already in the Misc.au3


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Think about it, the Input control is a window, use the _WinAPI_DestroyWindow($a_HotKey)

I was telling you about the _SendMessage because you had created the function which is already in the Misc.au3

Oh, ok, I was trying _WinAPI_DestroyWindow($a_HotKey) and forgot that the $hWnd should actually be $a_Hotkey[0]...

This script is a little bit outdated but I'll change that when I integrate into what I'm working with.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

Generally speaking...

_SendMessage($handle, $WM_SETTEXT, 0, "This works.", 0, "int", "str")

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Alright new problem...

How can I set the data for this control?

_SendMessage($a_Hotkey[0], $WM_SETTEXT, "This does not work.')
Anywhere near right?

Look at the GuiEdit.au3 include in the beta

Edit: forgot to mention you could of used _WinAPI_CreateWindowEx to create the control and it would of returned a handle not an array

Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok, I tried using the _WinAPI_CreateWindowEx() and it worked fine, but I still couldn't find anyway to edit the text. I then switched to using the _GuiEdit functions from Beta but still no luck. Apparently _GUICtrlEdit_Create() isn't meant to be used for hotkeys. However, I changed the line in it:

$hEdit = _WinAPI_CreateWindowEx ($iExStyle, "Edit", "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd)
to

$hEdit = _WinAPI_CreateWindowEx ($iExStyle, "msctls_hotkey32", "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd)
And that worked well as a hotkey control but still now luck changing the text. For example, I tried this:

_GUICtrlEdit_SetText($hotkey, 'YAY!!!')
But it didn't work.

Here is what I am currently working with:

#include <GUIConstants.au3>
#Include <WinAPI.au3>
#Include <GuiEdit.au3>

Opt("WinTitleMatchMode", 4)
Opt("WinSearchChildren", 1)

Global Const $HKM_SETHOTKEY = $WM_USER+1
Global Const $HKM_GETHOTKEY = $WM_USER+2
Global Const $HKM_SETRULES = $WM_USER+3

Global Const $HOTKEYF_SHIFT = 0x01
Global Const $HOTKEYF_CONTROL= 0x02
Global Const $HOTKEYF_ALT = 0x04

$gui_Main = GuiCreate('Get Hotkey', 300, 200)

$bt = GuiCtrlCreateButton('See Value', 10, 40, 100, 30);
GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hotkey = __GUICtrlEdit_Create($gui_Main, 'TESTING', 10, 10, 200, 20, BitOr($WS_CHILD, $WS_VISIBLE, $WS_TABSTOP), 'user32')

GuiSetState()

While 1
    $gm = GuiGetMsg()
    If $gm = $GUI_EVENT_CLOSE Then ExitLoop

    If $gm = $bt Then
        $i_HotKey = _SendMessage($hotkey, $HKM_GETHOTKEY)
        $n_Flag = BitShift($i_HotKey, 8)
        $sz_Flag = ""
        If BitAnd($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + "
        If BitAnd($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + "
        If BitAnd($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + "
        
        InputBox('HotKey control return:', $i_HotKey & @LF & 'Chr(' & $i_HotKey & ') = ', $sz_Flag & Chr($i_HotKey))
        _GUICtrlEdit_SetText($hotkey, 'YAY!!!')
    EndIf
WEnd

Exit

Func __GUICtrlEdit_Create($hWnd, $sText, $iX, $iY, $iWidth = 150, $iHeight = 150, $iStyle = 0x003010C0, $iExStyle = 0x00000200)
    If Not IsHWnd($hWnd) Then _WinAPI_ShowError ("Invalid Window handle for _GUICtrlEdit_Create 1st parameter")
    If Not IsString($sText) Then _WinAPI_ShowError ("2nd parameter not a string for _GUICtrlEdit_Create")
    
    Local $hEdit

    If $iWidth = -1 Then $iWidth = 150
    If $iHeight = -1 Then $iHeight = 150
    If $iStyle = -1 Then $iStyle = 0x003010C0
    If $iExStyle = -1 Then $iExStyle = 0x00000200

    If BitAND($iStyle, $ES_READONLY) = $ES_READONLY Then
        $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $ES_MULTILINE, $iStyle)
    Else
        $iStyle = BitOR($WS_CHILD, $WS_VISIBLE, $ES_MULTILINE, $WS_TABSTOP, $iStyle)
    EndIf
;================================================================================================
=========
    $hEdit = _WinAPI_CreateWindowEx ($iExStyle, "msctls_hotkey32", "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd)
    _SendMessage($hEdit, $WM_SETFONT, _WinAPI_GetStockObject ($DEFAULT_GUI_FONT), True)
    _GUICtrlEdit_SetText($hEdit, $sText)
    _GUICtrlEdit_SetLimitText($hEdit, 0)
    Return $hEdit
EndFunc ;==>_GUICtrlEdit_Create

EDIT:

_SendMessage($hotkey, $WM_SETTEXT, 0, "This works.", 0, "int", "str")
Didn't work either. Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I tried this:

_GUICtrlEdit_SetText($hotkey, 'YAY!!!')
But it didn't work.

EDIT:

_SendMessage($hotkey, $WM_SETTEXT, 0, "This works.", 0, "int", "str")
Didn't work either.
Check the text of the control with AutoIt Window Info, before and after. Both of these lines do what they're supposed to do.

Problem is that hotkey control can't do what you expect it to do, which is, serve both as hotkey and edit control at the same time.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I don't have time to look at this right now but I think you need to be look at http://msdn2.microsoft.com/en-us/library/bb778003.aspx

Thanks a lot GaryFrost! I found what I needed there... apparently you can't set the text to whatever you want, it has to be a hotkey which is why it took me a while to figure out. Here's an example of what will work:

_SendMessage($hotkey, $HKM_SETHOTKEY, 577, 0);Sets it to Ctrl + A

Problem is that hotkey control can't do what you expect it to do, which is, serve both as hotkey and edit control at the same time.

I sort of thought that was the problem but didn't know how else to deal with it. Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

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

;~ Opt("WinTitleMatchMode", 4)

Global Const $HKM_SETHOTKEY = $WM_USER + 1
Global Const $HKM_GETHOTKEY = $WM_USER + 2
Global Const $HKM_SETRULES = $WM_USER + 3

Global Const $HOTKEYF_ALT = 0x04
Global Const $HOTKEYF_CONTROL = 0x02
Global Const $HOTKEYF_EXT = 0x80 ; Extended key
Global Const $HOTKEYF_SHIFT = 0x01

; invalid key combinations
Global Const $HKCOMB_A = 0x8  ; ALT
Global Const $HKCOMB_C = 0x4  ; CTRL
Global Const $HKCOMB_CA = 0x40 ; CTRL+ALT
Global Const $HKCOMB_NONE = 0x1  ; Unmodified keys
Global Const $HKCOMB_S = 0x2  ; SHIFT
Global Const $HKCOMB_SA = 0x20 ; SHIFT+ALT
Global Const $HKCOMB_SC = 0x10 ; SHIFT+CTRL
Global Const $HKCOMB_SCA = 0x80 ; SHIFT+CTRL+ALT

$gui_Main = GUICreate('Get Hotkey', 300, 500)

$bt = GUICtrlCreateButton('See Value', 10, 250, 100, 30);
GUICtrlSetState(-1, $GUI_DEFBUTTON)

$hWnd = _WinAPI_CreateWindowEx (0, 'msctls_hotkey32', '', BitOR($WS_CHILD, $WS_VISIBLE), 10, 10, 200, 200, $gui_Main)

#cs
    Set rules for invalid key combinations. If the user does not supply a
    modifier key, use ALT as a modifier. If the user supplies SHIFT as a
    modifier key, use SHIFT + ALT instead.
#ce

_SendMessage($hWnd, $HKM_SETRULES, _
BitOR($HKCOMB_NONE, $HKCOMB_S), _                      ; invalid key combinations
BitOR(BitShift($HOTKEYF_ALT, -16), BitAND(0, 0xFFFF))) ; add ALT to invalid entries

#cs
    Set CTRL + ALT + A as the default hot key for this window.
    0x41 is the virtual key code for 'A'.
#ce

$VirturalKeyCode = '0x' & Hex(Asc('A'))

_SendMessage($hWnd, $HKM_SETHOTKEY, BitOR($VirturalKeyCode, 0x100 * BitOR($HOTKEYF_CONTROL, $HOTKEYF_ALT)))

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $bt
            $i_HotKey = _SendMessage($hWnd, $HKM_GETHOTKEY)
            $n_Flag = BitShift($i_HotKey, 8) ; high byte
            $i_HotKey = BitAND($i_HotKey, 0xFF) ; low byte
            $sz_Flag = ""
            If BitAND($n_Flag, $HOTKEYF_SHIFT) Then $sz_Flag = "SHIFT + " 
            If BitAND($n_Flag, $HOTKEYF_CONTROL) Then $sz_Flag = $sz_Flag & " CTRL + " 
            If BitAND($n_Flag, $HOTKEYF_ALT) Then $sz_Flag = $sz_Flag & " ALT + " 
            InputBox('HotKey control return:', $i_HotKey & @LF & 'Chr(' & $i_HotKey & ') = ', $sz_Flag & Chr($i_HotKey))
    EndSwitch
WEnd
_WinAPI_DestroyWindow ($hWnd)

Exit


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Ahh, that's helps! I was wondering why the Inputbox wasn't showing the last letter of the whole control... I had figured out a way to make it work but your way is much more efficient. Thanks...


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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