Dll functions exported by QM

These dll functions and interfaces are provided by qm.exe. Declared in QmDll.

 

In some function descriptions is specified QM version when the function has been added. If not specified, the function has been added before QM 2.1.9. Some functions are not available in exe. It is specified in function descriptions. Almost all functions support Unicode. If a function does not support Unicode, it is specified in its description. All file functions support special folders.

Interfaces


IStringMap, CreateStringMap

 

QM 2.2.0.

String map object. A string map is an array of string pairs.

 


ICsv, CreateCsv

 

QM 2.3.0.

CSV object. CSV is a file format used to save tables.

 


IXml, IXmlNode, CreateXml

 

QM 2.3.0.

XML object. XML is a file format used to save tables and hierarchical data structures.

 


Functions

Compare: StrCompare, StrCompareN, MemCompare, q_stricmp, q_strnicmp, q_memicmp

Character type: isdigit, isalnum, __iscsym

Memory: q_malloc, q_calloc, q_realloc, q_free, q_msize, q_strdup

QM key codes: QmKeyCodeToVK, QmKeyCodeFromVK

Key state: RealGetKeyState, GetMod

QM items and folders: SilentImport, SilentExport

QM threads: EnumQmThreads, GetQmThreadInfo

QM menus and toolbars: GetToolbarOwner, GetLastSelectedMenuItem

Standard menu: MenuSetString, MenuGetString

Window: IsHungWindow, RealGetNextWindow, SubclassWindow, SetWinStyle, IsWindow64Bit

Multiple monitors: MonitorFromIndex, MonitorIndex, AdjustWindowPos

Rich edit: RichEditLoad, RichEditSave

Performance: GetCPU, GetDiskUsage

Security: SetPrivilege

Session: IsLoggedOn, EnsureLoggedOn

System/user info: IsUserAdmin, GetUserInfo

Process info: GetProcessUacInfo, GetProcessIntegrityLevel, EnumProcessesEx, ProcessNameToId, GetProcessExename

Run program: StartProcess, AllowActivateWindows

File system, PIDL: GetFileOrFolderSize, GetFullPath, PidlToStr, PidlFromStr

Shortcut: CreateShortcutEx, GetShortcutInfoEx

Icon, image: GetFileIcon, GetWindowIcon, SaveBitmap, LoadPictureFile

Setup: RegisterComComponent

Drag and drop: QmRegisterDropTarget, QmUnregisterDropTarget

Exe: GetExeResHandle, ExeExtractFile, ExeGetResourceData

Math: Crc32, Round, RandomNumber, RandomInt

Tools: GetQmCodeEditor, InsertStatement, HtmlHelp, SpecFoldersMenu, CreateRegExpMenu, RecGetWindowName, OnScreenRect, CompileAllItems, FormatKeyString, EditReplaceSel

 


#StrCompare $s1 $s2 [insens]

 

QM 2.3.0.

Compare two strings.

 

#StrCompareN $s1 $s2 n [insens]

 

QM 2.3.0.

Compare maximum n characters (bytes) of two strings.

 

#MemCompare $s1 $s2 n [insens]

 

QM 2.3.0.

Compare exactly n bytes of two memory blocks. Unlike the string functions, can compare binary data. The string functions never compare memory after the terminating null character.

 

s1, s2 - strings. Can be str or lpstr variables or string constants. With MemCompare, also can be pointers of any type.

n - number of bytes to compare.

insens - case insensitive if nonzero.

 

These functions return:

 

0 s1 and s2 are equal. Note that null and "" are considered equal.
1 s1 is > s2. It means that s1 would be below s2 in a sorted list.
-1 s1 is < s2. It means that s1 would be above s2 in a sorted list.

 

These functions should be used instead of similar Windows API and msvcrt.dll functions, because:

 

1. Support Unicode (when QM is running in Unicode mode).

2. Case insensitive comparison is much faster, especially when the strings are ASCII.

3. Don't afraid null strings. Null and "" are considered equal.

4. The return value is strictly 0 or 1 or -1.

 

You can also use matchw, findrx, some str functions and operators. However they cannot be used in sorting.

 

To compare strings also can be used CompareString, lstrcmp, orther Windows API and msvcrt.dll functions, all documented in the MSDN Library. Note that the case insensitive ANSI versions cannot compare UTF-8 text containing non ASCII characters. In QM, text normally is UTF-8 in Unicode mode.

 

The following 3 functions exist for backward compatibility. Use the above functions instead.

 

#q_stricmp $s1 $s2
#q_strnicmp $s1 $s2 count
#q_memicmp $s1 $s2 count

 


[q_isdigit]#isdigit char

 

QM 2.3.0.

Returns a nonzero value if char is a digit '0' to '9'. This function replaces the msvcrt.dll function because the later also would return nonzero for superscript characters.

 

[q_isalnum]#isalnum char

 

QM 2.3.0.

Returns a nonzero value if char is a digit '0' to '9' or a letter (including non ASCII). This function replaces the msvcrt.dll function because the later also would return nonzero for superscript characters.

 

The return value consists of flags: C1_DIGIT (4), C1_ALPHA (0x100), C1_UPPER (1), C1_LOWER (2).

 

[q_iscsym]#__iscsym char ;;ASCII letter, digit or _

 

QM 2.3.0.

