main() { UINT x, *x_p1, *x_p2; UCHAR c, *c_p1, *c_p2; /* fire up debugger */ /* */ #ifdef DEBUGGING if ((trcfile = fopen("tracer.trc", "w")) == NULL) { printf("Can't open PC file"); exit(0); } else { #endif for (x=0;x<test1_len;x++) { test1[x] = x+50; } for (x=0;x<test2_len;x++) { test2[x] = x*7; } TRACE_ARR(test1,test1_len); TRACE_ARR(test2,test2_len); TRACE_STR("a test of TRACE_STR"); TRACE_STR("below should be an equals delimiter"); TRACE_DELIM('='); x=42000; TRACE_INT(x); c='a'; TRACE_CHR(c); x_p1 = &x; x_p2 = &x; c_p1 = &c; c_p2 = &c; /* just to invoke enter/exit defines */ call_time_once(); TRACE_FARP(x_p1); TRACE_FARP(x_p2); TRACE_FARP(c_p1); TRACE_FARP(c_p2); #ifdef DEBUGGING fclose(trcfile); } #endif // dump_arr(test1,test1_len); // dump_arr(test2,test2_len); }
void adjust_xy( short ck , short oldX, short oldY, short &newX, short &newY ) { TRACE_ENTER("adjust_xy"); if (ck) //control key? { // | center of leftmost rectangle // v newX = max( (cxBlock / 2), // | centered to inside rectangle // v min( ((oldX/cxBlock)*cxBlock) + (cxBlock / 2), // | center of rightmost rectangle // v (cxBlock * (DIVISIONS -1)) + (cxBlock / 2) ) ) ; TRACE_INT(newX); // | center of leftmost rectangle // v newY = max( (cyBlock / 2), // | centered to inside rectangle // v min( ((oldY/cyBlock)*cyBlock) + (cyBlock / 2), // | center of rightmost rectangle // v (cyBlock * (DIVISIONS -1)) + (cyBlock / 2) ) ) ; TRACE_INT(newY); } else { newX = max(0,min(oldX,cxClient)); newY = max(0,min(oldY,cyClient)); } TRACE_EXIT("adjust_xy"); }
main() { TLazyTables &data = ReplGetDataReference(); TIndexAdaptor ia; TBaseIndex baseIndex; Tnc8 *sv; Ts64 iv; //ReplUseExternalBase(data); size_t failCount = 0, successCount = 0; ReplDo( "set person:name { dept 1, position 7 } \"Sammy\"\n" "set person:name { dept 2, position 6 } \"Summer\"\n" "set person:name { dept 3, position 5 } \"Salty\"\n" "set person:name { dept 4, position 4 } \"Samuri\"\n" "set person:name { dept 2, position 3 } \"Sasha\"\n" "set person:name { dept 6, position 2 } \"Summer\"\n" "set person:name { dept 7, position 1 } \"Seth\"\n"); puts("Before modifying table:"); ReplDoPrint("person"); ia.setf("dept %i position %i", 3, 5); baseIndex = ia.findBaseIndex(data, "person"); TRACE_INT(baseIndex); END_LINE; data.setString("person:name", baseIndex, "*****"); puts("After test 1:"); ReplDoPrint("person"); sv = data.getString("person:name", 2); if(strcmp(sv, "*****") != 0) { puts("FAILURE 1"); failCount++; } else successCount++; ia.clear(); ia.setf("position %i name %s", 6, "Summer"); baseIndex = ia.findBaseIndex(data, "person"); data.setInteger("person:dept", baseIndex, 22); puts("After test 2:"); ReplDoPrint("person"); iv = data.getInteger("person:dept", 1); if(iv != 22) { failCount++; puts("FAILURE 2"); } else successCount++; printf(""FRMT_SIZE_T" success. "FRMT_SIZE_T" failures\n", successCount, failCount); }
long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static HWND hwndChild[DIVISIONS][DIVISIONS]; static short shift_key, // boolean indicators for shift & control_key; // control keys. POINT point; short rpt_cnt, // repeat count of key passed to us. x, y; // TRACE_STR("ENTER WndProc"); switch(message) { case WM_CREATE : { for (x = 0 ; x < DIVISIONS ; x++) for (y = 0 ; y < DIVISIONS ; y++) { // create our children for mouse input events... hwndChild[x][y] = CreateWindow(szChildClass, NULL, WS_CHILDWINDOW | WS_VISIBLE, 0, 0, 0, 0, hwnd, (y << 8) | x, GetWindowWord(hwnd,GWW_HINSTANCE), NULL); TRACE_STR("Child Window x/y and thier pointers..."); TRACE_INT(x); TRACE_INT(y); TRACE_FARP((const void *)hwndChild[x][y]); } return 0; } case WM_SIZE : { TRACE_STR("WM_SIZE"); //Horizontal size of a block cxClient = LOWORD(lParam); cxBlock = LOWORD(lParam)/DIVISIONS; TRACE_INT(cxBlock); //Vertical size of a block cyClient = HIWORD(lParam); cyBlock = HIWORD(lParam)/DIVISIONS; TRACE_INT(cyBlock); // slap'em on the correct place on the parent client area for (x = 0 ; x < DIVISIONS ; x++) for (y = 0 ; y < DIVISIONS ; y++) { MoveWindow(hwndChild[x][y], x*cxBlock, y*cyBlock, cxBlock, cyBlock, TRUE); } return 0; } case WM_SETFOCUS : { // in case its not showing at all... ShowCursor(TRUE); return 0; } case WM_KILLFOCUS : { // kill it when we lose focus ShowCursor(FALSE); return 0; } case WM_KEYDOWN : { // get the repeat count passed to us... rpt_cnt = LOWORD(lParam & 0xFF); if (shift_key) rpt_cnt *= REPEAT_SCALING; GetCursorPos(&point); // from raw screen to our window... ScreenToClient(hwnd,&point); //translate to nearest valid rectangle center... // if out of the window .. bring it into window // if control key is down, center the mouse on the next center // with loop back. if (control_key) { adjust_xy(control_key,point.x,point.y,x,y); } else { x = max(0,min(point.x,cxClient)); y = max(0,min(point.y,cyClient)); } switch(wParam) { case VK_CONTROL : { control_key = TRUE; // adjust it now if the user is pressing the control key. adjust_xy(control_key,point.x,point.y,x,y); break; } case VK_SHIFT : { shift_key = TRUE; break; } case VK_UP : { if (control_key) { y -= cyBlock; } else { y -= rpt_cnt; } break; } case VK_DOWN : { if (control_key) { y += cyBlock; } else { y += rpt_cnt; } break; } case VK_LEFT : { if (control_key) { x -= cxBlock; } else { x -= rpt_cnt; } break; } case VK_RIGHT : { if (control_key) { x += cxBlock; } else { x += rpt_cnt; } break; } case VK_HOME : { if (control_key) { x = cxBlock / 2; y = cyBlock / 2; } else { y=1; x=1; } break; } case VK_END : { if (control_key) { x = ((DIVISIONS - 1) * cxBlock) + (cxBlock / 2) ; y = ((DIVISIONS - 1) * cyBlock) + (cyBlock / 2) ; } else { x = cxClient - 1; y = cyClient - 1; } break; } case VK_RETURN : case VK_SPACE : { TRACE_STR("Return or Space pressed..."); point.x = x; point.y = y; TRACE_STR("Adjusted x/y in parent coord"); TRACE_INT(point.x); TRACE_INT(point.y); ClientToScreen(hwnd,&point); TRACE_STR("Adjusted x/y in screen coord"); TRACE_INT(point.x); TRACE_INT(point.y); ScreenToClient(hwndChild[x/cxBlock][y/cyBlock],&point); TRACE_STR("Adjusted x/y in child coord"); TRACE_INT(point.x); TRACE_INT(point.y); TRACE_STR("Sending message to Child Window..."); TRACE_FARP((const void *)hwndChild[x/cxBlock][y/cyBlock]); SendMessage(hwndChild[x/cxBlock][y/cyBlock], WM_LBUTTONDOWN, // the message... MK_LBUTTON, //wParam MAKELONG(point.x,point.y) //x,y coord. ); break; } } // incase x or y are negative... if (control_key) { // adjust x to be inside client windows if (x < 0) { x = ((DIVISIONS - 1) * cxBlock) + (cxBlock / 2); } else if (x > (cxClient-1)) { x = cxBlock / 2; } // adjust y to be inside client windows if (y < 0) { y = ((DIVISIONS - 1) * cyBlock) + (cyBlock / 2); } else if (y > (cyClient-1)) { y = cyBlock / 2; } } else { // adjust x to be inside client windows if (x < 0) { x = cxClient - 1; } else if (x > (cxClient - 1)) { x = 0; } // adjust y to be inside client windows if (y < 0) { y = cyClient - 1; } else if (y > (cyClient - 1)) { y = 0; } } point.x = x ; point.y = y ; ClientToScreen(hwnd,&point); SetCursorPos(point.x,point.y); return 0; } case WM_KEYUP : { switch(wParam) { case VK_CONTROL : { control_key = FALSE; break; } case VK_SHIFT : { shift_key = FALSE; break; } } return 0; } case WM_LBUTTONDOWN : { /* //current x,y of mouse converted to Block coordinates. x = LOWORD(lParam)/cxBlock; y = HIWORD(lParam)/cyBlock; if(x < DIVISIONS && y < DIVISIONS) { //here if in a valid area of the screen fState[x][y] ^= 1; //xor the bit stored there now... rect.left = x * cxBlock ; rect.top = y * cyBlock ; rect.right = (x+1) * cxBlock ; rect.bottom = (y+1) * cyBlock ; // only invalidate this particular block // don't erase... InvalidateRect(hwnd,&rect,FALSE); } else { //default beep... MessageBeep(0); } */ // whack the entire client area.. and ERASE IT! MessageBeep(0); return 0; } case WM_DESTROY : { // insert a WM_QUIT in the queue... TRACE_STR("WM_DESTROY.."); PostQuitMessage (0); TRACE_STR("EXIT WndProc"); return 0; } }//switch // TRACE_STR("EXIT WndProc"); // *********************extremely important!!! ****************** // ** extremely important!!! ** // ** extremely important!!! ** return DefWindowProc (hwnd, message, wParam, lParam); // ** extremely important!!! ** // ** extremely important!!! ** // *********************extremely important!!! ****************** } //WndProc
long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static char *pBuffer = NULL; static int cxChar, cyChar, cxClient, cyClient, cxBuffer, cyBuffer, xCaret, yCaret; HDC hdc; //handle to device context int x, y, i; PAINTSTRUCT ps; TEXTMETRIC tm; TRACE_STR("ENTER WndProc"); switch(message) { case WM_CREATE : { TRACE_DELIM('='); TRACE_STR("WM_CREATE.."); hdc = GetDC(hwnd); SelectObject (hdc, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hdc, &tm); // Suggested character width for all chars in fixed width font... cxChar = tm.tmAveCharWidth; // character height cyChar = tm.tmHeight; ReleaseDC (hwnd,hdc); TRACE_STR("EXIT WM_CREATE.."); TRACE_STR("EXIT WndProc"); return 0; } case WM_SIZE: { TRACE_STR("WM_SIZE.."); // current window size in pixels... cyClient = HIWORD(lParam); cxClient = LOWORD(lParam); TRACE_INT(cxClient); TRACE_INT(cyClient); //Window size in characters in current font... cxBuffer = max(1,cxClient/cxChar); cyBuffer = max(1,cyClient/cyChar); TRACE_INT(cxBuffer); TRACE_INT(cyBuffer); if (pBuffer != NULL) free(pBuffer); if ( ( ((LONG) (cxBuffer * cyBuffer)) > 65535L ) || ((pBuffer = (char *) malloc (cxBuffer * cyBuffer)) == NULL) ) { MessageBox (hwnd, "Window too large. Cannot" "Allocate enough memory.", "Type", MB_ICONEXCLAMATION | MB_OK ); } else { TRACE_FARP(pBuffer); for (y=0; y < cyBuffer ; y++) for (x = 0; x < cxBuffer ; x++) BUFFER(x,y) = ' '; } xCaret = 0; yCaret = 0; if (hwnd == GetFocus()) { SetCaretPos (xCaret * cxChar, yCaret * cyChar); } TRACE_STR("EXIT WM_SIZE.."); TRACE_STR("EXIT WndProc"); return 0; } case WM_SETFOCUS : { TRACE_STR("ENTER WM_SETFOCUS.."); CreateCaret(hwnd, NULL, cxChar, cyChar); SetCaretPos(xCaret * cxChar, yCaret * cyChar); ShowCaret(hwnd); TRACE_STR("EXIT WM_SETFOCUS.."); TRACE_STR("EXIT WndProc"); return 0; } case WM_KEYDOWN : { TRACE_STR("ENTER WM_KEYDOWN..."); TRACE_INT(wParam); switch(wParam) { case VK_HOME: { xCaret = 0; break; } case VK_END: { xCaret = cxBuffer - 1; break; } case VK_PRIOR: { yCaret = 0; break; } case VK_NEXT: { yCaret = cyBuffer - 1; break; } case VK_LEFT: { xCaret = max(xCaret - 1, 0); break; } case VK_RIGHT: { xCaret = min(xCaret + 1, cxBuffer - 1); break; } case VK_UP: { yCaret = max(yCaret - 1, 0); break; } case VK_DOWN: { yCaret = min(yCaret + 1, cyBuffer - 1); break; } case VK_DELETE: { for (x = xCaret ; x < cxBuffer; x++) BUFFER(x,yCaret) = BUFFER(x+1, yCaret); BUFFER(cxBuffer - 1, yCaret) = ' '; HideCaret(hwnd); hdc = GetDC(hwnd); SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT)); TextOut(hdc, xCaret * cxChar, yCaret * cyChar, &BUFFER(xCaret,yCaret), cxBuffer - xCaret ); ShowCaret(hwnd); ReleaseDC(hwnd, hdc); break; } } SetCaretPos(xCaret*cxChar, yCaret*cyChar); TRACE_STR("EXIT WM_KEYDOWN..."); TRACE_STR("EXIT WndProc"); return 0; } case WM_CHAR : { TRACE_STR("ENTER WM_CHAR..."); TRACE_INT(wParam); for (i = 0; i < (int) LOWORD(lParam) ; i++) { switch(wParam) { case '\b': //backspace { TRACE_STR(">>BACKSPACE.."); if(xCaret > 0) { xCaret--; SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1L ); } TRACE_STR(">>END BACKSPACE.."); break; } case '\t': //tab { TRACE_STR(">>TAB.."); // EXTREMELY curious! do { // this is acted upon immediately! // it calls WndProc for 'hwnd' with the indicated // message/wParam/lParam... SendMessage(hwnd, WM_CHAR, ' ', 1L ); } while (xCaret % 8 != 0); TRACE_STR(">>END TAB.."); break; } case '\n': //linefeed { TRACE_STR(">>LINEFEED.."); if (++yCaret == cyBuffer) yCaret = 0; TRACE_STR(">>END LINEFEED.."); break; } case '\r': //carraige return { TRACE_STR(">>CARRAIGE RETURN.."); xCaret = 0; if (++yCaret == cyBuffer) yCaret = 0; TRACE_STR(">>END CARRAIGE RETURN.."); break; } case '\x1B': //excape (!) { TRACE_STR(">>ESCAPE..."); for(y=0;y<cyBuffer; y++) { for(x=0; x<cxBuffer; x++) { BUFFER(x,y) = ' '; } } xCaret = 0; yCaret = 0; InvalidateRect(hwnd,NULL,FALSE); TRACE_STR(">>END ESCAPE..."); break; } default : { TRACE_STR(">>default..."); BUFFER(xCaret,yCaret) = (char) wParam; HideCaret(hwnd); hdc = GetDC(hwnd); SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT)); TextOut(hdc, xCaret*cxChar, yCaret*cyChar, &BUFFER(xCaret,yCaret), 1); ShowCaret(hwnd); ReleaseDC(hwnd,hdc); if(++xCaret == cxBuffer) { xCaret = 0; if(++yCaret == cyBuffer) yCaret = 0; } TRACE_STR(">>END default..."); break; } } } SetCaretPos (xCaret * cxChar, yCaret * cyChar); TRACE_STR("EXIT WM_CHAR..."); TRACE_STR("EXIT WndProc"); return 0; } case WM_PAINT : { TRACE_STR("WM_PAINT.."); // Invalidate the entire client area and erase it.... //get the device context handle for use in painting the sucker... hdc = BeginPaint(hwnd, &ps); // set up the font as fixed width font... SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT)); for (y = 0; y<cyBuffer; y++) { TextOut(hdc, 0, y * cyChar, &BUFFER(0,y), cxBuffer); } EndPaint (hwnd, &ps); TRACE_STR("EXIT WM_PAINT..."); TRACE_STR("EXIT WndProc"); return 0; } case WM_DESTROY : { // insert a WM_QUIT in the queue... TRACE_STR("WM_DESTROY.."); PostQuitMessage (0); TRACE_STR("EXIT WndProc"); return 0; } }//switch TRACE_STR("EXIT WndProc"); return DefWindowProc (hwnd, message, wParam, lParam); } //WndProc
long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam) { static BOOL fState[DIVISIONS][DIVISIONS]; static short shift_key, // boolean indicators for shift & control_key; // control keys. HDC hdc; //handle to device context PAINTSTRUCT ps; POINT point; RECT rect; short rpt_cnt, // repeat count of key passed to us. x, y; // TRACE_STR("ENTER WndProc"); switch(message) { case WM_SIZE : { TRACE_STR("WM_SIZE"); //Horizontal size of a block cxClient = LOWORD(lParam); cxBlock = LOWORD(lParam)/DIVISIONS; TRACE_INT(cxBlock); //Vertical size of a block cyClient = HIWORD(lParam); cyBlock = HIWORD(lParam)/DIVISIONS; TRACE_INT(cyBlock); return 0; } case WM_SETFOCUS : { // in case its not showing at all... ShowCursor(TRUE); return 0; } case WM_KILLFOCUS : { // kill it when we lose focus ShowCursor(FALSE); return 0; } case WM_KEYDOWN : { // get the repeat count passed to us... rpt_cnt = LOWORD(lParam & 0xFF); if (shift_key) rpt_cnt *= REPEAT_SCALING; GetCursorPos(&point); // from raw screen to our window... ScreenToClient(hwnd,&point); //translate to nearest valid rectangle center... // if out of the window .. bring it into window // if control key is down, center the mouse on the next center // with loop back. if (control_key) { adjust_xy(control_key,point.x,point.y,x,y); // // | center of leftmost rectangle // // v // x = max( (cxBlock / 2), // // | centered to inside rectangle // // v // min( ((point.x/cxBlock)*cxBlock) + (cxBlock / 2), // // | center of rightmost rectangle // // v // (cxBlock * (DIVISIONS -1)) + (cxBlock / 2) // ) // ) ; // TRACE_INT(x); // // | center of leftmost rectangle // // v // y = max( (cyBlock / 2), // // | centered to inside rectangle // // v // min( ((point.y/cyBlock)*cyBlock) + (cyBlock / 2), // // | center of rightmost rectangle // // v // (cyBlock * (DIVISIONS -1)) + (cyBlock / 2) // ) // ) ; } else { x = max(0,min(point.x,cxClient)); y = max(0,min(point.y,cyClient)); } switch(wParam) { case VK_CONTROL : { control_key = TRUE; adjust_xy(control_key,point.x,point.y,x,y); break; } case VK_SHIFT : { shift_key = TRUE; break; } case VK_UP : { if (control_key) { y -= cyBlock; } else { y -= rpt_cnt; } break; } case VK_DOWN : { if (control_key) { y += cyBlock; } else { y += rpt_cnt; } break; } case VK_LEFT : { if (control_key) { x -= cxBlock; } else { x -= rpt_cnt; } break; } case VK_RIGHT : { if (control_key) { x += cxBlock; } else { x += rpt_cnt; } break; } case VK_HOME : { if (control_key) { x = cxBlock / 2; y = cyBlock / 2; } else { y=1; x=1; } break; } case VK_END : { if (control_key) { x = ((DIVISIONS - 1) * cxBlock) + (cxBlock / 2) ; y = ((DIVISIONS - 1) * cyBlock) + (cyBlock / 2) ; } else { x = cxClient - 1; y = cyClient - 1; } break; } case VK_RETURN : case VK_SPACE : { SendMessage(hwnd, WM_LBUTTONDOWN, // the message... MK_LBUTTON, //wParam MAKELONG(x,y) //x,y coord. ); break; } } // incase x or y are negative... if (control_key) { // adjust x to be inside client windows if (x < 0) { x = ((DIVISIONS - 1) * cxBlock) + (cxBlock / 2); } else if (x > (cxClient-1)) { x = cxBlock / 2; } // adjust y to be inside client windows if (y < 0) { y = ((DIVISIONS - 1) * cyBlock) + (cyBlock / 2); } else if (y > (cyClient-1)) { y = cyBlock / 2; } } else { // adjust x to be inside client windows if (x < 0) { x = cxClient - 1; } else if (x > (cxClient - 1)) { x = 0; } // adjust y to be inside client windows if (y < 0) { y = cyClient - 1; } else if (y > (cyClient - 1)) { y = 0; } } point.x = x ; point.y = y ; ClientToScreen(hwnd,&point); SetCursorPos(point.x,point.y); return 0; } case WM_KEYUP : { switch(wParam) { case VK_CONTROL : { control_key = FALSE; break; } case VK_SHIFT : { shift_key = FALSE; break; } } return 0; } case WM_LBUTTONDOWN : { //current x,y of mouse converted to Block coordinates. x = LOWORD(lParam)/cxBlock; y = HIWORD(lParam)/cyBlock; if(x < DIVISIONS && y < DIVISIONS) { //here if in a valid area of the screen fState[x][y] ^= 1; //xor the bit stored there now... rect.left = x * cxBlock ; rect.top = y * cyBlock ; rect.right = (x+1) * cxBlock ; rect.bottom = (y+1) * cyBlock ; // only invalidate this particular block // don't erase... InvalidateRect(hwnd,&rect,FALSE); } else { //default beep... MessageBeep(0); } // whack the entire client area.. and ERASE IT! return 0; } case WM_PAINT : { TRACE_STR("WM_PAINT.."); //get the device context handle for use in painting the sucker... hdc = BeginPaint(hwnd, &ps); // draw lines from each point to EVERY OTHER DAMN POINT ON THE SCREEN for (x = 0;x < DIVISIONS; x++) for (y= 0 ; y < DIVISIONS ; y++) { // draw a rectangle and fill w/ current brush (if an // x was there previously it will be erased! Rectangle(hdc, x*cxBlock, y*cyBlock, (x+1)*cxBlock, (y+1)*cyBlock); // draw an X if true! if(fState[x][y]) { MoveTo(hdc,x*cxBlock,y*cyBlock); LineTo(hdc,(x+1)*cxBlock,(y+1)*cyBlock); MoveTo(hdc,x*cxBlock,(y+1)*cyBlock); LineTo(hdc,(x+1)*cxBlock,y*cyBlock); } } EndPaint (hwnd, &ps); TRACE_STR("EXIT WM_PAINT..."); TRACE_STR("EXIT WndProc"); return 0; } case WM_DESTROY : { // insert a WM_QUIT in the queue... TRACE_STR("WM_DESTROY.."); PostQuitMessage (0); TRACE_STR("EXIT WndProc"); return 0; } }//switch // TRACE_STR("EXIT WndProc"); return DefWindowProc (hwnd, message, wParam, lParam); } //WndProc