Sending a message using the Win32 ASM change Notepad window title

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; by bobo
; Send.asm
; 从一个程序向另一个窗口程序发送消息
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.386
		.model flat,stdcall
		option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include		windows.inc
include		user32.inc
includelib	user32.lib
include		kernel32.inc
includelib	kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.data
hWnd		dd	?
szBuffer	db	256 dup (?)

		.const
szCaption	db	'SendMessage',0
szReturn	db	'SendMessage returned!',0
szDestClass	db	'Notepad',0	;记事本窗口的窗口类
szText		db	'改变记事本窗口的标题!!!',0

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		.code
start:
		invoke	FindWindow,addr szDestClass,NULL
		.if	eax
			mov	hWnd,eax	;找到记事本窗口则发送消息
			
			invoke	SendMessage,hWnd,WM_SETTEXT,0,addr szText
			invoke	MessageBox,NULL,offset szReturn,offset szCaption,MB_OK		
		.endif
		invoke	ExitProcess,NULL
		end	start

Program starts first call FindWindow, find Notepad window according to the window of the class Notepad window,

WM_SETTEXT then sends message; After sending a dialog box;

Test useless Notepad window open, or may be useful in the Notepad window title has changed;

If no ASM integrated development environment, constructed as follows;

set command to set the environment variable is valid only once;

set path = xxxxx, after this command is to test the new settings additional xxxx, does not affect the value of a previously set path;

First download and install MASM32;

Published 475 original articles · won praise 545 · Views 3.04 million +

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/104110046
Recommended