00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <windows.h>
00012 #include <windowsx.h>
00013
00014 #include "update.h"
00015
00016 #if __SC__
00017 #pragma ZTC align 1
00018 #endif
00019
00020 char _szControlName[] = "Update";
00021
00022 #define CBWNDEXTRA (12)
00023 #define GWL_PARTSINJOB (0)
00024 #define GWL_PARTSCOMPLETE (4)
00025 #define GWL_FONT (8)
00026
00027 ATOM NEAR RegisterControlClass (HINSTANCE hInstance);
00028 LRESULT CALLBACK MeterWndFn
00029 (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
00030
00031
00032 #if __WATCOMC__
00033 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00034 #else
00035 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00036 #endif
00037 static BOOL unregister=TRUE;
00038 switch (dwReason) {
00039 case DLL_PROCESS_ATTACH: {
00040
00041 if(!RegisterControlClass(hDLL)){
00042 unregister=FALSE;
00043 }
00044 break;
00045 }
00046 case DLL_PROCESS_DETACH:
00047 if(unregister)UnregisterClass(_szControlName, hDLL);
00048
00049 break;
00050 }
00051 return (int)TRUE;
00052 }
00053
00054 #if __SC__
00055 #pragma startaddress(DllMain)
00056 #endif
00057
00058 ATOM NEAR RegisterControlClass (HINSTANCE hInstance) {
00059 WNDCLASS wc;
00060 wc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
00061 wc.lpfnWndProc = MeterWndFn;
00062 wc.cbClsExtra = 0;
00063 wc.cbWndExtra = CBWNDEXTRA;
00064 wc.hInstance = hInstance;
00065 wc.hIcon = (HICON) NULL;
00066 wc.hCursor = LoadCursor((HINSTANCE)NULL,IDC_ARROW);
00067 wc.hbrBackground = (HBRUSH) NULL;
00068 wc.lpszMenuName = NULL;
00069 wc.lpszClassName = _szControlName;
00070 return(RegisterClass(&wc));
00071 }
00072
00073 LRESULT CALLBACK MeterWndFn
00074 (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
00075 LRESULT lResult = 0;
00076 char szPercentage[10];
00077 RECT rcClient, rcPrcnt;
00078 PAINTSTRUCT ps;
00079 WORD wPartsInJob, wPartsComplete;
00080 HBRUSH hBrush,hOldBrush;
00081 DWORD dwColor;
00082 HFONT hFont;
00083 SIZE Size;
00084 switch (uMsg) {
00085 case WM_GETDLGCODE:
00086 lResult = DLGC_STATIC;
00087 break;
00088 case WM_SETFONT:
00089 SetWindowLong(hWnd, GWL_FONT, (LONG)wParam);
00090 if (lParam)
00091 InvalidateRect(hWnd, NULL, FALSE);
00092 break;
00093 case WM_GETFONT:
00094 lResult = GetWindowLong(hWnd, GWL_FONT);
00095 break;
00096 case WM_ENABLE:
00097 InvalidateRect(hWnd, NULL, FALSE);
00098 break;
00099 case WM_CREATE:
00100 SendMessage(hWnd, MM_SETPARTSINJOB, 100, 0l);
00101 SendMessage(hWnd, MM_SETPARTSCOMPLETE, 50, 0);
00102 break;
00103 case WM_PAINT:
00104 wPartsInJob = (WORD)
00105 SendMessage(hWnd, MM_GETPARTSINJOB, 0, 0l);
00106 wPartsComplete = (WORD)
00107 SendMessage(hWnd, MM_GETPARTSCOMPLETE, 0, 0l);
00108 if (wPartsInJob == 0) {
00109 wPartsInJob = 1;
00110 wPartsComplete = 0;
00111 }
00112 wsprintf(szPercentage,"%d%%",(100 * wPartsComplete) / wPartsInJob);
00113 BeginPaint(hWnd, &ps);
00114 hFont = GetWindowFont(hWnd);
00115 if (hFont != NULL)SelectObject(ps.hdc, hFont);
00116 SetBkColor(ps.hdc, GetSysColor(COLOR_WINDOW));
00117 SetTextColor(ps.hdc, RGB(0,0,255));
00118 hBrush=CreateSolidBrush(RGB(0,0,255));
00119 hOldBrush= SelectObject(ps.hdc, hBrush);
00120 dwColor = GetBkColor(ps.hdc);
00121 SetBkColor(ps.hdc, SetTextColor(ps.hdc, dwColor));
00122 GetClientRect(hWnd, &rcClient);
00123 SetRect(&rcPrcnt, 0, 0,
00124 (rcClient.right * wPartsComplete) / wPartsInJob,
00125 rcClient.bottom);
00126 SetTextAlign(ps.hdc, TA_CENTER | TA_TOP);
00127 GetTextExtentPoint(ps.hdc, "X", 1,&Size);
00128 ExtTextOut(ps.hdc, rcClient.right / 2,
00129 (rcClient.bottom - Size.cy) / 2,
00130 ETO_OPAQUE | ETO_CLIPPED, &rcPrcnt,
00131 szPercentage, lstrlen(szPercentage), NULL);
00132 rcPrcnt.left = rcPrcnt.right;
00133 rcPrcnt.right = rcClient.right;
00134 dwColor = GetBkColor(ps.hdc);
00135 SetBkColor(ps.hdc, SetTextColor(ps.hdc, dwColor));
00136 GetTextExtentPoint(ps.hdc, "X", 1,&Size);
00137 ExtTextOut(ps.hdc, rcClient.right / 2,
00138 (rcClient.bottom - Size.cy) / 2,
00139 ETO_OPAQUE | ETO_CLIPPED, &rcPrcnt,
00140 szPercentage, lstrlen(szPercentage), NULL);
00141 SelectObject(ps.hdc,hOldBrush);
00142 DeleteObject(hBrush);
00143 EndPaint(hWnd, &ps);
00144 break;
00145 case MM_SETPARTSINJOB:
00146 SetWindowLong(hWnd, GWL_PARTSINJOB, (long)wParam);
00147 InvalidateRect(hWnd, NULL, FALSE);
00148 UpdateWindow(hWnd);
00149 break;
00150 case MM_GETPARTSINJOB:
00151 lResult = (LONG) GetWindowLong(hWnd, GWL_PARTSINJOB);
00152 break;
00153 case MM_SETPARTSCOMPLETE:
00154 SetWindowLong(hWnd, GWL_PARTSCOMPLETE, (long)wParam);
00155 InvalidateRect(hWnd, NULL, FALSE);
00156 UpdateWindow(hWnd);
00157 break;
00158 case MM_GETPARTSCOMPLETE:
00159 lResult = (LONG) GetWindowLong(hWnd, GWL_PARTSCOMPLETE);
00160 break;
00161 default:
00162 lResult = DefWindowProc(hWnd, uMsg, wParam, lParam);
00163 break;
00164 }
00165 return(lResult);
00166 }