org.safs.natives.win32
Interface User32


public interface User32

A JNA Library definition for the Windows user32.dll

JNA Home Page

Since:
2009.02.03
See Also:
NativeWrapper

Nested Class Summary
static interface User32.CallWndProcCallBack
          Callback function interface to CallWndProc for hook type WH_CALLWNDPROC
static class User32.CWPSTRUCT
           
static interface User32.GetMsgProcCallBack
          Callback function interface to GetMsgProc for hook type WH_GETMESSAGE
static class User32.KBDLLHOOKSTRUCT
          define Hook structure about a low-level keyboard input event.
static interface User32.KeyBoardCallBack
          Callback function interface to KeyboardProc for hook type WH_KEYBOARD
static interface User32.LLKeyBoardCallBack
          Callback function interface to LowLevelKeyboardProc for hook type WH_KEYBOARD_LL
static interface User32.LLMouseCallBack
          Callback function interface to LowLevelMouseProc for hook type WH_MOUSE_LL
static interface User32.MouseCallBack
          Callback function interface to MouseProc for hook type WH_MOUSE
static class User32.MOUSEHOOKSTRUCT
          Refer to MSDN: Contains information about a mouse event passed to a WH_MOUSE hook procedure typedef struct tagMOUSEHOOKSTRUCT { POINT pt; HWND hwnd; UINT wHitTestCode; ULONG_PTR dwExtraInfo; } MOUSEHOOKSTRUCT, *PMOUSEHOOKSTRUCT, *LPMOUSEHOOKSTRUCT;
static class User32.MSG
          typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG
static class User32.MSLLHOOKSTRUCT
          Contains information about a low-level mouse input event.
static class User32.POINT
          typedef struct tagPOINT { LONG x; LONG y; } POINT, *PPOINT;
static interface User32.WNDENUMPROC
          Callback Function used for User32 EnumWindows
 
Field Summary
static User32 INSTANCE
           
 
Method Summary
 Pointer CallNextHookEx(Pointer hhk, int nCode, NativeLong wParam, Pointer lParam)
          Refer to MSDN: LRESULT WINAPI CallNextHookEx(_in_opt HHOOK hhk, _in int nCode, _in WPARAM wParam, _in LPARAM lParam);
 Pointer DispatchMessageA(User32.MSG msg)
          Dispatches a message to a window procedure.
 boolean EnumChildWindows(NativeLong parent, User32.WNDENUMPROC lpEnumFunc, Pointer arg)
          The EnumChildWindows function enumerates all child windows of the parent window by passing the handle to each child window, in turn, to an application-defined callback function.
 boolean EnumWindows(User32.WNDENUMPROC lpEnumFunc, Pointer arg)
          The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function.
 NativeLong GetDesktopWindow()
          HWND GetDesktopWindow(VOID) The GetDesktopWindow function returns a handle to the main Desktop window (the window on which all other windows are painted).
 NativeLong GetForegroundWindow()
          HWND GetForegroundWindow(VOID) The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working).
 int GetGuiResources(Pointer hProcess, int uiFlags)
          DWORD WINAPI GetGuiResources(_in HANDLE hProcess, _in DWORD uiFlags);
 short GetKeyState(int vkcode)
          SHORT WINAPI GetKeyState(__in int nVirtKey)
 NativeLong GetMenu(NativeLong hWnd)
           
 int GetMenuItemCount(NativeLong hMenu)
           
 int GetMenuItemID(NativeLong hMenu, int nPos)
           
 int GetMenuState(NativeLong hMenu, int uId, int uFlags)
           
 int GetMenuStringW(NativeLong hMenu, int uIDItem, Pointer lpString, int nMaxCount, int uFlag)
           
 int GetMessageA(User32.MSG pMsg, NativeLong hwnd, int wMsgFilterMin, int wMsgFilterMax)
          Refer to MSDN: BOOL WINAPI GetMessage(__out LPMSG lpMsg,__in_opt HWND hWnd, __in UINT wMsgFilterMin, __in UINT wMsgFilterMax);
 NativeLong GetSubMenu(NativeLong hMenu, int nPos)
           
 int GetWindowTextA(NativeLong hWnd, Pointer lpString, int nMaxCount)
          int WINAPI GetWindowText( __in HWND hWnd, __out LPTSTR lpString, __in int nMaxCount );
 int GetWindowThreadProcessId(NativeLong hWnd, Pointer pidOut)
          The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window.
 boolean IsMenu(NativeLong hMenu)
           
 boolean IsWindow(NativeLong hWnd)
           
 Pointer SetWindowsHookExA(int idHook, StdCallCallback lpfn, Pointer hMod, int dwThreadId)
          Refer to MSDN: HHOOK WINAPI SetWindowsHookEx(__in int idHook,__ *in HOOKPROC lpfn,__in HINSTANCE hMod,__in DWORD dwThreadId);
 Pointer SetWindowsHookExW(int idHook, StdCallCallback lpfn, Pointer hMod, int dwThreadId)
           
 boolean TranslateMessage(User32.MSG msg)
          Translates virtual-key messages into character messages.
 boolean UnhookWindowsHookEx(Pointer hProcess)
          Refer to MSDN: BOOL WINAPI UnhookWindowsHookEx(__in HHOOK hhk)
 

