SendMessage.exe: Access to advanced Windows features
Posted: 02 Dec 2016 20:28
SendMessage.exe is an auxiliary .exe program that works as a wrapper for the Win-32 API SendMessage function. This function allows you to have access to several interesting Windows features in a very simple way. You may read an introduction to the use of SendMessage at this article.
The operation of SendMessage.exe program is simple: it takes 3 values from the parameters and invoke the SendMessage function with them. This is the general usage format:
In this format, Message is the number of the wanted System-Defined Message and the other two parameters vary accordingly. The optional window title allows to send the message to another window, instead of the current cmd.exe one. The key to make good use of SendMessage features is to know the values that can be used with it, but this information is not presented in the Windows API documentation in a coherent way. I spent more time browsing the documentation looking for useful cmd.exe message numbers than the time it tooks me to write the SendMessage.asm program! This is a list of the message numbers that I have successfully tested so far:
WM_VSCROLL=277 request: Scrolls the window's vertical scroll bar.
Possible values for wParam=request:
WM_HSCROLL=276 request: Scrolls the window's horizontal scroll bar.
Possible values for wParam=request:
WM_SYSCOMMAND=274 item: Selects an item from the window menu.
Possible values for wParam=item:
Note 1: SC_SCROLL=0xFFF3=65523 is an undocumented value that was researched by S.O. user MC ND.
All previous values are defined in SendMessageValues.bat companion file as auxiliary variables via SET /A commands. For example:
As conclusion of previous description, the next command scrolls the cmd.exe window one page down:
Interesting! Isn't it? Try it yourself:
Note 2: MF_ENABLED, MF_GRAYED and MF_DISABLED values are not menu items, but parameters of Win-32 API EnableMenuItem function instead; this function is also included in SendMessage.exe program for convenience. When you use these values in wParam, the lParam must have the menu item that is processed; for example: SendMessage %WM_SYSCOMMAND% %MF_DISABLED% %SC_CLOSE% disable the red X "close" button. You may also specify an item by its position in the menu instead of its name; for example: SendMessage %WM_SYSCOMMAND% %MF_GRAYED% 3 disable and gray the third item in the menu.
Note that this is work in progress: there are much more messages that could be successfully used in the cmd.exe window, but it is necessary to test each one of them. My next step is try to implement the ACM messages that would permit the playing of silent .AVI video files. If you want that I test other values, post here such request with a link to the wanted messages.
IMPORTANT: SendMessage.exe does NOT check the values given in the parameters in any way; it just use such values to invoke SendMessage API function. I don't know if some of the values not listed here may be potentially dangerous! The full documentation of all possible values is given in a link above. If you don't know what you are doing, just don't use any value not listed here. I will NOT be responsible for any damage that could be caused by the use of SendMessage.exe program! On the other hand, I'll appreciate it if you post here some additional values that you may successfully tested.
Antonio
The operation of SendMessage.exe program is simple: it takes 3 values from the parameters and invoke the SendMessage function with them. This is the general usage format:
Code: Select all
SendMessage.exe ["title"] Message [wParam [lParam]]
In this format, Message is the number of the wanted System-Defined Message and the other two parameters vary accordingly. The optional window title allows to send the message to another window, instead of the current cmd.exe one. The key to make good use of SendMessage features is to know the values that can be used with it, but this information is not presented in the Windows API documentation in a coherent way. I spent more time browsing the documentation looking for useful cmd.exe message numbers than the time it tooks me to write the SendMessage.asm program! This is a list of the message numbers that I have successfully tested so far:
WM_VSCROLL=277 request: Scrolls the window's vertical scroll bar.
Possible values for wParam=request:
- SB_TOP=6: Scrolls to top.
- SB_PAGEUP=2: Scrolls one page up.
- SB_LINEUP=0: Scrolls one line up.
- SB_LINEDOWN=1: Scrolls one line down.
- SB_PAGEDOWN=3: Scrolls one page down.
- SB_BOTTOM=7: Scrolls to bottom.
- SB_THUMBPOSITION=4: Scrolls the line given in high part of wParam to top of screen:
set /A request=(line<<16)+SB_THUMBPOSITION
WM_HSCROLL=276 request: Scrolls the window's horizontal scroll bar.
Possible values for wParam=request:
- SB_LEFT=6: Scrolls to left-most column.
- SB_PAGELEFT=2: Scrolls one page left.
- SB_LINELEFT=0: Scrolls one column left.
- SB_LINERIGHT=1: Scrolls one column right.
- SB_PAGERIGHT=3: Scrolls one page right.
- SB_RIGHT=7: Scrolls to right-most column.
- SB_THUMBPOSITION=4: Scrolls the column given in high part of wParam to left of screen:
set /A request=(column<<16)+SB_THUMBPOSITION
WM_SYSCOMMAND=274 item: Selects an item from the window menu.
Possible values for wParam=item:
- SC_MONITORPOWER=61808: Power the display on/low/off via lParam= -1/1/2.
- SC_KEYMENU=61696: Open the Alt-letter menu; code of letter in lParam.
- SC_TASKLIST=61744: Open the Start menu.
- SC_SCREENSAVE=61760: Executes the screen saver.
- SC_NEXTWINDOW=61504: Selects next window.
- SC_PREVWINDOW=61520: Selects previous window.
- SC_MOVE=61456: Enables window move.
- SC_SIZE=61440: Enables window resize.
- SC_MINIMIZE=61472: Minimizes the window.
- SC_MAXIMIZE=61488: Maximizes the window.
- SC_RESTORE=61728: Restores the window.
- SC_CLOSE=61536: Closes the window.
- SC_SCROLL=65523: Enables "Scroll mode" in cmd.exe window. (Note 1)
- MF_ENABLED=0: Enables the menu item. (Note 2)
- MF_GRAYED=1: Disables and gray the menu item. (Note 2)
- MF_DISABLED=2: Disables the menu item, but not gray it. (Note 2)
Note 1: SC_SCROLL=0xFFF3=65523 is an undocumented value that was researched by S.O. user MC ND.
All previous values are defined in SendMessageValues.bat companion file as auxiliary variables via SET /A commands. For example:
Code: Select all
set /A WM_VSCROLL=277, SB_PAGEDOWN=3
As conclusion of previous description, the next command scrolls the cmd.exe window one page down:
Code: Select all
SendMessage.exe %WM_VSCROLL% %SB_PAGEDOWN%
Interesting! Isn't it? Try it yourself:
Note 2: MF_ENABLED, MF_GRAYED and MF_DISABLED values are not menu items, but parameters of Win-32 API EnableMenuItem function instead; this function is also included in SendMessage.exe program for convenience. When you use these values in wParam, the lParam must have the menu item that is processed; for example: SendMessage %WM_SYSCOMMAND% %MF_DISABLED% %SC_CLOSE% disable the red X "close" button. You may also specify an item by its position in the menu instead of its name; for example: SendMessage %WM_SYSCOMMAND% %MF_GRAYED% 3 disable and gray the third item in the menu.
Note that this is work in progress: there are much more messages that could be successfully used in the cmd.exe window, but it is necessary to test each one of them. My next step is try to implement the ACM messages that would permit the playing of silent .AVI video files. If you want that I test other values, post here such request with a link to the wanted messages.
IMPORTANT: SendMessage.exe does NOT check the values given in the parameters in any way; it just use such values to invoke SendMessage API function. I don't know if some of the values not listed here may be potentially dangerous! The full documentation of all possible values is given in a link above. If you don't know what you are doing, just don't use any value not listed here. I will NOT be responsible for any damage that could be caused by the use of SendMessage.exe program! On the other hand, I'll appreciate it if you post here some additional values that you may successfully tested.
Antonio