uLib  User mode C/C++ extended API library for Win32 programmers.
Supplementary User32 APIs

Module Description

User32 related functions. (UserUtil.cpp)

Groups

 Clipboard Support
 
 Floating Point Window Data
 
 MessageBox Supplements
 
 GUI Control Support
 

Macros

#define SYSMET(Id)   GetSystemMetrics( SM_##Id )
 
#define GWL(hwnd, Item)   GetWindowLong( hwnd, GWL_##Item )
 
#define GWLP(hwnd, Item)   GetWindowLongPtr( hwnd, GWLP_##Item )
 
#define SYSICO(Id)   LoadIcon( NULL, IDI_##Id )
 
#define SYSCUR(Id)   LoadCursor( NULL, IDC_##Id )
 
#define LOADICO(Id)   LoadIcon( hInstance, CSTR( Id ))
 
#define WS_VISICHILD   (WS_CHILD | WS_VISIBLE)
 
#define WS_SCROLL   (WS_VSCROLL | WS_HSCROLL)
 
#define CS_REDRAW   (CS_HREDRAW | CS_VREDRAW)
 
#define WM_Cut(hCtl)   SendMessage( hCtl, WM_CUT, 0,0 )
 
#define WM_Copy(hCtl)   SendMessage( hCtl, WM_COPY, 0,0 )
 
#define WM_Paste(hCtl)   SendMessage( hCtl, WM_PASTE, 0,0 )
 
#define WM_Clear(hCtl)   SendMessage( hCtl, WM_CLEAR, 0,0 )
 
#define SimpleBeep()   MessageBeep( -1 )
 
#define GetAcceleratorCount(hacc)   CopyAcceleratorTable( (HACCEL)(hacc), NULL, 0 )
 
#define GetWndStyle(hwnd)   GetWindowLong( hwnd, GWL_STYLE )
 
#define SetWndStyle(hwnd, style)   SetWindowLong( hwnd, GWL_STYLE, style )
 
#define GetWndExStyle(hwnd)   GetWindowLong( hwnd, GWL_EXSTYLE )
 
#define SetWndExStyle(hwnd, style)   SetWindowLong( hwnd, GWL_EXSTYLE, style )
 
#define WM_GetFont(hwnd)   (HFONT)SendMessage( hwnd, WM_GETFONT, 0,0 )
 
#define WM_SetFont(hwnd, hfnt, rdrw)   (void)SendMessage( hwnd, WM_SETFONT, (WPARAM)hfnt, rdrw )
 
#define WM_SetRedraw(hwnd, on)   SendMessage( hwnd, WM_SETREDRAW, on, 0 )
 

Functions

UINT DispatchMessagesFor (HWND hWnd)
 
UINT GetWndHeight (HWND hWnd)
 
UINT GetWndWidth (HWND hWnd)
 
bool GetWndSize (HWND hWnd, SIZE *pSize)
 
bool GetWndPos (HWND hWnd, POINT *pPos)
 
BOOL GetWindowMinimizeRect (HWND hTrayApp, RECT *pRect)
 
bool CenterWindow (HWND hWnd, HWND hOwner)
 
void GetChildWndRect (HWND hCtrl, RECT *pRc)
 
bool EnableChildWnd (HWND Owner, UINT Id, bool Enable)
 
HWND GetChildWndWithId (HWND hParent, UINT ChildId)
 
HWND SetParentWnd (HWND hWnd, HWND newParent)
 
HWND CreateWindowIndirect (LPCREATESTRUCT pc)
 
INT_PTR DialogBoxParamEx (HINSTANCE hInst, CSTR Template, HWND hParent, DLGPROC DlgProc, LPARAM lParam, LANGID Language)
 
HWND CreateDialogParamEx (HINSTANCE hInst, CSTR Template, HWND hParent, DLGPROC DlgProc, LPARAM lParam, LANGID Language)
 
bool GetRequiredWindowSize (HWND hWnd, IN const PSIZE pClient, OUT PSIZE pWindow)
 
