ReactOS  0.4.12-dev-14-gd0c8636
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define BUFFERSIZE   512
 

Functions

static INT LengthOfStrResource (IN HINSTANCE hInst, IN UINT uID)
 
INT AllocAndLoadString (OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPWSTR *lpTarget,...)
 
BOOL StatusBarLoadAndFormatString (IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID,...)
 
BOOL StatusBarLoadString (IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID)
 
INT GetTextFromEdit (OUT LPWSTR lpString, IN HWND hDlg, IN UINT Res)
 
VOID GetError (VOID)
 
VOID DisplayString (LPWSTR Msg)
 
HIMAGELIST InitImageList (UINT StartResource, UINT EndResource, UINT Width, UINT Height, ULONG type)
 
VOID ResourceMessageBox (HINSTANCE hInstance, HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
 

Macro Definition Documentation

◆ BUFFERSIZE

#define BUFFERSIZE   512

Definition at line 280 of file misc.c.

Referenced by ResourceMessageBox().

Function Documentation

◆ AllocAndLoadString()

INT AllocAndLoadString ( OUT LPWSTR lpTarget,
IN HINSTANCE  hInst,
IN UINT  uID 
)

Definition at line 50 of file misc.c.

Referenced by LoadAndFormatString(), StatusBarLoadAndFormatString(), StatusBarLoadString(), and VarListLoadAndFormatString().

53 {
54  INT ln;
55 
57  uID);
58  if (ln++ > 0)
59  {
60  (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
61  ln * sizeof(WCHAR));
62  if ((*lpTarget) != NULL)
63  {
64  INT Ret;
65  if (!(Ret = LoadStringW(hInst, uID, *lpTarget, ln)))
66  {
67  LocalFree((HLOCAL)(*lpTarget));
68  }
69  return Ret;
70  }
71  }
72  return 0;
73 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static LPWSTR
Definition: misc.c:35
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23

◆ DisplayString()

VOID DisplayString ( LPWSTR  Msg)

Definition at line 211 of file misc.c.

Referenced by DoCreate(), DoDeleteService(), InitMainWnd(), MainWndCommand(), PrintFileDacl(), test_pack_GOPHER_FIND_DATAA(), and test_pack_GOPHER_FIND_DATAW().

212 {
214 }
struct @1571 Msg[]
#define MB_ICONEXCLAMATION
Definition: winuser.h:779
smooth NULL
Definition: ftsmooth.c:416
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
static const WCHAR L[]
Definition: oid.c:1087
#define MB_OK
Definition: winuser.h:784

◆ GetError()

VOID GetError ( VOID  )

Definition at line 192 of file misc.c.

Referenced by CreateMainWindow(), GetServiceDescription(), InitEditWnd(), LoadDIBImage(), SetServiceAccount(), SetServiceConfig(), and SetServiceDescription().

193 {
194  LPWSTR lpMsgBuf = NULL;
195 
199  NULL,
200  GetLastError(),
202  (VOID*)&lpMsgBuf,
203  0,
204  NULL );
205 
206  MessageBoxW(NULL, lpMsgBuf, L"Error!", MB_OK | MB_ICONERROR);
207 
208  LocalFree(lpMsgBuf);
209 }
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
static const WCHAR L[]
Definition: oid.c:1087
#define MB_ICONERROR
Definition: winuser.h:781
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MB_OK
Definition: winuser.h:784
#define MAKELANGID(p, s)
Definition: nls.h:15
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ GetTextFromEdit()

INT GetTextFromEdit ( OUT LPWSTR  lpString,
IN HWND  hDlg,
IN UINT  Res 
)

Definition at line 174 of file misc.c.

177 {
178  INT len = GetWindowTextLengthW(GetDlgItem(hDlg, Res));
179  if(len > 0)
180  {
181  GetDlgItemTextW(hDlg,
182  Res,
183  lpString,
184  len + 1);
185  }
186  else
187  lpString = NULL;
188 
189  return len;
190 }
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2195
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
int WINAPI GetWindowTextLengthW(_In_ HWND)
GLenum GLsizei len
Definition: glext.h:6722

