soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
utilities.h
1#ifndef __UTILITIES__H__
2#define __UTILITIES__H__
3
4#include <utilities-def.h>
5#include <windows.h>
6#include <interface/sstring-i.h>
7#include <interface/sxml-i.h>
8#ifdef __cplusplus
9extern "C" {
10#define StringA SNS::IStringA
11#define StringW SNS::IStringW
12#define XmlDoc SNS::IXmlDoc
13#else
14#define StringA IStringA
15#define StringW IStringW
16#define XmlDoc IXmlDoc
17#endif//__cplusplus
18
19/**
20 * @brief Calculates the width of a rectangle.
21 *
22 * @param rc Pointer to a RECT structure containing the coordinates of the rectangle.
23 * @return The width of the rectangle.
24 */
25UTILITIES_API int RectWidth(LPCRECT rc);
26
27/**
28 * @brief Calculates the height of a rectangle.
29 *
30 * @param rc Pointer to a RECT structure containing the coordinates of the rectangle.
31 * @return The height of the rectangle.
32 */
33UTILITIES_API int RectHeight(LPCRECT rc);
34
35#ifdef _WIN32
36/**
37 * @brief Converts a size from HIMETRIC units to pixels.
38 *
39 * @param lpSizeInHiMetric Pointer to a SIZEL structure containing the size in HIMETRIC units.
40 * @param lpSizeInPix Pointer to a SIZEL structure that receives the size in pixels.
41 */
42UTILITIES_API void SHiMetricToPixel(const SIZEL* lpSizeInHiMetric, LPSIZEL lpSizeInPix);
43
44/**
45 * @brief Converts a size from pixels to HIMETRIC units.
46 *
47 * @param lpSizeInPix Pointer to a SIZEL structure containing the size in pixels.
48 * @param lpSizeInHiMetric Pointer to a SIZEL structure that receives the size in HIMETRIC units.
49 */
50UTILITIES_API void SPixelToHiMetric(const SIZEL* lpSizeInPix, LPSIZEL lpSizeInHiMetric);
51
52/**
53 * @brief Updates a DIB (Device-Independent Bitmap) pixmap.
54 *
55 * @param bmp Handle to the bitmap to update.
56 * @param wid Width of the bitmap.
57 * @param hei Height of the bitmap.
58 * @param bitsPixel Number of bits per pixel.
59 * @param stride Number of bytes in each scan line.
60 * @param pjBits Pointer to the bitmap bits.
61 * @return TRUE if successful, FALSE otherwise.
62 */
63BOOL UTILITIES_API UpdateDIBPixmap(HBITMAP bmp, int wid, int hei, int bitsPixel, int stride, CONST VOID* pjBits);
64#endif
65
66/**
67 * @brief Converts a wide string to an integer.
68 *
69 * @param src Pointer to the wide string to convert.
70 * @param supportHex TRUE if the string may contain a hexadecimal number, FALSE otherwise.
71 * @return The converted integer.
72 */
73UTILITIES_API int Str2IntW(LPCWSTR src, BOOL supportHex);
74
75/**
76 * @brief Converts a narrow string to an integer.
77 *
78 * @param src Pointer to the narrow string to convert.
79 * @param supportHex TRUE if the string may contain a hexadecimal number, FALSE otherwise.
80 * @return The converted integer.
81 */
82UTILITIES_API int Str2IntA(LPCSTR src, BOOL supportHex);
83
84/**
85 * @brief Creates an IStringA object from a narrow string.
86 *
87 * @param src Pointer to the narrow string.
88 * @return Pointer to the created IStringA object.
89 */
90UTILITIES_API StringA* CreateIStringA(LPCSTR src);
91
92/**
93 * @brief Creates an IStringW object from a wide string.
94 *
95 * @param src Pointer to the wide string.
96 * @return Pointer to the created IStringW object.
97 */
98UTILITIES_API StringW* CreateIStringW(LPCWSTR src);
99#ifdef _UNICODE
100#define Str2Int Str2IntW
101#define file_length file_length_W
102#else
103#define Str2Int Str2IntA
104#define file_length file_length_A
105#endif
106/**
107 * @brief Creates an IXmlDoc object.
108 *
109 * @return Pointer to the created IXmlDoc object.
110 */
111UTILITIES_API XmlDoc* CreateIXmlDoc();
112
113/**
114 * @brief Gets the scaling factor of a window.
115 *
116 * @param hWnd Handle to the window.
117 * @return The scaling factor of the window.
118 */
119int UTILITIES_API GetWindowScale(HWND hWnd);
120
121/**
122 * @brief Checks if a file path is valid.
123 *
124 * @param path Pointer to the file path.
125 * @return TRUE if the file path is valid, FALSE otherwise.
126 */
127BOOL UTILITIES_API IsFilePathValid(LPCTSTR path);
128
129/**
130 * @brief Checks if a font is available.
131 *
132 * @param fontName Pointer to the font name.
133 * @return TRUE if the font is available, FALSE otherwise.
134 */
135BOOL UTILITIES_API HasFont(LPCTSTR fontName);
136
137/**
138 * @brief Checks if the system supports maximizing windows by dragging.
139 *
140 * @return TRUE if supported, FALSE otherwise.
141 */
142BOOL UTILITIES_API IsSupportMaxMove();
143
144/**
145 * @brief Gets the length of a file.
146 *
147 * @param path Pointer to the file path (narrow string).
148 * @return The length of the file in bytes.
149 */
150long UTILITIES_API file_length_A(const char* path);
151
152/**
153 * @brief Gets the length of a file.
154 *
155 * @param path Pointer to the file path (wide string).
156 * @return The length of the file in bytes.
157 */
158long UTILITIES_API file_length_W(const wchar_t* path);
159
160/**
161 * @brief Loads an icon or cursor from memory.
162 *
163 * @param buf Pointer to the memory buffer containing the icon or cursor data.
164 * @param cbSize Size of the memory buffer.
165 * @param fIcon TRUE if the data is an icon, FALSE if it is a cursor.
166 * @param width Width of the icon or cursor.
167 * @param height Height of the icon or cursor.
168 * @param cFlag Flags for loading the icon or cursor.
169 * @return Handle to the loaded icon or cursor.
170 */
171HANDLE UTILITIES_API LoadIconFromMemory(const void* buf, UINT cbSize, BOOL fIcon, int width, int height, UINT cFlag);
172
173/**
174 * @brief Creates a region from a bitmap.
175 *
176 * @param hBmp Handle to the bitmap.
177 * @param cr Color value for the region.
178 * @param crMask Mask color value.
179 * @return Handle to the created region.
180 */
181HRGN UTILITIES_API CreateRegionFromBitmap(HBITMAP hBmp, COLORREF cr, COLORREF crMask);
182
183#ifdef __cplusplus
184}
185#endif//__cplusplus
186#endif // __UTILITIES__H__