Returns 1 if char is a valid character for a QM or C++ identifier, or 0 if not. This function replaces the msvcrt.dll function because the later also would return nonzero for some non ASCII characters.

 

For other character types, can be used similar msvcrt.dll functions, for example isalpha, isprint. Also can be used Windows API functions, for example IsCharAlpha, GetStringType. All documented in the MSDN Library.

 

These functions don't support Unicode. To get Unicode UTF-16 character type, use W versions of Windows API functions, for example IsCharAlphaW.

 


!*q_malloc size ;;QM malloc

 

Allocates size bytes of memory. Returns pointer to the allocated memory block.

 

!*q_calloc elemcount elemsize ;;QM calloc

 

Allocates elemcount*elemsize bytes of memory and fills with 0. Returns pointer to the allocated memory block.

 

!*q_realloc !*mem size ;;QM realloc

 

Allocates more or leass memory. mem can be memory allocated with one of these functions, or 0. Returns pointer to the allocated memory block. It can be different or the same as mem.

 

q_free !*mem ;;QM free

 

Frees memory allocated with one of these functions. mem can be 0.

 

#q_msize !*mem ;;QM _msize

 

Gets size of memory allocated with one of these functions.

 

$q_strdup $s ;;QM _strdup

 

Allocates duplicate string. s can be any string, not necessary allocated with one of these functions. The function allocates memory using q_malloc and copies s there.

 

These functions also can be used with memory that is allocated or will be freed by str variables. For this purpose don't use malloc and other functions from msvcrt.dll, because QM uses other memory allocation functions.

 


#QmKeyCodeToVK $qmkey int*virtualkey ;;Returns number of characters eaten.

 

Converts from QM key code (string) to Windows virtual-key code (integer). qmkey may contain more than one QM key code. The function stores virtual-key code of the first QM key code into the int variable whose address is vk, and returns number of parsed characters (eg 3 for F12). vk will be 0 if qmkey is invalid.

 

QM 2.2.1: Instead can be used key. It converts multiple key codes, variables, etc.

 

QmKeyCodeFromVK virtualkey str*qmkey

 

Converts virtual-key code to QM key code.

 


#RealGetKeyState vk ;;Returns 1 if the key is pressed. If vk contains flag 0x100 - if toggled. vk is virtual-key code.

 

QM 2.2.1.

Checks if the specified key or mouse button is pressed or toggled. Can be used instead of ifk. More reliable than GetKeyState and GetAsyncKeyState.

 

Returns 1 if the key is pressed, 0 if not. If vk contains flag 0x100 (eg VK_CAPITAL|0x100), returns 1 if the key is toggled, 0 if not.

 

vk - virtual-key code 1 to 255. Add flag 0x100 to check toggled state.

 


#GetMod ;;Returns: 1 Shift, 2 Ctrl, 4 Alt, 8 Win.

 

Checks whether modifier keys are pressed. The return value is combination of the following values: 1 - Shift is pressed, 2 - Ctrl is pressed, 4 - Alt is pressed, 8 Win is pressed. For example, if Ctrl and Alt are pressed, the return value is 6.

 


#SilentImport $_file [flags] ;;_file: qml file to import; flags: 1 add shared. Returns 1 if successful.

 

Imports qml file. Any dialogs or error messages are not displayed. Not available in exe.

 

#SilentExport $item $_file [flags] ;;item: qm item or folder name or +id; _file: folder or qml file or ""; flags: 1 no import, 2 no open, 4 no shared, 8 no partial/renamed, 0x100 make zip. Returns 1 if successful.

 

Exports qm item or folder. Any dialogs or error messages are not displayed. Not available in exe.

 


#EnumQmThreads [QMTHREAD*arr] [nelem] [flags] [$threadname] ;;flags: must be 0

 

Gets information about currently running QM threads, except special threads. Returns the number of threads.

 

arr - caller-allocated array of nelem elements of QMTHREAD type. Can be 0. See example.

nelem - number of elements in arr.

flags - currently not used and must be 0.

threadname (2.2.0) - QM item name (in quotes, or string variable) or id. If 0 or "", enumerates all threads.

 

This type is used with EnumQmThreads and GetQmThreadInfo:

 

type QMTHREAD qmitemid threadid threadhandle flags tuid

 

qmitemid - QM item id. Can be used to display item name (str.getmacro or qmitem) or end thread (shutdown).

threadid - thread id. Can be used with shutdown -6 (end thread) and with Windows API functions.

threadhandle - thread handle. Can be used with wait (wait until thread exits), shutdown -6, and with Windows API functions.

flags - currently is not used.

tuid (QM 2.2.0) - unique thread id. Can be used with shutdown -6. Cannot be used with Windows API functions. Unlike thread id and handle, the same unique id value is not reused for new threads.

 

Examples

 

 Display all threads
int i n=EnumQmThreads(0 0 0 0)
ARRAY(QMTHREAD) a.create(n)
for i 0 EnumQmThreads(&a[0] n 0 0)
	out _s.getmacro(a[i].qmitemid 1)

 Is Function55 running?
if(EnumQmThreads(0 0 0 "Function55")) out "running"

 


#GetQmThreadInfo handle QMTHREAD*qt ;;Returns 1 on success, 0 on failure. handle=0 - current thread.

 

QM 2.2.0.

Gets information about a QM thread. Fills variable of type QMTHREAD (described above). It must not be a special thread.

 

