| 
                  KostX
                  
 
 Joined: 19 Sep 2012
 Posts: 41
 
 | Hi everyone. I subclassed the edit control with next code, and it works fine:
 
     invoke  CreateWindowEx, 0, clEdit, 0, WS_VISIBLE + WS_CHILD + WS_BORDER + WS_TABSTOP + ES_LEFT + ES_AUTOHSCROLL,\
                             5, 50, 775, 20, [hMain], IDE_PATH, [hModule], 0
     ; New EDITBOX window proc                                                                                                                      
     [b]mov     dword [wpExpDirectory], eax[\b]
     
proc EditProc, hControl, Msg, wParam, lParam
     push    ebx edx ebp
     cmp     [Msg], WM_KEYDOWN
     je      .wmkeydown
     cmp     [Msg], WM_CHAR
     je      .wmchar
     cmp     [Msg], WM_CONTEXTMENU
     je      .wmcontextmenu
     cmp     [Msg], WM_COMMAND
     je      .wmcommand
     xor     eax, eax
     je      .finish
             .wmkeydown:
                     invoke  GetMenu, [hControl]
                     cmp     eax, IDE_PATH
                     jne     @f
                             ; Were'in path edit box. Catch return key
                             cmp     [wParam], VK_RETURN
                             je      .ReturnKey
                     @@:
                     ; ... do nothin' yet
             jmp     .finish
                     .ReturnKey:
                             stdcall malloc, PATH_MAX_LEN
                             test    eax, eax
                             je      .Processed
                             mov     ebx, eax
                             invoke  GetWindowText, [hControl], ebx, PATH_MAX_LEN
                             test    eax, eax
                             je      .Processed
                             invoke  lstrlen, ebx
                             cmp     byte [ebx + eax - 1], '\'
                             je      .PathOK
                                     cmp     word [ebx + eax], '\'
                             .PathOK:
                             stdcall FolderOpen, ebx
                             .Processed:
                                     stdcall memfree, ebx
                                     ; Refresh File view
                                     stdcall RefreshExplorer, [hWnd]
                                     ; Set cursor at the end of the text
                                     invoke  SendMessage, [hControl], EM_LINELENGTH, 0, 0
                                     invoke  SendMessage, [hControl], EM_SETSEL, eax, -1
                             jmp     .finish
                    [B] .wmchar:
                             cmp     [wParam], 9 ; Enter
                             jne     @f
                                     invoke  MessageBox, 0, 0, 0, 0
                             @@:
                             xor     eax, eax
                             ;inc     eax
                     jmp     .finish[/B]
             .wmcontextmenu:
                     invoke  LoadMenu, [hModule], IDM_TEXTBOX
                     stdcall SetMenuStyle, eax
                     push    eax
                     invoke  GetSubMenu, eax, 0
                     mov     ebx, eax
                     ; Setup menu items
                     sub     esp, 8
                     lea     esi, dword [esp]
                             mov     dword [esi + 0], 0
                             mov     dword [esi + 4], 0
                             lea     edi, dword [esi + 4]
                             invoke  SendMessage, [hControl], EM_GETSEL, esi, edi
                             mov     eax, dword [esi]
                             cmp     eax, dword [edi]
                             jne     @f
                                     ; Gray Cut and Copy items
                                     invoke  EnableMenuItem, ebx, IDMi_CUT, MF_BYCOMMAND + MF_GRAYED
                                     invoke  EnableMenuItem, ebx, IDMi_COPY, MF_BYCOMMAND + MF_GRAYED
                                     invoke  EnableMenuItem, ebx, IDMi_DELETE, MF_BYCOMMAND + MF_GRAYED
                             @@:
                     add     esp, 8
                     invoke  OpenClipboard, [hControl]
                     invoke  IsClipboardFormatAvailable, CF_TEXT
                     test    eax, eax
                     jne     @f
                             invoke  EnableMenuItem, ebx, IDMi_PASTE, MF_BYCOMMAND + MF_GRAYED
                     @@:
                     invoke  CloseClipboard
                     ; Show context menu
                     xor     esi, esi
                     sub     edi, edi
                     mov     si,  word [lParam + 0]
                     mov     di,  word [lParam + 2]
                     invoke  TrackPopupMenu, ebx, TPM_LEFTALIGN + TPM_LEFTBUTTON + TPM_RIGHTBUTTON, esi, edi, 0, [hControl], 0
                     invoke  DestroyMenu;, pop eax
                     xor     eax, eax
             jmp     .End
             .wmcommand:
                     cmp     word [wParam], IDMi_SELECTALL
                     je      .selectall
                     cmp     word [wParam], IDMi_CUT
                     je      .cut
                     cmp     word [wParam], IDMi_COPY
                     je      .copy
                     cmp     word [wParam], IDMi_PASTE
                     je      .paste
                     cmp     word [wParam], IDMi_DELETE
                     je      .delete
             jmp     .finish
                     .selectall:
                             invoke  SendMessage, [hControl], EM_SETSEL, 0, -1
                     jmp     .finish
                     .cut:
                             invoke  SendMessage, [hControl], WM_CUT, 0, 0
                     jmp     .finish
                     .copy:
                             invoke  SendMessage, [hControl], WM_COPY, 0, 0
                     jmp     .finish
                     .paste:
                             invoke  SendMessage, [hControl], WM_PASTE, 0, 0
                     jmp     .finish
                     .delete:
                             invoke  SendMessage, [hControl], WM_CLEAR, 0, 0
                     jmp     .finish
     .finish:
             [b]invoke  CallWindowProc, [wpExpDirectory], [hControl], [Msg], [wParam], [lParam][/b]
     .End:
             pop     ebp edx ebx
     ret
     .Error:
     jmp     .finish
endp
    
But, when I saved old edit WndProc into GWL_USERDATA, the EDIT control doesn't want to get VK_RETURN or VK_ESCAPE on WM_KEYDOWN. I tried to get one from WM_CHAR with 9th byte(return), the result the same.
     
     invoke  CreateWindowEx, 0, clEdit, 0, WS_VISIBLE + WS_CHILD + WS_BORDER + WS_TABSTOP + ES_LEFT + ES_AUTOHSCROLL,\
                             5, 50, 775, 20, [hMain], IDE_PATH, [hModule], 0
     [b]; New EDITBOX window proc
     mov     ebx, eax
     invoke  SetWindowLong, eax, GWLP_WNDPROC, EditProc
     invoke  SetWindowLong, ebx, GWL_USERDATA, eax[/b]
     ; ...
     ; ...
proc EditProc, hControl, Msg, wParam, lParam
     push    ebx edx ebp
     ; ...
     ; ...
     ; ...
.finish:
             [b]invoke  GetWindowLong, [hControl], GWL_USERDATA
             invoke  CallWindowProc, eax, [hControl], [Msg], [wParam], [lParam][/b]
     .End:
             pop     ebp edx ebx
     ret
     .Error:
     jmp     .finish
endp
    
Control's old procedure successfully stores and retrieves from GWL_USERDATA member. Window works fine, beside the trouble with VK_ENTER and VK_ESCAPE. I found out it with debugger.
 
So, how can I solve this???[/b]
 Last edited by KostX on 09 Nov 2014, 02:10; edited 1 time in total
 |