--- mstools/samples/fontview/status.c 2018/08/09 18:20:01 1.1.1.1 +++ mstools/samples/fontview/status.c 2018/08/09 18:20:49 1.1.1.2 @@ -1,23 +1,22 @@ -#include "FirstAid.H" - -#define NOMINMAX // we will get min/max from stdlib.h +#define NOMINMAX #include -//#include #include // For 'abs' -//typedef LONG (APIENTRY *WNDPROC)(HWND, UINT, DWORD, LONG); +#if !defined (APIENTRY) +#define APIENTRY FAR PASCAL +#endif #define MAXSTATUS 10 typedef struct _tagStatus { - HWND hwnd; - INT iMaxWidth, iMinWidth, iGiveWidth; + HWND hwnd; + int iMaxWidth, iMinWidth, iGiveWidth; } Status; Status statusField[MAXSTATUS]; HWND hwndStatus; -INT cntStatusField = 0; -INT dyStatus, cxStatusBorder, cyStatusBorder, cxFrame, cyFrame, dyField; +int cntStatusField = 0; +int dyStatus, cxStatusBorder, cyStatusBorder, cxFrame, cyFrame, dyField; HFONT hfontStatus; TEXTMETRIC tmStatusFont; HBRUSH hbrBtnFace; @@ -27,334 +26,339 @@ LONG APIENTRY StatusFieldProc (HWND, UIN BOOL InitStatusBar (HANDLE hInstance) { - WNDCLASS wndclass; + WNDCLASS wndclass; - hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); + hbrBtnFace = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = (WNDPROC)StatusProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = hInstance; - wndclass.hIcon = NULL; - wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); - wndclass.hbrBackground = hbrBtnFace; - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = "SamplerStatus"; - - if (!RegisterClass (&wndclass)) - return FALSE; - - wndclass.style = CS_HREDRAW | CS_VREDRAW; - wndclass.lpfnWndProc = (WNDPROC)StatusFieldProc; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = hInstance; - wndclass.hIcon = NULL; - wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); - wndclass.hbrBackground = hbrBtnFace; - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = "StatusField"; + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = (WNDPROC)StatusProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = NULL; + wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.hbrBackground = hbrBtnFace; + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = "SamplerStatus"; + + if (!RegisterClass (&wndclass)) + return FALSE; + + wndclass.style = CS_HREDRAW | CS_VREDRAW; + wndclass.lpfnWndProc = (WNDPROC)StatusFieldProc; + wndclass.cbClsExtra = 0; + wndclass.cbWndExtra = 0; + wndclass.hInstance = hInstance; + wndclass.hIcon = NULL; + wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); + wndclass.hbrBackground = hbrBtnFace; + wndclass.lpszMenuName = NULL; + wndclass.lpszClassName = "StatusField"; - if (!RegisterClass (&wndclass)) - return FALSE; + if (!RegisterClass (&wndclass)) + return FALSE; } -BOOL CreateStatusBar (HWND hwnd, HANDLE hInst, INT iId) +BOOL CreateStatusBar (HWND hwnd, HANDLE hInst, int iId) { - cxStatusBorder = GetSystemMetrics (SM_CXBORDER); - cyStatusBorder = GetSystemMetrics (SM_CYBORDER); + cxStatusBorder = GetSystemMetrics (SM_CXBORDER); + cyStatusBorder = GetSystemMetrics (SM_CYBORDER); -//OutputDebugString (__FILE__": Calling CreateWindow\n"); - hwndStatus = CreateWindow ("SamplerStatus", "SamplerStatus", - WS_CHILD //| WS_CLIPSIBLINGS - | WS_BORDER | WS_VISIBLE, - 0, 0, 0, 0, - hwnd, (HMENU)iId, hInst, NULL); - - if (!hwndStatus) { - return FALSE; - } -//OutputDebugString (__FILE__": CreateWindow Succeeded\n"); - return TRUE; + hwndStatus = CreateWindow ("SamplerStatus", "SamplerStatus", + WS_CHILD | WS_BORDER | WS_VISIBLE, + 0, 0, 0, 0, + hwnd, (HMENU)iId, hInst, NULL); + + if (!hwndStatus) { + return FALSE; + } + return TRUE; } int StatusBarHeight (HWND hwnd) { - RECT rect; - GetClientRect (hwndStatus, &rect); - return rect.bottom-rect.top; + RECT rect; + GetClientRect (hwndStatus, &rect); + return rect.bottom-rect.top; - hwnd; // unreferenced + hwnd; // unreferenced formal parameter } BOOL AdjustStatusBar (HWND hwnd) { - RECT rect; - GetClientRect (hwnd, &rect); - MoveWindow (hwndStatus, - rect.left-cxStatusBorder, - rect.bottom - dyStatus + cyStatusBorder, - rect.right - rect.left + (cxStatusBorder*2), - dyStatus, - TRUE); - return TRUE; + RECT rect; + GetClientRect (hwnd, &rect); + MoveWindow (hwndStatus, + rect.left-cxStatusBorder, + rect.bottom - dyStatus + cyStatusBorder, + rect.right - rect.left + (cxStatusBorder*2), + dyStatus, + TRUE); + return TRUE; } -HWND AddStatusField (HANDLE hInst, INT iId, INT iMin, INT iMax, BOOL bNewGroup) +HWND AddStatusField (HANDLE hInst, int iId, int iMin, int iMax, BOOL bNewGroup) { - LONG lStyle; + LONG lStyle; - if (cntStatusField >= MAXSTATUS) return (HWND)0; // No room left in our fixed array + if (cntStatusField >= MAXSTATUS) return (HWND)0; // No room left in our fixed array - statusField[cntStatusField].hwnd = CreateWindow ("StatusField", "", - WS_CHILD //| WS_CLIPSIBLINGS - | WS_VISIBLE, - 0, 0, 0, 0, - hwndStatus, (HMENU)iId, hInst, NULL); - - if (!statusField[cntStatusField].hwnd) return (HWND)0; // CreateWindow failed for some reason - - if (iMin < 0) { - statusField[cntStatusField].iMinWidth = tmStatusFont.tmAveCharWidth*abs(iMin); - } else { - statusField[cntStatusField].iMinWidth = iMin; - } - - if (iMax < 0) { - statusField[cntStatusField].iMaxWidth = tmStatusFont.tmAveCharWidth*abs(iMax); - } else { - statusField[cntStatusField].iMaxWidth = iMax; - } - - if (bNewGroup) { - lStyle = GetWindowLong (statusField[cntStatusField].hwnd, GWL_STYLE); - lStyle |= WS_GROUP; - SetWindowLong (statusField[cntStatusField].hwnd, GWL_STYLE, lStyle); - } + statusField[cntStatusField].hwnd = CreateWindow ("StatusField", "", + WS_CHILD | WS_VISIBLE, + 0, 0, 0, 0, + hwndStatus, (HMENU)iId, hInst, NULL); + + if (!statusField[cntStatusField].hwnd) return (HWND)0; // CreateWindow failed for some reason + + if (iMin < 0) { + statusField[cntStatusField].iMinWidth = tmStatusFont.tmAveCharWidth*abs(iMin); + } else { + statusField[cntStatusField].iMinWidth = iMin; + } + + if (iMax < 0) { + statusField[cntStatusField].iMaxWidth = tmStatusFont.tmAveCharWidth*abs(iMax); + } else { + statusField[cntStatusField].iMaxWidth = iMax; + } + + if (bNewGroup) { + lStyle = GetWindowLong (statusField[cntStatusField].hwnd, GWL_STYLE); + lStyle |= WS_GROUP; + SetWindowLong (statusField[cntStatusField].hwnd, GWL_STYLE, lStyle); + } - return statusField[cntStatusField++].hwnd; + return statusField[cntStatusField++].hwnd; } BOOL DestroyStatusBar (void) { - return DeleteObject (hbrBtnFace); + return DeleteObject (hbrBtnFace); } LONG APIENTRY StatusProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam) { - HDC hdc; - PAINTSTRUCT ps; - INT x, y, i; - INT wAvailWidth, wFlexWidth, cntFlexWidth, wNeedWidth, cntNeedWidth; - RECT rect, border; - HBRUSH hBrush; - - switch (msg) { - case WM_CREATE: -#ifdef NOCREATEFONT // CreateFont is failing in NT - hfontStatus = (HFONT)NULL; -#else - hfontStatus = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, - ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS, NULL); - if (!hfontStatus) { - MessageBox (GetFocus(), "Failed To Create Font", "StatusProc", MB_OK); - } -#endif - hdc = GetDC (hwnd); - SelectObject (hdc, hfontStatus); - GetTextMetrics (hdc, &tmStatusFont); - cxStatusBorder = GetSystemMetrics (SM_CXBORDER); - cyStatusBorder = GetSystemMetrics (SM_CYBORDER); - cxFrame = 3*cxStatusBorder; - cyFrame = 3*cyStatusBorder; - dyField = tmStatusFont.tmHeight + (2*cyStatusBorder); - dyStatus = dyField + (2*cyFrame); - ReleaseDC (hwnd, hdc); - return DefWindowProc (hwnd, msg, wParam, lParam); - - case WM_SIZE: - if (cntStatusField) { - GetClientRect (hwnd, &rect); - wAvailWidth = rect.right - rect.left - (cxStatusBorder*8); - wNeedWidth = 0; - cntNeedWidth = 0; - cntFlexWidth = 0; - - /* First Pass: Dole out to fields that have a minimum need */ - for (i=0; i0) && (statusField[i].iMaxWidth ==0)) { - ++cntFlexWidth; - } - - /* For those that have a max that is greater then their min... */ - /* Includes (0,n) and (n,>n) */ - if (statusField[i].iMaxWidth > statusField[i].iGiveWidth) { - wNeedWidth += (statusField[i].iMaxWidth - statusField[i].iGiveWidth); - ++cntNeedWidth; - } - } - - /* Second Pass: Dole out to fields that have a stated maximum need */ - /* This will also hit those who had no minimum, but did have a maximum */ - /* It will still not give anything to those with no min, no max */ - if ((cntNeedWidth > 0) && (wAvailWidth > 0)) { - if (wNeedWidth > wAvailWidth) { - wNeedWidth = wAvailWidth; - } - wNeedWidth = wNeedWidth / cntNeedWidth; - for (i=0; i statusField[i].iGiveWidth) { - statusField[i].iGiveWidth += wNeedWidth; - wAvailWidth -= (statusField[i].iGiveWidth + cxStatusBorder*2); - if (GetWindowLong(statusField[i].hwnd, GWL_STYLE) & WS_GROUP) { - wAvailWidth -= cxStatusBorder*4; - } - } - } - } - - /* Third Pass: Dole out the remaining to fields that want all they can get */ - /* This includes those who had a minimum, but no maximum */ - if ((cntFlexWidth > 0) && (wAvailWidth > 0)) { - wFlexWidth = wAvailWidth / cntFlexWidth; - for (i=0; i0) && (statusField[i].iMaxWidth ==0)) { + ++cntFlexWidth; + } + + /* For those that have a max that is greater then their min... */ + /* Includes (0,n) and (n,>n) */ + if (statusField[i].iMaxWidth > statusField[i].iGiveWidth) { + wNeedWidth += (statusField[i].iMaxWidth - statusField[i].iGiveWidth); + ++cntNeedWidth; + } + } + + /* Second Pass: Dole out to fields that have a stated maximum need */ + /* This will also hit those who had no minimum, but did have a maximum */ + /* It will still not give anything to those with no min, no max */ + if ((cntNeedWidth > 0) && (wAvailWidth > 0)) { + if (wNeedWidth > wAvailWidth) { + wNeedWidth = wAvailWidth; + } + wNeedWidth = wNeedWidth / cntNeedWidth; + for (i=0; i statusField[i].iGiveWidth) { + statusField[i].iGiveWidth += wNeedWidth; + wAvailWidth -= (statusField[i].iGiveWidth + cxStatusBorder*2); + if (GetWindowLong(statusField[i].hwnd, GWL_STYLE) & WS_GROUP) { + wAvailWidth -= cxStatusBorder*4; + } + } + } + } + + /* Third Pass: Dole out the remaining to fields that want all they can get */ + /* This includes those who had a minimum, but no maximum */ + if ((cntFlexWidth > 0) && (wAvailWidth > 0)) { + wFlexWidth = wAvailWidth / cntFlexWidth; + for (i=0; i