handle - thread handle. For example, mac returns thread handle when you use it to run a function. If 0 - current thread.

 


#GetToolbarOwner hwndTb ;;Returns handle of a QM toolbar's owner window

 

QM 2.2.0.

Returns handle of the window to which the toolbar is attached. Returns 0 if the toolbar is not attached to a window. Use this function instead of GetWindow or other Windows API, because QM toolbars are not necessarily owned as Windows interprets it.

 

hwndTb - toolbar window handle. Note that it is handle of toolbar, not of its owner window.

 

QM 2.2.0.9. Also available in exe.

 


GetLastSelectedMenuItem str*label [str*command] [flags] ;;flags: 1 get pidl always

 

QM 2.2.0.

Yo can call this function after showing a popup menu to get clicked item string. To show the menu, use mac as function. If mac returns a nonzero value, call this function. See example.

 

label - receives selected menu item label string. Can be 0.

command - receives selected menu item code string. With an expand-folder menu - selected file path or ITEMIDLIST string. Can be 0.

 

Not available in exe.

 

Example

 

 Show menu "Drives" and get selected item info
if(mac("Drives"))
	str s
	GetLastSelectedMenuItem 0 &s 0
	mes s

 


MenuSetString hMenu item $s ;;item: > 0 id, <=0 -position

 

QM 2.3.0.

Changes menu item text.

 

#MenuGetString hMenu item str*s ;;item: > 0 id, <=0 -position. Returns 1 on success, 0 on failure.

 

QM 2.3.0.

Gets menu item text.

 

hMenu - menu handle.

item - menu item id or negative position.

s - sets or receives menu item text.

 

The menu cannot be a QM popup menu. It must be a menu created using Windows API functions, such as CreatePopupMenu. It must belong to qm/exe process.

 


#IsHungWindow hwnd ;;Returns: 1 hung, 0 not, -1 invalid hwnd

 

Returns 1 if the window is hung. A window is hung if it does not respond for certain time, eg 10 s. Windows XP hides a hung window and replaces it with a ghost window.

 

hwnd - window handle.

 


#RealGetNextWindow hwndFrom [flags] ;;Gets next window, skipping invisible and other windows that would be skipped by Alt+Tab. flags: 1 retry from top, 2 skip minimized

 

QM 2.2.1.

Returns handle of next window in Z order, skipping invisible and other windows that would be skipped by Alt+Tab.


hwndFrom - handle of window behind which in Z order to search. If 0, starts from the top of the Z order.
flags:
1 - if hwndFrom is not 0 and there is no matching windows behind it, retry from the top of the Z order (like Alt+Tab).
2 - skip minimized windows.


#SubclassWindow hwnd newWndProc

 

QM 2.3.0.

Replaces window procedure. Returns address of old procedure. If the window is ANSI, calls SetWindowLongA. If Unicode, calls SetWindowLongW. Read more about subclassing in the MSDN Library.

 

hwnd - window handle. The window must belong to qm/exe process.

newproc - address of new window procedure. The function must begin with function hWnd message wParam lParam and end with ret CallWindowProc(oldproc hWnd message wParam lParam).

 


SetWinStyle hwnd style [flags] ;;flags: 0 set, 1 add, 2 remove, 4 exstyle, 8 update nonclient, 16 update client


Changes window style or extended style.

hwnd - window handle. Can be top-level or child window.
style - style or extended style. Window styles are documented in the
MSDN Library. To view available styles and extended styles, type .WS_ .

flags: 0 set, 1 add, 2 remove, 4 style is extended style, 8 update nonclient area, 16 update client area (QM 2.2.1).

 

Example:

 remove Notepad's title bar:
int h=win("Notepad")
SetWinStyle h WS_CAPTION 2|8

 

 


#IsWindow64Bit hwnd [flags] ;;flags: 1 hwnd is pid; returns: 0 32-bit, 1 64-bit, -1 error

 

QM 2.2.0.

Lets you to know if a process is 64-bit. Always returns 0 on 32-bit Windows.

 

Return values:

0 - not 64-bit.

1 - 64-bit.

-1 - error.

 

hwnd - handle of a window that belongs to the process. If flags includes 1, then hwnd must be process id. You can use process id 0 to specify current process (qm or exe).

 

See also: _win64

 


#MonitorFromIndex [monitor] [flags] [RECT*r] ;;flags: 1 work area, 32 monitor is hmonitor. monitor: 0 primary, 1-30 index, -1 mouse, -2 active window, -3 primary, or window handle

 

QM 2.2.1.

Returns handle of monitor that is specified by index or some other property. Also can get monitor coordinates.

monitor - requested monitor. Like with _monitor, it can be monitor index 1-30, or 0 (primary), -1 (mouse), -2 (active window), -3 (primary), or window handle.

flags:

1 - get work area coordinates.

32 - monitor is monitor handle.

 

r - address of a RECT variable that receives monitor coordinates, relative to the primary monitor. Can be 0 if not needed.

 

Other functions that can be used to get monitor handle: MonitorFromWindow, MonitorFromPoint, MonitorFromRect. Documented in the MSDN Library.

 


#MonitorIndex hmonitor ;;Returns 1-based monitor index.

 

QM 2.2.1.

Returns 1-based monitor index. Returns 0 if the handle is invalid.

 

hmonitor - monitor handle.

 


