Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrcfg / toolbox.cpp
blob2595376d07fbab1a632d8831e0606e932d519603
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
11 * INCLUDES ___________________________________________________________________
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
22 #include "afscfg.h"
23 #include <WINNT\afsapplib.h>
24 #include <stdio.h>
25 #include "toolbox.h"
29 * EXPORTED FUNCTIONS _________________________________________________________
32 void SetEnable(HWND hDlg, UINT nControl, ENABLE_STATE eState)
34 HWND hControl = GetDlgItem(hDlg, nControl);
36 BOOL bEnable;
38 switch (eState) {
39 case ES_ENABLE:
40 bEnable = TRUE;
41 break;
43 case ES_DISABLE:
44 bEnable = FALSE;
45 break;
47 case ES_TOGGLE:
48 bEnable = !IsWindowEnabled(hControl);
49 break;
52 EnableWindow(hControl, bEnable);
55 void SetElapsedTime(HWND hwnd, DWORD nCtrlID, ULONG ulMin, ULONG ulMax, ULONG ulTime)
57 SYSTEMTIME stMin;
58 SET_ELAPSED_TIME_FROM_SECONDS (&stMin, ulMin);
60 SYSTEMTIME stMax;
61 SET_ELAPSED_TIME_FROM_SECONDS (&stMax, ulMax);
63 SYSTEMTIME st;
64 SET_ELAPSED_TIME_FROM_SECONDS (&st, ulTime);
66 HWND hElapsed = ::GetDlgItem(hwnd, nCtrlID);
67 EL_SetRange (hElapsed, &stMin, &stMax);
68 EL_SetTime (hElapsed, &st);
71 void GetElapsedTime(HWND hwnd, DWORD nCtrlID, DWORD& dwTime)
73 SYSTEMTIME stFinal;
75 HWND hElapsed = ::GetDlgItem(hwnd, nCtrlID);
76 EL_GetTime (hElapsed, &stFinal);
78 dwTime = GET_SECONDS_FROM_ELAPSED_TIME(&stFinal);
81 LPCTSTR SecondsToElapsedTime(UINT uiNumSeconds)
83 static TCHAR szTime[64], sz[32];
85 *szTime = 0;
86 *sz = 0;
88 int nHours, nMinutes, nSeconds;
90 nHours = uiNumSeconds / 3600;
91 nMinutes = (uiNumSeconds % 3600) / 60;
92 nSeconds = (uiNumSeconds % 3600) % 60;
94 if (nHours)
95 _stprintf(szTime, TEXT("%d hours"), nHours);
97 if (nMinutes) {
98 if (nHours)
99 lstrcat(szTime, TEXT(", "));
100 _stprintf(sz, TEXT("%d minutes"), nMinutes);
101 lstrcat(szTime, sz);
104 if (nSeconds) {
105 if (nHours || nMinutes)
106 lstrcat(szTime, TEXT(", "));
107 _stprintf(sz, TEXT("%d seconds"), nSeconds);
108 lstrcat(szTime, sz);
111 return szTime;
114 BOOL IsButtonChecked(HWND hDlg, UINT uiCtrlID)
116 return SendMessage(GetDlgItem(hDlg, uiCtrlID), BM_GETCHECK, 0, 0) == BST_CHECKED;
119 int GetButtonState(HWND hDlg, UINT uiCtrlID)
121 return SendMessage(GetDlgItem(hDlg, uiCtrlID), BM_GETCHECK, 0, 0);
124 void SetCheck(HWND hDlg, UINT uiCtrlID, int nChecked)
126 SendMessage(GetDlgItem(hDlg, uiCtrlID), BM_SETCHECK, nChecked, 0);
129 TCHAR *GetResString(UINT nMsgID, TCHAR *pszMsg, UINT nLen)
131 GetString(pszMsg, nMsgID, nLen);
133 return pszMsg;
136 void ShowWnd(HWND hDlg, UINT uiCtrlID, BOOL bShow)
138 ShowWindow(GetDlgItem(hDlg, uiCtrlID), bShow ? SW_SHOW : SW_HIDE);
141 void EnableWnd(HWND hDlg, UINT uiCtrlID, BOOL bEnable)
143 EnableWindow(GetDlgItem(hDlg, uiCtrlID), bEnable);
146 void SetWndText(HWND hDlg, UINT uiCtrlID, LPCTSTR pszMsg)
148 SetWindowText(GetDlgItem(hDlg, uiCtrlID), pszMsg);
151 void SetWndText(HWND hDlg, UINT uiCtrlID, UINT nMsgID)
153 TCHAR szMsg[cchRESOURCE];
155 GetString(szMsg, nMsgID);
157 SetWndText(hDlg, uiCtrlID, szMsg);
160 TCHAR *GetWndText(HWND hDlg, UINT uiCtrlID, TCHAR *pszTextBuffer, int nTextLen)
162 GetWindowText(GetDlgItem(hDlg, uiCtrlID), pszTextBuffer, nTextLen);
164 return pszTextBuffer;
167 void ForceUpdateWindow(HWND hWnd)
169 InvalidateRect(hWnd, 0, TRUE);
170 UpdateWindow(hWnd);
173 void ForceUpdateWindow(HWND hDlg, UINT uiCtrlID)
175 ForceUpdateWindow(GetDlgItem(hDlg, uiCtrlID));
178 int AddLBString(HWND hDlg, UINT uiCtrlID, LPCTSTR pszString)
180 return SendMessage(GetDlgItem(hDlg, uiCtrlID), LB_ADDSTRING, 0, (LONG)pszString);
183 int ClearListBox(HWND hDlg, UINT uiCtrlID)
185 return SendMessage(GetDlgItem(hDlg, uiCtrlID), LB_RESETCONTENT, 0, 0);
188 void SetUpDownRange(HWND hDlg, UINT uiCtrlID, int nMinVal, int nMaxVal)
190 SendMessage(GetDlgItem(hDlg, uiCtrlID), UDM_SETRANGE, 0, (LPARAM)MAKELONG((short)nMaxVal, (short)nMinVal));
193 void MakeBold(HWND hWnd)
195 HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
197 LOGFONT logFont;
199 GetObject(hFont, sizeof(LOGFONT), &logFont);
201 logFont.lfWeight = FW_BOLD;
203 HFONT hNewFont = CreateFontIndirect(&logFont);
204 ASSERT(hNewFont);
206 SendMessage(hWnd, WM_SETFONT, (WPARAM)hNewFont, MAKELPARAM(TRUE, 0));
209 int MsgBox(HWND hParent, UINT uiTextID, UINT uiCaptionID, UINT uType)
211 TCHAR szText[cchRESOURCE];
212 TCHAR szCaption[cchRESOURCE];
214 GetString(szText, uiTextID);
215 GetString(szCaption, uiCaptionID);
217 return MessageBox(hParent, szText, szCaption, uType);
220 void HideAndDisable(HWND hDlg, UINT uiCtrlID)
222 ShowWnd(hDlg, uiCtrlID, SW_HIDE);
223 SetEnable(hDlg, uiCtrlID, ES_DISABLE);
226 void ShowAndEnable(HWND hDlg, UINT uiCtrlID, BOOL bShowAndEnable)
228 int nShow = SW_SHOW;
229 ENABLE_STATE es = ES_ENABLE;
231 if (!bShowAndEnable) {
232 nShow = SW_HIDE;
233 es = ES_DISABLE;
236 ShowWnd(hDlg, uiCtrlID, nShow);
237 SetEnable(hDlg, uiCtrlID, es);
240 void MoveWnd(HWND hDlg, UINT nCtrlID, int xOffset, int yOffset)
242 HWND hCtrl = GetDlgItem(hDlg, nCtrlID);
244 RECT rect;
245 GetWindowRect(hCtrl, &rect);
247 POINT p1, p2;
248 p1.x = rect.left;
249 p1.y = rect.top;
250 p2.x = rect.right;
251 p2.y = rect.bottom;
253 ScreenToClient(hDlg, &p1);
254 ScreenToClient(hDlg, &p2);
256 rect.left = p1.x;
257 rect.top = p1.y;
258 rect.right = p2.x;
259 rect.bottom = p2.y;
261 MoveWindow(hCtrl, rect.left + xOffset, rect.top + yOffset, rect.right - rect.left, rect.bottom - rect.top, TRUE);