I've tried to make the program spy on WM_MENUSELECT,
but it won't seem to work.........
anybody have an idea ?
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
ClassName db "SimpleWinClass",0
AppName db "My First Window",0
MenuName db "FirstMenu",0
ButtonClassName db "button",0
ButtonText db "Touch Me !",0
EditClassName db "edit",0
lpText db "EAX==0x00000001",0
lpCaption db "WM_CREATE",0
lpText2 db "EAX==0x00000002",0
lpCaption2 db "WM_DESTROY",0
lpText3 db "EAX==0x00000111",0
lpCaption3 db "WM_COMMAND",0
lpText4 db "EAX==0x00000084",0
lpCaption4 db "WM_MENUSELECT",0
Touch db "Touch Me",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ?
hwndEdit HWND ?
buffer db 512 dup(?)
.const
ButtonID equ 1
EditID equ 2
IDM_Touch equ 1
IDM_EXIT equ 2
.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_APPWORKSPACE+2
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_ASTERISK
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_NO
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,WS_EX_TOOLWINDOW,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,300,150,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke MessageBox,NULL,ADDR lpText2,ADDR lpCaption2,MB_OK
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke MessageBox,NULL,ADDR lpText,ADDR lpCaption,MB_OK
invoke CreateWindowEx,WS_EX_TOOLWINDOW, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\
ES_AUTOHSCROLL,\
50,35,200,25,hWnd,EditID,hInstance,NULL
mov hwndEdit,eax
invoke SetFocus, hwndEdit
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
75,70,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
.ELSEIF uMsg==WM_COMMAND
invoke MessageBox,NULL,ADDR lpText3,ADDR lpCaption3,MB_OK
mov eax,wParam
.IF lParam==0
.IF ax==IDM_Touch
invoke SetWindowText,hwndEdit,ADDR Touch
invoke SendMessage,hwndEdit,WM_KEYDOWN,VK_END,NULL
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ELSE
.IF ax==ButtonID
shr eax,16
.IF ax==BN_CLICKED
invoke MessageBox,NULL,ADDR lpText,ADDR lpCaption,MB_OK
;invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
.IF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ENDIF
xor eax,eax
ret
WndProc endp
end start
but it won't seem to work.........
anybody have an idea ?
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
ClassName db "SimpleWinClass",0
AppName db "My First Window",0
MenuName db "FirstMenu",0
ButtonClassName db "button",0
ButtonText db "Touch Me !",0
EditClassName db "edit",0
lpText db "EAX==0x00000001",0
lpCaption db "WM_CREATE",0
lpText2 db "EAX==0x00000002",0
lpCaption2 db "WM_DESTROY",0
lpText3 db "EAX==0x00000111",0
lpCaption3 db "WM_COMMAND",0
lpText4 db "EAX==0x00000084",0
lpCaption4 db "WM_MENUSELECT",0
Touch db "Touch Me",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ?
hwndEdit HWND ?
buffer db 512 dup(?)
.const
ButtonID equ 1
EditID equ 2
IDM_Touch equ 1
IDM_EXIT equ 2
.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_APPWORKSPACE+2
mov wc.lpszMenuName,OFFSET MenuName
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_ASTERISK
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_NO
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
INVOKE CreateWindowEx,WS_EX_TOOLWINDOW,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,300,150,NULL,NULL,\
hInst,NULL
mov hwnd,eax
INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
INVOKE UpdateWindow, hwnd
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke MessageBox,NULL,ADDR lpText2,ADDR lpCaption2,MB_OK
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke MessageBox,NULL,ADDR lpText,ADDR lpCaption,MB_OK
invoke CreateWindowEx,WS_EX_TOOLWINDOW, ADDR EditClassName,NULL,\
WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or\
ES_AUTOHSCROLL,\
50,35,200,25,hWnd,EditID,hInstance,NULL
mov hwndEdit,eax
invoke SetFocus, hwndEdit
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText,\
WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\
75,70,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
.ELSEIF uMsg==WM_COMMAND
invoke MessageBox,NULL,ADDR lpText3,ADDR lpCaption3,MB_OK
mov eax,wParam
.IF lParam==0
.IF ax==IDM_Touch
invoke SetWindowText,hwndEdit,ADDR Touch
invoke SendMessage,hwndEdit,WM_KEYDOWN,VK_END,NULL
.ELSE
invoke DestroyWindow,hWnd
.ENDIF
.ELSE
.IF ax==ButtonID
shr eax,16
.IF ax==BN_CLICKED
invoke MessageBox,NULL,ADDR lpText,ADDR lpCaption,MB_OK
;invoke SendMessage,hWnd,WM_COMMAND,IDM_GETTEXT,0
.ENDIF
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
.IF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ENDIF
xor eax,eax
ret
WndProc endp
end start
Maybe you should include the code for it ?
ps: Use Code Tags for code :)
.IF uMsg == WM_MENUSELECT
INT 3
.endif
ps: Use Code Tags for code :)
Hi JimmyClif
Of course I did put in the code, but it didn't seem to work.
I wrote it like this:
.IF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ENDIF
:)
Of course I did put in the code, but it didn't seem to work.
I wrote it like this:
.IF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ENDIF
:)
The WM_MENUSELECT message is sent to a menu's owner window when the user selects a menu item.
But your window has no menu! You have to create it first.
But your window has no menu! You have to create it first.
Ups, I forgot to include the .rc file, so here it is
attached.
attached.
The branch:
Move it before DefWindowProc branch:
.IF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ENDIF
never recieves control.
Move it before DefWindowProc branch:
.ELSEIF uMsg==WM_MENUSELECT
invoke MessageBox,NULL,ADDR lpText4,ADDR lpCaption4,MB_OK
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
Hi Four-F, yes that works, BUT then the menu won't show.....:confused:
...BUT then the menu won't show...
Whet MessageBox gets displayed it grabs focus and this breaks normal processing of WM_MENUSELECT message. Don't use MessageBox for this.
Take a look at this utility:
VKDEBUG v1.1 released
It ideally does you want.
Download it, install and then compile code in attach. And have fun!
Hi Four-F
Yeah, that looks nice, but Spy++ does the job too....
How can it be created in MY program, so it WILL spy
on WM_MENUSELECT ?
If I can't make it display a MessageBox, what can be
done then....?
Yeah, that looks nice, but Spy++ does the job too....
How can it be created in MY program, so it WILL spy
on WM_MENUSELECT ?
If I can't make it display a MessageBox, what can be
done then....?
Yeah, that looks nice, but Spy++ does the job too....
Spy++ is quite different story. It installs hooks and every message passing to hooked window procedure goes to spy first.
It collects messages and displays that info.
If I can't make it display a MessageBox, what can be done then....?
Display it id Edit control like vkdebug.
I don't understand why you want to spy message handling of your own window,
but take a look at this (c-source code):
Control Spy
There is nothing about menu spying there, but you can simply adapt source to your need.
Perhaps if you call DefWindowProc after you show the messagebox, the menu would still show. It seems logical, if the menu is opened by windows in DefWindowProc.