Field Detail

INSTANCE

static final User32 INSTANCE
Method Detail

GetForegroundWindow

NativeLong GetForegroundWindow()
HWND GetForegroundWindow(VOID) The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working).

The user should not normally call this method directly, but should try to call the NativeWrapper library instead.

Returns:
HWND wrapped in a JNA NativeLong
See Also:
NativeWrapper.GetForegroundWindow()

GetDesktopWindow

NativeLong GetDesktopWindow()
HWND GetDesktopWindow(VOID) The GetDesktopWindow function returns a handle to the main Desktop window (the window on which all other windows are painted).

The user should not normally call this method directly, but should try to call the NativeWrapper library instead.

Returns:
HWND wrapped in a JNA NativeLong
See Also:
NativeWrapper.GetDesktopWindow()

EnumWindows

boolean EnumWindows(User32.WNDENUMPROC lpEnumFunc,
                    Pointer arg)
The EnumWindows function enumerates all top-level windows on the screen by passing the handle to each window, in turn, to an application-defined callback function. EnumWindows continues until the last top-level window is enumerated or the callback function returns FALSE.

Parameters:
lpEnumFunc - instance of callback function WNDENUMPROC
arg -
Returns:

EnumChildWindows

boolean EnumChildWindows(NativeLong parent,
                         User32.WNDENUMPROC lpEnumFunc,
                         Pointer arg)
The EnumChildWindows function enumerates all child windows of the parent window by passing the handle to each child window, in turn, to an application-defined callback function. EnumChildWindows continues until the last child window is enumerated or the callback function returns FALSE.

Parameters:
Handle - to parent window
lpEnumFunc - instance of callback function WNDENUMPROC
arg -
Returns:

GetWindowThreadProcessId

int GetWindowThreadProcessId(NativeLong hWnd,
                             Pointer pidOut)
The GetWindowThreadProcessId function retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window.

Parameters:
hWnd - -- [in] Handle to the window.
pidOut - -- [out] Pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.
Returns:
-- The return value is the identifier of the thread that created the window.

GetGuiResources

int GetGuiResources(Pointer hProcess,
                    int uiFlags)
DWORD WINAPI GetGuiResources(_in HANDLE hProcess, _in DWORD uiFlags);

Retrieves the count of handles of GUI objects used by the specified process.

We usually want to get USER objects. These are: Accelerator table -- Keyboard Accelerators, Caret -- Carets, Cursor -- Cursors, DDE conversation -- Dynamic Data Exchange Management Library, Hook -- Hooks, Icon -- Icons, Menu -- Menus, Window -- Windows, Window position -- Windows.

GDI objects: Bitmap -- Bitmaps, Brush -- Brushes, DC -- Device Contexts, Enhanced metafile -- Metafiles, Enhanced-metafile DC -- Metafiles, Font -- Fonts and Text, Memory DC -- Device Contexts, Metafile -- Metafiles, Metafile DC -- Metafiles, Palette -- Colors, Pen and extended pen -- Pens, Region -- Regions.

