#include #include #define WM_CHARGEREADY (WM_USER+0) long FAR PASCAL _export ScrollProc (HWND hwnd, WORD message, WORD wParam, LONG lParam); FARPROC lpfnOldScr[4]; FARPROC lpfnScrollProc; int nFocus; class ChargeInfoWindow { int _cxClient , _cyClient ; HWND _hwndParent; HWND hwndCharge[4]; HWND hwndDescript[5]; public: ChargeInfoWindow(HWND hwndParent, HANDLE hInstance); HWND GetChargeHandle(int i) { return hwndCharge[i]; } //boundary conditions Size(int cx, int cy,int height); Set(Charge * c); Charge Get(); int GetcxClient(){ return _cxClient ; } int GetcyClient(){ return _cyClient ; } }; ChargeInfoWindow::ChargeInfoWindow(HWND hwndParent, HANDLE hInstance) :_hwndParent(hwndParent) { lpfnScrollProc = MakeProcInstance ((FARPROC) ScrollProc, hInstance) ; for (int n = 0 ; n < 4 ; n++) { hwndCharge[n] = CreateWindow ("EDIT", NULL, WS_BORDER | WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT, 0, 0, 0, 0, hwndParent, n, hInstance, NULL) ; hwndDescript[n] = CreateWindow ("STATIC", NULL, WS_CHILD | WS_VISIBLE , 0, 0, 0, 0, hwndParent, n+3, hInstance, NULL) ; lpfnOldScr[n] = (FARPROC) GetWindowLong (hwndCharge[n], GWL_WNDPROC) ; SetWindowLong (hwndCharge[n], GWL_WNDPROC, (LONG) lpfnScrollProc) ; } //title window hwndDescript[4] = CreateWindow ("STATIC", NULL, WS_CHILD | WS_VISIBLE , 0, 0, 0, 0, hwndParent, n+3, hInstance, NULL) ; } ChargeInfoWindow::Size(int cx, int cy,int height) { TEXTMETRIC tm ; int cyChar; int cxChar; HDC hdc; hdc = GetDC (_hwndParent) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmMaxCharWidth; cyChar = tm.tmHeight; //+tm.tmDescent; ReleaseDC (_hwndParent, hdc) ; for (int n = 0 ; n < 4 ; n++) { MoveWindow (hwndDescript[n], cx-7*cxChar, (cyChar+1)*(n+1)+1, 2*cxChar,cyChar, TRUE) ; MoveWindow (hwndCharge[n], cx-5*cxChar, (cyChar+1)*(n+1)+1, 5*cxChar,cyChar, TRUE) ; } SetWindowText(hwndDescript[0],"X = "); SetWindowText(hwndDescript[1],"Y = "); SetWindowText(hwndDescript[2],"Z = "); SetWindowText(hwndDescript[3],"Q = "); //title window move MoveWindow (hwndDescript[4], cx-7*cxChar, 1, 7*cxChar,cyChar, TRUE) ; _cxClient = 7*cxChar; _cyClient = 6*cxChar; SetWindowText(hwndDescript[4],"Active charge"); } ChargeInfoWindow::Set(Charge * c) { char buf[30]; gcvt(c->x,5,buf); SetWindowText(hwndCharge[0],buf); gcvt(c->y,5,buf); SetWindowText(hwndCharge[1],buf); gcvt(c->z,5,buf); SetWindowText(hwndCharge[2],buf); gcvt(c->q,4,buf); SetWindowText(hwndCharge[3],buf); } Charge ChargeInfoWindow::Get() { WORD len0=GetWindowTextLength(hwndCharge[0]); WORD len1=GetWindowTextLength(hwndCharge[1]); WORD len2=GetWindowTextLength(hwndCharge[2]); WORD len3=GetWindowTextLength(hwndCharge[3]); //char * buf0= new char[len0]; //char * buf1= new char[len1]; //char * buf2= new char[len2]; //char * buf3= new char[len3]; //GetWindowText(hwndCharge[0], buf0, len0); //GetWindowText(hwndCharge[1], buf1, len1); //GetWindowText(hwndCharge[2], buf2, len2); //GetWindowText(hwndCharge[3], buf3, len3); char buf0[100]; char buf1[100]; char buf2[100]; char buf3[100]; char *endptr; SendMessage(hwndCharge[0],WM_GETTEXT,8,(LONG)buf0); SendMessage(hwndCharge[1],WM_GETTEXT,8,(LONG)buf1); SendMessage(hwndCharge[2],WM_GETTEXT,8,(LONG)buf2); SendMessage(hwndCharge[3],WM_GETTEXT,8,(LONG)buf3); Charge c; //c.x=atof(buf0); //c.y=atof(buf1); //c.z=atof(buf2); //c.q=atof(buf3); c.x=strtod(buf0, &endptr); c.y=strtod(buf1, &endptr); c.z=strtod(buf2, &endptr); c.q=strtod(buf3, &endptr); return c; } long FAR PASCAL _export ScrollProc (HWND hwnd, WORD message, WORD wParam, LONG lParam) { short n = GetWindowWord (hwnd, GWW_ID) ; switch (message) { case WM_KEYDOWN: if (wParam == VK_RETURN) { SendMessage(GetParent(hwnd),WM_CHARGEREADY,0,0); SetFocus( GetParent(hwnd) ); } return CallWindowProc (lpfnOldScr[n], hwnd, message, wParam, lParam) ; //return 0; // case WM_SETFOCUS: //MessageBox(GetParent(hwnd), "dupa","cipa",MB_OK); // nFocus = n ; // break ; } return CallWindowProc (lpfnOldScr[n], hwnd, message, wParam, lParam) ; }