bool GetWindowClientSize (HWND hWnd, IN const PSIZE pWindow, OUT PSIZE pClient)
 
bool RefreshWnd (HWND hWnd)
 
bool RedrawWnd (HWND hWnd, UINT Flags)
 
bool RedrawWndRect (HWND hWnd, PRECT pRect, UINT Flags)
 
bool RedrawWndRgn (HWND hWnd, HRGN hRgn, UINT Flags)
 
bool MoveWnd (HWND hWnd, int X, int Y, bool Repaint)
 
bool ResizeWnd (HWND hWnd, int W, int H, bool Repaint)
 
bool __cdecl SetCaption (HWND hwnd, CSTR fmt,...)
 
void WINAPI SetRedraw (HWND hwnd, bool on)
 
HICON WINAPI LoadSmallIcon (HINSTANCE hInst, CSTR Id)
 
PVOID WINAPI LoadCustomResource (HMODULE hModule, CSTR Id, CSTR Type, UINT *pSize OPTOUT=NULL)
 
PVOID WINAPI LoadCustomResourceEx (HMODULE hModule, CSTR Id, CSTR Type, LANGID Language OPTIN=0, UINT *pSize OPTOUT=NULL)
 
IPicture *WINAPI LoadPictureResource (HMODULE hModule, CSTR Id, CSTR Type)
 
IPicture *WINAPI LoadPictureFile (CSTR FName)
 
void WINAPI PaintPicture (IPicture *pPic, HDC hdc, int x, int y, int cx=0, int cy=0)
 
bool WINAPI PaintPictureEx (IPicture *pPic, HDC hdc, long x, long y, long cx=0, long cy=0, long imx=0, long imy=0, long imw=0, long imh=0, PRECT prMeta=NULL)
 
long WINAPI HiMetricToPix (long hiMetric)
 
long WINAPI PixToHiMetric (long Pix)
 

Macro Definition Documentation

◆ SYSMET

#define SYSMET (   Id)    GetSystemMetrics( SM_##Id )

Definition at line 923 of file UtilFunc.h.

◆ GWL

#define GWL (   hwnd,
  Item 
)    GetWindowLong( hwnd, GWL_##Item )

Definition at line 926 of file UtilFunc.h.

◆ GWLP

#define GWLP (   hwnd,
  Item 
)    GetWindowLongPtr( hwnd, GWLP_##Item )

Definition at line 927 of file UtilFunc.h.

◆ SYSICO

#define SYSICO (   Id)    LoadIcon( NULL, IDI_##Id )

Definition at line 930 of file UtilFunc.h.

◆ SYSCUR

#define SYSCUR (   Id)    LoadCursor( NULL, IDC_##Id )

Definition at line 931 of file UtilFunc.h.

◆ LOADICO

#define LOADICO (   Id)    LoadIcon( hInstance, CSTR( Id ))

Definition at line 934 of file UtilFunc.h.

◆ WS_VISICHILD

#define WS_VISICHILD   (WS_CHILD | WS_VISIBLE)

Definition at line 938 of file UtilFunc.h.

◆ WS_SCROLL

#define WS_SCROLL   (WS_VSCROLL | WS_HSCROLL)

Definition at line 939 of file UtilFunc.h.

◆ CS_REDRAW

#define CS_REDRAW   (CS_HREDRAW | CS_VREDRAW)

Definition at line 942 of file UtilFunc.h.

◆ WM_Cut

#define WM_Cut (   hCtl)    SendMessage( hCtl, WM_CUT, 0,0 )

Definition at line 946 of file UtilFunc.h.

◆ WM_Copy

#define WM_Copy (   hCtl)    SendMessage( hCtl, WM_COPY, 0,0 )

Definition at line 947 of file UtilFunc.h.

◆ WM_Paste

#define WM_Paste (   hCtl)    SendMessage( hCtl, WM_PASTE, 0,0 )

Definition at line 948 of file UtilFunc.h.

◆ WM_Clear

#define WM_Clear (   hCtl)    SendMessage( hCtl, WM_CLEAR, 0,0 )

Definition at line 949 of file UtilFunc.h.

◆ SimpleBeep

#define SimpleBeep ( )    MessageBeep( -1 )

Definition at line 952 of file UtilFunc.h.

◆ GetAcceleratorCount

#define GetAcceleratorCount (   hacc)    CopyAcceleratorTable( (HACCEL)(hacc), NULL, 0 )

Definition at line 953 of file UtilFunc.h.

◆ GetWndStyle

#define GetWndStyle (   hwnd)    GetWindowLong( hwnd, GWL_STYLE )

Definition at line 1121 of file UtilFunc.h.

◆ SetWndStyle

#define SetWndStyle (   hwnd,
  style 
)    SetWindowLong( hwnd, GWL_STYLE, style )