Parameters:
hProcess - - HANDLE received from OpenProcess
uiFlags - -- 0= get count of GDI objects. 1=count of USER objects.
Returns:

SetWindowsHookExA

Pointer SetWindowsHookExA(int idHook,
                          StdCallCallback lpfn,
                          Pointer hMod,
                          int dwThreadId)
Refer to MSDN: HHOOK WINAPI SetWindowsHookEx(__in int idHook,__ *in HOOKPROC lpfn,__in HINSTANCE hMod,__in DWORD dwThreadId);

Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread.

Parameters:
idHook - -- the type of hook procedure to be installed.
lpfn - -- a pointer to the hook procedure.
hMod - -- a handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId - -- the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
Returns:
the return value is the handle to the hook procedure if the function succeeds.

SetWindowsHookExW

Pointer SetWindowsHookExW(int idHook,
                          StdCallCallback lpfn,
                          Pointer hMod,
                          int dwThreadId)

UnhookWindowsHookEx

boolean UnhookWindowsHookEx(Pointer hProcess)
Refer to MSDN: BOOL WINAPI UnhookWindowsHookEx(__in HHOOK hhk)

Removes a hook procedure installed in a hook chain by the SetWindowsHookEx function.

Parameters:
hProcess - -- A handle to the hook to be removed. This parameter is a hook handle obtained by a previous call to SetWindowsHookEx.
Returns:
0 if fails; non zero if succeeds.

CallNextHookEx

Pointer CallNextHookEx(Pointer hhk,
                       int nCode,
                       NativeLong wParam,
                       Pointer lParam)
Refer to MSDN: LRESULT WINAPI CallNextHookEx(_in_opt HHOOK hhk, _in int nCode, _in WPARAM wParam, _in LPARAM lParam);

Passes the hook information to the next hook procedure in the current hook chain. A hook procedure can call this function either before or after processing the hook information

Parameters:
hhk - -- optional, this parameter is ignored.
nCode - -- hook code,next hook procedure uses this code to determine how to process the hook information.
wParam - -- the wParam value, its meaning depends on the type of hook associated with the current hook chain.
lParam - -- the lParam value, its meaning depends on the type of hook associated with the current hook chain.
Returns:
a internal value returned by the next hook procedure in the chain;current hook procedure must also return this value.

GetMessageA

int GetMessageA(User32.MSG pMsg,
                NativeLong hwnd,
                int wMsgFilterMin,
                int wMsgFilterMax)
Refer to MSDN: BOOL WINAPI GetMessage(__out LPMSG lpMsg,__in_opt HWND hWnd, __in UINT wMsgFilterMin, __in UINT wMsgFilterMax);

Retrieves a message from the calling thread's message queue. The function dispatches incoming sent messages until a posted message is available for retrieval.

Parameters:
pMsg - -- A pointer to an MSG structure that receives message information from the thread's message queue.
hwnd - -- A handle to the window whose messages are to be retrieved. The window must belong to the current thread. If this value is NULL, this method obtains messages for any window that belongs to the calling thread.
wMsgFilterMin - -- the lowest message value obtained.
wMsgFilterMax - -- the lowest message value obtained. If wMsgFilterMin and wMsgFilterMax are both zero, this method returns all available messages; that is, no range filtering is performed.
Returns:
0 if retrieves WM_QUIT; nonzero if other than WM_QUIT.

TranslateMessage

boolean TranslateMessage(User32.MSG msg)
Translates virtual-key messages into character messages.

