4 LengthOfStrResource(IN HINSTANCE hInst
,
16 /* There are always blocks of 16 strings */
17 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
19 /* Find the string table block */
20 if ((hrSrc
= FindResourceW(hInst
, lpName
, (LPWSTR
)RT_STRING
)) &&
21 (hRes
= LoadResource(hInst
, hrSrc
)) &&
22 (lpStr
= LockResource(hRes
)))
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
++)
30 lpStr
+= (*lpStr
) + 1;
33 /* Found the string */
40 AllocAndLoadString(OUT LPTSTR
*lpTarget
,
46 ln
= LengthOfStrResource(hInst
,
50 (*lpTarget
) = (LPTSTR
)LocalAlloc(LMEM_FIXED
,
52 if ((*lpTarget
) != NULL
)
55 if (!(Ret
= LoadString(hInst
, uID
, *lpTarget
, ln
)))
57 LocalFree((HLOCAL
)(*lpTarget
));
66 LoadAndFormatString(IN HINSTANCE hInstance
,
75 if (AllocAndLoadString(&lpFormat
,
79 va_start(lArgs
, lpTarget
);
80 /* let's use FormatMessage to format it because it has the ability to allocate
81 memory automatically */
82 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
91 LocalFree((HLOCAL
)lpFormat
);
98 StatusBarLoadAndFormatString(IN HWND hStatusBar
,
100 IN HINSTANCE hInstance
,
105 LPTSTR lpFormat
, lpStr
;
108 if (AllocAndLoadString(&lpFormat
,
112 va_start(lArgs
, uID
);
113 /* let's use FormatMessage to format it because it has the ability to allocate
114 memory automatically */
115 Ret
= FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
126 Ret
= (BOOL
)SendMessage(hStatusBar
,
130 LocalFree((HLOCAL
)lpStr
);
133 LocalFree((HLOCAL
)lpFormat
);
140 StatusBarLoadString(IN HWND hStatusBar
,
142 IN HINSTANCE hInstance
,
148 if (AllocAndLoadString(&lpStr
,
152 Ret
= (BOOL
)SendMessage(hStatusBar
,
156 LocalFree((HLOCAL
)lpStr
);
164 GetTextFromEdit(OUT LPTSTR lpString
,
168 INT len
= GetWindowTextLength(GetDlgItem(hDlg
, Res
));
183 VOID
GetError(DWORD err
)
188 err
= GetLastError();
190 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
191 FORMAT_MESSAGE_FROM_SYSTEM
|
192 FORMAT_MESSAGE_IGNORE_INSERTS
,
195 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
200 MessageBox(NULL
, lpMsgBuf
, _T("Error!"), MB_OK
| MB_ICONERROR
);
208 * Toolbar custom control routines
211 typedef struct _TBCUSTCTL
215 BOOL HideVertical
: 1;
217 } TBCUSTCTL
, *PTBCUSTCTL
;
220 ToolbarDeleteControlSpace(HWND hWndToolbar
,
221 const TBBUTTON
*ptbButton
)
223 if ((ptbButton
->fsStyle
& TBSTYLE_SEP
) &&
224 ptbButton
->dwData
!= 0)
226 PTBCUSTCTL cctl
= (PTBCUSTCTL
)ptbButton
->dwData
;
228 DestroyWindow(cctl
->hWndControl
);
230 HeapFree(ProcessHeap
,
240 ToolbarUpdateControlSpaces(HWND hWndToolbar
,
241 ToolbarChangeControlCallback ChangeCallback
)
247 Vert
= ((SendMessage(hWndToolbar
,
250 0) & CCS_VERT
) != 0);
252 nButtons
= SendMessage(hWndToolbar
,
261 if (SendMessage(hWndToolbar
,
266 if ((tbtn
.fsStyle
& TBSTYLE_SEP
) && tbtn
.dwData
!= 0)
268 PTBCUSTCTL cctl
= (PTBCUSTCTL
)tbtn
.dwData
;
270 cctl
->IsVertical
= Vert
;
272 if (cctl
->HideVertical
)
274 ShowWindow(cctl
->hWndControl
,
275 (Vert
? SW_HIDE
: SW_SHOW
));
278 else if (cctl
->IsVertical
!= Vert
)
280 ChangeCallback(hWndToolbar
,
285 /* show/hide the separator */
286 SendMessage(hWndToolbar
,
288 (WPARAM
)cctl
->iCommand
,
289 (LPARAM
)Vert
&& cctl
->HideVertical
);
297 ToolbarInsertSpaceForControl(HWND hWndToolbar
,
304 RECT rcControl
, rcItem
;
306 cctl
= HeapAlloc(ProcessHeap
,
312 cctl
->HideVertical
= HideVertical
;
313 cctl
->hWndControl
= hWndControl
;
314 cctl
->iCommand
= iCmd
;
316 if (GetWindowRect(hWndControl
,
321 tbtn
.iBitmap
= rcControl
.right
- rcControl
.left
;
322 tbtn
.idCommand
= iCmd
;
323 tbtn
.fsStyle
= TBSTYLE_SEP
;
324 tbtn
.dwData
= (DWORD_PTR
)cctl
;
326 if (SendMessage(hWndToolbar
,
332 tbtn
.fsState
|= TBSTATE_HIDDEN
;
334 cctl
->IsVertical
= TRUE
;
337 cctl
->IsVertical
= FALSE
;
339 if (SendMessage(hWndToolbar
,
344 if (SendMessage(hWndToolbar
,
349 SetWindowPos(hWndControl
,
353 rcItem
.right
- rcItem
.left
,
354 rcItem
.bottom
- rcItem
.top
,
357 ShowWindow(hWndControl
,
362 else if (tbtn
.fsState
& TBSTATE_HIDDEN
)
364 ShowWindow(hWndControl
,
375 InitImageList(UINT NumImages
, UINT StartResource
)
378 HIMAGELIST hImageList
;
382 /* Create the toolbar icon image list */
383 hImageList
= ImageList_Create(TB_BMP_WIDTH
,
385 ILC_MASK
| ILC_COLOR24
,
391 /* Add all icons to the image list */
392 for (i
= StartResource
, k
= 0; k
< NumImages
; i
++, k
++)
394 hBitmap
= LoadImage(hInstance
,
401 Ret
= ImageList_AddMasked(hImageList
,
405 DeleteObject(hBitmap
);
414 DestroyImageList(HIMAGELIST hImageList)
416 if (! ImageList_Destroy(hImageList))