2 * Copyright 2000, International Business Machines Corporation and others.
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
11 * INCLUDES ___________________________________________________________________
18 #include <afs/param.h>
23 #include <WINNT\afsapplib.h>
29 * EXPORTED FUNCTIONS _________________________________________________________
32 void SetEnable(HWND hDlg
, UINT nControl
, ENABLE_STATE eState
)
34 HWND hControl
= GetDlgItem(hDlg
, nControl
);
48 bEnable
= !IsWindowEnabled(hControl
);
52 EnableWindow(hControl
, bEnable
);
55 void SetElapsedTime(HWND hwnd
, DWORD nCtrlID
, ULONG ulMin
, ULONG ulMax
, ULONG ulTime
)
58 SET_ELAPSED_TIME_FROM_SECONDS (&stMin
, ulMin
);
61 SET_ELAPSED_TIME_FROM_SECONDS (&stMax
, ulMax
);
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
)
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];
88 int nHours
, nMinutes
, nSeconds
;
90 nHours
= uiNumSeconds
/ 3600;
91 nMinutes
= (uiNumSeconds
% 3600) / 60;
92 nSeconds
= (uiNumSeconds
% 3600) % 60;
95 _stprintf(szTime
, TEXT("%d hours"), nHours
);
99 lstrcat(szTime
, TEXT(", "));
100 _stprintf(sz
, TEXT("%d minutes"), nMinutes
);
105 if (nHours
|| nMinutes
)
106 lstrcat(szTime
, TEXT(", "));
107 _stprintf(sz
, TEXT("%d seconds"), nSeconds
);
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
);
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
);
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);
199 GetObject(hFont
, sizeof(LOGFONT
), &logFont
);
201 logFont
.lfWeight
= FW_BOLD
;
203 HFONT hNewFont
= CreateFontIndirect(&logFont
);
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
)
229 ENABLE_STATE es
= ES_ENABLE
;
231 if (!bShowAndEnable
) {
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
);
245 GetWindowRect(hCtrl
, &rect
);
253 ScreenToClient(hDlg
, &p1
);
254 ScreenToClient(hDlg
, &p2
);
261 MoveWindow(hCtrl
, rect
.left
+ xOffset
, rect
.top
+ yOffset
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, TRUE
);