AdjustWindowPos hwnd RECT*r [flags] [monitor] ;;flags: 1 work area, 2 actually move, 4 raw x y, 8 only move into screen, 16 can resize, 32 monitor is hmonitor. monitor: 0 primary, 1-30 index, -1 mouse, -2 active window, -3 primary, or window handle

 

QM 2.2.1.

Adjusts window or rectangle coordinates like mes and other QM functions do. If negative, adjusts so that the window would be at the right or bottom of the screen. If 0, adjusts so that the window would be at the center of the screen. Ensures that whole window is in the screen. Ensures that the window will be in the specified monitor.

 

If the window is minimized, does not restore it but ensures that the window will be in correct position when restored. If the window is maximized, does not change its position and size, except when need to move to another monitor, but ensures that the window will be in correct position when restored to normal. All this is if hwnd is nonzero and flag 2 used. If hwnd is nonzero, the function always returns rectangle of normal (not minimized or maximized) window, regardless of its current state.

hwnd - window handle. Can be 0 if you only need to adjust r.

r - address of a RECT variable. On input, it must contain requested window coordinates in r.left and r.top. If hwnd is 0, r.right and r.bottom also must be specified, else they are not used. The coordinates are relative to the monitor, except when flag 8 used (read below). On output, the variable will contain normal coordinates, ie relative to the primary monitor. Can be 0 if flag 8 used or to use r.left= 0 and r.top=0.

flags:

1 - when calculating new coordinates, use work area instead of whole screen.

2 - actually move the window. By default, only modifies r.

4 - use raw x y relative to the monitor. Negative and 0 x y don't have special meaning.

8 - only move the window or rectangle to the nearest position in the work area, if it is not completely there. If hwnd is not 0, r is not used and can be 0. Else r must contain normal coordinates. If monitor is 0, uses the monitor that contains the biggest part of the window or rectangle, or is nearest.

16 - resize if needed. By default the function can only move. Should be used only with flag 8.

32 - monitor is monitor handle.


monitor - requested monitor. The same as with MonitorFromIndex and
_monitor.

 


#RichEditLoad hwndRE $_file ;;Returns 1 if successful.

 

Loads a file to a rich edit control.

 

#RichEditSave hwndRE $_file ;;Returns 1 if successful.

 

Saves rich edit control text to a file.

 

hwndRE - control handle.

_file - file. If ends with .rtf, uses RTF format, else text format.

 

Rich edit control's class usually is RichEdit20A or RichEdit20W. The control must belong to qm/exe process.

 


#GetCPU ;;Returns % CPU usage, 0 to 100.

 

Returns % of processor usage since last call. When calling first time in thread, result is undefined.

 


#GetDiskUsage ;;Returns % disk usage, 0 to 100.

 

Returns % of disk usage (all physical disks) since last call. That is, % of time spent in disk read/write mode. When calling first time in thread, result is undefined. Should not be called too frequently (with < 100 ms period), or results may be incorrect. Only administrators and users in the Performance Logs User Group can use this function.

 


#SetPrivilege $privilege ;;Returns 1 if successful.

 

Some Windows API functions require certain privileges. This function enables a privilege in current process. Note that not all privileges can be enabled, especially when QM is running not as administrator.

 


#IsLoggedOn ;;Returns: 0 not logged on, 1 normal, 2 locked, 3 switched off, 4 custom desktop.

 

Checks whether QM is running on interactive desktop. Returns 0 if not logged on, 1 if normal (runs on interactive desktop), 2 if locked (directly or by a secure screen saver), 3 if switched off, 4 custom desktop.

 


#EnsureLoggedOn [unlock] ;;Returns: 0 cannot ensure, 1 normal, 2 successfully unlocked.

 

Checks whether QM is running on interactive desktop. If computer is locked, and unlock is nonzero, attempts to unlock. Returns 0 if cannot ensure interactive desktop, 1 if normal, 2 if successfully unlocked. The unlock method and settings are the same as specified in the Temporarily Unlock Computer dialog.

 

Unlocking is not available in exe (unlock value is ignored).

 

Some triggers (scheduler, event log, etc) may launch the macro while QM is not running on interactive desktop (e.g., while computer is locked). Then the macro runs in the background. However, many commands (keyboard, mouse, etc) then don't work, because background users cannot access keyboard, mouse and monitor. To ensure that the macro will not run in the background, you can check the checkboxes in Properties -> Macro properties or use EnsureLoggedOn or IsLoggedOn in the macro.

 

Example

 

 If QM is not running on interactive desktop, try to unlock computer; if it fails, exit
if(!EnsureLoggedOn(1)) ret

 


#GetUserInfo str*s [flags] ;;flags: 0 user name, 1 computer name, 0x100 UTF-16

 

QM 2.3.0.

Gets user name or computer name.

 

s - address of a str variable that receives it.

 


#IsUserAdmin ;;Returns 1 if QM (or exe) is running as administrator

 

QM 2.2.0.

Returns 1 if current process (QM or exe) is running as administrator. You should use this function instead of IsUserAnAdmin which is available only on XP and later OS.

 


#GetProcessUacInfo hwnd [flags] ;;returns: 0 not Vista or failed, 1 UAC off or non-admin account, 2 admin, 3 uiAccess, 4 user; flags: 1 hwnd is pid (pid 0 = current process)

 

QM 2.2.0.