Parameters:
msg - -- A pointer to an MSG structure that contains message information retrieved from the calling thread's message queue by using the GetMessage or PeekMessage function.
Returns:
nonzero if the message is translated (that is, a character message is posted to the thread's message queue). 0 if the message is not translated.

DispatchMessageA

Pointer DispatchMessageA(User32.MSG msg)
Dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.

Parameters:
msg - -- A pointer to a structure that contains the message.
Returns:
The return value specifies the value returned by the window procedure. Although its meaning depends on the message being dispatched, the return value generally is ignored.

GetKeyState

short GetKeyState(int vkcode)
SHORT WINAPI GetKeyState(__in int nVirtKey)

Retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off-alternating each time the key is pressed.

Parameters:
vkcode - -- A virtual key.
Returns:
The return value specifies the status of the specified virtual key. (see details in MSDN)

GetWindowTextA

int GetWindowTextA(NativeLong hWnd,
                   Pointer lpString,
                   int nMaxCount)
int WINAPI GetWindowText( __in HWND hWnd, __out LPTSTR lpString, __in int nMaxCount );


GetMenu

NativeLong GetMenu(NativeLong hWnd)
Parameters:
hWnd - A handle to the window whose menu handle is to be retrieved.
Returns:
The return value is a handle to the menu. If the specified window has no menu, the return value is NULL. If the window is a child window, the return value is undefined.

IsMenu

boolean IsMenu(NativeLong hMenu)
Parameters:
hMenu - A handle to be tested.
Returns:
If the handle is a menu handle, the return value is nonzero If the handle is not a menu handle, the return value is zero

GetMenuItemCount

int GetMenuItemCount(NativeLong hMenu)
Parameters:
hMenu - A handle to the menu to be examined
Returns:
If the function succeeds, the return value specifies the number of items in the menu If the function fails, the return value is -1

GetMenuStringW

int GetMenuStringW(NativeLong hMenu,
                   int uIDItem,
                   Pointer lpString,
                   int nMaxCount,
                   int uFlag)
Parameters:
hMenu - A handle to the menu
uIDItem - The menu item to be changed, as determined by the uFlag parameter
lpString - The buffer that receives the null-terminated string. If the string is as long or longer than lpString, the string is truncated and the terminating null character is added. If lpString is NULL, the function returns the length of the menu string
nMaxCount - The maximum length, in characters, of the string to be copied. If the string is longer than the maximum specified in the nMaxCount parameter, the extra characters are truncated. If nMaxCount is 0, the function returns the length of the menu string
uFlag - Indicates how the uId parameter is interpreted. This parameter can be one of the following values MF_BYCOMMAND (0x00000000L) ; MF_BYPOSITION (0x00000400L)
Returns:
If the function succeeds, the return value specifies the number of characters copied to the buffer, not including the terminating null character. If the function fails, the return value is zero. If the specified item is not of type MIIM_STRING or MFT_STRING, then the return value is zero.

GetMenuItemID

int GetMenuItemID(NativeLong hMenu,
                  int nPos)
Parameters:
hMenu - A handle to the menu that contains the item whose identifier is to be retrieved
nPos - The zero-based relative position of the menu item whose identifier is to be retrieved
Returns:
The return value is the identifier of the specified menu item. If the menu item identifier is NULL or if the specified item opens a submenu, the return value is -1

GetMenuState

int GetMenuState(NativeLong hMenu,
                 int uId,
                 int uFlags)
Parameters:
hMenu - A handle to the menu that contains the menu item whose flags are to be retrieved
uId - The menu item for which the menu flags are to be retrieved, as determined by the uFlags parameter
uFlags - Indicates how the uId parameter is interpreted. This parameter can be one of the following values MF_BYCOMMAND (0x00000000L) ; MF_BYPOSITION (0x00000400L)
Returns:
If the specified item does not exist, the return value is -1. If the menu item opens a submenu, the low-order byte of the return value contains the menu flags associated with the item, and the high-order byte contains the number of items in the submenu opened by the item. Otherwise, the return value is a mask (Bitwise OR) of the menu flags.

GetSubMenu

NativeLong GetSubMenu(NativeLong hMenu,
                      int nPos)
Parameters:
hMenu - A handle to the menu
nPos - The zero-based relative position in the specified menu of an item that activates a drop-down menu or submenu
Returns:
If the function succeeds, the return value is a handle to the drop-down menu or submenu activated by the menu item. If the menu item does not activate a drop-down menu or submenu, the return value is NULL

IsWindow

boolean IsWindow(NativeLong hWnd)
Parameters:
hWnd - A handle to the window to be tested
Returns:
If the window handle identifies an existing window, return true.