◆ InitImageList()

HIMAGELIST InitImageList ( UINT  StartResource,
UINT  EndResource,
UINT  Width,
UINT  Height,
ULONG  type 
)

Definition at line 219 of file misc.c.

Referenced by CMainToolbar::Create(), FloatToolbarCreateHistoryGui(), FloatToolbarCreateToolsGui(), InitDependPage(), MainWndCreateToolbarClient(), pCreateToolbar(), and PopulateTreeView().

224 {
225  HANDLE hImage;
227  UINT i;
228  INT ret;
229 
230  /* Create the toolbar icon image list */
231  himl = ImageList_Create(Width,
232  Height,
234  EndResource - StartResource,
235  0);
236  if (himl == NULL)
237  return NULL;
238 
239  ret = 0;
240  for (i = StartResource; i <= EndResource && ret != -1; i++)
241  {
242  hImage = LoadImageW(hInstance,
243  MAKEINTRESOURCEW(i),
244  type,
245  Width,
246  Height,
248  if (hImage == NULL)
249  {
250  ImageList_Destroy(himl);
251  himl = NULL;
252  break;
253  }
254 
255  if (type == IMAGE_BITMAP)
256  {
257  ret = ImageList_AddMasked(himl,
258  hImage,
259  RGB(255, 0, 128));
260  }
261  else if (type == IMAGE_ICON)
262  {
263  ret = ImageList_AddIcon(himl,
264  hImage);
265  }
266 
267  DeleteObject(hImage);
268  }
269 
270  if (ret == -1)
271  {
272  ImageList_Destroy(himl);
273  himl = NULL;
274  }
275 
276  return himl;
277 }
#define IMAGE_ICON
Definition: winuser.h:212
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HIMAGELIST himl
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:893
#define ILC_COLOR32
Definition: commctrl.h:343
GLenum GLclampf GLint i
Definition: glfuncs.h:14
HINSTANCE hInstance
Definition: charmap.c:20
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:769
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
smooth NULL
Definition: ftsmooth.c:416
#define RGB(r, g, b)
Definition: wingdi.h:2917
unsigned int UINT
Definition: ndis.h:50
INT WINAPI ImageList_AddIcon(HIMAGELIST himl, HICON hIcon)
Definition: imagelist.c:505
int ret
#define LR_LOADTRANSPARENT
Definition: winuser.h:1083
#define ILC_MASK
Definition: commctrl.h:336
#define IMAGE_BITMAP
Definition: winuser.h:211
INT WINAPI ImageList_AddMasked(HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
Definition: imagelist.c:528
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

◆ LengthOfStrResource()

static INT LengthOfStrResource ( IN HINSTANCE  hInst,
IN UINT  uID 
)
static

Definition at line 14 of file misc.c.

16 {
17  HRSRC hrSrc;
18  HGLOBAL hRes;
19  LPWSTR lpName, lpStr;
20 
21  if (hInst == NULL)
22  {
23  return -1;
24  }
25 
26  /* There are always blocks of 16 strings */
27  lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
28 
29  /* Find the string table block */
30  if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
31  (hRes = LoadResource(hInst, hrSrc)) &&
32  (lpStr = (WCHAR*) LockResource(hRes)))
33  {
34  UINT x;
35 
36  /* Find the string we're looking for */
37  uID &= 0xF; /* position in the block, same as % 16 */
38  for (x = 0; x < uID; x++)
39  {
40  lpStr += (*lpStr) + 1;
41  }
42 
43  /* Found the string */
44  return (int)(*lpStr);
45  }
46  return -1;
47 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ LPCSTR lpName
Definition: winbase.h:2729
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
HINSTANCE hInst
Definition: dxdiag.c:13
INT x
Definition: msvc.h:62
static LPWSTR
Definition: misc.c:35
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ LoadAndFormatString()

DWORD LoadAndFormatString ( IN HINSTANCE  hInstance,
IN UINT  uID,
OUT LPWSTR lpTarget,
  ... 
)

Definition at line 76 of file misc.c.

80 {
81  DWORD Ret = 0;
83  va_list lArgs;
84 
85  if (AllocAndLoadString(&lpFormat,
86  hInstance,
87  uID) > 0)
88  {
89  va_start(lArgs, lpTarget);
90  /* let's use Format to format it because it has the ability to allocate
91  memory automatically */
93  lpFormat,
94  0,
95  0,
96  (LPWSTR)lpTarget,
97  0,
98  &lArgs);
99  va_end(lArgs);
100 
101  LocalFree((HLOCAL)lpFormat);
102  }
103 
104  return Ret;
105 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
char * va_list
Definition: acmsvcex.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
#define va_start(ap, A)
Definition: acmsvcex.h:91
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ ResourceMessageBox()

VOID ResourceMessageBox ( HINSTANCE  hInstance,
HWND  hwnd,
UINT  uType,
UINT  uCaptionId,
UINT  uMessageId 
)

Definition at line 283 of file misc.c.

Referenced by AdvancedPageProc(), CopyProfileDlgProc(), OnApply(), OnSet(), OnVirtMemDialogOk(), and RenameProfileDlgProc().

289 {
290  WCHAR szErrorText[BUFFERSIZE];
291  WCHAR szErrorCaption[BUFFERSIZE];
292 
293  LoadStringW(hInstance, uMessageId, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
294  LoadStringW(hInstance, uCaptionId, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
295 
296  MessageBoxW(hwnd, szErrorText, szErrorCaption, uType);
297 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define BUFFERSIZE
Definition: misc.c:280
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)

◆ StatusBarLoadAndFormatString()

BOOL StatusBarLoadAndFormatString ( IN HWND  hStatusBar,
IN INT  PartId,
IN HINSTANCE  hInstance,
IN UINT  uID,
  ... 
)

Definition at line 108 of file misc.c.

113 {
114  BOOL Ret = FALSE;
115  LPWSTR lpFormat, lpStr;
116  va_list lArgs;
117 
118  if (AllocAndLoadString(&lpFormat,
119  hInstance,
120  uID) > 0)
121  {
122  va_start(lArgs, uID);
123  /* let's use FormatMessage to format it because it has the ability to allocate
124  memory automatically */
126  lpFormat,
127  0,
128  0,
129  (VOID*)&lpStr,
130  0,
131  &lArgs);
132  va_end(lArgs);
133 
134  if (lpStr != NULL)
135  {
137  SB_SETTEXT,
138  (WPARAM)PartId,
139  (LPARAM)lpStr);
140  LocalFree((HLOCAL)lpStr);
141  }
142 
143  LocalFree((HLOCAL)lpFormat);
144  }
145 
146  return Ret;
147 }
static BOOL
Definition: misc.c:82
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
UINT_PTR WPARAM
Definition: windef.h:207
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
unsigned int BOOL
Definition: ntddk_ex.h:94
HWND hStatusBar
Definition: main.cpp:35
#define SB_SETTEXT
Definition: commctrl.h:1919
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define va_start(ap, A)
Definition: acmsvcex.h:91
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LPARAM
Definition: msvc.h:38

◆ StatusBarLoadString()

BOOL StatusBarLoadString ( IN HWND  hStatusBar,
IN INT  PartId,
IN HINSTANCE  hInstance,
IN UINT  uID 
)

Definition at line 150 of file misc.c.

Referenced by MainWndMenuHint().

154 {
155  BOOL Ret = FALSE;
156  LPWSTR lpStr;
157 
158  if (AllocAndLoadString(&lpStr,
159  hInstance,
160  uID) > 0)
161  {
163  SB_SETTEXT,
164  (WPARAM)PartId,
165  (LPARAM)lpStr);
166  LocalFree((HLOCAL)lpStr);
167  }
168 
169  return Ret;
170 }
static BOOL
Definition: misc.c:82
UINT_PTR WPARAM
Definition: windef.h:207
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
HWND hStatusBar
Definition: main.cpp:35
#define SB_SETTEXT
Definition: commctrl.h:1919
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LPARAM
Definition: msvc.h:38