News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Insert Text from hot keys

Started by Magnum, December 12, 2012, 01:44:51 AM

Previous topic - Next topic

Magnum

Fixing some old code. I could find the final version on the old board.

It's putting the string into the buffer but the hot key isn't working.

I held down the F7 key to go to the end. Never saw any error messages.

I will do an F2 near the end of the code.

I don't think I need that window either.

Andy



; HotKey_Txt.asm
;

include \masm32\include\masm32rt.inc

WinMain PROTO   :DWORD,:DWORD,:DWORD,:DWORD

.data

hglb dd 0 ; ',\ ; need space before quote
str1 db '¿Cómo estás hoy. Wie geht es Ihnen?'

ClassName db "DLGCLASS",0
DlgName db "MyDialog",0
AppName db "Hotkey Example",0
loaded db "Ctrl+Alt+A was pressed.",0
Voila db "PPPPP",0

.data?

hInstance HINSTANCE ?
CommandLine LPSTR ?

.code
start:
invoke GetModuleHandle, NULL
mov    hInstance,eax                     
invoke GetCommandLine
mov CommandLine,eax
    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
      invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hWnd:HWND
mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,NULL
mov   wc.cbWndExtra,NULL
push  hInst
pop   wc.hInstance
mov   wc.hbrBackground,COLOR_WINDOW+1
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,0
invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
mov   hWnd,eax
INVOKE ShowWindow, hWnd,SW_MINIMIZE
INVOKE UpdateWindow, hWnd

.WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                invoke IsDialogMessage, hWnd, ADDR msg
                .if eax==FALSE
                        INVOKE TranslateMessage, ADDR msg
                        INVOKE DispatchMessage, ADDR msg
                .endif
.ENDW
mov     eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
         
    .if uMsg==WM_CREATE
            invoke RegisterHotKey,hWnd,065h,MOD_CONTROL or MOD_ALT, 041h ; CTRL ALT A
      .ELSEIF uMsg==WM_DESTROY
            invoke UnregisterHotKey,hWnd,065h
invoke PostQuitMessage,NULL
      .ELSEIF uMsg == WM_HOTKEY

; OpenClipboard
; SetClipboardData
; CloseClipboard

; mov eax,wParam
;              .if eax==065h
;         invoke MessageBox,NULL, ADDR loaded,ADDR Voila,  MB_ICONEXCLAMATION
 
    ; Put text on the clipboard.
 
    invoke OpenClipboard,NULL
    .IF (eax)
      invoke EmptyClipboard
      invoke GlobalAlloc,GMEM_MOVEABLE,SIZEOF str1    ;INVOKE  GlobalFree,hglb
      .IF (eax)
        mov hglb, eax
        invoke GlobalLock,hglb
         
        invoke MemCopy,ADDR str1,eax,SIZEOF str1
        invoke GlobalUnlock,hglb
        invoke SetClipboardData,CF_TEXT,hglb
         
        .IF (eax == 0)
          print "SetClipboardData failed",13,10
        .ENDIF


INVOKE  GlobalFree,hglb

      .ELSE
        print "GlobalAlloc failed",13,10
      .ENDIF
      invoke CloseClipboard

    .ELSE
      print "OpenClipboard failed",13,10
    .ENDIF
   
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor    eax,eax
ret
WndProc endp

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org