News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Changing Scroll postion of another process

Started by sonic, July 23, 2007, 09:53:40 AM

Previous topic - Next topic

sonic

My code launces the text file with users default text editor using shellexecute. Then i used the FindExecutable to find the name of file which is used to view the text file and then snapshot to get process id and followed by Openprocess to get handle. Now how to send message to scroll the text file to bottom.

ramguru

Simple as that:
invoke SendMessage, hWnd, WM_VSCROLL, SB_LINEDOWN, 0

sonic

Thanks for reply but i already tried this thing and it doesn't work.

invoke SendMessage,hProcess,WM_VSCROLL,SB_BOTTOM,NULL

ramguru

I can guess what you did wrong, better attach code...

sonic

#4
Ok. Here is the code

ramguru

I changed your code ... 'cause you wasn't thinking what you were doing...there is difference between process handle and window handle

.data
notepad    db 'Notepad',0
edit       db 'Edit',0
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke InitCommonControls
invoke DialogBoxParam, hInstance, IDD_MAIN, 0, offset DlgProc, 0
invoke ExitProcess, eax

DlgProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
mov eax,uMsg

.if eax == WM_INITDIALOG
invoke LoadIcon,hInstance,200
invoke SendMessage, hWin, WM_SETICON, 1, eax
.elseif eax == WM_COMMAND
mov eax,wParam
.if eax == IDB_EXIT
invoke SendMessage, hWin, WM_CLOSE, 0, 0

.elseif eax==IDB_OPEN

invoke CreateFile,addr szFileName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov    ebx, eax
invoke lstrlen,addr szText
invoke WriteFile, ebx, addr szText, eax, addr lpBW, 0
invoke CloseHandle, ebx

invoke ShellExecute, hWin, addr open, addr szFileName, 0, 0, SW_SHOWNORMAL

invoke Sleep, 500

invoke  FindWindow,   ADDR notepad, 0
invoke  FindWindowEx, eax, 0, ADDR edit, 0

invoke SendMessage, eax, WM_VSCROLL, SB_BOTTOM, 0

.endif
.elseif eax == WM_CLOSE

sonic

Quote from: ramguru'cause you wasn't thinking what you were doing.
hmmm...Maybe u were correct

Quote from: ramguruthere is difference between process handle and window handle
Thanks for pointing out that . Didn't knew it  :(

I knew the FindWindow method but the problem is that the class can't be hardcoded cause different editors could be having different class. Is there any alternate method or same method tweaked to work :dazzled:

ramguru

Another approach w/o class, but more risky, because main window may contain more than one child window...

invoke Sleep, 500

invoke GetForegroundWindow
invoke GetWindow, eax, GW_CHILD

invoke SendMessage, eax, WM_VSCROLL, SB_BOTTOM, 0

sonic

Thanks ramguru this seems to work. but sometimes it doesn't. BTW why is the sleep needed there. It seems more i delay there the more effective this becomes. Is there any api to convert the process handle to window handle.

ramguru

sleep is needed because by the time CPU reaches, say "invoke GetForegroundWindow", to execute, your text editor may not be started yet, so you have to kinda delay the following code. Sleep of course is not accurate, it may take more than 500 miliseconds for text-editor to start, you don't know exactly, therefore it's better to use CreateProcess+WaitForSingleObject or WinExec instead of ShellExecute. As for API that can get window handle from process handle, sorry I don't know any such... You also may want to take a look at EnumWindows EnumChildWindows APIs