Definition at line 1122 of file UtilFunc.h.

◆ GetWndExStyle

#define GetWndExStyle (   hwnd)    GetWindowLong( hwnd, GWL_EXSTYLE )

Definition at line 1123 of file UtilFunc.h.

◆ SetWndExStyle

#define SetWndExStyle (   hwnd,
  style 
)    SetWindowLong( hwnd, GWL_EXSTYLE, style )

Definition at line 1124 of file UtilFunc.h.

◆ WM_GetFont

#define WM_GetFont (   hwnd)    (HFONT)SendMessage( hwnd, WM_GETFONT, 0,0 )

Definition at line 1127 of file UtilFunc.h.

◆ WM_SetFont

#define WM_SetFont (   hwnd,
  hfnt,
  rdrw 
)    (void)SendMessage( hwnd, WM_SETFONT, (WPARAM)hfnt, rdrw )

Definition at line 1128 of file UtilFunc.h.

◆ WM_SetRedraw

#define WM_SetRedraw (   hwnd,
  on 
)    SendMessage( hwnd, WM_SETREDRAW, on, 0 )

Definition at line 1132 of file UtilFunc.h.

Function Documentation

◆ DispatchMessagesFor()

UINT DispatchMessagesFor ( HWND  hWnd)

Translate and dispatch all pending messages for hWnd (using PeekMessage).
Return nr of messages dispatched.. zero if none.

Definition at line 17 of file UserUtil.cpp.

◆ GetWndHeight()

UINT GetWndHeight ( HWND  hWnd)

Definition at line 507 of file UserUtil.cpp.

◆ GetWndWidth()

UINT GetWndWidth ( HWND  hWnd)

Definition at line 515 of file UserUtil.cpp.

◆ GetWndSize()

bool GetWndSize ( HWND  hWnd,
SIZE *  pSize 
)

Get size of the window

Definition at line 523 of file UserUtil.cpp.

◆ GetWndPos()

bool GetWndPos ( HWND  hWnd,
POINT *  pPos 
)

Get pos of the window, in screen coords.

Definition at line 537 of file UserUtil.cpp.

◆ GetWindowMinimizeRect()

BOOL GetWindowMinimizeRect ( HWND  hTrayApp,
RECT *  pRect 
)

Undoc: user32.dll, Vista+, Export=Name/Ordinal
"If hTrayApp is an eligible tray window, the returned rect contains the coords of the taskbar button."
Note: On test with a normal top level window it seems to return the taskbar area between [Start] and the tray icons.
Ergo, it could be used to get the taskbar height and position.

Definition at line 549 of file UserUtil.cpp.

◆ CenterWindow()

bool CenterWindow ( HWND  hWnd,
HWND  hOwner 
)

Center hWnd over hOwner.

Definition at line 563 of file UserUtil.cpp.

◆ GetChildWndRect()

void GetChildWndRect ( HWND  hCtrl,
RECT *  pRc 
)

Child wnd rect, in parent coords.

Definition at line 602 of file UserUtil.cpp.

◆ EnableChildWnd()

bool EnableChildWnd ( HWND  Owner,
UINT  Id,
bool  Enable 
)

Definition at line 608 of file UserUtil.cpp.

◆ GetChildWndWithId()