Returns some Vista UAC info of a process (running program):

 

Return values:

0 - not Vista, or failed.

1 - UAC turned off, or the process is running as standard user on standard user account.

2 - The process is running as administrator.

3 - The process is running not as administrator but has uiAccess privileges.

4 - The process is running on administrator account but not as administrator.

 

hwnd - handle of a window that belongs to the process. If flags includes 1, then hwnd must be process id. You can use process id 0 to specify current process.

 

See also: IsUserAdmin (see above)

 


#GetProcessIntegrityLevel hwnd [flags] ;;returns: 0 not Vista or failed, 1 Low, 2 Medium, 3 High, 4 System; flags: 1 hwnd is pid (pid 0 = current process)

 

QM 2.2.0.

Returns the Vista integrity level of a process:

 

0 - not Vista, or failed.

1 - Low.

2 - Medium.

3 - Administrator or uiAccess.

4 - System.

 

hwnd - handle of a window that belongs to the process. If flags includes 1, then hwnd must be process id. You can use process id 0 to specify current process.

 


EnumProcessesEx ARRAY(int)*pids [ARRAY(str)*names] [flags] ;;flags: 1 full path, 2 current user session only

 

Gets names and/or process ids of all processes (running programs).

 

pids - address of array that receives process ids. Can be 0 if not needed.

names - address of array that receives process names. Can be 0 if not needed.

flags:

1 - get full paths. Note: cannot get full paths of processes running in other user sessions if QM is running not as administrator.

2 (QM 2.2.0) - enumerate only processes running in current user session (fast user switching).

 

Example

 

ARRAY(str) a
EnumProcessesEx 0 &a 0
for(_i 0 a.len) out a[_i]

 


#ProcessNameToId $exename [ARRAY(int)*allpids] [flags] ;;allpids can be 0; flags: 1 current user session only

 

Returns process id.

 

QM 2.2.0. Added third argument flags.

 

exename - program name or full path.

allpids - address of array that receives process ids of all matching processes. Can be 0 if not needed.

flags:

1 - find only processes running in current user session (fast user switching).

 


#GetProcessExename pid str*exename flags ;;flags: 1 full path. Returns: 1 success, 0 failed.

 

QM 2.2.1.

Gets name or full path of the executable file that started specified process (running program).

 

pid - process id.

exename - address of a str variable that receives the name.

 

The process here must be identified using process id. To use window instead, can be used str.getwinexe.

 


#StartProcess flags $path [$cl] [$defdir] [*hProcess] ;;flags: 0 as QM, 1 medium, 2 high, 3 high with consent, 4 low, 5 as QM -uiAccess, 16 get pid, hibyte showcmd

 

QM 2.2.0.

Runs an executable file with specified privileges (administrator, user, etc). Mostly useful on Vista, but can be used on all OS.

 

flags - privileges that you need. Available values are described in the Make Exe topic. Search for StartProcess.

path - executable file path.

cl - command line.

defdir - default directory.

hProcess - address of an int variable that receives process handle. Later you must close it using CloseHandle. If you use flag 16, the function retrieves process id instead of handle, and you must not close it.

 

QM 2.2.1. The highest byte of flags can contain suggested window state (maximized, hidden, etc), like with run. To store a value to the highest byte, use value<<24. For example, to run the program hidden, use flags|(16<<24).

 

Not available in exe.

 


#AllowActivateWindows ;;Returns 1 if successful

 

By default, Windows does not allow background programs to activate windows. QM is usually running in the background. Use this function to temporarily allow QM to activate windows. For example, this function is called by act, run and ShowDialog.

 


%GetFileOrFolderSize $folder

 

QM 2.2.0.

Returns the size of a file, folder or drive. Calculating folder size may took several seconds because are enumerated all files in the folder and subfolders. For drives, returns the used size (total-available). To get drive sizes, uses API function GetDiskFreeSpaceEx, except for network drives.

 


GetFullPath $sAny str*sFull

 

QM 2.3.0.

Gets full path of a file or folder. Expands special folders, etc. Does not check if the file exists.

 

sAny - full or relative path. If it is relative path, prepends current directory. Can begin or be "." (current directory) or ".." (parent) or "" (same as "."). If it is a drive letter without "\", appends "\".

sFull - receives full path.

 


#PidlToStr ITEMIDLIST*pidl str*s flags ;;Returns 1 if successful. flags: 1 must be path, 2 must be pidl string

 

Converts ITEMIDLIST to file system path or string in QM format (":: XXXX..."). Read more.

 

ITEMIDLIST*PidlFromStr $s

 

Converts path or ":: XXXX..." string to ITEMIDLIST. Use CoTaskMemFree to free it.

 


#CreateShortcutEx $shortcut SHORTCUTINFO*si ;;Returns 1 if successful.

 

Creates shortcut. All si members except target are optional. You can also use simpler function CreateShortcut.

 

#GetShortcutInfoEx $shortcut SHORTCUTINFO*si ;;Returns 1 if successful.

 

Gets shortcut's parameters (target path, icon, etc).

 

shortcut - shortcut file (.lnk) path.

si - address of a variable that contains or receives shortcut properties. The variable must be of type SHORTCUTINFO which is described below.

 

type SHORTCUTINFO ~target ~param ~initdir ~descr ~iconfile iconindex showstate @hotkey

 

Some members:

