ReactOS  0.4.13-dev-563-g0561610
misc.c
Go to the documentation of this file.
1 #include <precomp.h>
2 
3 static INT
5  IN UINT uID)
6 {
7  HRSRC hrSrc;
8  HGLOBAL hRes;
9  LPWSTR lpName, lpStr;
10 
11  if (hInst == NULL)
12  {
13  return -1;
14  }
15 
16  /* There are always blocks of 16 strings */
17  lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
18 
19  /* Find the string table block */
20  if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) &&
21  (hRes = LoadResource(hInst, hrSrc)) &&
22  (lpStr = LockResource(hRes)))
23  {
24  UINT x;
25 
26  /* Find the string we're looking for */
27  uID &= 0xF; /* position in the block, same as % 16 */
28  for (x = 0; x < uID; x++)
29  {
30  lpStr += (*lpStr) + 1;
31  }
32 
33  /* Found the string */
34  return (int)(*lpStr);
35  }
36  return -1;
37 }
38 
39 INT
42  IN UINT uID)
43 {
44  INT ln;
45 
47  uID);
48  if (ln++ > 0)
49  {
50  (*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED,
51  ln * sizeof(TCHAR));
52  if ((*lpTarget) != NULL)
53  {
54  INT Ret;
55  if (!(Ret = LoadString(hInst, uID, *lpTarget, ln)))
56  {
57  LocalFree((HLOCAL)(*lpTarget));
58  }
59  return Ret;
60  }
61  }
62  return 0;
63 }
64 
65 DWORD
67  IN UINT uID,
68  OUT LPTSTR *lpTarget,
69  ...)
70 {
71  DWORD Ret = 0;
73  va_list lArgs;
74 
76  hInstance,
77  uID) > 0)
78  {
79  va_start(lArgs, lpTarget);
80  /* let's use FormatMessage to format it because it has the ability to allocate
81  memory automatically */
83  lpFormat,
84  0,
85  0,
86  (LPTSTR)lpTarget,
87  0,
88  &lArgs);
89  va_end(lArgs);
90 
92  }
93 
94  return Ret;
95 }
96 
97 BOOL
99  IN INT PartId,
101  IN UINT uID,
102  ...)
103 {
104  BOOL Ret = FALSE;
105  LPTSTR lpFormat, lpStr;
106  va_list lArgs;
107 
109  hInstance,
110  uID) > 0)
111  {
112  va_start(lArgs, uID);
113  /* let's use FormatMessage to format it because it has the ability to allocate
114  memory automatically */
116  lpFormat,
117  0,
118  0,
119  (LPTSTR)&lpStr,
120  0,
121  &lArgs);
122  va_end(lArgs);
123 
124  if (lpStr != NULL)
125  {
126  Ret = (BOOL)SendMessage(hStatusBar,
127  SB_SETTEXT,
128  (WPARAM)PartId,
129  (LPARAM)lpStr);
130  LocalFree((HLOCAL)lpStr);
131  }
132 
134  }
135 
136  return Ret;
137 }
138 
139 BOOL
141  IN INT PartId,
143  IN UINT uID)
144 {
145  BOOL Ret = FALSE;
146  LPTSTR lpStr;
147 
148  if (AllocAndLoadString(&lpStr,
149  hInstance,
150  uID) > 0)
151  {
152  Ret = (BOOL)SendMessage(hStatusBar,
153  SB_SETTEXT,
154  (WPARAM)PartId,
155  (LPARAM)lpStr);
156  LocalFree((HLOCAL)lpStr);
157  }
158 
159  return Ret;
160 }
161 
162 
163 INT
165  IN HWND hDlg,
166  IN UINT Res)
167 {
168  INT len = GetWindowTextLength(GetDlgItem(hDlg, Res));
169  if(len > 0)
170  {
171  GetDlgItemText(hDlg,
172  Res,
173  lpString,
174  len + 1);
175  }
176  else
177  lpString = NULL;
178 
179  return len;
180 }
181 
182 
184 {
185  LPVOID lpMsgBuf;
186 
187  if (err == 0)
188  err = GetLastError();
189 
193  NULL,
194  err,
196  (LPTSTR) &lpMsgBuf,
197  0,
198  NULL );
199 
200  MessageBox(NULL, lpMsgBuf, _T("Error!"), MB_OK | MB_ICONERROR);
201 
202  LocalFree(lpMsgBuf);
203 }
204 
205 
206 
207 /*
208  * Toolbar custom control routines
209  */
210 
211 typedef struct _TBCUSTCTL
212 {
218 
219 BOOL
221  const TBBUTTON *ptbButton)
222 {
223  if ((ptbButton->fsStyle & TBSTYLE_SEP) &&
224  ptbButton->dwData != 0)
225  {
226  PTBCUSTCTL cctl = (PTBCUSTCTL)ptbButton->dwData;
227 
228  DestroyWindow(cctl->hWndControl);
229 
231  0,
232  cctl);
233  return TRUE;
234  }
235 
236  return FALSE;
237 }
238 
239 VOID
241  ToolbarChangeControlCallback ChangeCallback)
242 {
243  BOOL Vert;
244  DWORD nButtons, i;
245  TBBUTTON tbtn;
246 
247  Vert = ((SendMessage(hWndToolbar,
248  TB_GETSTYLE,
249  0,
250  0) & CCS_VERT) != 0);
251 
252  nButtons = (DWORD)SendMessage(hWndToolbar,
254  0,
255  0);
256 
257  for (i = 0;
258  i != nButtons;
259  i++)
260  {
261  if (SendMessage(hWndToolbar,
262  TB_GETBUTTON,
263  (WPARAM)i,
264  (LPARAM)&tbtn))
265  {
266  if ((tbtn.fsStyle & TBSTYLE_SEP) && tbtn.dwData != 0)
267  {
268  PTBCUSTCTL cctl = (PTBCUSTCTL)tbtn.dwData;
269 
270  cctl->IsVertical = Vert;
271 
272  if (cctl->HideVertical)
273  {
274  ShowWindow(cctl->hWndControl,
275  (Vert ? SW_HIDE : SW_SHOW));
276  goto ShowHideSep;
277  }
278  else if (cctl->IsVertical != Vert)
279  {
280  ChangeCallback(hWndToolbar,
281  cctl->hWndControl,
282  Vert);
283 
284 ShowHideSep:
285  /* show/hide the separator */
286  SendMessage(hWndToolbar,
288  (WPARAM)cctl->iCommand,
289  (LPARAM)Vert && cctl->HideVertical);
290  }
291  }
292  }
293  }
294 }
295 
296 BOOL
298  HWND hWndControl,
299  INT Index,
300  INT iCmd,
301  BOOL HideVertical)
302 {
303  PTBCUSTCTL cctl;
304  RECT rcControl, rcItem;
305 
306  cctl = HeapAlloc(ProcessHeap,
307  0,
308  sizeof(TBCUSTCTL));
309  if (cctl == NULL)
310  return FALSE;
311 
312  cctl->HideVertical = HideVertical;
313  cctl->hWndControl = hWndControl;
314  cctl->iCommand = iCmd;
315 
316  if (GetWindowRect(hWndControl,
317  &rcControl))
318  {
319  TBBUTTON tbtn = {0};
320 
321  tbtn.iBitmap = rcControl.right - rcControl.left;
322  tbtn.idCommand = iCmd;
323  tbtn.fsStyle = TBSTYLE_SEP;
324  tbtn.dwData = (DWORD_PTR)cctl;
325 
326  if (SendMessage(hWndToolbar,
327  TB_GETSTYLE,
328  0,
329  0) & CCS_VERT)
330  {
331  if (HideVertical)
332  tbtn.fsState |= TBSTATE_HIDDEN;
333 
334  cctl->IsVertical = TRUE;
335  }
336  else
337  cctl->IsVertical = FALSE;
338 
339  if (SendMessage(hWndToolbar,
341  (WPARAM)Index,
342  (LPARAM)&tbtn))
343  {
344  if (SendMessage(hWndToolbar,
346  (WPARAM)Index,
347  (LPARAM)&rcItem))
348  {
349  SetWindowPos(hWndControl,
350  NULL,
351  rcItem.left,
352  rcItem.top,
353  rcItem.right - rcItem.left,
354  rcItem.bottom - rcItem.top,
355  SWP_NOZORDER);
356 
357  ShowWindow(hWndControl,
358  SW_SHOW);
359 
360  return TRUE;
361  }
362  else if (tbtn.fsState & TBSTATE_HIDDEN)
363  {
364  ShowWindow(hWndControl,
365  SW_HIDE);
366  }
367  }
368  }
369 
370  return FALSE;
371 }
372 
373 
375 InitImageList(UINT NumImages, UINT StartResource)
376 {
378  HIMAGELIST hImageList;
379  UINT i, k;
380  INT Ret;
382 
383  /* Create the toolbar icon image list */
384  hImageList = ImageList_Create(TB_BMP_WIDTH,
387  NumImages,
388  0);
389  if (! hImageList)
390  return NULL;
391 
392  /* Add all icons to the image list */
393  for (i = StartResource, k = 0; k < NumImages; i++, k++)
394  {
397  IMAGE_BITMAP,
398  TB_BMP_WIDTH,
401 
402  Ret = ImageList_AddMasked(hImageList,
403  hBitmap,
404  RGB(255, 255, 254));
405 
407  }
408 
409  return hImageList;
410 
411 }
412 
413 /*
414 static BOOL
415 DestroyImageList(HIMAGELIST hImageList)
416 {
417  if (! ImageList_Destroy(hImageList))
418  return FALSE;
419  else
420  return TRUE;
421 }
422 */
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IN
Definition: typedefs.h:38
#define TB_BUTTONCOUNT
Definition: commctrl.h:1082
#define TRUE
Definition: types.h:120
INT GetTextFromEdit(OUT LPWSTR lpString, IN HWND hDlg, IN UINT Res)
Definition: misc.c:174
#define DWORD_PTR
Definition: treelist.c:76
#define SW_HIDE
Definition: winuser.h:762
static BOOL
Definition: misc.c:82
#define TBSTYLE_SEP
Definition: commctrl.h:954
#define LANG_NEUTRAL
Definition: nls.h:22
#define TB_GETBUTTON
Definition: commctrl.h:1081
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
#define SUBLANG_DEFAULT
Definition: nls.h:168
_In_ LPCSTR lpName
Definition: winbase.h:2729
VOID ToolbarUpdateControlSpaces(HWND hWndToolbar, ToolbarChangeControlCallback ChangeCallback)
Definition: misc.c:240
BOOL ToolbarInsertSpaceForControl(HWND hWndToolbar, HWND hWndControl, INT Index, INT iCmd, BOOL HideVertical)
Definition: misc.c:297
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
UINT_PTR WPARAM
Definition: windef.h:207
BOOL HideVertical
Definition: misc.c:215
LONG left
Definition: windef.h:291
#define SWP_NOZORDER
Definition: winuser.h:1232
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define TB_INSERTBUTTON
Definition: commctrl.h:1242
BYTE fsStyle
Definition: commctrl.h:924
VOID(* ToolbarChangeControlCallback)(HWND hWndToolbar, HWND hWndControl, BOOL Vert)
Definition: misc.h:31
LONG right
Definition: windef.h:293
BOOL WINAPI DestroyWindow(_In_ HWND)
int32_t INT
Definition: typedefs.h:56
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define TB_GETITEMRECT
Definition: commctrl.h:1105
#define CCS_VERT
Definition: commctrl.h:2221
VOID GetError(VOID)
Definition: misc.c:192
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HINSTANCE hInstance
Definition: charmap.c:20
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:801
#define va_end(ap)
Definition: acmsvcex.h:90
BOOL IsVertical
Definition: misc.c:216
unsigned int BOOL
Definition: ntddk_ex.h:94
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
char * va_list
Definition: acmsvcex.h:78
DWORD LoadAndFormatString(IN HINSTANCE hInstance, IN UINT uID, OUT LPTSTR *lpTarget,...)
Definition: misc.c:86
#define SW_SHOW
Definition: winuser.h:769
HWND hWndControl
Definition: misc.c:213
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
DWORD_PTR dwData
Definition: commctrl.h:930
int iBitmap
Definition: commctrl.h:921
#define LMEM_FIXED
Definition: winbase.h:349
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
struct _TBCUSTCTL * PTBCUSTCTL
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define GetDlgItemText
Definition: winuser.h:5651
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define TB_BMP_WIDTH
Definition: precomp.h:20
#define ILC_COLOR24
Definition: commctrl.h:342
#define RGB(r, g, b)
Definition: wingdi.h:2918
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND hStatusBar
Definition: main.cpp:35
#define TB_BMP_HEIGHT
Definition: precomp.h:21
#define FormatMessage
Definition: winbase.h:3609
#define SB_SETTEXT
Definition: commctrl.h:1921
int idCommand
Definition: commctrl.h:922
HIMAGELIST InitImageList(UINT StartResource, UINT EndResource, UINT Width, UINT Height, ULONG type)
Definition: misc.c:219
#define MB_ICONERROR
Definition: winuser.h:781
INT iCommand
Definition: misc.c:214
#define LR_LOADTRANSPARENT
Definition: winuser.h:1083
#define ILC_MASK
Definition: commctrl.h:336
GLenum GLsizei len
Definition: glext.h:6722
#define RT_STRING
Definition: pedump.c:368
#define MessageBox
Definition: winuser.h:5688
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define err(...)
HANDLE ProcessHeap
Definition: servman.c:15
static DWORD
Definition: misc.c:47
struct _TBCUSTCTL TBCUSTCTL
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HINSTANCE hInst
Definition: dxdiag.c:13
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
unsigned int UINT
Definition: ndis.h:50
#define MB_OK
Definition: winuser.h:784
#define IMAGE_BITMAP
Definition: winuser.h:211
#define TB_HIDEBUTTON
Definition: commctrl.h:1017
#define TBSTATE_HIDDEN
Definition: commctrl.h:947
#define SendMessage
Definition: winuser.h:5709
#define OUT
Definition: typedefs.h:39
static LPWSTR
Definition: misc.c:35
#define GetWindowTextLength
Definition: winuser.h:5665
#define MAKELANGID(p, s)
Definition: nls.h:15
BOOL StatusBarLoadAndFormatString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID,...)
Definition: misc.c:108
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define LoadImage
Definition: winuser.h:5681
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
INT WINAPI ImageList_AddMasked(HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
Definition: imagelist.c:560
#define TB_GETSTYLE
Definition: commctrl.h:1131
static HBITMAP
Definition: button.c:44
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
BYTE fsState
Definition: commctrl.h:923
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL ToolbarDeleteControlSpace(HWND hWndToolbar, const TBBUTTON *ptbButton)
Definition: misc.c:220
static HBITMAP hBitmap
Definition: timezone.c:35
int k
Definition: mpi.c:3369
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define HeapFree(x, y, z)
Definition: compat.h:394
#define LoadString
Definition: winuser.h:5685
BOOL StatusBarLoadString(IN HWND hStatusBar, IN INT PartId, IN HINSTANCE hInstance, IN UINT uID)
Definition: misc.c:150