HWND GetChildWndWithId ( HWND  hParent,
UINT  ChildId 
)

Find child with given ID.

Definition at line 617 of file UserUtil.cpp.

◆ SetParentWnd()

HWND SetParentWnd ( HWND  hWnd,
HWND  newParent 
)

SetParentWnd adds some special handling to SetParent, permitting change from
top-level to child and vice-versa, which may be required in special situations,
such as when implementing a resource editor. Note: BE CAREFUL!

Definition at line 1167 of file UserUtil.cpp.

◆ CreateWindowIndirect()

HWND CreateWindowIndirect ( LPCREATESTRUCT  pc)

CreateWindowIndirect creates a window from the CREATESTRUCT spec.

Definition at line 1050 of file UserUtil.cpp.

◆ DialogBoxParamEx()

INT_PTR DialogBoxParamEx ( HINSTANCE  hInst,
CSTR  Template,
HWND  hParent,
DLGPROC  DlgProc,
LPARAM  lParam,
LANGID  Language 
)

Execute a modal internationalized dialog.
If the internationalized dialog resource doesen't exist
the function returns -1, and GetLastError() returns ERROR_INVALID_PARAMETER.

Parameters
hInstInstance containing the dialog resource.
TemplateId of the dialog
hParentParent of the dialog
DlgProcDialog proc callback
lParamDialog creation parameter
LanguageLanguage of the dialog resource

Definition at line 1061 of file UserUtil.cpp.

◆ CreateDialogParamEx()

HWND CreateDialogParamEx ( HINSTANCE  hInst,
CSTR  Template,
HWND  hParent,
DLGPROC  DlgProc,
LPARAM  lParam,
LANGID  Language 
)

Create a modeless internationalized dialog. If the internationalized dialog resource doesen't exist
the function returns NULL, and GetLastError() returns ERROR_INVALID_PARAMETER.

Parameters
hInstInstance containing the dialog resource.
TemplateId of the dialog
hParentParent of the dialog
DlgProcDialog proc callback
lParamDialog creation parameter
LanguageLanguage of the dialog resource

Definition at line 1077 of file UserUtil.cpp.

◆ GetRequiredWindowSize()

bool GetRequiredWindowSize ( HWND  hWnd,
IN const PSIZE  pClient,
OUT PSIZE  pWindow 
)

[PRELIMINARY/TENTATIVE] Compute required window size for a given client size.
(Note: This function may be changed or removed).

Definition at line 1094 of file UserUtil.cpp.

◆ GetWindowClientSize()

bool GetWindowClientSize ( HWND  hWnd,
IN const PSIZE  pWindow,
OUT PSIZE  pClient 
)

[PRELIMINARY/TENTATIVE] Get effective client size for a given window size.
(Note: This function may be changed or removed).

Definition at line 1109 of file UserUtil.cpp.

◆ RefreshWnd()

bool RefreshWnd ( HWND  hWnd)

Combines InvalidateRect and UpdateWindow.

Definition at line 1126 of file UserUtil.cpp.

◆ RedrawWnd()

bool RedrawWnd ( HWND  hWnd,
UINT  Flags 
)

See [MSDN] RedrawWindow.

Definition at line 1134 of file UserUtil.cpp.

◆ RedrawWndRect()

bool RedrawWndRect ( HWND  hWnd,
PRECT  pRect,
UINT  Flags 
)

See [MSDN] RedrawWindow.

Definition at line 1139 of file UserUtil.cpp.

◆ RedrawWndRgn()

bool RedrawWndRgn ( HWND  hWnd,
HRGN  hRgn,
UINT  Flags 
)

See [MSDN] RedrawWindow.

Definition at line 1144 of file UserUtil.cpp.

◆ MoveWnd()

bool MoveWnd ( HWND  hWnd,
int  X,
int  Y,
bool  Repaint 
)

See [MSDN} SetWindowPos.

Definition at line 1151 of file UserUtil.cpp.

◆ ResizeWnd()

bool ResizeWnd ( HWND  hWnd,
int  W,
int  H,
bool  Repaint 
)