target - file/folder path, or ITEMIDLIST string.

hotkey - hot key. Low-order byte is virtual-key code. High-order byte is combination of HOTKEYF_ALT, HOTKEYF_CONTROL, HOTKEYF_SHIFT, HOTKEYF_EXT.

 

Example

 

 Create shortcut with all possible attributes
SHORTCUTINFO si.target="$system$\notepad.exe"
si.iconfile="shell32.dll"
si.iconindex=4
si.descr="test descr"
si.hotkey=HOTKEYF_CONTROL<<8|VK_F6
si.initdir="$my qm$"
si.param="-p"
si.showstate=SW_MAXIMIZE
CreateShortcutEx("$desktop$\test.lnk" &si)

 


#GetFileIcon _file [index] [flags] ;;Returns icon handle if successful. Later call DestroyIcon. flags: 1 large, 2 don't use shell icon

 

Extracts icon from an icon file, or gets icon for a file that itself does not contain icons. Returns icon handle. When it is no longer needed, destroy it using DestroyIcon.

 

_file - any file or folder. Can be path or ITEMIDLIST string. Can be only filename.

index - 0, or icon index (0-based). If negative, index is interpreted as negative resource id. Alternatively, icon index can be appended to _file. Example: "shell32.dll,3".

flags:

1 - get large icon (32x32). By default, gets small icon (16x16).

2 - don't use shell icon. Read more below.

 

For ico files, always extracts icon from the file. For other files, extracts icon from the file if index is nonzero, or icon index is appended to _file, or flag 2 is used. Otherwise, gets icon shell icon (icon that would be displayed in Windows Explorer).

 

If _file begins with dot and does not contain more dots, gets icon associated with that file type. Example: ".txt".

 

If _file begins with semicolon, it is interpreted as resource id in exe. Examples: ":150", "&:150", ":151 file.ico".

 

To get window icon, use GetWindowIcon.

 

Example

int hi=GetFileIcon("shell32.dll" 3 1)
int dc=GetDC(0)
DrawIconEx dc 300 200 hi 32 32 0 0 DI_NORMAL
ReleaseDC 0 dc
DestroyIcon hi

 


#GetWindowIcon hwnd ;;Returns icon handle if successful. Later call DestroyIcon.

 

Gets icon that is displayed in top-left corner of window hwnd.

 


#SaveBitmap hbitmap $_file ;;Returns 1 if successful.

 

Saves bitmap to a file.

 

hbitmap - bitmap handle.

_file - .bmp file.

 


#LoadPictureFile _file [flags] ;;Returns bitmap handle. flags: 1 return stdole.IPicture

 

Loads bitmap from a bmp, jpg or gif file.

 

If _file begins with semicolon , it is interpreted as bitmap resource id in exe. Examples: ":1", ":2 file.bmp".

 


#RegisterComComponent $path flags ;;flags: 1 unregister, 2 check extension (must be dll or ocx), 4 run as admin, 8 show error/success message box

 

QM 2.2.0.

Registers or unregisters a COM component (dll, ocx). Returns 1 if successful, 0 if not.

 

Requires admin privileges. Use flag 4 to run as admin (possibly with a "run as" or consent dialog, especially in exe).

 

QM 2.2.1. Internally runs regsvr32.exe. Now can also register 64-bit dlls. Added flag 8.

 


#QmRegisterDropTarget hwndTarget hwndNotify flags ;;flags: 1 notify on enter, 2 notify on over, 4 notify on leave, 16 need only files, 32 need .lnk

 

QM 2.2.0.

Registers a window as an OLE drag and drop target. Returns 1 on success, 0 on failure.

 

Can be used to receive paths of dropped files, other shell objects and Internet links. Also can be used to receive dropped data of other formats (text, HTML, etc).

 

The most important advantage over WS_EX_ACCEPTFILES/WM_DROPFILES is that this method works well on Windows Vista. WM_DROPFILES does not work on Vista under UAC, because Vista does not allow to drag and drop files from Medium integrity level (IL) processes (like Windows Explorer) to windows of higher IL processes (like QM). Other advantages - you can receive not only file system paths, but also ITEMIDLIST strings of other shell objects, URLs of dropped Internet links, and data of other formats.

 

The information below may be hard to understand. Also, most of it is not useful in most cases. You can start from the example. Also, you can ask about it in the QM forum.

 

QmRegisterDropTarget arguments:

 

hwndTarget - the handle of the target window. It can be a top level window (e.g. a custom dialog) or a child window (e.g. an edit control in a dialog).

hwndNotify - the handle of the window that will receive notifications. For example, if the target is a control in a dialog, you'll probably want to receive notifications in the dialog procedure, and therefore set hwndNotify to the dialog handle (hDlg). Can be 0 if it is the same window.

flags - 1 notify on enter, 2 notify on over, 4 notify on leave, 16 need only files, 32 need .lnk (don't extract shortcut target).

On drag and drop events, the hwndNotify window receives WM_QM_DRAGDROP message. By default, the message is sent only on drop, unless flags 1, 2, and/or 4 are used.

 

wParam - 0 on drag enter, 1 on drag over, 2 on drag leave, 3 on drop.

lParam - address of variable of QMDRAGDROPINFO type. Members:

 

hwndTarget - target window handle.

dataObj - IDataObject interface pointer. Available on drag enter and drop. Can be used to extract data of various formats. Window Vista: when running under UAC, only GetData function is valid, and can retrieve only data decribed as TYMED_HGLOBAL.

formats - array of available formats. Available on drag enter and drop. A format is described by a FORMATETC type.

keyState - modifier keys and mouse buttons.

pt - mouse pointer position.

effect - combination of available drop effects (copy, move, link, etc). Available on drag enter, over and drop. If you did not use flag 16, you should remove effects you don't accept. To remove, use the & operator.

files - list of dropped files, other shell objects and Internet links. Valid only on drop. In most cases, it is the only member you need.

 

IDataObject, FORMATETC, keyState, effect are documented in the MSDN Library. Look for IDropTarget and IDataObject interfaces. In most cases you will not need it.

 

Usually you'll need only files. To register drop target window, call QmRegisterDropTarget with flags 16. Then the message will be sent only on drop, and QM sets proper effect. In the window or dialog procedure, assign lParam to a QMDRAGDROPINFO* variable, get files, and return 0. See example.

 

If you also need other notifications, set other flags. Also, on WM_QM_DRAGDROP return 1. To return 1 from a dialog procedure, use ret DT_Ret(hDlg 1). Always return 1 if you have modified effect.

 

Toolbars: By default, the child toolbar control is a drop target. To replace default drag and drop feature, use something like this in hook procedure on WM_INITDIALOG: QmRegisterDropTarget(wParam hWnd 16). Or you can register the toolbar window (QmRegisterDropTarget(hWnd 0 16)) as a drop target. It is covered by the child toolbar control, so you would have to make the control smaller. On WM_INITDIALOG, resize the control (siz), and on WM_SIZE return 1.

 

Exe: On Vista, drag and drop does not work if the drop source process has lower integrity level.

 

Example

 

Function DropTargetExampleDialog

 

\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

str controls = "3"
str e3
if(!ShowDialog("DropTargetExampleDialog" &DropTargetExampleDialog &controls)) ret

 BEGIN DIALOG
 0 "" 0x90C80A44 0x100 0 0 223 41 "Dialog"
 1 Button 0x54030001 0x4 4 22 46 14 "OK"
 2 Button 0x54030000 0x4 54 22 46 14 "Cancel"
 3 Edit 0x54030080 0x200 4 4 216 14 ""
 END DIALOG
 DIALOG EDITOR: "" 0x2020006 "" ""

ret
 messages
sel message
	case WM_INITDIALOG
	QmRegisterDropTarget(id(3 hDlg) hDlg 16)
	case WM_DESTROY
	case WM_COMMAND goto messages2
	case WM_QM_DRAGDROP
	QMDRAGDROPINFO& di=+lParam
	 set edit box
	str s.getl(di.files 0) ;;get first file
	s.setwintext(id(3 hDlg))
	 to get all dropped files, you can use eg foreach. Example: foreach(s di.files) out s
ret
 messages2
sel wParam
	case IDOK
	case IDCANCEL
ret 1

 


#QmUnregisterDropTarget hwndTarget

 

QM 2.2.0.

Unregisters drop target. Optional. Returns 1 on success, 0 on failure.

 


#GetExeResHandle

 

QM 2.1.9.

Returns module handle that can be used with API resource functions. Useful in exe.

 


#ExeExtractFile resid $dest [flags] ;;Returns: 1 success, 0 failed. flags: must be 0

 

QM 2.2.0.

Extracts a file added to exe. The file can be added to exe using #exe addfile or using a resource editor (use resource type RT_RCDATA (10)). Returns 1 on success, 0 on failure. This function works only in exe. It should not be used when the macro runs in QM.

 

resid - resource id. Use the same resid as with #exe addfile.

dest - destination file. To extract to exe's folder, use "$qm$\filename.ext" or just "filename.ext". To extract to temporary folder, use for example "$temp$\myexename\filename.ext". If the folder does not exist, creates. If the file already exists, compares resource data with existing file data, and replaces existing file only if it is different.

flags - currently not used and must be 0.

 

Example

 

#if EXE

#exe addfile "$desktop$\test.txt" 1

str fn="$temp$\testexe\test.txt"
if(!ExeExtractFile(1 fn)) ret
run fn

#else

run "$desktop$\test.txt"

#endif

 

Example of extracting a dll file and calling functions from it.

 


#ExeGetResourceData resType resId str*data ;;Returns: 1 success, 0 failed. resType: if 0, uses RT_RCDATA

 

QM 2.2.0.

Stores exe resource data to a str variable. Returns 1 on success, 0 on failure. This function is used in exe. It also works while the macro runs in QM, if the exe is already created.

 

resType - resource type. If 0, uses RT_RCDATA.

resId - resource id.

data - address of a str variable that will receive the data.

 

Example

 

#exe addfile "$desktop$\test.txt" 1
str s
if(!ExeGetResourceData(0 1 &s)) ret
out s

 


#Crc32 !*data nbytes ;;Returns CRC of data. If data is string, nbytes can be string length or -1.

 

Calculates CRC checksum of a string or binary data. See also: str.encrypt (MD5).

 


^Round ^number [cDec] ;;Returns number rounded to cDec digits after decimal point

 

QM 2.2.1.

Returns number rounded to cDec digits after decimal point. Can be used to convert a floating-point (double) value to nearest int value.

 

This and other math functions are added to the math category.

 

Examples

 

int i
i=1.1 ;;1
i=1.9 ;;1
i=Round(1.1 0) ;;1
i=Round(1.9 0) ;;2
i=Round(1.5 0) ;;2 (.5 rounds to the nearest even number)
i=Round(2.5 0) ;;2 (.5 rounds to the nearest even number)
double d=Round(1.5555 2) ;;1.56

 


^RandomNumber ;;Returns random number between 0.0 and 1.0, not including them

 

QM 2.2.1.

Random number generator. Returns a random value between 0 and 1, not including them. The value can be multiplied to get a random double number in any range.

 


#RandomInt bound1 bound2 ;;Returns random number between bound1 and bound2, including them

 

QM 2.2.1.

Returns a random integer value between bound1 and bound2, including them.

 


#GetQmCodeEditor

 

QM 2.3.0.

Returns QM code editor control handle. If there are two controls, returns one that is currently active, ie has focus or had focus more recently. Use this function instead of id(2210 _hwndqm).

 

In QM 2.3.0 and later, QM code editor, output and some other controls are based on Scintilla control. In older versions - rich edit control. Therefore, if you have macros created in older QM versions that use rich edit control messages with these controls, they may stop working. Also, str.getwintext and str.setwintext now does not work because the new control does not support WM_GETTEXT and WM_SETTEXT messages. Now use Scintilla messages. The required constants are in SCI reference file. Also, control id 2203 has been changed to 2210 (primary) and 2211 (right/bottom). See also: InsertStatement (below).

 

Scintilla is a free source code editing component. Copyright 1998-2003 by Neil Hodgson, All Rights Reserved.

 

Example

 

str s
int h=GetQmCodeEditor
int lens=SendMessage(h SCI.SCI_GETTEXTLENGTH 0 0)
s.fix(SendMessage(h SCI.SCI_GETTEXT lens+1 s.all(lens)))
out s

 


InsertStatement $s [label] [icon] [flags] ;;flags: 1 simple, 2 set focus, 4 don't indent

 

QM 2.3.0.

Inserts QM code into the QM editor. Inserts at current position. Inserts as separate line, properly indents, etc.

 

s - one or more QM statements (commands).

label - label of menu item or toolbar button. Default: "Label". With other item types, it is appended as comments.

icon - icon file.

flags: 1 - simply insert the string in current position, not necessary as separate line. 2 - set focus. 4 - don't indent.

 

Not available in exe.


[HtmlHelpU]#HtmlHelp hwndCaller $pszFile uCommand dwData ;;Same as WinAPI function HtmlHelp, but supports UTF-8. For reference, search for HtmlHelp in MSDN Library.

 

Controls HTML help. Same as the Windows API function with same name. For reference, search for HtmlHelp in the MSDN Library.

 


#SpecFoldersMenu hwnd str*s ;;returns 1 if selected

 

Shows menu of special folders and gets selected string.

 

hwnd - menu owner window handle.

s - address of a str variable that receives the string.

 


#CreateRegExpMenu [flags] ;;flags must be 0

 

QM 2.1.9.

Creates menu for regular expressions to use with TrackPopupMenuEx.

 


#RecGetWindowName hwnd str*s [flags] ;;flags: must be 0

 

Gets window name as it would be recorded, with respect to the settings in the Recording Windows dialog. Actually it will not be just window name, because QM records windows as win function. Returns 1 if it is win function, 2 if it is some other expression, 0 if fails.

 

hwnd - window handle.

s - address of a str variable that receives the string.

 

QM 2.3.0. Works well with controls too. Formats either id or child function, which is better in that case.

 

Not available in exe.

 


OnScreenRect action RECT*r ;;action: 1 begin, 0 move, 2 end, 3 temporarily hide

 

QM 2.2.0.

Draws on-screen rectangle.

 

r - address of a RECT variable that contains rectangle coordinates.

 

Not available in exe.

 


CompileAllItems $startfrom [flags] ;;flags: must be 0

 

Compiles multiple macros and functions. Purpose - quickly check for errors multiple macros and functions. startfrom can be either item name or id (<0x10000). If startfrom is 0, compiles all. If startfrom is folder, compiles all in that folder. If startfrom is not folder, compiles all starting from startfrom. Should be called soon after startup. Otherwise, some items may be skipped. Does not compile menus and toolbars. On error, pops up error message with item id. Item id can be edited to skip several subsequent items. Click OK to continue, or Cancel to stop.

 

Not available in exe.

 


FormatKeyString !vk !mod str*s ;;mod: 1 Shift, 2 Ctrl, 4 Alt, 8 Win.

 

QM 2.1.9.

Gets keystroke text for a key and/or modifiers. The text will be like "Ctrl+Page Up".

 

vk - virtual-key code.

mod - modifiers. See GetMod.

s - address of a str variable that receives the text. If s initially is not empty, appends to the end.

 


EditReplaceSel hDlg cid $s [flags] ;;flags: 1 replace all, 2 set focus

 

QM 2.3.0.

Inserts or replaces text in an Edit control. Unlike str.setwintext, can replace only selection, or just insert if there is no selection. Also, does not disable Undo. The function is intended to use in QM dialogs, but also works with edit controls in other threads and processes, except flag 2.

 

hDlg, cid - either Edit control handle and 0, or parent window handle and Edit control id.

s - text.