See [MSDN} SetWindowPos.

Definition at line 1159 of file UserUtil.cpp.

◆ SetCaption()

bool __cdecl SetCaption ( HWND  hwnd,
CSTR  fmt,
  ... 
)

SetWindowText a'la printf..
The function uses an internal buffer of 256 TCHARs.

Definition at line 284 of file UserUtil.cpp.

◆ SetRedraw()

void WINAPI SetRedraw ( HWND  hwnd,
bool  on 
)

Send WM_SETREDRAW, and if on is true call InvalidateRect()
to ensure a forthwith redraw of the window contents.

Definition at line 500 of file GdiUtil.cpp.

◆ LoadSmallIcon()

HICON WINAPI LoadSmallIcon ( HINSTANCE  hInst,
CSTR  Id 
)

Small icon convenience routine (wrap for LoadImage())

Definition at line 628 of file UserUtil.cpp.

◆ LoadCustomResource()

PVOID WINAPI LoadCustomResource ( HMODULE  hModule,
CSTR  Id,
CSTR  Type,
UINT *pSize  OPTOUT = NULL 
)

Find, Load, and Lock a resource of arbitrary type.

◆ LoadCustomResourceEx()

PVOID WINAPI LoadCustomResourceEx ( HMODULE  hModule,
CSTR  Id,
CSTR  Type,
LANGID Language  OPTIN = 0,
UINT *pSize  OPTOUT = NULL 
)

Find, Load, and Lock a resource of arbitrary type in a specific language.
If the resource isn't found in the specified language, the default language is tried.

◆ LoadPictureResource()

IPicture* WINAPI LoadPictureResource ( HMODULE  hModule,
CSTR  Id,
CSTR  Type 
)

Load any IPicture supported file stored as a custom resource.
Note: Uses SHCreateMemStream, and is therefore not reentrant.

Definition at line 900 of file UserUtil.cpp.

◆ LoadPictureFile()

IPicture* WINAPI LoadPictureFile ( CSTR  FName)

Load any IPicture supported file.
Uses SHCreateStreamOnFile() and OleLoadPicture() to get an IPicture.

Definition at line 928 of file UserUtil.cpp.

◆ PaintPicture()

void WINAPI PaintPicture ( IPicture *  pPic,
HDC  hdc,
int  x,
int  y,
int  cx = 0,
int  cy = 0 
)

Paint an IPicture on a normal MM_TEXT mode HDC.
The whole picture is rendered without aspect constraints.

Parameters
pPicPointer to the IPicture to render.
hdcDisplay context to paint on, MM_TEXT mode is expected.
x,yPosition in hdc of upper left corner, in pixels.
cx,cyWidth and height to cover, in pixels.

Definition at line 977 of file UserUtil.cpp.

◆ PaintPictureEx()

bool WINAPI PaintPictureEx ( IPicture *  pPic,
HDC  hdc,
long  x,
long  y,
long  cx = 0,
long  cy = 0,
long  imx = 0,
long  imy = 0,
long  imw = 0,
long  imh = 0,
PRECT  prMeta = NULL 
)

Paint an IPicture on a normal MM_TEXT mode HDC.
Supports all Render parameters using Pixel measures, not HiMetric.

Parameters
pPicPointer to the IPicture to render.
hdcDisplay context to paint on, MM_TEXT mode is expected.
x,yPosition in hdc of upper left corner, in pixels.
cx,cyWidth and height to cover in hdc, in pixels.
imx,imyPosition in picture of upper left corner to render, in pixels.
imw,imhWidth and height of picure area to include, in pixels.

Definition at line 999 of file UserUtil.cpp.

◆ HiMetricToPix()

long WINAPI HiMetricToPix ( long  hiMetric)

Return measure in pixels.

Definition at line 958 of file UserUtil.cpp.

◆ PixToHiMetric()

long WINAPI PixToHiMetric ( long  Pix)

Return measure in hi-metric units.

Definition at line 965 of file UserUtil.cpp.