/* C source code compiled with Microsoft's Visual C/C++ 6.0 (with the Feb 2003 MSDN library of API's) http://jdmcox.com/USAPhotoMaps.rc http://jdmcox.com/resource.h http://jdmcox.com/ijl15.dll http://jdmcox.com/ijl15.zip http://jdmcox.com/zlib.zip int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) case WM_CREATE: case WM_USER4: case WM_USER3: case WM_USER2: case WM_USER: case WM_COMMAND: case ID_STOPPOSITIONING: case ID_STOPDOWNLOADING: case ID_FILE_DOWNLOADMAPDATA_FILLSCREEN: case ID_FILE_DOWNLOADMAPDATA_1METERPIXELPHOTOS: case ID_FILE_DOWNLOADMAPDATA_ENTERLATLON: case ID_FILE_SHOWELEVATIONSQUARES: case ID_FILE_CONVERTELEVATIONDATA: case ID_FILE_DOWNLOADMAPDATA_TIGERSTREETS: case ID_FILES_OPENMAPFILE: case ID_FILES_NEWMAPFILE: case ID_FILE_BOUNDARYFORBIGJPEG: case ID_FILE_TERRAFETCHER_REGION: case ID_FILES_PRINT: case ID_FILE_RUNSTREETSTRIPS: case ID_FILE_IMPORT_IMPORTSTPUSHPINS: case ID_FILE_IMPORT_IMPORTFORERUNNERLOGBOOK: case ID_FILE_IMPORT_IMPORTGPXTRACKS: case ID_FILE_IMPORT_GEOCACHINGLOCFILES: case ID_FILE_EXPORTTRACKSTOGPX: case ID_FILE_EXPORT: case ID_FILES_CLOSE: case ID_VIEW_LATITUDELONGITUDE_DEGREES: case ID_VIEW_MAPTYPE_PHOTO: case ID_VIEW_BRIGHTNESS_BRIGHTER: case ID_VIEW_GRID: case ID_VIEW_CONTOURS: case ID_VIEW_SHOWUSGSLANDMARKS: case ID_VIEW_SHOWWAYPOINTNAMES: case ID_VIEW_TIGERLINES_INTERSTATES: case ID_VIEW_MAPOFUSA: case ID_VIEW_BIGJPEG: case ID_VIEW_OPTIONS_EVERYTHINGELSE: case ID_GOTO_ADDRESS: case ID_GOTO_TOWNSHIP: case ID_GOTO_USGSLANDMARK: case ID_GOTO_TIGERSTREET: case ID_GOTO_LATLON: case ID_ZOOM_1METERPIXEL: case ID_TEXT_SHOWALL: case ID_TEXT_LISTALL: case ID_TEXT_ENTER: case ID_ROUTE_SHOW: case ID_ROUTE_CREATE: case ID_ROUTETOTRACKS: case ID_GPS_ROUTE_APPENDTOTRACKS: case ID_WAYPOINTS_SHOW: case ID_WAYPOINTS_OPENFILE: case ID_GPS_HELP: case ID_GPS_COMMPORT: case ID_GPS_WAYPOINTS_UPLOAD: case ID_GPS_WAYPOINTS_DOWNLOAD: case ID_GPS_TRACKS_UPLOAD: case ID_GPS_TRACKS_DOWNLOAD: case ID_GPS_TRACKS_SHOW: case ID_GPS_TRACKS_COMBINE: case ID_GPS_ROUTES_SEND: case ID_GPS_ROUTES_RECEIVE: case ID_GPS_LOCATION_COPYPOSITION01CSVTOTRACKFORMAT: case ID_GPS_LOCATION_DISPLAYPOSITION01CSV: case ID_GPS_LOCATION_SHOWLOCATIONSPACEBAR: case ID_APRS_RECEIVED_DATA: case ID_APPROACHCONTROL_SANFRANCISCO: case ID_HELP_PHOTOMAPHELP: case ID_HELP_HTTP: case ID_HELP_CHECKFORNEWERVERSION: case ID_HELP_GETDATEOFPHOTOTOPO: case ID_HELP_TIGERDATA: case ID_HELP_TIGERCOUNTIES: case ID_HELP_ABOUTPHOTOMAP: case WM_USER_COMM: case GOT_LAST_DLE: case WM_MOUSEMOVE: case WM_LBUTTONDOWN: case WM_RBUTTONUP: case WM_LBUTTONUP: case WM_RBUTTONDOWN: case WM_KEYUP: case WM_KEYDOWN: case VK_RIGHT: case WM_PAINT: case WM_CLOSE: */ #include //put ws2_32.lib in Project/Settings/Link #include #include // for timeSetEvent add winmm.lib to Project -Settings -Link #include //put comctl32.lib in Project/Settings/Link #include "SetupAPI.h"//put setupapi.lib in Project/Settings/Link #include //put wininet.lib in Project/Settings/Link #include //for sqrt, etc #include //for sprintf #include //for _beginthreadex & select "multithreading" in Settings: C/C++ Category: Code Generation #include "ijl.h"//put ijl15.lib in Project/Settings/Link #include "zlib.h"//put zlib.lib and zdll.lib in Project/Settings/Link and zlib.dll and zlib1.dll in WINDOWS/System32 #include "zconf.h" #include //put gdi32.lib and msimg32.lib in Project/Settings/Link //#include "mmsystem.h"//for PlaySound - put winmm.lib in Project/Settings/Link #include #include "resource.h" //#include //for _msize #include //? and put ddraw.lib and dxguid.lib in Project/Settings/Link // and use Microsoft DirectX 9.0 (February 2005) and point to it in Tools/Options/Directories #define PI 3.141592653589793 #define MAX_TILE_SIZE 26000 #define MAX_IMAGE_SIZE 200*200*3 #define TOTAL_LOCS 5000 #define MAX_PTR 14400 #define AREA_SIZE 50 #define IDENT_COUNT 7 #define HUNDRED_MILES 100000 #define UP 1 #define DOWN 2 #define LEFT 3 #define RIGHT 4 #define WM_USER_COMM WM_USER + 1 #define WM_USER2 WM_USER_COMM + 1 #define WM_USER3 WM_USER2 + 1 #define WM_USER4 WM_USER3 + 1 #define WM_USER6 WM_USER4 + 1 #define WM_USB WM_USER6 + 1 #define WM_USER8 WM_USB + 1 #define WM_APRS_COMM WM_USER8 + 1 #define WM_APRS_IS_COMM WM_APRS_COMM + 1 #define WM_APRS_SERVER WM_APRS_IS_COMM + 1 #define LINE_TO 213 #define EDIT 321 #define OK 211 #define EXIT 123 #define DELEET 312 #define URL_LINK 331 #define HELP 111 #define DEG 333 #define DEGMIN 112 #define DEGMINSEC 113 #define ITSUTM 221 #define ITSUSNG 332 #define DLE 16 #define ETX 3 #define ACK 6 #define NAK 21 #define GOT_FIRST_DLE 1 #define GOT_PID 2 #define GOT_DATASIZE 3 #define GOT_DATA 4 #define GOT_CHECKSUM 5 #define GOT_LAST_DLE 6 #define GOT_ETX 7 #define RECORDS 27 #define XFER_CMPLT 12 #define PVT_DATA 51 #define ROUTE_HEADER 29 #define ROUTE_DATA 30 #define ROUTE_LINK 98 #define TRACKHEADER 99 #define TRACK 34 #define WAYPOINT 35 #define ROUTEHEADER 29 #define ROUTE 30 #define ROUTELINK 98 #define NOBUTTON 99 #define LBUTTON 100 #define RBUTTON 101 #define MENU 102 #define FROMCOMM 60 #define WAYPOINT_SIZE 150 #define FROM_L 7123 #define FROM_T 7124 #define FROM_R 7125 #define FROM_B 7126 #define FROM_TL 7127 #define FROM_BL 7128 #define FROM_TR 7129 #define FROM_BR 7130 #define MAX_TEXT 60 #define GREEN 0xFF00 #define RED 0xFF #define YELLOW 0xFFFF #define WHITE 0xFFFFFF #define LIGHTGRAY 0xE0E0E0 #define GETWAYPOINTS 601 #define GETTRACKS 602 #define SENDWAYPOINTS 603 #define SENDINGROUTES 606 #define BEGINRECORDS8 9001 #define BEGINRECORDS9 9002 #define SENDTRACKS 9004 #define STARTPVT 9005 #define SENDROUTE 9006 #define RECEIVEROUTE 9007 #define TAB 9 #define MEGABYTE 1024*1024 #define MILLION 1000000 #define HUNDREDTHOUSAND 100000 #define TENTHOUSAND 10000 #define THOUSAND 1000 #define HUNDRED 100 #define TEN 10 #define PHOTO 1 #define TOPO 2 #define URBANAREA 3 #define TRACKSDOWNLOAD 1 #define POSITION 2 #define WAYPOINTSDOWNLOAD 3 #define IOCTL_GARMIN_USB_BULK_OUT_PACKET_SIZE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x851, METHOD_BUFFERED, FILE_ANY_ACCESS) #define IOCTL_GARMIN_USB_INTERRUPT_IN CTL_CODE(FILE_DEVICE_UNKNOWN, 0x850, METHOD_BUFFERED, FILE_ANY_ACCESS) #define USB_MAX_BUFFER_SIZE 4096 #define USB_INTERRUPT_DATA_SIZE 64 #define PACKETSIZE 200 #define GLL 1 #define GGA 2 #define RMC 3 #define MAX_DEMS 2000 #define ELEVBUF2SIZE 4*1024*1024 #define TIGERS 750000 #define MAXPTIGERS 100 #define MAXNAMEPTRS 16000 #define BUFSIZE 11000 #define SMALLBUFSIZE 50000 #define MAXAPRS 25600 #define FULL 1 #define HALF 2 #define QUARTER 3 #define EIGHTH 4 #define PORTRAIT 1 #define LANDSCAPE 2 #define GETSETPAPERORIENT 30 #define APRSFRAME 1 #define TYPE 2 #define ADDRESS 3 #define ADDEND 4 #define CONTROL 5 #define PROTOCOL 6 #define INFO 7 #define KISSEND 0 #define FEND 0xC0 #define FESC 0xDB #define TFEND 0xDC #define TFESC 0xDD #define PRIMARY 1 #define SECONDARY 2 #define OVERLAY 3 #define BITMAPFILEHEADER_SIZE 14 #define XBITMAP 20 #define YBITMAP 20 #define HOMEINDEX 0 #define GPSINDEX 1 #define OBJECTINDEX 2 #define TRANSMITHOME 1 #define TRANSMITGPS 2 #define TRANSMITNONE 3 #define LOG108 log(1.08) #define MAXOBJECTS 65 #define GRAVITY 9.80665 // meters / (second squared) #define TIMER_RESOLUTION 1 #define MAXPLANES 25 #define MYWEBPAGESIZE 15000 //#define onetime0 //char Bug[] = "Bug.txt"; char Version[] = "Version 2.78\r\n\r\nMay 20, 2011\r\n\r\nby Doug Cox\r\n"; BOOL debug = FALSE, approachcontrol = FALSE; //BOOL autodownload = TRUE; int PacketSize; BOOL dontcleanup = FALSE, ClearStationsFlag = FALSE; char ToInternet[256]; char IgateInsert[] = ",qAR,"; char Quit[] = "QUIT\n"; char IgateErrorCaption[] = "Igate Error"; //COMMANDS: Hxxx Axxx Sxxx T (heading, altitude, speed, tower) then Enter int AirportUTMEasting, AirportUTMNorthing, PlaneRadius = 7, AtPlane, command, existingIAS, finalIAS, existingTAS, existingAlt, finalAlt; int RateOfDescent, RateOfSlowing, HeadingChange, CircleX, CircleY, CircleX2, CircleY2, MetersPerPixel, SpotX, SpotY, xUTM, yUTM, ThirtyMiles; int cmd, Centerline, DownwindAlt, DownwindIAS, TAS, GlideSlopeAlt, GlideSlopeIntercept; double d1, d2, PI2, PIdiv2, heading, iHeading, radians, radianheading, TurnRadius, dThirtyMiles, hypotenuse, downwindOffsetHeading; double BankAngle = 25.0, TwentyfiveDegreeBank, MetersPerSec, Meters, xMeters, yMeters, SecondsPerCircle, dCenterline, GlideSlope, dDistance; char NewPlane[] = " Left-click on a location for an arriving airplane "; char CenterLine[] = " Right-click on a runway approach end for an extended centerline "; char Heading[6]; char ApproachAltitude[6]; char Airspeed[6]; char Command[16]; char tempPlane[8]; char centerline[8]; char downwindAlt[8]; char downwindIAS[8]; char gs[8]; char fieldelev[8]; BOOL planecommand = FALSE, showdata = TRUE, righturn, rightdownwind, passedzero, fromuser3 = FALSE; HWND hwndEdit2, hwndEdit3, hwndEdit4, hwndEdit5; SIZE Size; int maxRows, maxCols; char *lpPart[1] = {NULL};//weird, but from Microsoft int xTopLeft, xBottomRight, yTopLeft, yBottomRight; int time = 0, prevtime, LastBeacon, LastCourse, firstposX, LastX, LastPosition; int sbSpeed, sbCourse, sbBeacon, sbSlowSpeed = 10, sbSlowBeacon = 180, sbHighSpeed = 50, sbHighBeacon = 180, sbTurnTime = 10, sbAngle = 35, sbConstant = 0; double speed, ndist, edist; char SlowSpeedSB[12];// = "10"; char SlowBeaconSB[12];// = "180"; char HighSpeedSB[12];// = "50"; char HighBeaconSB[12];// = "180"; char TurnTimeSB[12];// = "10"; char AngleSB[4];// = "35"; char ConstantSB[12];// = "0"; char current_course[10], current_speed[10]; BOOL smartbeaconing = FALSE, testingsmartbeaconing = FALSE, gotfirstpos, compressit = FALSE; DWORD bilrows, bilcols; int Northest = 0, Eastest = 0x0FFFFFFF, Southest = 0x0FFFFFFF, Westest = 0; int WminusEx30, NminusS; int UTMNbilBuf[2048][2048]; int UTMEbilBuf[2048][2048]; int UTMN30Buf[2048*2048]; int UTME30Buf[2048*2048]; WORD UTMElevBuf[2048*2048]; int nw, sw, se, ne, nwN, nwE, swN, swE, neN, neE, seN, seE; int elevN, elevW, elevS, elevE, elevNS, elevEW, elev; int kPtr, kaddr, addr, isaprslinebeg, linebeg, linend, saveBaud, aprsi = 0, aprsin = 0, Aprsi = 0, CurrentAprsi, APRSBaud = 0, wx, MaxText, toHwndComm, SP, DC, SE, Speed, Course; int dataloc, aprsISbeg, aprsISend, APRSHelpSize, symbolindex, homesymbolindex = -1, gpssymbolindex = -1, transmitto = TRANSMITNONE, KissLen, blanklen; int symbolrow, symbolcol, FilterLen = 0, stationPtr, msgPtr, NumOfStations, staptr, smallest, stationlinebeg, stationIndex, xIndex, yIndex; int ObjectX, ObjectY, objectPtr, ObjectPtr, ObjectUTMN, ObjectUTME, ObjectUTMZ, objectindex, ObjectToMove = -1; int APRSUTMEasting, APRSUTMNorthing, symbol, DestBegin, DestEnd, LastGPSEasting = 0, LastGPSNorthing = 0, lat1, lon1; unsigned int uTimerID = NULL; //double radius, Meters; //double POWER[10] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}; //double HEIGHT[10] = {10,20,40,80,160,320,640,1280,2560,5120}; //double GAIN; WORD hash; WORD serverPort = 1448; BYTE ach, SymbolTable, GPtype; DWORD hAPRSThread, hAPRSThread2, hAPRSThread3, TacticalFileSize; double Lat1, Lon1, LatMin, LonMin, beginE, endE, beginN, endN; BOOL aprs = FALSE, ataprs = FALSE, tnc = FALSE, inaprs = FALSE, kiss = FALSE, gotfesc, dontshow, shutitdown = FALSE, Message = FALSE, transmitted = FALSE, showline = FALSE; BOOL weatherlessposition = FALSE, gotcr = FALSE, aprsimulate, gotpos = FALSE, firsttx, showlist = 0x11000000, goodmessage = FALSE, usetactical = FALSE, gotrackname; BOOL mycallnotfound, homelatlonnotfound, transmittonotfound, homesymbolnotfound, gpssymbolnotfound, destinationnotfound, commentnotfound, beaconnotfound, sbnotfound, compressnotfound; BOOL markobject = FALSE, fromstationinfo = FALSE, gotsymbol = FALSE, atobj = FALSE, sendit = FALSE, itsobject = FALSE, frommessage = FALSE, fromobject = FALSE; BOOL gettinginternet = FALSE, gettingreceived = FALSE, gettingsaved = FALSE, fromctrli = FALSE, compressed = TRUE, itslive = TRUE, sendmyloc = FALSE, fromindex; BOOL okay = FALSE, igate = FALSE; char StationsInfo[] = "Stations Info "; char QRZ[32] = "http://www.QRZ.com/db/"; char Tactical[] = "TacticalCalls.txt"; char TacticalCalls[1024]; char Compressed[13]; char Overlay[2]; char ObjectName[32]; char ObjectsDta[] = "Objects.dta"; char Object[] = "'s Object"; char CircleRadius[12]; TCHAR tchBuffer[32]; char APRStime[5]; char Stations[10240]; char StationsTitle[] = "000 Stations"; char Call[20]; char AprsLine[128]; int Ptrs[1000]; int PtrsCopy[1000]; char Msg[10240]; char MsgTo[10]; char SendMsg[68]; char LAT1[4], LON1[4], LAT2[4], LON2[4]; BYTE hashMyCall[10] = "\0"; char Filter[128];// = "user NOCALL";//NOCALL pass -1 vers usaphotomaps 278 filter a/39/-123/36/-120\n"; char Filter1[] = "user NOCALL"; char Filter2[] = " pass "; char Filter3[] = " vers usaphotomaps 278"; char Filter4[] = " filter a/"; char MyLoc[128];// = "KI6NLA>APZUSA,TCPIP*:=3724.44N/12206.98W-USAPhotoMaps\n"; char InternetUNPROTO[] = ">APZUSA,TCPIP*:"; char Filter5[] = " -p/CW"; //char APRSBufferTxt[] = "APRS log01.txt"; char APRSBufferTxt[16] = "\0"; //char APRSlog[] = "APRS log01.dta"; char APRSlog[16] = "\0"; char APRStxt[MAX_PATH];// = "APRS log34.txt"; //char FINDU[] = "C:\\Program Files\\Internet Explorer\\iexplore.exe "; char APRSComm[] = "\\\\.\\COM "; char APRSHelp[] = "APRSHelp.txt"; char *pAPRSHelp; char NoAPRSFile[] = "Couldn't find APRSHelp.txt"; char Tier2Server[24];// = "missouri.aprs2.net"; char aprs2net[] = ".aprs2.net"; char missouri[] = "missouri"; char montana[] = "montana"; char nebraska[] = "nebraska"; char southwest[] = "southwest"; char socal[] = "socal"; char midwest[] = "midwest"; char central[] = "central"; char aprswest[] = "aprswest"; char newengland[] = "newengland"; char westtn[] = "westtn"; char Simultaneously[] = "Internet data,\nPrevious data,\nand Received data\ncan only be selected exclusively."; unsigned char APRSRegValue[] = "COM "; char Findu[512]; BYTE aprsBuf[MEGABYTE];; char APRSCommPort[3] = "\0\0"; char Symbol[20]; char MyCall[10] = "\0"; char HomeLatLon[24];//3724.44N/12206.98W char GPSLatLon[19];//3724.44N/12206.98W char HomeSymbol[20] = "\0"; char GPSSymbol[20] = "\0"; char Destination[32]; char Comment[32]; char CourseSpeed[8]; char Beacon[12] = "\0"; char Kiss[128]; char MYCALL[17] = "MYCALL";//KI6NLA char UNPROTO[44] = "UNPROTO"; char FirstDest[] = " APZUSA VIA "; char BTEXT[68] = "BTEXT";//3724.44N/12206.98W-jdmcox@jdmcox.com char MESSAGE[68] = "BTEXT :"; char OBJECT[68] = "BTEXT ;"; char Ack[28] = "BTEXT :"; char BEACON[17] = "BEACON EVERY 0"; char Shutdown[] = "BEACON EVERY 0"; char BeaconEvery1[] = "BEACON EVERY 1"; char Blank1[32]; char ShowList1[256] = "\0"; char ShowList2[256] = "\0"; char ShowList3[256] = "WX\r\n"; char ShowList4[256] = "Digi\r\n"; char ShowList5[256] = "\0"; char ShowList6[256] = "\0"; char saveRegValue1; char saveRegValue2; char GetZipCode[] = "http://jdmcox.com/ZipCode.dta"; char ZipCode[] = "ZipCode.dta"; char Dest[10]; char Addr[10]; char Nmea[100]; char KissPos[256]; char aprsTemp[4]; char aprsWindSpeed[4]; char aprsGust[4]; char aprsWindDir[4]; char aprsHumidity[4]; char wind[] = " wind "; char NoDescript[] = "No Descript"; char SecretIP[24];// = "192.168.1.100:1448"; //char ServerIP[24]; char CallsignError[] = "An FCC callsign is required to transmit."; struct { int UTMEasting; int UTMNorthing; int x; int y; int UTME1; // for trails int UTMN1; int UTME2; int UTMN2; int UTME3; int UTMN3; int UTME4; int UTMN4; int UTME5; int UTMN5; int UTME6; int UTMN6; int IAS; int TAS; int heading; int altitude; int newIAS; int newHeading; int newAltitude; double radianheading; double newRadianheading; double RadiansPerSecond; BYTE Turn; } Plane[MAXPLANES]; int plane; struct { int UTME1; int UTME2; int UTMN1; int UTMN2; int GSE; int GSN; int GSInterceptAlt; }Line[10]; int lines; struct { int UTMN; int UTME; int UTMZ; COLORREF CircleColor; DOUBLE CircleRadius; char Name[32]; char Time[8]; char Comment[44]; char SymbolType; BYTE Symbol; BYTE itsmiles; BYTE intense; BYTE extra; } Objects[MAXOBJECTS]; // 65, was 25 struct { int UTMN; int UTME; int UTMZ; WORD Time; char Call[10]; char DescOrWx[24]; char Status[49]; char SymbolType; char Symbol; char RedDot; } Aprs[MAXAPRS]; HANDLE hAPRSFile = NULL, hAPRSComm; HWND hwndAPRSDlg, hwndComm = NULL, hwndAPRS, hwndListDlg, hwndCtrlC, hwndMyCall, hwndDestination, hwndBtext, hwndBeacon, hwndStationInfoDlg, hwndSymbolDlg, hwndEditObjectDlg; HWND hwndSend, hwndEdit1, hwndStartKISS, hwndStopKISS, hwndMessageDlg = NULL, hwndMessage, hwndObject, hwndTranslate, hwndStationsDlg, hwndTacticalDlg, hwndInfoButton; TIME_ZONE_INFORMATION tzi; RECT editRect, rcBitmap; HDC hdcSymMem = 0, hdcSymMem1, hdcSymMem2; LPMEASUREITEMSTRUCT lpmis; LPDRAWITEMSTRUCT lpdis; TEXTMETRIC tm; struct { char symbol; char Primary[15]; char Secondary[16]; char PrimaryGPS[3]; char SecondaryGPS[3]; } APRSSymbols[95] = { '!',"Police Stn","Emergency","BB","OB", '"',"No Symbol","No Symbol","BC","OC", '#',"Digi","Digi No.","BD","OD", '$',"Phone","Bank","BE","OE", '%',"DX Cluster","No Symbol","BF","OF", '&',"HF Gateway", "Gateway No.","BG","OG", '\'',"Plane","Crash site","BH","OH", '(',"Mob Sat Stn","Cloudy","BI","OI", ')',"WheelChair","MEO","BJ","OJ", '*',"Snowmobile","Snow","BK","OK", '+',"Red Cross","Church","BL","OL", ',',"Boy Scout","Girl Scout","BM","OM", '-',"Home","Home (HF)","BN","ON", '.',"X","UnknownPos","BO","OO", '/',"Red Dot","Destination","BP","OP", '0',"Circle (0)","Circle No.","P0","A0", '1',"Circle (1)","No Symbol","P1","A1", '2',"Circle (2)","No Symbol","P2","A2", '3',"Circle (3)","No Symbol","P3","A3", '4',"Circle (4)","No Symbol","P4","A4", '5',"Circle (5)","No Symbol","P5","A5", '6',"Circle (6)","No Symbol","P6","A6", '7',"Circle (7)","No Symbol","P7","A7", '8',"Circle (8)","No Symbol","P8","A8", '9',"Circle (9)","Petrol Stn","P9","A9", ':',"Fire","Hail","MR","NR", ';',"Campground","Park","MS","NS", '<',"Motorcycle","Gale F1","MT","NT", '=',"Rail Eng.","No Symbol","MU","NU", '>',"Car","Car No.","MV","NV", '?',"File svr","Info Kiosk","MW","NW", '@',"HC Future","Hurricane","MX","NX", 'A',"Aid Stn.","Box No.","PA","AA", 'B',"BBS","Snow blwng","PB","AB", 'C',"Canoe","Coast Guard","PC","AC", 'D',"No Symbol","Drizzle","PD","AD", 'E',"Eyeball","Smoke","PE","AE", 'F',"Tractor","Fr'ze Rain","PF","AF", 'G',"Grid Squ.","Snow Shwr","PG","AG", 'H',"Hotel","Haze","PH","AH", 'I',"Tcp/ip","Rain Shwr","PI","AI", 'J',"No Symbol","Lightning","PJ","AJ", 'K',"School","Kenwood","PK","AK", 'L',"Usr Log-ON","Lighthouse","PL","AL", 'M',"MacAPRS","No Symbol","PM","AM", 'N',"NTS Stn","Nav Buoy","PN","AN", 'O',"Balloon","Rocket","PO","AO", 'P',"Police","Parking","PP","AP", 'Q',"TBD","Quake","PQ","AQ", 'R',"Rec Veh'le","Restaurant","PR","AR", 'S',"Shuttle","Sat/Pacsat","PS","AS", 'T',"SSTV","T'storm","PT","AT", 'U',"Bus","Sunny","PU","AU", 'V',"ATV","VORTAC","PV","AV", 'W',"WX Service","WXS No.","PW","AW", 'X',"Helo","Pharmacy","PX","AX", 'Y',"Yacht","No Symbol","PY","AY", 'Z',"WinAPRS","No Symbol","PZ","AZ", '[',"Jogger","Wall Cloud","HS","DS", '\\',"Triangle","No Symbol","HT","DT", ']',"PBBS","No Symbol","HU","DU", '^',"Plane lrge","Plane No.","HV","DV", '_',"WX Station","WX Stn No.","HW","DW", '`',"Dish Ant.","Rain","HX","DX", 'a',"Ambulance","Diamond No.","LA","SA", 'b',"Bike","Dust blwng","LB","SB", 'c',"ICP","CivDef No.","LC","SC", 'd',"Fire Station","DX Spot","LD","SD", 'e',"Horse","Sleet","LE","SE", 'f',"Fire Truck","Funnel Cld","LF","SF", 'g',"Glider","Gale","LG","SG", 'h',"Hospital","HAM store","LH","SH", 'i',"IOTA","Blk Box No.","LI","SI", 'j',"Jeep","WorkZone","LJ","SJ", 'k',"Truck","SUV","LK","SK", 'l',"Laptop","Area Locns","LL","SL", 'm',"Mic-E Rptr","Milepost","LM","SM", 'n',"Node","Triang No.","LN","SN", 'o',"EOC","Circle sm","LO","SO", 'p',"Rover","Part Cloud","LP","SP", 'q',"Grid squ.","No Symbol","LQ","SQ", 'r',"Antenna","Restrooms","LR","SR", 's',"Power Boat","Boat No.","LS","SS", 't',"Truck Stop","Tornado","LT","ST", 'u',"Truck 18wh","Truck No.","LU","SU", 'v',"Van","Van No.","LV","SV", 'w',"Water Stn","Flooding","LW","SW", 'x',"XAPRS","No Symbol","LX","SX", 'y',"Yagi","Sky Warn","LY","SY", 'z',"Shelter","Shelter No.","LZ","SZ", '{',"No Symbol","Fog","J1","Q1", '|',"TNC Stream Sw","TNC Stream SW","J2","Q2", '}',"No Symbol","No Symbol","J3","Q3", '~',"TNC Stream Sw","TNC Stream SW","J4","Q4", '\1',"","""",""}; int BigWidth, BigHeight, BigTop, BigLeft, xBigLoc, yBigLoc; char PrinterName[64]; DWORD PrinterNameLen = 64; DWORD dwSizeNeeded, dwNumItems, dwItem, dwNeeded; HANDLE hPrinter; LPPRINTER_INFO_5 lpInfo; LPDEVMODE pDevMode; char *ExploristBuf; char Explorist[] = "I'm still waiting for help from any eXplorist owner!\n\njdmcox@jdmcox.com"; char Routine[] = "Routine not finished!"; //char ATDI[] = "\ //The lat/lon, as well as the\nelevation data website address,\nis now in the Windows Clipboard."; char CommPort[3]; char GPX[MAX_PATH]; char FullGPX[MAX_PATH]; char csv[] = "csv"; char xml[] = "xml"; char txt[] = "txt"; char gpx[] = "gpx"; char gz[] = "gz"; char FullGeocaching[MAX_PATH]; char Geocaching[MAX_PATH]; //BOOL waypointedited; struct { char name[48]; WORD begin; WORD end; }Photo[100]; int P; int Width, Height, Resolution; BYTE *PhotoBuf; BYTE *photo_pixel_buf; char PhotoName[48] = "Photos\\"; char Photos[] = "Photo"; POINTS points; HWND hwndDescEdit, hwndPhoto; char StreetName[50]; BOOL first = FALSE, show = FALSE; HWND hwndStreet = NULL, hwndShowButton, hwndStreetEdit; HDC hdcShowButton, hdcStreetEdit; BYTE *Pixels; char Big[] = " Press Esc to exit Use the Arrow keys (or hold the left button down and move the mouse) to pan a large image"; char FullJpgFile[MAX_PATH]; char JpgFile[MAX_PATH]; BOOL showjpeg = FALSE; HWND hwndBig; int Radius; char Cdata[] = ""; char Region[] = "Region=4\r\nFormat=UTM\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\n"; char TerraFetcherRegion[] = "TerraFetcherRegion.txt"; char Path1[] = "Path="; char Path2[] = "\r\nWidth=800\r\nFormat=UTM\r\n"; char TerraFetcherPath[] = "TerraFetcherPath.txt"; struct { int x; int y; int z; } CurLandmark[100]; int cl, NormalOrientation; BOOL showinglandmarks; char ElevationFile[MAX_PATH];// = "NED_46542986.bil"; char ShortElevationFile[MAX_PATH]; char ElevationDir[] = "Elevation"; char NewElevFile[MAX_PATH] = "Elevation\\"; int Lams, TotalLams, Xmodifier, Ymodifier, Dots, USAIndex, USAxPos, USAyPos; char *USABuf;//to hold Texas.txt, etc POINT Dot[2000]; POINT *pUSA;//to hold screen offsets int DotUSAIndex[2000]; char DotUSAName[500][25]; char USA[] = " Press Esc - or click on a Map Location dot"; //char USA[] = " The United States of America"; char UnzipUSA[] = "unzip.exe -n StateOutlines.zip"; double *LambertX, *LambertY; double Xlambert, Ylambert, ScreenModifier; BOOL usamap = FALSE, notfromusa = TRUE, usatext = FALSE, maximized = TRUE; int Zone1600[10] = {165,295,445,585,725,865,1025,1165,1315,1485};//1600 int Zone1280[10] = {110,235,355,470,580,700,815,935,1060,1190};//1280 int Zone1152[10] = {100,210,320,425,525,625,735,840,950,1070};//1152 int Zone1024[10] = {95,185,285,375,470,560,655,755,855,955};//1024 int Zone800[10] = {90,140,215,290,360,435,510,585,665,740};//800 int *pZone; char ZoneNum[3] = "10"; int Lon1600x[9] = {3,206,416,629,847,1058, 1268,1475,1568}; int Lon1600y[9] = {974,1016,1043,1055,1053,1035,1005,960,538}; int Lon1280x[9] = {2,165,331,500,674,842,1011,1175,1248}; int Lon1280y[9] = {780,810,832,842,840,827,802,765,419}; int Lon1152x[9] = {0,145,295,450,604,758,907,1059,1123}; int Lon1152y[9] = {702,733,752,760,760,748,723,691,378}; int Lon1024x[9] = {0,130,264,402,538,675,805,939,995}; int Lon1024y[9] = {625,649,666,670,670,662,642,613,337}; char Lons[] = "120\260114\260108\260102\260 96\260 90\260 84\260 78\260 72\260"; int *pLonx, *pLony; HWND hwndUSA; HRGN hRgn; #ifdef onetime0 BOOL onetime1, onetime2, onetime3; #endif int Spaces2Move = 0; BOOL directdraw; RECT rect1, rect2, rect3, rect4; HDC hdcBack, hdcBack2; LPDIRECTDRAW7 lpDD7; DDSURFACEDESC2 ddsd; LPDIRECTDRAWSURFACE7 lpDDSPrimary, lpDDSBack, lpDDSBack2; int xbeg, ybeg; //int xPosOld, xbegOld = -1, yPosOld, ybegOld; BOOL cachenotfull = TRUE; BOOL right, top; BOOL getarea = FALSE; int proxy = 0; int ProxyUserLen, ProxyPassLen; char ProxyUserName[50]; char ProxyPassword[50]; char CheckforUpdate[] = "http://jdmcox.com//"; char NewerVersion[] = "A newer version is available"; char NewerDate[] = "This version with a newer date is available"; char SameVersion[] = "Still the same version"; WSADATA wsaData; WSADATA IgatewsaData; SOCKET s, s2, s3, sListen, sAccept; struct sockaddr_in dest, saServer; struct hostent *he; char Fips[6]; char CountyFromLatLon1[] = "http://nationalatlas.gov/servlet/com.esri.esrimap.Esrimap?Name=VBAtlas&cmd=Identify&ClickX="; char CountyFromLatLon2[] = "&ClickY="; char CountyFromLatLon3[] = "&bgoff=T&visLayers=Counties,States"; int tUTMEasting, tUTMNorthing, tUTMZone; BYTE *tempBuffer; int gotX, gotY; int NamePtrs[MAXPTIGERS][MAXNAMEPTRS]; char *NamePtr1, *NamePtr2; int Bigx, np, gotit, pts, pname, HighestFeatureType; int TigerAngle, CountySize, County; int RowBegin, point, TigerPointE, TigerPointN, TigerPointA, Angle1, Angle2; ULONG tiger; DWORD TigerPtr; DWORD NumofPolys, NameBegin, NameLen, pNameBeginLatLon, FeatureType; DWORD PolyPtrs[TIGERS/2]; DWORD IndexSize, TigerSize, namesize; DWORD TigerNameSize[MAXPTIGERS]; char SmallBuf[SMALLBUFSIZE]; char SmallBuf2[1024]; char *pCounties; int *TigerUTM; int *pTiger[MAXPTIGERS]; char *pTigerNames[MAXPTIGERS], *Buf1, *pTigerIndex, *pTigerBoundaries; char ZippedTiger[MAX_PATH]; char TigerState[2]; char SmallBufDta[] = "SmallBuf.dta"; char Tiger[] = "TIGER/Line data"; char TigerCounties[] = "TigerCounties.txt"; char TigerDir[] = "TigerData"; char OldTigerZip[] = ".\\TigerData\\TGRxxxxx.zip"; char TigerZip[] = "TGRxxxxx.zip"; char TigerData[] = "TGRxxxxx"; char TigerMet[] = "TGRxxxxx.MET"; char TigerRecord1[] = "TGRxxxxx.RT1"; char TigerRecord2[] = "TGRxxxxx.RT2"; char TigerDta[] = "TigerData\\TGR?????_??_1.dta"; char TigerName[] = "TigerData\\TGR?????_??_2.dta"; char TigerIndex[] = "TigerData\\Boundaries_XX.txt"; char TigerBounds[] = "xxxxx: "; char GetTigerZip[] = "http://www2.census.gov/geo/tiger/tiger2006se/VA/TGRxxxxx.ZIP"; char Unzip[] = "unzip.exe -n TGRxxxxx.zip TGRxxxxx.MET TGRxxxxx.RT1 TGRxxxxx.RT2"; char Downloading[] = "Downloading"; char Downloaded[] = " 12,456,890 bytes of 123456"; char Converting[] = "Converting"; char Converted[] = "12,456,890 of 12,456,890 bytes "; char GetUnzip[] = "http://jdmcox.com/unzip.exe"; char unzipFile[] = "unzip.exe"; BOOL gotstreet = FALSE, streetflag = FALSE, accepted, downloaded, notcancelled = TRUE, downloadingstreets = FALSE, froms = FALSE, showit; //POINT pt[TIGERS];//for PolyPolyline POINT *pt; HANDLE hNameFile, hIndexFile, hSmallFile, hFindFile, hMutex; HWND hwndTiger, hwndCounties; RECT tigerRect; char CmdLine[255]; char RunPgmGpx[255]; char runpgm[] = "\\GSAK.gpx"; BOOL gsak = FALSE; char FileOut[25]; char Find[101]; int HelpSize, GPSHelpSize, TigerHelpSize, CountyHelpSize, FindSize, NextFind, Lines, ScreenLines, LastLineFromChar, BigJpegDataSize; HWND hwndGPS, hwndHelp, CurrentHelp, hwndTigerHelp, hwndElevationHelp, hwndApproachHelp; HANDLE hFind; char Q[] = " (the same as pressing the Q key)"; BOOL Reply = FALSE; BOOL simulate = FALSE, savebuf = TRUE; BOOL showposition = FALSE; WORD *MyDem; int TarSize; char WaypointsPath[MAX_PATH]; BOOL downloaderror, gotem, firstbad; char FirstLetter[2]; char SelectedUSGSLoc[100]; char GetConus[] = "http://jdmcox.com/CONUS.LAS"; char comment[50]; char name[50]; char SerialRouteLink[] = "\x10\x62\x15\x03\0\0\0\0\0\0\0\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0\x92\x10\x03"; char RouteLink[] = "\3\0\0\0\0\0\0\0\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\0"; DWORD dwBytesWrit, USGSfileSize; char BulkDta[] = "Bulk.dta"; BYTE BulkBuf[USB_MAX_BUFFER_SIZE]; BYTE Bulk[10000]; int ReadPtr, LastError; char Temp[] = "dwBytesRead = "; char Temp2[] = " Last Error = "; BOOL xfercmplt; char NotRoute[] = "That's not a route file."; int ArrayIndex; unsigned char *RowBufs; DWORD Col, ColPtr; HANDLE aThreads[100];//presuming open threads is < 100 int ZoomandBelow = 2; char NewUSNG[20]; char PhotoZoom1[] = "&1 Meter/pixel"; char PhotoZoom2[] = "Zoomed to &2 Meters/pixel"; char PhotoZoom4[] = "Zoomed to &4 Meters/pixel"; char PhotoZoom8[] = "&Zoomed to 8 Meters/pixel"; char PhotoZoomBig8[] = "&8 Meters/pixel"; char PhotoZoom16[] = "Zoomed to &16 Meters/pixel"; char PhotoZoom32[] = "Zoomed to &32 Meters/pixel"; char PhotoZoom64[] = "Zoomed to &64 Meters/pixel"; char TopoZoom1[] = "&4 Meters/pixel"; char TopoZoom2[] = "Zoomed to &8 Meters/pixel"; char TopoZoom4[] = "Zoomed to &16 Meters/pixel"; char TopoZoom8[] = "Zoomed to &32 Meters/pixel"; char TopoZoomBig8[] = "&64 Meters/pixel"; char TopoZoom16[] = "Zoomed to &128 Meters/pixel"; char TopoZoom32[] = "Zoomed to &256 Meters/pixel"; char TopoZoom64[] = "Zoomed to &512 Meters/pixel"; char UrbanZoom1[] = "1/&4 Meter/pixel"; char UrbanZoom2[] = "&Zoomed to 1/2 Meters/pixel"; char UrbanZoom4[] = "Zoomed to &1 Meters/pixel"; char UrbanZoom8[] = "Zoomed to &2 Meters/pixel"; char UrbanZoomBig8[] = "4 &Meters/pixel"; char UrbanZoom16[] = "Zoomed to 8 Meters/pixel"; char UrbanZoom32[] = "Zoomed to 16 Meters/pixel"; char UrbanZoom64[] = "Zoomed to 32 Meters/pixel"; char Accept[] = "Accept: */*\r\n\r\n"; unsigned char *pBuf; unsigned char *ConusLatData, *ConusLonData, *PrviLatData, *PrviLonData, *LatData, *LonData, *pDemIniBuf, *HawaiiLatData, *HawaiiLonData, *AlaskaLatData, *AlaskaLonData; char DemFileName[50]; char DemIni[200]; char ConusLas[] = "CONUS.LAS"; char ConusLos[] = "CONUS.LOS"; char PrviLas[] = "Prvi.las"; char PrviLos[] = "Prvi.los"; char HawaiiLas[] = "hawaii.las"; char HawaiiLos[] = "hawaii.los"; char AlaskaLas[] = "alaska.las"; char AlaskaLos[] = "alaska.los"; int GotoEasting, GotoNorthing; char *AddrBuf; char Address[100]; char xCity[100]; char State[20]; char ZIP[10]; BOOL gotaddr, gotcity, gotzip; //http://nmviewogc.cr.usgs.gov/tnm/FindAddress?street=&city=&state=&zipcode=94306&Cmd=Zoom+to+Address //http://nmviewogc.cr.usgs.gov/tnm/FindAddress.jsp nm_web1@usgs.gov char Address1[250] = "http://nmviewogc.cr.usgs.gov/tnm/FindAddress?street="; //3292+Tea+Rose+Dr char Address2[] = "&city="; //El+Dorado+Hills char Address3[] = "&state="; //CA char Address4[] = "&zipcode="; //95762 char Address5[] = "&Cmd=Zoom+to+Address"; int saveRowOffset, saveColOffset, saveZoom, savePixelsPerTile, saveMetersPerTile, saveImageSize, saveTilesDown, saveTilesAcross, colAddr, tempyLoc, tempxLoc; //char ElevInfo[] = "Move the cursor to the middle of a grid area with no elevation showing, and press the left mouse button to put the lat/lon for that area (as well as the elevation data's website address) into the Windows Clipboard.\r\n\r\n\Then go to that website and paste the latitude and longitude into their boxes.\r\n\r\n\Close this Window to exit this mode."; char *ElevBuf; BYTE *ElevBuf2; HWND hwndElevation; HINTERNET hInternet, hConnectHandle, hResourceHandle; BOOL fromgotocity = FALSE; int qm, CityUTMEasting, CityUTMNorthing; HWND hwndState, hwndCity; HANDLE hStateFile; char City[100]; int StateIndex, CityIndex, NumOfPtrs; char *USGSBuf = NULL; char *StateBuf; char States[][3] = {" ","AK","AL","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","PR","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY"}; char USGSFile[MAX_PATH]; char PtrFile[MAX_PATH]; char StatesPath[] = "\\States\\??.txt"; char ZonePath[] = "\\States\\??.dta"; char PtrPath[] = "\\States\\??.ptr"; char USGSData[100]; int WaypointToMove = -1; struct Ptr10 { int UTMN; int UTME; DWORD ptr; } *PtrBuf; typedef struct { int col; unsigned char *RowBufs; char URLName[80]; } THREADPARAMS; THREADPARAMS tp; int RowBufSize[2900]; struct _Pvt { float alt;//12 float epe;//16 float eph;//20 float epv;//24 double tow;//30 double lat;//38 double lon;//46 float lon_vel;//54 float lat_vel;//58 float alt_vel;//62 float msl_hght;//66 int grmn_days;//72 WORD leap_sec;//70 WORD fix;//28 } Pvt;//64 bytes BYTE *FromUSBBuf = NULL; int PrevTnum; int Param, *pParam = &Param; int Packets; int USBptr, PacketPtr; UINT PvtBegin = 0xFFFFFFFF - 76; BYTE USBBuf[USB_INTERRUPT_DATA_SIZE]; DWORD hDeviceThread = NULL, hReadFileThread = NULL; DWORD dwBytesToSend, dwBytesReceived, dwBytesReturned; char Buf2[300]; char Numero[4]; BOOL hevent0set, gotFD, gotFF, getprotocol; //Packet format: //0 Packet type (0=transport, 0x14=Garmin) //4 (WORD) Packet ID //8 (DWORD) Data Size //12+ Data BYTE Packet[PACKETSIZE]; HANDLE hUSBFile, hEvent0, hEvent1, hEvent2, hEvent3, hUSGSFile, hPtrFile; HANDLE hUSB; //HANDLE hDeviceFile; OVERLAPPED ol, ol2, ol3, APRSol; HDEVINFO DevInfo; SP_DEVINFO_DATA DevInfoData = {sizeof(SP_DEVINFO_DATA)}; SP_DEVICE_INTERFACE_DATA InterfaceData; PSP_DEVICE_INTERFACE_DETAIL_DATA DevDetailData = 0; int MapType = PHOTO; char Index[MAX_PATH] = "C:\\Program Files\\Internet Explorer\\iexplore.exe http:\\\\jdmcox.com\\"; char TerraServer[MAX_PATH] = "C:\\Program Files\\Internet Explorer\\iexplore.exe "; char DownloadErr[MAX_PATH] = "C:\\Program Files\\Internet Explorer\\iexplore.exe file:///"; char URLink[] = "C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.geocaching.com/seek/cache_details.aspx?wp=GCM8JR"; char DownloadErr2[] = "\\DownloadError.htm"; char SDTS[] = "http://www.atdi-us.com/SDTS_DL_b.htm"; //char SDTS[200] = "http://www.atdi-us.com/sdts.exe?csys=1DMS&lat="; //char SDTSMiddle[] = "&lon="; //char SDTSEnd[] = "&submit=Get+Data"; //char SDTSdata[200] = "http://www.atdi-us.com/S/SDTS/1663222.dem.sdts.tar.gz"; char ShortSDTSfilename[100]; char SDTSfilename[MAX_PATH]; //http://www.atdi-us.com/sdts.exe?csys=1DMS&lat=37.14&lon=-122.04&submit=Get+Data int GifBufSize; BYTE *GifBuf; BYTE pixel_buf[MAX_IMAGE_SIZE]; BYTE ColorTable[256]; char AsciiTotal[6] = "17142"; char BigWaypointFile[] = "Waypoint file is bigger than 1,000,000 bytes!"; char BigJpegFilename[50] = "eXXXXXXnYYYYYYYzZZp.txt"; char BigJpegData[50]; int i, v, w, x, y, z, X1, Y1, X2, Y2; char TrackName[MAX_PATH]; char PreTracks[] = "Track,UTM Zone,UTM Northing,UTM Easting,UTC Hour,Min,Sec,Month,Date,Year,Alt(Meters)\r\n"; char Noo[] = "New,"; char PseudoTrack[] = ",00,00,00,,,,0\r\n"; char PositionHeader[] = ",UTM Zone,UTM Northing,UTM Easting,UTC Hour,Min,Sec,Month,Date,Year,Altitude,HorizEPE,VertEPE,Speed\r\n"; char PositionCsv[] ="Position??.csv"; int HorizPoint[20][20], VertPoint[20][20]; int OneMeterTilesDown, OneMeterTilesAcross, OneMeterTileSize, xFraction, yFraction; int p1MeterSize; BYTE *p1Meter; DWORD *p1MeterX, *p1MeterY; BOOL missing1meter = FALSE, onepressed = FALSE; int currentpoint; char OutsideUSA[] = "\r\nis outside the U.S.A."; HWND hwndButton, hwndButton2, hwndButton3, hwndInstr, hwndEdit = NULL; char TrackEdit[] = "\ When the mouse pointer is over a track point:\r\n\ \r\n\ Press and hold the Right mouse button to move that point.\r\n\ or\r\n\ Press and hold the Left mouse button \ to draw a new segment line from a point \ with no next segment line (at the end of an entire Segment).\r\n\ or\r\n\ Press the Delete key to delete the next segment line from that point.\r\n\ or\r\n\ Click the Left mouse button on a point \ that's not the end of an entire Segment \ and not part of the first entire Segment to \ open a window for selecting a color \ for that entire Segment. See GPS -Help for more on this.\r\n\ \r\n\ If a track point is moved over the next \ track point, it will be deleted, and that \ next track point will be attached to the \ previous track point.\r\n\ \r\n\ If you add, delete or move a track point, \ the elevations in USAPhotoMaps will be \ saved, replacing the GPS altitudes."; //Magellan Meridian char Ma[] = "Default"; char Mb[] = "Box"; char Mc[] = "House"; char Md[] = "Aerial"; char Me[] = "Airport"; char Mf[] = "Amusement"; char Mg[] = "ATM"; char Mh[] = "Auto Repair"; char Mi[] = "Boating"; char Mj[] = "Camping"; char Mk[] = "Exit Ramp"; char Ml[] = "First Aid"; char Mm[] = "Fixed Nav Aid"; char Mn[] = "Floating Buoy"; char Mo[] = "Fuel"; char Mp[] = "Garden"; char Mq[] = "Golf"; char Mr[] = "Hotel"; char Ms[] = "Hunt/Fish"; char Mt[] = "Large City"; char Mu[] = "Lighthouse"; char Mv[] = "Major City"; char Mw[] = "Marina"; char Mx[] = "Medium City"; char My[] = "Museum"; char Mz[] = "Obstruction"; char aa[] = "Park"; char ab[] = "Resort"; char ac[] = "Restaurant"; char ad[] = "Rock"; char ae[] = "Scuba"; char af[] = "RV Service"; char ag[] = "Shooting"; char ah[] = "Sightseeing"; char ai[] = "Small City"; char aj[] = "Sounding"; char ak[] = "Sports Arena"; char al[] = "Tourist Info"; char am[] = "Truck Service"; char an[] = "Winery"; char ao[] = "Wreck"; char ap[] = "Zoo"; //Magellan 315 char Xa[] = "Default"; char Xb[] = "Box"; char Xc[] = "Red Buoy"; char Xd[] = "Green Buoy"; char Xe[] = "Anchor"; char Xf[] = "Rocks"; char Xg[] = "Red Day"; char Xh[] = "Green Day"; char Xi[] = "Bell"; char Xj[] = "Danger"; char Xk[] = "Diver Down"; char Xl[] = "Fish"; char Xm[] = "House"; char Xn[] = "Mark"; char Xo[] = "Car"; char Xp[] = "Tent"; char Xq[] = "Boat"; char Xr[] = "Food"; char Xs[] = "Fuel"; char Xt[] = "Tree"; //Garmin char G0[] = "Anchor"; char G1[] = "Bell"; char G2[] = "Diamond (Green)"; char G3[] = "Diamond (Red)"; char G4[] = "Diver Down (Striped Flag)"; char G5[] = "diver down (Code Flag A)"; char G6[] = "Bank"; char G7[] = "Fishing Area"; char G8[] = "Gas Station"; char G9[] = "Horn"; char G10[] = "Residence"; char G11[] = "Restaurant"; char G12[] = "Light"; char G13[] = "Bar"; char G14[] = "Danger Area"; char G15[] = "Square (Green)"; char G16[] = "Square (Red)"; char G17[] = "Bouy"; char G18[] = "Waypoint"; char G19[] = "Shipwreak"; char G20[] = "Invisible"; char G21[] = "Man Overboard"; char G22[] = "Bouy (Amber)"; char G23[] = "Bouy (Black)"; char G24[] = "Bouy (Blue)"; char G25[] = "Bouy (Green)"; char G26[] = "Bouy (Green/Red)"; char G27[] = "Bouy (Green/White)"; char G28[] = "Bouy (Orange)"; char G29[] = "Bouy (Red)"; char G30[] = "Bouy (Red/Green)"; char G31[] = "Bouy (Red/White)"; char G32[] = "Bouy (Violet)"; char G33[] = "Bouy (White)"; char G34[] = "Bouy (White/Green)"; char G35[] = "Bouy (White/Red)"; char G36[] = "Dot"; char G37[] = "Radio Beacon"; char G150[] = "Boat Ramp"; char G151[] = "Campground"; char G152[] = "Restroom"; char G153[] = "Shower"; char G154[] = "Drinking Water"; char G155[] = "Telephone"; char G156[] = "Medical Facility"; char G157[] = "Information"; char G158[] = "Parking Area"; char G159[] = "Park"; char G160[] = "Picnic Area"; char G161[] = "Scenic Area"; char G162[] = "Skiing Area"; char G163[] = "Swimming Area"; char G164[] = "Dam"; char G165[] = "Controlled Area"; char G166[] = "Danger Area"; char G167[] = "Restricted Area"; char G168[] = "Invisible"; char G169[] = "Ball Park"; char G170[] = "Car"; char G171[] = "Hunting Area"; char G172[] = "Shopping Center"; char G173[] = "Hotel"; char G174[] = "Mine"; char G175[] = "Trail Head"; char G176[] = "Truck Stop"; char G177[] = "User Exit"; char G178[] = "Civil"; char G179[] = "Circle X"; char G8192[] = "Interstate Hwy"; char G8193[] = "US Hwy"; char G8194[] = "State Hwy"; char G8195[] = "Mile Marker"; char G8196[] = "TracBack Point"; char G8197[] = "Golf Course"; char G8198[] = "City (Small)"; char G8199[] = "City (Medium)"; char G8200[] = "City (Large)"; char G8201[] = "Intl Frwy"; char G8202[] = "Intl National Frwy"; char G8203[] = "Capitol City"; char G8204[] = "Amusement Park"; char G8205[] = "Bowling"; char G8206[] = "Car Rental"; char G8207[] = "Car Repair"; char G8208[] = "Fast Food"; char G8209[] = "Fitness Center"; char G8210[] = "Movie Theater"; char G8211[] = "Museum"; char G8212[] = "Pharmacy"; char G8213[] = "Pizza"; char G8214[] = "Post Office"; char G8215[] = "RV Park"; char G8216[] = "School"; char G8217[] = "Stadium"; char G8218[] = "Deptartment Store"; char G8219[] = "Zoo"; char G8220[] = "Convenience Store"; char G8221[] = "Live Theater"; char G8222[] = "Ramp Intersection"; char G8223[] = "Street Intersection"; char G8224[] = "?"; char G8225[] = "?"; char G8226[] = "Scales"; char G8227[] = "Toll Booth"; char G8228[] = "Summit"; char G8229[] = "Exit Without Services"; char G8230[] = "Geographic Place Name, Man-Made"; char G8231[] = "Geographic Place Name, Water"; char G8232[] = "Geographic Place Name, Land"; char G8233[] = "Bridge"; char G8234[] = "Building"; char G8235[] = "Cemetary"; char G8236[] = "Church"; char G8237[] = "Civil Location"; char G8238[] = "Crossing"; char G8239[] = "Ghost Town"; char G8240[] = "Levee"; char G8241[] = "Military"; char G8242[] = "Oil Field"; char G8243[] = "Tunnel"; char G8244[] = "Beach"; char G8245[] = "Forest"; char G8246[] = "Summit"; char G8247[] = "Large Ramp Intersection"; char G8248[] = "Large Exit Without Services"; char G8249[] = "Police"; char G8250[] = "Gambling"; char G8251[] = "Snow Skiing"; char G8252[] = "Ice Skating"; char G8253[] = "Tow Truck"; char G8254[] = "Border"; char G16384[] = "Airport"; char G16385[] = "Intersection"; char G16386[] = "NDB"; char G16387[] = "VOR"; char G16388[] = "Heliport"; char G16389[] = "Private Field"; char G16390[] = "Soft Field"; char G16391[] = "Tall Tower"; char G16392[] = "Short Tower"; char G16393[] = "Glider Area"; char G16394[] = "Ultralight Area"; char G16395[] = "Parachute Area"; char G16396[] = "VOR/TACAN"; char G16397[] = "VOR-DME"; char G16398[] = "Initial Approach"; char G16399[] = "Localizer Outer Marker"; char G16400[] = "MAP"; char G16401[] = "TACAN"; char G16402[] = "Seaplane Base"; char tempLatLon[400]; BOOL atwaypoint = FALSE, movewaypoint = FALSE, fromlineto = FALSE; char Togps[] = "ToGPS.txt"; char ToGarmin[] = "ToGPS.dta"; unsigned char ToGPS[50000]; int tgcount; char Contourson[] = "&Contours On C"; char Contoursoff[] = "&Contours Off C"; char tempBuf[20]; char *pIdentLoc; char tempNewLoc[10000]; char tempLatLonUTM[50] = "\0"; //MENUITEMINFO mii; char *tempDta; int tempPtr[2902]; int pointer; int FadeIncrement = 0; BOOL fade = FALSE, wastopo = FALSE; char *pURLName; char USAPhotoMapsKey[] = "USAPhotoMaps.dta"; char Key[] = "\0\0\0\0\0\0\0"; char Begging[] = "\r\nIf you find this program useful or enjoyable,\r\n\ I would REALLY appreciate a donation.\r\n\ \r\n\ If you email me that the check's in the mail,\r\n\ I'll email you a very small data file\r\n\ to put in the USAPhotoMaps folder\r\n\ so this message won't appear again.\r\n\ \r\n\ (or click on the PayPal icon at jdmcox.com)\r\n\ \r\n\ jdmcox@jdmcox.com\r\n\ Doug Cox\r\n\ 140 Monroe Dr\r\n\ Palo Alto, CA 94306"; char Streets[MAX_PATH] = "C:\\Program Files\\Microsoft Streets & Trips\\Streets.exe"; char Streets2[MAX_PATH] = "C:\\Program Files\\Microsoft Streets & Trips\\"; char Streets3[] = "C:\\Program Files\\Microsoft Streets and Trips\\Streets.exe"; char Streets4[] = "C:\\Program Files\\Microsoft Streets and Trips\\"; // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 BYTE ZoomTable[] = {0, 3, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 2}; // 1 2 4 8 8 16 32 64 4 8 16 32 64128256 COLORREF WaypointColor = 0x00FF00, TrackColor = 0xC08000, RouteColor = 0xFFFFFF, PositionColor = 0xFFFF00, TextColor = 0x00FFFF, APRSColor = 0xFF, TigerColor = 0xFF; COLORREF StartColor = 0x00FF00, EndColor = 0x0FF, TrackSegmentColor; DWORD ExitCode; STARTUPINFO si; PROCESS_INFORMATION pi; char PushPins[MAX_PATH]; char ScreenFile[] = "Screen01.jpg"; char ShowNameComment[] = "ShowNameComment=YES\r\n"; char DontShowNameComment[] = "ShowNameComment=NO\r\n"; char ShowDescription[] = "ShowDescription=YES\r\n"; char Deg[] = "LatLonUTM=DEG\r\n"; char Min[] = "LatLonUTM=MIN\r\n"; char Sec[] = "LatLonUTM=SEC\r\n"; char Utm[] = "LatLonUTM=UTM\r\n"; char Usng[] = "LatLonUTM=USNG\r\n"; char Zoom1[] = "ZoomLevel=1\r\n"; char Zoom2[] = "ZoomLevel=2\r\n"; char Zoom3[] = "ZoomLevel=3\r\n"; char Zoom4[] = "ZoomLevel=4\r\n"; char Zoom5[] = "ZoomLevel=5\r\n"; char Zoom6[] = "ZoomLevel=6\r\n"; char Zoom7[] = "ZoomLevel=7\r\n"; char Zoom8[] = "ZoomLevel=8\r\n"; char DoShowNearest[] = "ShowLatlon=YES\r\n"; char DontShowNearest[] = "ShowLatlon=NO\r\n"; char DoShowName[] = "ShowName=YES\r\n"; char DontShowName[] = "ShowName=NO\r\n"; char DoSortbyName[] = "SortbyName=YES\r\n"; char DontSortbyName[] = "SortbyName=NO\r\n"; char ZoomTo8Meters[] = "ZoomTo8Meters=YES\r\n"; char DontZoomTo8Meters[] = "ZoomTo8Meters=NO\r\n"; char Topo[] = "Topo=YES\r\n"; char NotTopo[] = "Topo=NO\r\n"; char UrbanColor[] = "Topo=QQ\r\n"; char OpenAtClosing[] = "OpenAtClosing=YES\r\n"; char DontOpenAtClosing[] = "OpenAtClosing=NO\r\n"; char FadeIncr[] = "FadeIncrement=00\r\n"; char Spaces2[] = "Spaces2Move=0\r\n"; char WaypointColour[] = "WaypointColor=0x00FF00\r\n"; char RouteColour[] = "RouteColor=0xFFFFFF\r\n"; char TrackColour[] = "TrackColor=0xC08000\r\n"; char PositionColour[] = "PositionColor=0xFFFF00\r\n"; char TextColour[] = "TextColor=0x00FFFF\r\n"; char APRSColour[] = "APRSColor=0x0000FF\r\n"; char TigerColour[] = "TigerColor=0x0000FF\r\n"; char Meter1PhotoDot[] = "1MeterPhotoWaypointDot=4\r\n"; char Meter2PhotoDot[] = "2MeterPhotoWaypointDot=3\r\n"; char Meter4PhotoDot[] = "4MeterPhotoWaypointDot=3\r\n"; char Meter8PhotoDot[] = "8MeterPhotoWaypointDot=3\r\n"; char Meter16PhotoDot[] = "16MeterPhotoWaypointDot=3\r\n"; char Meter32PhotoDot[] = "32MeterPhotoWaypointDot=3\r\n"; char Meter64PhotoDot[] = "64MeterPhotoWaypointDot=3\r\n"; char Meter4TopoDot[] = "4MeterTopoWaypointDot=6\r\n"; char Meter8TopoDot[] = "8MeterTopoWaypointDot=4\r\n"; char Meter16TopoDot[] = "16MeterTopoWaypointDot=3\r\n"; char Meter32TopoDot[] = "32MeterTopoWaypointDot=3\r\n"; char Meter64TopoDot[] = "64MeterTopoWaypointDot=3\r\n"; char Meter128TopoDot[] = "128MeterTopoWaypointDot=3\r\n"; char Meter256TopoDot[] = "256MeterTopoWaypointDot=3\r\n"; char Meter512TopoDot[] = "512MeterTopoWaypointDot=3\r\n"; char Meter14UrbanDot[] = "14MeterUrbanWaypointDot=6\r\n"; char Meter12UrbanDot[] = "12MeterUrbanWaypointDot=6\r\n"; char Meter1LineWidth[] = "1MeterLineWidth=3\r\n"; char Meter2LineWidth[] = "2MeterLineWidth=2\r\n"; char Meter4LineWidth[] = "4MeterLineWidth=2\r\n"; char Meter8LineWidth[] = "8MeterLineWidth=2\r\n"; char Meter16LineWidth[] = "16MeterLineWidth=2\r\n"; char Meter32LineWidth[] = "32MeterLineWidth=1\r\n"; char Meter64LineWidth[] = "64MeterLineWidth=1\r\n"; char Meter4TopoLine[] = "4MeterTopoLine=2\r\n"; char Meter8TopoLine[] = "8MeterTopoLine=2\r\n"; char Meter16TopoLine[] = "16MeterTopoLine=2\r\n"; char Meter32TopoLine[] = "32MeterTopoLine=2\r\n"; char Meter64TopoLine[] = "64MeterTopoLine=2\r\n"; char Meter128TopoLine[] = "128MeterTopoLine=2\r\n"; char Meter256TopoLine[] = "256MeterTopoLine=2\r\n"; char PhotoDot1[] = "4", PhotoDot2[] = "4", PhotoDot4[] = "4", PhotoDot8[] = "4", PhotoDot16[] = "4", PhotoDot32[] = "4", PhotoDot64[] = "4"; char TopoDot4[] = "6", TopoDot8[] = "4", TopoDot16[] = "3", TopoDot32[] = "3", TopoDot64[] = "3", TopoDot128[] = "3", TopoDot256[] = "3", TopoDot512[] = "3"; char UrbanDot14[] = "6", UrbanDot12[] = "6"; char LineWidth1[] = "2", LineWidth2[] = "2", LineWidth4[] = "2", LineWidth8[] = "2", LineWidth16[] = "2", LineWidth32[] = "2", LineWidth64[] = "2"; char TopoLine4[] = "4", TopoLine8[] = "4", TopoLine16[] = "4", TopoLine32[] = "4", TopoLine64[] = "2", TopoLine128[] = "2", TopoLine256[] = "2"; char ShowText[] = "ShowText=YES\r\n"; char DontShowText[] = "ShowText=NO \r\n"; char APRSBAUD[] = "APRSBaud="; char APRSCOM[] = "APRSCommPort="; char APRSMyCall[] = "MyCall="; char APRSHomeLatLon[] = "HomeLatLon=";//3724.44N/12206.98W char APRSTransmitTo[] = "TransmitTo="; char None[] = "NONE"; char Home[] = "HOME"; char GPS[] = "GPS "; char APRSHomeSymbol[] = "HomeSymbol="; char APRSGPSSymbol[] = "GPSSymbol="; char APRSDestination[] = "Destination="; char APRSComment[] = "Comment="; char APRSBeacon[] = "BEACON="; char SBSlowSpeed[] = "SBSlowSpeed="; char SBSlowBeacon[] = "SBSlowBeacon="; char SBHighSpeed[] = "SBHighSpeed="; char SBHighBeacon[] = "SBHighBeacon="; char SBTurnTime[] = "SBTurnTime="; char SBAngle[] = "SBAngle="; char SBConstant[] = "SBConstant="; char SB[] = "SmartBeaconing=YES\r\n"; char Compressit[] = "Compressit=YES\r\n"; char USAPMini[] = "USAPM.ini"; char *pUSAPMbufIn; char USAPMbufOut[100]; char *pRoutes, *prs; char Raut[300]; char RouteDist[10]; char Acres[20]; int prevDist[TOTAL_LOCS]; int prefInMouseLoc, prefInZoom, prefInLatlon; int prefOutMouseLoc, prefOutZoom, prefOutLatlon, prefOutName; int sign, decPos, trackUTMZone, offset, nearest; double routeDist, d, xleg, yleg, legsquared; double totalRouteDist[MAX_PTR]; double Easting, Northing; char IniBAK[] = "USAPhotoMapsBAK.ini"; char ProgName[] = "USAPhotoMaps"; char USAPhotoMapsIni[] = "USAPhotoMaps.ini"; //0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 char UTM[] = "USAPhotoMaps UTM: Easting xxx,xxx Northing x,xxx,xxx Zone xx Zoom: 1 meter /pixel Elev: xxxx' Photo "; char USNG[] = "USAPhotoMaps USNG: Zoom: 1 meter /pixel Elev: xxxx' Photo "; char LatLon[] = "USAPhotoMaps N W Zoom: 1 meter /pixel Elev: xxxx' Photo "; char Nearest[]= "USAPhotoMaps Zoom: 1 meter /pixel"; char RowName[] ="USAPhotoMaps Row Name: zZZy "; char Registry[] = "Couldn't open the Registry!"; char Instruct[] = "USAPhotoMaps.txt"; char ElevationHelp[] = "ElevationHelp.txt"; char ApproachControlHelp[] = "ApproachControl.txt"; char AdvancedApproachControlHelp[] = "AdvancedApproachControl.txt"; char NoHelpFile[] = "Couldn't find USAPhotoMaps.txt"; //char ElevationLocs[] = "ElevationLocs.txt"; //char NoElevationLocs[] = "Couldn't find ElevationLocs.txt"; char USAPhotoMapsData[] = "USAPhotoMapsData"; char BIGPhotoMapsData[] = "BigPhotoMapsData"; char pointerFileName[] = "USAPhotoMapsData\\z00y00000.xxx"; char fileName[] = "USAPhotoMapsData\\z00y00000.xxx";//row data file char cachName[] = "USAPhotoMapsData\\z00y00000.xxx";//row data file char TigerHelp[] = "Tiger.txt"; int West, North, East, South, remainder; int lSquare, rSquare, tSquare, bSquare; int MetersPerTile = 200; int PadBytes; char CurrentDir[MAX_PATH]; char CurrentTrackDir[MAX_PATH]; WORD DType; char *ptrToAscii; typedef struct { BOOL timing; BOOL garmintiming; BOOL nmeatiming; BOOL gotprotocol; HWND hwnd; int time; } TIMERFLAGS; TIMERFLAGS TimerFlags; int fromFlag = NOBUTTON; char Oops[] = "Oops"; int garminflag = 0; unsigned char ReceivedPID, ReceivedDataSize, ReceivedData[0xFF]; char fileName0, fileName1, fileName2; char PreError[] = "The ChangeZone error\noccurred when called from "; char Error[300]; int Baud; unsigned long hThread, hDownloadThread, hDownloadStatesThread, hDownloadUTMThread, hUSBThread = 0, hHTTPThread, hCacheThread; int SizeOfDP; char DownloadProgress[40] = "000000 of "; int Pointers[2902], oldPointers[2902], oldNumOfPointers; int FirstOffset, PointerOffset, NumOfPointers; int rowOffset, colOffset, TopRowOffset, TilesAcross, oldTilesAcross, TilesDown, oldTilesDown; int row, col; unsigned int big_buf_size, big_jpeg_size; void *big_buf;//points to big un-jpeged data void *big_jpeg_buf;//points to big jpeg data char PrintInfo[] = "Select Landscape Orientation\nin Print Preferences"; PRINTDLG pd; DOCINFO di = { sizeof(DOCINFO), "USAPM", NULL, NULL, 0 }; POINT Polypoints[1000];//for Polyline int xcon, ycon; int num, tnum; int ScreenElev[41<<6];//[41][64]; int highest, lowest; int xCon, yCon, xConMax, yConMax, Diff, TotalDiff, topleftrow, topleftcol; int llElev, lrElev, urElev, tl, bl, tr, br, mid, contour, diff; char New[40<<6];//2560 WORD *DemData[500]; int Associated[500]; COLORREF color, colorDiff; int *pDem, WaypointProt; int Noffset, Eoffset, ElevOffset, IdentOffset, LocOffset, SymOffset; char NewProtocol[] = "Email jdmcox@jdmcox.com\nand tell him the new\nwaypoint protocol is "; char ElevIni[] = "Elev.ini"; char DemName[MAX_PATH]; char *pDemIni; int NumOfDems, ScreenDems, DemNameBegin, ElevRow, ElevCol, ElevRowCounter, ElevColCounter; char CourierNew[] = "Courier New"; char ComicSansMS[] = "Comic Sans MS"; char Sanserif[] = "Microsoft Sans Serif"; char Arial[] = "Arial"; //char Roman[] = "Roman"; //char Fixedsys[] = "Fixedsys"; //char System[] = "System"; LOGFONT lf, lf2, lf3, lf4, lf5, lf6; HFONT hFont, hFont2; BOOL showElev = FALSE, reliefShading = FALSE; struct DEMS { int Zone; int North; int West; int South; int East; int Rows; int Cols; // double Lat; // double Lon; char Name[17]; char Meas; } Dem[MAX_DEMS]; unsigned char FirstIni[] = "*Washington,DC&X=1613&Y=21532&Z=18\r\n"; char Area[AREA_SIZE];//Map Location char myLat[20] = "38.889447";// = "18.468"; char myLon[20] = "77.044418";// = "66.121"; static char NewLocations[MAX_PATH];//e.g."PuertoRico.xml" static char NewLocationsFullPath[MAX_PATH];//e.g."C://My Documents//USAPhotoMaps//PuertoRico.xml" //01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 //char URLName[] = "http://terraserver-usa.com/tile.ashx?t=1&s=10&x=2890&y=20702&z=10";//http: char URLName[] = "http://msrmaps.com/tile.ashx?t=1&s=10&x=2890&y=20702&z=10";//http: char TopoURLName[] = "http://msrmaps.com/tile.ashx?t=2&s=12&x=936&y=5435&z=10 ";//4,348,672 750,348 char ColorURLName[] = "http://msrmaps.com/tile.ashx?t=4&s= "; //tile.ashx?t=4&s=8&x=11327&y=105600&z=10 //char URL[] = "\r\nhttp://msrmaps.com/GetImageArea.ashx?t=4&s= "; // 10&lon=-77.444444&lat=38.888888&w=1024&h=768"; // 012345678901234567890123456789012345678901234567890123456789 char GetDate[] = "http://msrmaps.com/ImageInfo.aspx?T=1&S=14&Z=10&X=180&Y=1295"; char GPSHelp[] = "GPSHelp.txt"; char GPStxt[] = "GPS.txt"; char GPSdta[] = "GPS.dta"; char USBdta[] = "USB.dta"; char Tracks[MAX_PATH]; char FullTracks[MAX_PATH]; char Waypoints[MAX_PATH]; char WaypointsFullPath[MAX_PATH]; char Routes[MAX_PATH]; char FullRoutes[MAX_PATH]; char NoGPSFile[] = "Couldn't find GPSHelp.txt"; char ZoneName[] = "10y"; char Ptr[] = ".ptr\0"; char Dta[] = ".dta\0"; char X[8], Y[8], Z[3]; int BeginX, BeginY, UTMZone, tempUTMZone, tempUTMN, tempUTME, BigBeginX, BigBeginY, beginX, beginY, endX, endY; int MapWidth, MapHeight; int iBuf, xBuf, UTMEasting = 0, UTMNorthing = 0, ScreenLeft, ScreenTop, ScreenRight, ScreenBottom; int InsertLoc, EmptyLoc, ChosenLoc, LineEnd = -1, Response, DotX, DotY, DotX2, DotY2, DotRadius, xLoc, yLoc, lButtonDotX, lButtonDotY; int LastWay, MouseLoc = DEG, IniNumber, fileSize, fileSize2, fileSizeWx, dataFileSize, DEMfileSize, DLECount; int cxChar, cyChar, cxScreen, cyScreen, TitleAndMenu, Frame, xFrame = 0; char Counter[] = "GPS"; char PreCounting[10]; char Counting[13] = "0000 of 0000"; char PostCounting[10]; char Up[] = "Sending "; char Down[] = "Receiving"; char Way[] = "Waypoints"; char Track[] = "Tracks "; char Routetxt[] = "Points "; char Number[6]; char USADta[] = "USA.not"; char TextDta[MAX_PATH];//e.g."Text.not"; char Not[] = ".not\0"; char Xml[] = ".xml\0"; char TextBuf[MAX_TEXT]; int xBeg, yBeg, TextBufSize, UTMCenterX, UTMCenterY, centerX, centerY, distance, LineRight, xPos, yPos, SavePosX, SavePosY; int HorizCenter, VertCenter; int Units, MapUnits, BaudUnits, count; unsigned char TileBuf[MAX_TILE_SIZE]; unsigned char Buf[50000]; int PrevMetersPerTile = 0, PrevPixelsPerTile; char LatLonUTM[600]; char GARMIN[] = "GARMIN"; char NMEA[] = "NMEA "; char USB[] = "USB "; char EXPL[] = "eXplor"; char eXploristDir[] = "eXplorist"; char *pProtocol; char LocBuf[100]; char IdentBuf[100]; char DescBuf[10000]; unsigned char Waypoint[WAYPOINT_SIZE]; signed int semicircleN, semicircleE; unsigned char checksum, c, c2; int LocNum, index, ProtocolCheck1, ProtocolCheck2, ProtocolCheck3; signed char Increment = 0; char *pHelp, *pGPSHelp, *pFind, *pTigerHelp, *pElevationHelp, *pApproachHelp; unsigned char *pIniBuf, *pIniBuf2; int Zoom = 1, zoom; int PixelsPerTile = 200; int ImageSize = MAX_IMAGE_SIZE; double Lat, Lon, LatRad, LonRad, degrees, minutes, seconds, tempLat, tempLon, lat, lon, dElev; double rad2deg = 180.0/PI, deg2rad = PI/180.0; double semicircle2deg = 180.0 / 2147483648.0; double semicircle2rad = PI / 2147483648.0; double deg2semicircle = 2147483648.0 / 180.0; double a0 = 6378137;//Equatorial Radius for WGS-84 datum double ECC_SQUARED = 0.006694379990;//Eccentricity Squared for WGS-84 datum double eccPrimeSquared = ECC_SQUARED/(1-ECC_SQUARED); double k0 = 0.9996; double A, B, Angle; UINT idThread, idThread2, idThread22, idThread3, idThread4, idThread5, idThread6, idThread7, idThread8, idThread9, idThread10, idThread11, idThread12, idThread13, idThread14, idThread15, idThread16, idThread17; DWORD RegKeyResult, RegValueSize = 21, RegValue2Size = MAX_PATH, RegType = REG_SZ; DWORD dwBytesRead, dwBytesWritten; char NewComm[] = "\\\\.\\COM "; unsigned char RegValue2[MAX_PATH]; unsigned char RegValue[] = "COM0 NMEA x ";//0 is Comm Port, x is Garmin type, ' ' is baud unsigned char OrigRegValue[] = "COM0 NMEA x ";//0 is Comm Port, x is Garmin type, ' ' is baud char SelectCommPort[] = "Select a Comm Port first."; char SubKey[] = "Software\\USAPhotoMaps"; PHKEY RegKeyHandle; BOOL brandnew = FALSE, autoLoc = FALSE, goodcomm = FALSE, showingtracks = FALSE, showlatlon = FALSE, deletestring, itsfull, makewaypoint = FALSE; BOOL sendingStop = FALSE, newLoc = FALSE, newText = FALSE, itsmagellan = 0, itsgarmin, itsusb, suspendedthread = FALSE, showname = FALSE, newelev = FALSE; BOOL fromOpen = FALSE, fromTracks = FALSE, fromGoTo = FALSE, gota100, gota300, gotd, d300 = TRUE, d301, d302, d310, d201, d210, showtext = TRUE, fillscreen = TRUE; BOOL downloading = FALSE, downloadflg, sendingWaypoints = FALSE, gettingroute = FALSE, sendingrouteheader = FALSE, sendingroute, sendingroutelink; BOOL drawing = FALSE, controldown = FALSE, showingroute = FALSE, inutmzone, gotzero, sockets, editingtracks = FALSE, sendingtrackheader = FALSE; BOOL gotway, gotname, gotcmt, gotdescr, gotelev, gotsym, enteringtext = FALSE, nomessages, feet, zoom1to8 = FALSE, USBdownloading = FALSE, showingdata = FALSE, showingtrackdata; BOOL sortbyname = FALSE, fromwaypoints = FALSE, itspstip, foroute = FALSE, gotroute = FALSE, sendroutewaypoints = FALSE, USBdownloadflg; BOOL ctrlnotused = TRUE, onetime, gridon = FALSE, contourson = FALSE, trackcolors, fromgoto, internetconnect, gotblanktile, fromposition = FALSE; BOOL gotelevini, itsmeridian = FALSE, gotver, goodread, newmin, onewaypoint = FALSE, openatclosing = TRUE, veryfirstime = TRUE, firstlbutton, firstrbutton; BOOL grid75 = FALSE, shownamecomment = FALSE, showdescription = FALSE, itsnetstumbler, bigjpeg = FALSE, buttondown = FALSE, gettingtracks = FALSE, onemeter = FALSE; BOOL itsx = FALSE, fromusbtracks = FALSE, copyit, itswpt, getelev = FALSE, distancemeasure = FALSE, notfromroute = TRUE, terrafetcher = FALSE, fromconvertloctoxml = FALSE; BOOL savetracks, mousewheel = FALSE, counteropen = FALSE, itsexplorist, notthere; int numofTracks, TrackNum, TrackSize, magflag = 0, waypointinini, showstreets = FALSE, saveshowstreets, showstreetnames = FALSE, onepositiondot = FALSE; char DirName[MAX_PATH]; //DLE PID SIZE DATA CHKSUM DLE ETX unsigned char Pid_Product_Rqst[] ="\x10\xFE\x02\x00\x00\x00\x10\x03";// to get Pid_Product_Data unsigned char StartPVTPacket[] = "\x10\x0A\x02\x31\x00\xC3\x10\x03"; unsigned char StopPVTPacket[] = "\x10\x0A\x02\x32\x00\xC2\x10\x03"; unsigned char SendWaypoints[] = "\x10\x0A\x02\x07\x00\xED\x10\x03"; unsigned char SendTracks[] = "\x10\x0A\x02\x06\x00\xEE\x10\x03"; unsigned char SendRoutes[] = "\x10\x0A\x02\x04\x00\xF0\x10\x03"; unsigned char BeginRecords[] = "\x10\x1B\x02\x06\x00\xDD\x10\x03";//x06 for sending 6 records unsigned char BeginRecords2[] = "\x10\x1B\x02\x10\x10\x00\xD3\x10\x03";//x10 for sending 16 records unsigned char EndRecords[] = "\x10\x0C\x02\x07\x00\xEB\x10\x03";//x07 for SendWaypoints type unsigned char ACKPacket[] = "\x10\x06\x02\x00\x00\x00\x10\x03"; //unsigned char ACKPacket2[] = "\x10\x06\x02\x00\x00\x00\x10\x10\x03";//if checksum is 0x10 unsigned char SendTrack[82];//82 is max NMEA length unsigned char SendRouteHeader[50]; //unsigned char SendMagellanHANDON[] = "$PMGNCMD,HANDON*70\x0D\x0A"; unsigned char SendMagellanHANDOFF[] = "$PMGNCMD,HANDOFF*3E\x0D\x0A"; //unsigned char SendMagellanTON[] = "$PMGNCMD,TON*27\0x0D\x0A";//doesn't work //unsigned char SendMagellanTOFF[] = "$PMGNCMD,TOFF*69\0x0D\x0A";//doesn't work //unsigned char SendMagellanChecksum[] = "$PMGNCSM,hh*hh\x0D\x0A"; unsigned char GetMagellanVersion[] = "$PMGNCMD,VERSION*28\x0D\x0A"; unsigned char GetMagellanWaypoints[] = "$PMGNCMD,WAYPOINT*71\x0D\x0A"; //unsigned char GetMagellanTracks[] = "$PMGNCMD,TRACK*3D\x0D\x0A"; unsigned char GetMagellanTracks[] = "$PMGNCMD,TRACK,2*23\x0D\x0A"; unsigned char GetMagellanRoute[] = "$PMGNCMD,ROUTE*2B\x0D\x0A"; unsigned char SendEnd[] = "$PMGNCMD,END*3D\x0D\x0A"; unsigned char SendMagWaypoints[100]; char Wpl[] = "$PMGNWPL,"; struct Posishun{ int UTMZ; int UTMN; int UTME; int Alt; int HorizEpe; int VertEpe; float Velocity; WORD Course; // float RateOfClimb; BYTE Hour; BYTE Min; BYTE Sec; BYTE Month; BYTE Date; BYTE Year; // BYTE New; // BYTE Filler; } Position[14400];//4 hours int pos = 0; BOOL newposition; int LineType, Time; BOOL posflag = TRUE; char Posit[] = "Position Data will be displayed here when you move the cursor over a position dot."; HWND hwndPosit; struct TRAC { signed int NUTM; signed int EUTM; unsigned int time; float alt; double dist; COLORREF color; unsigned char newtrk; unsigned char year;//year - 2000 } *trak; char Trac[] = "Track Data will be displayed here when you move the cursor over a track point."; HWND hwndTrack; struct { int NUTM; int EUTM; unsigned int time; } oldTrack; char MeridianFullName[MAX_PATH]; char MeridianName[MAX_PATH]; int trackcommas, firsttrack; unsigned int hour, minute, second; unsigned int Month, Day, Year; unsigned char *pTrackBuf; char OldTrackHead[] = "Track,UTM Zone,UTM Northing,UTM Easting,Month,Date,Hour,Min,Sec,Alt (Meters)\r\n"; char TrackHead[] = "Track,UTM Zone,UTM Northing,UTM Easting,Hour,Min,Sec,Month,Date,Year,Altitude\r\n"; unsigned char Trackid[100]; struct _SYSTEMTIME st, *lpSystemTime = &st; struct _FILETIME ft, *lpFileTime= &ft; LARGE_INTEGER li; __int64 quad; struct newloc { int NUTM; int EUTM; int UTMZone; int size; char *pWaypoints;//pointer to waypoint data in WaypointArray char *Ident;//pointer to name char *Location;//pointer to cmt char *Description;//pointer to desc char *Elev;//pointer to ele char *Sym;//pointer to sym } NewLoc[TOTAL_LOCS]; char *WaypointArray; char *tempWayArray; int NumOfWaypoints, WaypointSize, MaxWaySize, SendWaypointSize, firstx, size; char WaypointLimit[] = "The waypoint size limit has been reached.\nClose and re-open USAPhotoMaps to edit\nor add more waypoints."; char Ident[100]; char Location[100]; char Description[10000]; char Combined[100]; char BigJpegCombined[] = "Create eXXXXXXnYYYYYYYzZZx.jpg\n from eXXXXXXnYYYYYYYzZZx.txt\n(modified on mm/dd/yyyy at hh:mm)?"; char Elev[30]; char Sym[30]; char WashingtonXML[] = "Washington,DC.xml"; char Top[] = "\ \r\n\ \r\n"; char WashingtonWaypoint[] = "\r\nWashington\r\n\r\n\r\n"; int temp, tempNUTM, tempEUTM, temp2UTMZone, longest; char TheKey[] = "d9sa82";//no key"; char *tempWaypoints, *tempIdent, *tempLoc, *tempDesc, *tempElev, *tempSym; char Bottom[] = "\r\n"; char Name[] = ""; char EndName[] = "\r\n";//"; char Cmt[] = ""; char CmtEnd[] = "\r\n"; char Desc[] = ""; char DescEnd[] = "\r\n"; char WptEnd[] = "\r\n"; UINT u; float f, Velocity; double eleM; HWND hwnd, hwndCounter; struct Text {//80 bytes int NUTM; int EUTM; int angle;//the double Angle is converted to a long before use char text[MAX_TEXT]; struct Text *next; int Zoom; } *cur, *prev, *next, *new_node, *head, *chosen, *savedHead; struct { int Z; int N; int E; char Ident[52]; } RouteWay[TOTAL_LOCS]; int routeway; struct Route { int UTMZone; int NUTM; int EUTM; } *pRoute, *pr; int ptr; int pixelptr; struct { int Z; int N; int E; } Root[50][300]; int RouteNum, RouteSize[300], rte, RoutePoint; int totalroutelines, routeline, numofRoutes; char RouteName[3]; char RouteComment[300][21]; char Nums[500][7]; char Num[] = "ZZZZZZ"; char Rute[] = "$PMGNRTE,"; char SendRoute[82]; char TerraFetcherInfo[] = "\ Move the mouse cursor to a corner of the area\n\ you want to create a TerraFetcher Region file for,\n\ press and hold the left mouse button,\n\ and move the mouse to the\n\ diagonally opposite corner of that area,\n\ (use the Arrow keys to get an area larger than the screen)\n\ and then release the mouse button."; char BigJpegInfo[] = "\ Move the mouse cursor to a corner of the area\n\ you want to create a BIG jpeg file of,\n\ press and hold the left mouse button,\n\ and move the mouse to the diagonally opposite\n\ corner of that area,\n\ (use the Arrow keys to get an area larger than the screen)\n\ and then release the mouse button."; char SendingRoute[] = "\ Before you send a route to your GPS,\n\ all routes and waypoints in your GPS\n\ should be saved to an SD card or to\n\ USAPhotoMaps or another program,\n\ because your GPS could over-write them.\n\ \n\ The waypoints for the route are named\n\ \"1\" thru the number of them."; char CreateRoute[] = "\ Click the left mouse button to make a point.\n\ Move the mouse pointer to make a line.\n\ Click again to continue the route.\n\ Press Ctrl-Z to delete last point.\n\ Double-click or press Escape when finished."; CRITICAL_SECTION cs; DCB dcb, dcb2; WIN32_FIND_DATA fd; BITMAPINFOHEADER bmih, *pbmih = &bmih, bmih2, *pbmih2 = &bmih2, bmih3, *pbmih3 = &bmih3, bmih4, *pbmih4 = &bmih4, bmih5, *pbmih5 = &bmih5; BITMAPINFO bmi, *pbmi = &bmi, bmi2, *pbmi2 = &bmi2, bmi3, *pbmi3 = &bmi3, bmi4, *pbmi4 = &bmi4, bmi5, *pbmi5 = &bmi5; JPEG_CORE_PROPERTIES jcprops; IJLERR jerr; HANDLE hGZFile, hFile, hFile2, hFile3, hFile4, hPosFile = INVALID_HANDLE_VALUE, hComm, hEventExit, hEvent, hTimerEvent, hUSBEvent, hThreadEvent, hTigerEvent, hTigerReturn, hCacheOk, hCacheEvent, hAPRSEvent, hAPRSISEvent; PAINTSTRUCT ps, ps2; RECT rect, counterRect, posRect, socketsRect; HKEY hRegKey, hRegKey2; HDC hdc, hdcMem, hdcMem2 = NULL, hdcMem3 = NULL, hdcGrayMem, hdcBlackMem, hdcPrn, hdcButton, hdcMap; HBITMAP hBitmap, hBitmap2, hBitmap3, hPrnBitmap, hGrayBitmap, hRedBitmap, hSymbolBitmap = NULL; HBRUSH hBrush, hPositionBrush, hRedBrush, hWaypointBrush, hStartBrush, hEndBrush, hRadiationBrush, hAPRSBrush, hBlankBrush; HPEN hPen, hRoutePen, hTrackPen, hAPRSPen, hRedPen, hWhitePen, hBlackPen; HINSTANCE hInst; HMENU hMenu, hMenu2, hMenu3, hMenu4, hMenu5; COMMPROP cp, cp2; COMMTIMEOUTS cto, APRScto; OPENFILENAME ofn, ofn2, ofn3, ofn4, ofn5, ofn6, ofn7; HCURSOR hCursor, hDrawingCursor, hWaitingCursor; HGDIOBJ hObject, hObject2, hCircleBrush, hOldBrush, hOldPen; HINTERNET hOpen; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK InstructProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK CounterProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK TigerCountProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK PosProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK TrackProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK StreetProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK StreetEditProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK ElevationProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK BigProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK USAProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK DescEditProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK PhotoProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK EditListProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK EditInfoListProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK SymbolChartProc(HWND, UINT, WPARAM, LPARAM); WNDPROC pEditProc, pPosProc, pTrackProc, pElevProc, pStreetProc, pStreetEditProc, pCommProc, pEdit1Proc, pEdit2Proc, pDescEditProc, pStaticProc, pEditListProc, pInfoListProc; UINT WINAPI DownloadThread(void*); UINT WINAPI DownloadStatesThread(void*); UINT WINAPI DownloadStateOutlineThread(void*); UINT WINAPI DownloadUTMThread(void*); UINT WINAPI CommThread(void*); UINT WINAPI TigerCommThread(void*); UINT WINAPI TigerThread(void* pParam); UINT WINAPI TimerThread(void*); UINT WINAPI USBThread(void* pParam); UINT WINAPI URLThread(void*); UINT WINAPI FillCacheThread(void*); UINT WINAPI APRSCommThread(void*); UINT WINAPI aprsISthread(void*); UINT WINAPI aprsISthread2(void*); int CALLBACK GetLocationProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK CheckLocationProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK CheckTextProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK EditLocationProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK WelcomeProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK OpenProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK FindUSGSProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK GotoProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK GotoUSNGProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK GetLatLonProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK GetTextProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK EditTextProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK PreferencesProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK ColorsProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK DotProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK LineWidthProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK LatLonProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK TrackColorsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); int CALLBACK GetFilenameProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK USGSProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK AddressProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK FindProc(HWND, UINT, WPARAM, LPARAM); int CALLBACK DescriptionProc(HWND hBeg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK CommPortProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK LineProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); void Convert_TileBuf_hdcMem(unsigned char*, unsigned int); void LatLontoUTM(void); void UTMtoLatLon(void); void GetLatLon(void); void LatorLon(int, int); void GetUTM(int North, int West); void GetUSNG(int North, int West); void ShowDistance(int, int, int); void ShowNearest(int); void RedDot(HWND hwnd); void PrepWaypoint(void); int PrepMagellanWaypoint(void); void PrepRoute(void); int PrepTrack(void); void ClearLine(void); void GetURLName(void); void GetTopoURLName(void); void GetColorURLName(void); BOOL GetXYZfromIniBuf(void); void GetCommHandle(void); void GetCommHandle2(void); void IncCount(void); void IncNumber(void); void SetRegKey(int); void SetRegKey2(char*, int); void SaveLocs(void); void SaveText(void); void MenuChecks(void); void ShowZoom(void); void DoZoom(void); int PutSemicircles(int); void GetContour(void); BOOL PrepBox(int); void GPSockets(void); void DrawLineTo(int, int); void DrawLine2(int, int, int); void InitializeOpenFileNameLogFont(HWND); //void SendChecksum(void); void FillWaypointArray(int); int FillListBox(HWND); int ReadTracks(int); void WriteTracks(HANDLE, int); void ChangeZone(int xUTMZone, int from); void ShowError(int); void CheckRadio(HWND hwndDlg, int red, int green, int blue); int AsciiToHex(int); void GetRandomNum(void); DWORD PrepSendRoute(void); void ShowDownloadProgress(int); BOOL CheckFormat(int); void XMLError(int); void ShowTopo(void); void ShowPhoto(void); void ShowUrbanArea(void); void GetRowName(int, int); void GetDotRadius(void); void GetPointerElev(int); void ChangeBaud(void); void ShowWaypointData(int, int); void ConvertoMeridian(DWORD); void GetMagSym(int x); void GetSym(int); int GarminSym(void); void ChangeUSAPhotoMapsIni(void); void ChangeUSAPMIni(void); void SaveTracks(void); void FillZoomTable(void); void WriteDots(HANDLE hFile); void WriteLineWidth(HANDLE); void GetElevData(void); void GridSeventyFive(void); void store_pixel(int index); int decodeLZW(void); DWORD CreateTileBuf(unsigned char*, unsigned int); int CheckIniProc(unsigned char*, DWORD, int); void ShowPosition(void); void SendPacket(DWORD dwBytesToSend); void SaveDownloadedTracks(void); void SaveDownloadedWaypoints(void); void SignalUSBStop(void); void ShowPackets(void); void GetDems(void); void SavePosition(void); void GetFileName(void); void CreateTracks(void); void UncheckZoom(void); BOOL GetUSGSData(void); //DWORD ConvertSDTSData(void); //int ReadLatLonData(void); //int Subroutine(void); //void ConvertLatLon(void); BOOL GetDownloadedData(void); void FindIt(void); int BigJpeg(void); void SavenameCommentProc(void); void SaveDescriptionProc(void); //void PreGetTigerData(void); void GetTigerIndex(void); int CALLBACK MapLocationProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK GetTigerProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); void FreepTiger(void); void Uncheck(void); int LatLontoLambertAzimuthal(double, double); void GetCountyFromLatLon(void); void InitDirectDraw(void); void GetStateBorders(void); int GetXY(void); void ShowDistanceAngle(void); void ModifyZoom(void); void EditWaypoint(void); void EndRoute(void); void ConvertLocToXML(char *tempBuf, char *tempBuf2, int x, DWORD fileSize); void SendMagRoutes(void); //void GetExploristDir(void); int GetExploristWaypoints(int); void FillTrackFromNMEA(void); LRESULT CALLBACK CommProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK Edit2Proc(HWND, UINT, WPARAM, LPARAM); void GetAPRS(void); void GetAPRSLL(void); void GetAPRSLatLon(int); void GetAPRSLatLon2(int); void GetTNCLatLon(void); void MicE(int); void GetWX(int); void GetAPRSlogFile(void); void GetAPRSlogFile2(void); int Uncompress(int); void FillDescOrWx(int); void SaveAPRSlog(void); void SaveAPRSlogAsText(void); void ParseAPRS(int); void GetAPRSCommHandle(void); int CALLBACK APRSCommPortProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); void ChangeAPRSBaud(int); int CALLBACK APRSProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); DWORD AddtoUSAPMini(char*); void FillMYCALLUNPROTOBTEXTKISS(void); void ConvertoGPSLatLon(void); int CALLBACK ExcludeSymbolsCallsProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK ExcludeTracksProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK APRSEditProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); void GetKiss(void); void InitializeAPRSComm(void); HDC ReadBmpFile(char *FileName); void ShowIcon(int x); int CALLBACK MessageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK EditMessageProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK EditObjectProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK StationsProc(HWND hwndStationsDlg, UINT message, WPARAM wParam, LPARAM lParam); void SortStations(HWND hwndList); int CALLBACK StationInfoProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK GetObjectProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK SymbolsProc(HWND hwndListDlg, UINT message, WPARAM wParam, LPARAM lParam); void LoadObjects(void); void StationInfo(int x); int CALLBACK TacticalProc(HWND hwndTacticalDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK APRSServerProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK SecretIPProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK CircleProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); //int CALLBACK LocalServerProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int GetInitString(void); DWORD ConvertBILData(void); int CALLBACK SmartBeaconingProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); void GetCourse(int x); BOOL SmartBeacon(int x); void GetSpeed(int x); void LookForIgateMessages(void); DWORD Atoi(char*); void ApproachControl(void); int CALLBACK NewPlaneProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK CenterlineProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); int CALLBACK CommandProc(HWND, UINT, WPARAM, LPARAM); MSG msg; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { WNDCLASS wndclass; hInst = hInstance; wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_ICON1)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)CreateSolidBrush(LIGHTGRAY);//(HBRUSH)(COLOR_MENU+1);//GetStockObject(LTGRAY_BRUSH); wndclass.lpszMenuName = "USAPHOTOMAPS"; wndclass.lpszClassName = ProgName; if (!RegisterClass (&wndclass)) return 0; wndclass.lpfnWndProc = InstructProc; wndclass.hIcon = NULL; wndclass.lpszClassName = Instruct; RegisterClass(&wndclass); wndclass.lpfnWndProc = CounterProc; wndclass.hIcon = NULL; wndclass.lpszClassName = Counter; RegisterClass(&wndclass); wndclass.lpfnWndProc = TigerCountProc; wndclass.hIcon = NULL; wndclass.lpszClassName = Tiger; RegisterClass(&wndclass); wndclass.lpfnWndProc = USAProc; wndclass.hIcon = NULL; wndclass.lpszClassName = USA; RegisterClass(&wndclass); wndclass.lpfnWndProc = BigProc; wndclass.hIcon = NULL; wndclass.lpszClassName = Big; RegisterClass(&wndclass); wndclass.lpfnWndProc = PhotoProc; wndclass.hIcon = NULL; wndclass.lpszClassName = Photos; RegisterClass(&wndclass); if (szCmdLine[0] != 0) { for (x = 0, y = 0; szCmdLine[x] != 0; x++) if (szCmdLine[x] != '"') CmdLine[y++] = szCmdLine[x]; CmdLine[y] = 0; } if ((szCmdLine[0] == '-') && (szCmdLine[1] != 0)) { USAPhotoMapsData[0] = szCmdLine[1]; USAPhotoMapsData[1] = ':'; USAPhotoMapsData[2] = '\\'; pointerFileName[0] = szCmdLine[1]; pointerFileName[1] = ':'; pointerFileName[2] = '\\'; fileName[0] = szCmdLine[1]; fileName[1] = ':'; fileName[2] = '\\'; } hwnd = CreateWindow(ProgName, ProgName, WS_OVERLAPPEDWINDOW, // WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_THICKFRAME, 0, 0, 640, 480, NULL, NULL, hInstance, NULL); iCmdShow = SW_SHOWMAXIMIZED;//Petzold, p.59 ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } int compareIdent(void const *x, void const *y) { int w, z; BOOL xIdent, yIdent; if (((((struct newloc*)x)->Ident) != 0) && ((((struct newloc*)y)->Ident) != 0)) { for (w = 0; ((struct newloc*)x)->Ident[w] != '<'; w++) ; ((struct newloc*)x)->Ident[w] = 0;//change "" to "\0/cmt>" for (w = 0; ((struct newloc*)y)->Ident[w] != '<'; w++) ; ((struct newloc*)y)->Ident[w] = 0;//change "" to "\0/cmt>" z = _stricmp(((struct newloc*)x)->Ident, ((struct newloc*)y)->Ident); for (w = 0; ((struct newloc*)x)->Ident[w] != 0; w++) ; ((struct newloc*)x)->Ident[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++) ; ((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "" return z; } else { if ((((struct newloc*)x)->Ident) == 0) { xIdent = FALSE; for (w = 0; ((struct newloc*)x)->Location[w] != '<'; w++) ; ((struct newloc*)x)->Location[w] = 0;//change "" to "\0/cmt>" } else { xIdent = TRUE; for (w = 0; ((struct newloc*)x)->Ident[w] != '<'; w++) ; ((struct newloc*)x)->Ident[w] = 0;//change "" to "\0/cmt>" } if ((((struct newloc*)y)->Ident) == 0) { yIdent = FALSE; for (w = 0; ((struct newloc*)y)->Location[w] != '<'; w++) ; ((struct newloc*)y)->Location[w] = 0;//change "" to "\0/cmt>" } else { yIdent = TRUE; for (w = 0; ((struct newloc*)y)->Ident[w] != '<'; w++) ; ((struct newloc*)y)->Ident[w] = 0;//change "/cmt>" to "<\0/cmt>" } //now strcmp & put '<' back if ((xIdent == TRUE) && (yIdent == FALSE)) { z = _stricmp(((struct newloc*)x)->Ident, ((struct newloc*)y)->Location); for (w = 0; ((struct newloc*)x)->Ident[w] != 0; w++) ; ((struct newloc*)x)->Ident[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++) ; ((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "" } else if ((xIdent == FALSE) && (yIdent == TRUE)) { z = _stricmp(((struct newloc*)x)->Location, ((struct newloc*)y)->Ident); for (w = 0; ((struct newloc*)x)->Location[w] != 0; w++) ; ((struct newloc*)x)->Location[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++) ; ((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "" } else if ((xIdent == FALSE) && (yIdent == FALSE)) { z = _stricmp(((struct newloc*)x)->Location, ((struct newloc*)y)->Location); for (w = 0; ((struct newloc*)x)->Location[w] != 0; w++) ; ((struct newloc*)x)->Location[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++) ; ((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "" } return z; } } int compareLoc(void const *x, void const *y) { int w, z; BOOL xLoc, yLoc; if (((((struct newloc*) x)->Location) != 0) && ((((struct newloc*) y)->Location) != 0)) { for (w = 0; ((struct newloc*)x)->Location[w] != '<'; w++) ; ((struct newloc*)x)->Location[w] = 0;//change "" to "\0/cmt>" for (w = 0; ((struct newloc*)y)->Location[w] != '<'; w++) ; ((struct newloc*)y)->Location[w] = 0;//change "" to "\0/cmt>" z = _stricmp(((struct newloc*) x)->Location, ((struct newloc*) y)->Location); for (w = 0; ((struct newloc*)x)->Location[w] != 0; w++) ; ((struct newloc*)x)->Location[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++) ; ((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "" return z; } else//compare a Location with an Ident { if ((((struct newloc*)x)->Location) == 0) { xLoc = FALSE; for (w = 0; ((struct newloc*)x)->Ident[w] != '<'; w++) ; ((struct newloc*)x)->Ident[w] = 0;//change "" to "\0/cmt>" } else { xLoc = TRUE; for (w = 0; ((struct newloc*)x)->Location[w] != '<'; w++) ; ((struct newloc*)x)->Location[w] = 0;//change "" to "\0/cmt>" } if ((((struct newloc*)y)->Location) == 0) { yLoc = FALSE; for (w = 0; ((struct newloc*)y)->Ident[w] != '<'; w++) ; ((struct newloc*)y)->Ident[w] = 0;//change "" to "\0/cmt>" } else { yLoc = TRUE; for (w = 0; ((struct newloc*)y)->Location[w] != '<'; w++) ; ((struct newloc*)y)->Location[w] = 0;//change "/cmt>" to "<\0/cmt>" } //now strcmp & put '<' back if ((xLoc == TRUE) && (yLoc == FALSE)) { z = _stricmp(((struct newloc*)x)->Location, ((struct newloc*)y)->Ident); for (w = 0; ((struct newloc*)x)->Location[w] != 0; w++) ; ((struct newloc*)x)->Location[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++) ; ((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "" } else if ((xLoc == FALSE) && (yLoc == TRUE)) { z = _stricmp(((struct newloc*)x)->Ident, ((struct newloc*)y)->Location); for (w = 0; ((struct newloc*)x)->Ident[w] != 0; w++) ; ((struct newloc*)x)->Ident[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++) ; ((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "" } else if ((xLoc == FALSE) && (yLoc == FALSE)) { z = _stricmp(((struct newloc*)x)->Ident, ((struct newloc*)y)->Ident); for (w = 0; ((struct newloc*)x)->Ident[w] != 0; w++) ; ((struct newloc*)x)->Ident[w] = '<';//change "\0/cmt>" to "" for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++) ; ((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "" } } return z; } void SubSubProc(int y) { for (x = 0; Photo[x].name[0] != 0; x++) { if ((Photo[x].begin <= y) && (Photo[x].end >= y)) {//clicked on a photo in \Photos for (y = 0, z = 7; Photo[x].name[y] != 0; y++, z++) PhotoName[z] = Photo[x].name[y]; PhotoName[z] = 0; hFile = CreateFile(PhotoName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); fileSize = GetFileSize(hFile, NULL); if (fileSize) { PhotoBuf = (BYTE*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hFile, PhotoBuf, fileSize, &dwBytesRead, NULL) ; if ((PhotoBuf[0] != 0xFF) || (PhotoBuf[1] != 0xD8) || (PhotoBuf[2] != 0xFF)) {//if not a jpeg file VirtualFree(PhotoBuf, 0, MEM_RELEASE); CloseHandle(hFile); MessageBox(hwnd, "That's not a jpeg file.", ERROR, MB_OK); return; } if (photo_pixel_buf != NULL) { DestroyWindow(hwndPhoto); } jerr = ijlInit (&jcprops);//use Intel's ijl15.dll to convert JPEG files jcprops.JPGBytes = PhotoBuf;//source jcprops.JPGSizeBytes = fileSize; jcprops.JPGFile = NULL; jerr = ijlRead(&jcprops, IJL_JBUFF_READPARAMS); Width = jcprops.JPGWidth; Height = jcprops.JPGHeight; if (((rect.right-10) > Width) && ((rect.bottom-20) > Height)) Resolution = FULL; else if (((rect.right-10) > Width/2) && ((rect.bottom-20) > Height/2)) { Resolution = HALF; Width /= 2; Height /= 2; } else if (((rect.right-10) > Width/4) && ((rect.bottom-20) > Height/4)) { Resolution = QUARTER; Width /= 4; Height /= 4; } else if (((rect.right-10) > Width/8) && ((rect.bottom-20) > Height/8)) { Resolution = EIGHTH; Width /= 8; Height /= 8; } jcprops.DIBWidth = Width; jcprops.DIBHeight = Height; PadBytes = IJL_DIB_PAD_BYTES(Width, 3); jcprops.DIBPadBytes = PadBytes; photo_pixel_buf = (BYTE*)VirtualAlloc(NULL, ((Width + jcprops.DIBPadBytes) * Height * 3), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); jcprops.DIBBytes = photo_pixel_buf;//destination jcprops.DIBChannels = 3; jcprops.DIBColor = IJL_BGR; if (Resolution == FULL) jerr = ijlRead (&jcprops, IJL_JBUFF_READWHOLEIMAGE); else if (Resolution == HALF) jerr = ijlRead (&jcprops, IJL_JBUFF_READONEHALF); else if (Resolution == QUARTER) jerr = ijlRead (&jcprops, IJL_JBUFF_READONEQUARTER); else if (Resolution == EIGHTH) jerr = ijlRead (&jcprops, IJL_JBUFF_READONEEIGHTH); ijlFree(&jcprops); VirtualFree(PhotoBuf, 0, MEM_RELEASE); hMenu2 = CreateMenu();//to override parent menu bar x = Width+(Frame*2); y = Height+GetSystemMetrics(SM_CYCAPTION)+Frame; hwndPhoto = CreateWindow(Photos, NULL, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen-x, TitleAndMenu+Frame, x, y, hwndDescEdit, hMenu2, hInst, NULL); SetWindowText(hwndPhoto, PhotoName); } CloseHandle(hFile); break; } } } void CALLBACK TimerFunc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2) { PostMessage(hwnd, WM_USER3, 0, 0); } //sub-class procedure LRESULT CALLBACK DescEditProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { int y; if (message == WM_MOUSEMOVE) points = MAKEPOINTS(lParam); else if ((message == WM_KEYDOWN) && (wParam == VK_RETURN)) { y = SendMessage(hwndDescEdit, EM_LINEINDEX, -1, 0);//0-based line number of cursor SubSubProc(y); } else if (message == WM_LBUTTONDOWN) { y = SendMessage(hwndDescEdit, EM_CHARFROMPOS, 0, MAKELPARAM(points.x, points.y)); y &= 0xFFFF;//use low-word only for zero-based index from beginning of Description SubSubProc(y); } return CallWindowProc(pDescEditProc, hwnd2, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK EditProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { CurrentHelp = GetParent(hwnd2); if (message == WM_KEYDOWN) { if ((wParam == VK_ESCAPE)) { if ((CurrentHelp == hwndHelp) && (pHelp != NULL)) { free(pHelp); pHelp = NULL; } else if ((CurrentHelp == hwndGPS) && (pGPSHelp != NULL)) { free(pGPSHelp); pGPSHelp = NULL; } else if ((CurrentHelp == hwndTigerHelp) && (pTigerHelp != NULL)) { free(pTigerHelp); pTigerHelp = NULL; } else if ((CurrentHelp == hwndCounties) && (pCounties != NULL)) { free(pCounties); pCounties = NULL; } else if ((CurrentHelp == hwndElevationHelp) && (pElevationHelp != NULL)) { free(pElevationHelp); pElevationHelp = NULL; } SendMessage(CurrentHelp, WM_CLOSE, wParam, lParam); } else if ((wParam == VK_DELETE) && (editingtracks)) SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 0); if (!editingtracks) { if (wParam == 'F') { SendMessage(hwndInstr, WM_VSCROLL, SB_TOP, 0); if (CurrentHelp == hwndHelp) { pFind = pHelp; FindSize = HelpSize; } else if (CurrentHelp == hwndGPS) { pFind = pGPSHelp; FindSize = GPSHelpSize; } else if (CurrentHelp == hwndTigerHelp) { pFind = pTigerHelp; FindSize = TigerHelpSize; } else if (CurrentHelp == hwndAPRS) { pFind = pAPRSHelp; FindSize = APRSHelpSize; } NextFind = 0; DialogBox(hInst, "FIND", NULL, FindProc); } else if ((wParam == VK_F3) && (NextFind != 0)) ///////// FindIt(); ///////// } } else if (message == WM_DESTROY) { if ((CurrentHelp == hwndHelp) && (pHelp != NULL)) { free(pHelp); pHelp = NULL; } else if ((CurrentHelp == hwndGPS) && (pGPSHelp != NULL)) { free(pGPSHelp); pGPSHelp = NULL; } } return CallWindowProc(pEditProc, hwnd2, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK CommProc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { if ((firsttx) && (message == WM_KEYDOWN) && (wParam == VK_RETURN)) InitializeAPRSComm(); else if ((message == WM_CHAR) && (lParam != 8))//bell { toHwndComm++; if (toHwndComm == MaxText) { MessageBeep(MB_OK); toHwndComm = 0; SendMessage(hwndComm, EM_SETSEL, 0, -1); SendMessage(hwndComm, WM_CLEAR, 0, 0); } if (lParam != 0) {//if not from WM_APRS_COMM (it's user input) BYTE ch = (BYTE)wParam; WriteFile(hAPRSComm, &ch, 1, &dwBytesWritten, NULL); return 0;//don't show char } } else if ((message == WM_KEYDOWN) && (wParam == VK_ESCAPE)) DestroyWindow(hwndAPRSDlg); else if (message == WM_DESTROY) hwndComm = NULL; return CallWindowProc(pCommProc, hwnd3, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK Edit2Proc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { if ((message == WM_KEYDOWN) && (wParam == VK_RETURN)) { blanklen = GetDlgItemText(hwndAPRSDlg, IDC_EDIT2, Blank1, 32); WriteFile(hAPRSComm, Blank1, blanklen, &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); } return CallWindowProc(pEdit2Proc, hwnd3, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK PosProc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { if ((message == WM_KEYDOWN) && (wParam == VK_ESCAPE)) DestroyWindow(hwndPosit); else if (message == WM_DESTROY) { pos = 0;//to stop showing position dots - or tracks fromposition = FALSE; InvalidateRect(hwnd, &rect, FALSE); posflag = TRUE; } return CallWindowProc(pPosProc, hwnd3, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK StreetProc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: if ((HWND)(LPARAM)lParam == hwndShowButton) { if (show) { if (GetWindowText(hwndStreetEdit, StreetName, 50) != 0) { show = FALSE; SendMessage(hwndShowButton, WM_SETTEXT, 0, (LPARAM)"Hide This Street Name"); for (x = 0; StreetName[x] != 0; x++) if (StreetName[x] != ' ') StreetName[x] &= 0xDF;//make uppercase } } else { show = TRUE; SendMessage(hwndShowButton, WM_SETTEXT, 0, (LPARAM)"Display a Street Name"); } SetFocus(hwnd); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); return 0; } } return CallWindowProc(pStreetProc, hwnd3, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK StreetEditProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_KEYDOWN) { if (wParam == VK_RETURN) { SendMessage(hwndStreet, WM_COMMAND, 0, (LPARAM)hwndShowButton); } else if (wParam == VK_ESCAPE) { SetFocus(hwnd); } } return CallWindowProc(pStreetEditProc, hwnd2, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK TrackProc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_COMMAND: if ((autoLoc == FALSE) && (showingtracks)) { if ((HWND)(LPARAM)lParam == hwndButton) {//"Edit Track" or "Stop Editing" if (editingtracks == FALSE) { editingtracks = TRUE; SendMessage(hwndButton, WM_SETTEXT, 0, (LPARAM)"Stop &Editing"); firstlbutton = firstrbutton = TRUE; hwndButton3 = CreateWindow("BUTTON", "&Help", WS_CHILD | WS_VISIBLE, 0, 160, 50, 25, hwndTrack, (HMENU)92, hInst, NULL); hdcButton = GetDC(hwndButton3); hFont = CreateFontIndirect (&lf2); SelectObject(hdcButton, hFont); ReleaseDC(hwndButton3, hdcButton); SendMessage(hwndButton3, WM_SETFONT, (UINT)hFont, TRUE); } else { editingtracks = FALSE; SendMessage(hwndButton, WM_SETTEXT, 0, (LPARAM)"&Edit Tracks"); DestroyWindow(hwndButton3); hwndButton3 = NULL; } InvalidateRect(hwnd, &rect, FALSE); SetFocus(hwnd); } else if ((HWND)(LPARAM)lParam == hwndButton2) {//"Goto &Beginning of Tracks" if (trackUTMZone == UTMZone)// || (trackUTMZone < 10))//x < 10 in old Track.dta format { BeginY = trak[0].NUTM / MetersPerTile; BeginX = trak[0].EUTM / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen SendMessage(hwnd, WM_USER, 0, 0); } else if (trackUTMZone != 0) { UTMNorthing = trak[0].NUTM; UTMEasting = trak[0].EUTM; UTMZone = trak[0].time >> 26;//UTMZone in new Track.dta format ChangeZone(trackUTMZone, 1);//hwndButton2 BeginY = UTMNorthing / MetersPerTile; BeginX = UTMEasting / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; fromOpen = TRUE; Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); }//end of else else MessageBox(hwnd, "Can't.\nUTM zone isn't in track data.", ERROR, MB_OK); //???GetElevData(); InvalidateRect(hwnd, &rect, FALSE); SetFocus(hwnd); } else if ((hwndButton3 != 0) && ((HWND)(LPARAM)lParam == hwndButton3)) {//"Help" hMenu2 = CreateMenu();//to override parent menu bar y = __min(cyChar*35, cyScreen-TitleAndMenu); hwndEdit = CreateWindow(Instruct, "Edit Tracks", WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, Frame, TitleAndMenu+(GetSystemMetrics(SM_CYCAPTION)), 350, y, hwndTrack, hMenu2, hInst, NULL); SetWindowText(hwndInstr, TrackEdit); SetFocus(hwndInstr); } return 0; } break; case WM_DESTROY: SendMessage(hwndButton, WM_CLOSE, 0, 0); SendMessage(hwndButton2, WM_CLOSE, 0, 0); SendMessage(hwndButton3, WM_CLOSE, 0, 0); SendMessage(hwndEdit, WM_CLOSE, 0, 0); showingtracks = FALSE; if (trak != NULL) { InvalidateRect(hwnd, &rect, FALSE); free(trak); trak = NULL; } break; } return CallWindowProc(pTrackProc, hwnd3, message, wParam, lParam); } //sub-class procedure LRESULT CALLBACK ElevationProc(HWND hwnd3, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: getelev = FALSE; grid75 = FALSE; CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); InvalidateRect(hwnd, &rect, FALSE); break; } return CallWindowProc(pElevProc, hwnd3, message, wParam, lParam); } LRESULT CALLBACK EditListProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { if ((message == WM_KEYDOWN) && (wParam == VK_RETURN)) SendMessage(hwndStationsDlg, WM_COMMAND, (WPARAM)((LBN_DBLCLK<<16)|IDC_LIST1), 0); else if ((message == WM_KEYDOWN) && (wParam == VK_DELETE)) SendMessage(hwndStationsDlg, WM_COMMAND, (WPARAM)(VK_DELETE), 0); // else if ((message == WM_KEYDOWN) && (wParam == VK_ESCAPE)) // SendMessage(hwndStationsDlg, WM_COMMAND, (WPARAM)IDCANCEL, 0); return CallWindowProc(pEditListProc, hwnd2, message, wParam, lParam); } LRESULT CALLBACK EditInfoListProc(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam) { if ((message == WM_KEYDOWN) && (wParam == VK_RETURN)) SendMessage(hwndStationInfoDlg, WM_COMMAND, (WPARAM)((LBN_DBLCLK<<16)|IDC_LIST1), 0); return CallWindowProc(pInfoListProc, hwnd2, message, wParam, lParam); } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int BadSend; int idistX, idistY, tempMouseLoc; double distX, distY; static unsigned char *pRecords = &ReceivedData[0];//, *pTime = &ReceivedData[8]; static WORD Records; static int GarminFlag = GOT_ETX; static char BadWaypoint[] = "Waypoint wasn't received"; //static char BadCommPort[] = "The Comm Port doesn't seem to be valid"; static char FullArray[] = "The Locations array is full"; static BOOL nofile = FALSE, gotaDLE = FALSE, commas, qpressed; static BOOL flag = FALSE; static unsigned char *GrayArray; static int timeDiff, wParameter; static unsigned int uiTimer; static char PhotosDownloaded[] = " rows filled in."; static char CheckingConnection[] = "STANDBY (FOR UP TO 40 SECONDS)... WINDOWS IS CHECKING INTERNET CONNECTION..."; static DWORD TickCount, TickCount2; static int iLatLon = -1, Four; static int GotoX, GotoY, xCenter, yCenter; char ch; switch (message) { case WM_USER3: // approach control MetersPerPixel = MetersPerTile/PixelsPerTile; BitBlt(hdcMem3, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); SetBkMode(hdcMem3, TRANSPARENT); d1 = dThirtyMiles / (double)MetersPerPixel; __asm fld d1 // round a double up or down __asm fistp ThirtyMiles // to an integer CircleX = (AirportUTMEasting - ScreenLeft) / MetersPerPixel; CircleY = (ScreenTop - AirportUTMNorthing) / MetersPerPixel; hWhitePen = CreatePen(PS_SOLID, 1, 0xFFFFFF); hBlackPen = CreatePen(PS_SOLID, 1, 0); hObject = SelectObject(hdcMem3, hWhitePen); hBlankBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hOldBrush = SelectObject(hdcMem3, hBlankBrush); Ellipse(hdcMem3, CircleX - ThirtyMiles, CircleY - ThirtyMiles, CircleX + ThirtyMiles, CircleY + ThirtyMiles); SelectObject(hdcMem3, hOldBrush); DeleteObject(hBlankBrush); hWaypointBrush = CreateSolidBrush(WaypointColor); hOldBrush = SelectObject(hdcMem3, hWaypointBrush); if (dCenterline != 370.0) { GetDotRadius(); // for glide slope temp waypoint SetTextColor(hdcMem3, 0xFFFFFF); for (z = 0; z < lines; z++) { SelectObject(hdcMem3, hWhitePen); x = (Line[z].UTME1 - ScreenLeft) / MetersPerPixel; y = (ScreenTop - Line[z].UTMN1) / MetersPerPixel; MoveToEx(hdcMem3, x, y, NULL); x = (Line[z].UTME2 - ScreenLeft) / MetersPerPixel; y = (ScreenTop - Line[z].UTMN2) / MetersPerPixel; LineTo(hdcMem3, x, y); if (Line[z].GSE) { SelectObject(hdcMem3, hBlackPen); x = (Line[z].GSE - ScreenLeft) / MetersPerPixel; y = (ScreenTop - Line[z].GSN) / MetersPerPixel; Ellipse(hdcMem3, x-DotRadius, y-DotRadius, x+DotRadius, y+DotRadius); _itoa(Line[z].GSInterceptAlt, tempPlane, 10); w = lstrlen(tempPlane); tempPlane[w] = '\''; w++; TextOut(hdcMem3, x, y, tempPlane, w); } } } SelectObject(hdcMem3, hObject); DeleteObject(hBlackPen); DeleteObject(hWhitePen); // show waypoints for (x = 0; NewLoc[x].EUTM != 0; x++) { if ((UTMZone == NewLoc[x].UTMZone) && (NewLoc[x].EUTM > ScreenLeft) && (NewLoc[x].EUTM < ScreenRight) && (NewLoc[x].NUTM < ScreenTop) && (NewLoc[x].NUTM > ScreenBottom)) { DotX = (NewLoc[x].EUTM - ScreenLeft) * PixelsPerTile / MetersPerTile; DotY = (ScreenTop - NewLoc[x].NUTM) * PixelsPerTile / MetersPerTile; Ellipse(hdcMem3, DotX-DotRadius, DotY-DotRadius, DotX+DotRadius, DotY+DotRadius); if ((shownamecomment) && ((MapType == PHOTO) || (MapType == URBANAREA) || (Zoom < 5))) { char wp[50]; for (y = 0; y < NewLoc[x].size; y++) {// if (((sortbyname == TRUE) && (NewLoc[x].pWaypoints[y] == 'm') && (NewLoc[x].pWaypoints[y+2] == '>') && (NewLoc[x].pWaypoints[y-1] == 'a') && (NewLoc[x].pWaypoints[y+1] == 'e') && (NewLoc[x].pWaypoints[y-3] == '<')) || (((sortbyname == FALSE) && ((NewLoc[x].pWaypoints[y] == 'm') && (NewLoc[x].pWaypoints[y+2] == '>') && (NewLoc[x].pWaypoints[y+1] == 't') && (NewLoc[x].pWaypoints[y-2] == '<')) || ((NewLoc[x].pWaypoints[y] == 's') && (NewLoc[x].pWaypoints[y+2] == '>') && (NewLoc[x].pWaypoints[y-1] == 'e') && (NewLoc[x].pWaypoints[y+1] == 'c') && (NewLoc[x].pWaypoints[y-3] == '<'))))) { y += 3;//to name or comment for (z = 0; (z < 50) && (NewLoc[x].pWaypoints[y] != '<'); y++, z++) wp[z] = NewLoc[x].pWaypoints[y]; if (MapType != TOPO) { SetBkMode(hdcMem3, TRANSPARENT); SetTextColor(hdcMem3, WHITE); } TextOut(hdcMem3, DotX + 10, DotY - 10, wp, z); break; } } } } } SelectObject(hdcMem3, hOldBrush); DeleteObject(hWaypointBrush); if (distancemeasure) { hPen = CreatePen(PS_SOLID, 1, 0xFFFFFF); hObject = SelectObject(hdcMem3, hPen); MoveToEx(hdcMem3, xBeg, yBeg, NULL); LineTo(hdcMem3, xPos, yPos); SelectObject(hdcMem3, hObject); DeleteObject(hPen); fromuser3 = TRUE; ShowDistanceAngle(); fromuser3 = FALSE; } hRedBrush = CreateSolidBrush(RED); for (x = 0; x < plane; x++) { // show airplanes if (Plane[x].heading == 0) Plane[x].heading = 360; CircleY = (ScreenTop - AirportUTMNorthing) / MetersPerPixel; Plane[x].UTME6 = Plane[x].UTME5; Plane[x].UTMN6 = Plane[x].UTMN5; Plane[x].UTME5 = Plane[x].UTME4; Plane[x].UTMN5 = Plane[x].UTMN4; Plane[x].UTME4 = Plane[x].UTME3; Plane[x].UTMN4 = Plane[x].UTMN3; Plane[x].UTME3 = Plane[x].UTME2; Plane[x].UTMN3 = Plane[x].UTMN2; Plane[x].UTME2 = Plane[x].UTME1; Plane[x].UTMN2 = Plane[x].UTMN1; Plane[x].UTME1 = Plane[x].UTMEasting; Plane[x].UTMN1 = Plane[x].UTMNorthing; //////////////////////////////////////////////// if (Plane[x].Turn == 'R') { Plane[x].radianheading += Plane[x].RadiansPerSecond; if (Plane[x].radianheading <= Plane[x].newRadianheading) Plane[x].heading = (int)(Plane[x].radianheading * rad2deg); else { Plane[x].radianheading = Plane[x].newRadianheading; if (Plane[x].radianheading > PI2) Plane[x].radianheading -= PI2; Plane[x].heading = Plane[x].newHeading; Plane[x].Turn = 0; // done } if (Plane[x].heading > 360) Plane[x].heading -= 360; } else if (Plane[x].Turn == 'L') { Plane[x].radianheading -= Plane[x].RadiansPerSecond; if (Plane[x].radianheading >= Plane[x].newRadianheading) Plane[x].heading = (int)(Plane[x].radianheading * rad2deg); else { Plane[x].radianheading = Plane[x].newRadianheading; if (Plane[x].radianheading <= 0) Plane[x].radianheading += PI2; Plane[x].heading = Plane[x].newHeading; Plane[x].Turn = 0; // done } if (Plane[x].heading < 0) Plane[x].heading += 360; } //////////////////////////////////////////////// if ((Plane[x].IAS > Plane[x].newIAS) && (Plane[x].altitude == Plane[x].newAltitude)) { Plane[x].IAS -= 2; if (Plane[x].IAS < Plane[x].newIAS) Plane[x].IAS = Plane[x].newIAS; } else if ((Plane[x].IAS < Plane[x].newIAS) && (Plane[x].altitude == Plane[x].newAltitude)) { Plane[x].IAS += 2; if (Plane[x].IAS > Plane[x].newIAS) Plane[x].IAS = Plane[x].newIAS; } if (Plane[x].altitude > Plane[x].newAltitude) { Plane[x].altitude -= 34; if (Plane[x].altitude < Plane[x].newAltitude) Plane[x].altitude = Plane[x].newAltitude; } else if (Plane[x].altitude < Plane[x].newAltitude) { Plane[x].altitude += 34; if (Plane[x].altitude > Plane[x].newAltitude) Plane[x].altitude = Plane[x].newAltitude; } Plane[x].TAS = Plane[x].IAS + (Plane[x].IAS * Plane[x].altitude / 50000); Meters = Plane[x].TAS * MetersPerSec; xMeters = Meters * sin(Plane[x].radianheading); yMeters = Meters * cos(Plane[x].radianheading); __asm fld xMeters // round a double up or down __asm fistp y // to an integer Plane[x].UTMEasting += y; __asm fld yMeters // round a double up or down __asm fistp y // to an integer Plane[x].UTMNorthing += y; Plane[x].x = (Plane[x].UTMEasting - ScreenLeft) / (MetersPerPixel); Plane[x].y = (ScreenTop - Plane[x].UTMNorthing) / (MetersPerPixel); hOldBrush = SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, Plane[x].x - PlaneRadius,Plane[x].y - PlaneRadius, Plane[x].x + PlaneRadius, Plane[x].y + PlaneRadius); z = (Plane[x].UTME2 - ScreenLeft) / (MetersPerPixel); // z is x coordinate y = (ScreenTop - Plane[x].UTMN2) / (MetersPerPixel); SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, z - 3,y - 3, z + 3, y + 3); z = (Plane[x].UTME3 - ScreenLeft) / (MetersPerPixel); y = (ScreenTop - Plane[x].UTMN3) / (MetersPerPixel); SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, z - 3,y - 3, z + 3, y + 3); SelectObject(hdcMem3, hOldBrush); z = (Plane[x].UTME4 - ScreenLeft) / (MetersPerPixel); y = (ScreenTop - Plane[x].UTMN4) / (MetersPerPixel); SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, z - 3,y - 3, z + 3, y + 3); z = (Plane[x].UTME5 - ScreenLeft) / (MetersPerPixel); y = (ScreenTop - Plane[x].UTMN5) / (MetersPerPixel); SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, z - 3,y - 3, z + 3, y + 3); z = (Plane[x].UTME6 - ScreenLeft) / (MetersPerPixel); y = (ScreenTop - Plane[x].UTMN6) / (MetersPerPixel); SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, z - 3,y - 3, z + 3, y + 3); if ((planecommand) && (x == AtPlane)) { TextOut(hdcMem3, Plane[x].x-10, Plane[x].y-40, Command, lstrlen(Command)); TurnRadius = Plane[x].TAS * Plane[x].TAS * TwentyfiveDegreeBank; // in meters hBlankBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hObject = SelectObject(hdcMem3, hBlankBrush); for (cmd = 0; cmd < command; cmd++) { if (Command[cmd] == 'H') { TextOut(hdcMem3, Plane[x].x-100, Plane[x].y+10, " Use the commands L or R instead ", 33); break; } if ((Command[cmd] == 'R') || (Command[cmd] == 'L')) { // draw turn circles from TurnRadius and Plane[x].heading d1 = Plane[x].radianheading; d2 = TurnRadius/MetersPerPixel; CircleX = Plane[x].x + (int)((d2) * cos(d1)); CircleY = Plane[x].y + (int)((d2) * sin(d1)); CircleX2 = Plane[x].x - (int)((d2) * cos(d1)); CircleY2 = Plane[x].y - (int)((d2) * sin(d1)); } if (Command[cmd] == 'R') { hRedPen = CreatePen(PS_SOLID, 1, 0xF0); hOldPen = SelectObject(hdcMem3, hRedPen); SelectObject(hdcMem3, hBlankBrush); Ellipse(hdcMem3, CircleX - (DWORD)d2, CircleY - (DWORD)d2, CircleX + (DWORD)d2, CircleY + (DWORD)d2); SelectObject(hdcMem3, hOldPen); DeleteObject(hRedPen); break; } if (Command[cmd] == 'L') { hRedPen = CreatePen(PS_SOLID, 1, 0xF0); hOldPen = SelectObject(hdcMem3, hRedPen); SelectObject(hdcMem3, hBlankBrush); Ellipse(hdcMem3, CircleX2 - (DWORD)d2, CircleY2 - (DWORD)d2, CircleX2 + (DWORD)d2, CircleY2 + (DWORD)d2); SelectObject(hdcMem3, hOldPen); DeleteObject(hRedPen); break; } if ((Command[cmd] == 'A') && (Command[cmd+1] != 0)) { finalAlt = Atoi(&Command[cmd+1]); if (finalAlt < 1000) // 2 or 200 20 or 2000 200 or 20000 finalAlt *= 100; d1 = sin(Plane[x].radianheading); d2 = cos(Plane[x].radianheading); xUTM = Plane[x].UTMEasting; yUTM = Plane[x].UTMNorthing; for (existingAlt = Plane[x].altitude; existingAlt > finalAlt; existingAlt -= 34) { existingTAS = Plane[x].IAS + (Plane[x].IAS * existingAlt / 50000); Meters = (double)existingTAS * MetersPerSec; xMeters = Meters * d1; yMeters = Meters * d2; __asm fld xMeters // round a double up or down __asm fistp z // to an integer xUTM += z; __asm fld yMeters // round a double up or down __asm fistp z // to an integer yUTM += z; } SpotX = (xUTM - ScreenLeft) / MetersPerPixel; SpotY = (ScreenTop - yUTM) / MetersPerPixel; hRedPen = CreatePen(PS_SOLID, 1, 0xF0); hOldPen = SelectObject(hdcMem3, hRedPen); MoveToEx(hdcMem3, Plane[x].x, Plane[x].y, NULL); LineTo(hdcMem3, SpotX, SpotY); SelectObject(hdcMem3, hOldPen); DeleteObject(hRedPen); break; } if ((Command[cmd] == 'S') && (Command[cmd+1] != 0)) { finalIAS = Atoi(&Command[cmd+1]); existingIAS = Plane[x].IAS; d1 = sin(Plane[x].radianheading); d2 = cos(Plane[x].radianheading); xUTM = Plane[x].UTMEasting; yUTM = Plane[x].UTMNorthing; for ( ; existingIAS >= finalIAS; existingIAS -= 2) { existingTAS = existingIAS + (existingIAS * Plane[x].altitude / 50000); Meters = (double)existingTAS * MetersPerSec; xMeters = Meters * d1; yMeters = Meters * d2; __asm fld xMeters // round a double up or down __asm fistp z // to an integer xUTM += z; __asm fld yMeters // round a double up or down __asm fistp z // to an integer yUTM += z; } SpotX = (xUTM - ScreenLeft) / MetersPerPixel; SpotY = (ScreenTop - yUTM) / MetersPerPixel; hRedPen = CreatePen(PS_SOLID, 1, 0xF0); hOldPen = SelectObject(hdcMem3, hRedPen); MoveToEx(hdcMem3, Plane[x].x, Plane[x].y, NULL); LineTo(hdcMem3, SpotX, SpotY); SelectObject(hdcMem3, hOldPen); DeleteObject(hRedPen); break; } } SelectObject(hdcMem3, hObject); DeleteObject(hBlankBrush); } if (showdata) { if ((Plane[x].heading == Plane[x].newHeading) || (x == AtPlane)) { _itoa(Plane[x].heading, tempPlane, 10); SetTextColor(hdcMem3, 0xFFFFFF); } else { _itoa(Plane[x].newHeading, tempPlane, 10); SetTextColor(hdcMem3, 0x00FFFF); } for (y = 0; tempPlane[y] != 0; y++) ; tempPlane[y] = '°'; TextOut(hdcMem3, Plane[x].x-(Size.cx*4), Plane[x].y-8, tempPlane, y+1); if ((Plane[x].altitude == Plane[x].newAltitude) || (x == AtPlane)) { _itoa(Plane[x].altitude, tempPlane, 10); SetTextColor(hdcMem3, 0xFFFFFF); } else { _itoa(Plane[x].newAltitude, tempPlane, 10); SetTextColor(hdcMem3, 0x00FFFF); } for (y = 0; tempPlane[y] != 0; y++) ; tempPlane[y++] = '\''; TextOut(hdcMem3, Plane[x].x-(Size.cx*2), Plane[x].y-20, tempPlane, y); if ((Plane[x].IAS == Plane[x].newIAS) || (x == AtPlane)) { SetTextColor(hdcMem3, 0xFFFFFF); _itoa(Plane[x].IAS, tempPlane, 10); } else { SetTextColor(hdcMem3, 0x00FFFF); _itoa(Plane[x].newIAS, tempPlane, 10); } tempPlane[3] = ' '; tempPlane[4] = 'k'; tempPlane[5] = 't'; tempPlane[6] = 's'; TextOut(hdcMem3, Plane[x].x+10, Plane[x].y-8, tempPlane, 7); } } DeleteObject(hRedBrush); hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem3, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdc); break; case WM_SIZE: GetClientRect(hwnd, &rect); LineRight = (rect.right / 200) * 200;//right edge of photos (for Line To) return 0; case WM_CREATE: /*{ double Float[2]; Float[0] = 1.234567890; hFile = CreateFile("Float.dta", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, (double*)&Float[0], 8, &dwBytesWritten, NULL); CloseHandle(hFile); hFile = CreateFile("Float.dta", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); ReadFile(hFile, (double*)&Float[1], 8, &dwBytesRead, NULL); CloseHandle(hFile); b = ~(6+2+99) + 1;//214 tan(3.0 * deg2rad) = 1500' / d d = 1500 / tan(3.0 * deg2rad); // 28,621.7 ft d1 = d * 0.3048; // 8,723.8956936293380 meters d2 = d1 / 1852.0; // 4.71 nautical miles }*/ GlideSlope = tan(3.0 * deg2rad); // altitude / distance out PI2 = PI * 2.0; PIdiv2 = PI / 2.0; // dThirtyMiles = 5280.0 * 30.0 * 0.3048; // 482,80.32 meters dThirtyMiles = 1852.0 * 30.0; // 30 nautical miles in meters (55,560) MetersPerSec = 1852.0 / 3600.0; // 1 knot = 0.51444444 meters/sec TwentyfiveDegreeBank = (MetersPerSec * MetersPerSec) / (GRAVITY * tan(BankAngle * PI / 180.0)); if ((CmdLine[0] != 0) && (CmdLine[0] != '-') && (INVALID_HANDLE_VALUE != FindFirstFile(CmdLine, &fd))) {//if called from GSAK if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, SubKey, &hRegKey2)) { if (ERROR_SUCCESS == RegQueryValueEx(hRegKey2, "Install_Dir", NULL, &RegType, RegValue2, &RegValue2Size)) { gsak = TRUE; SetCurrentDirectory((char*)RegValue2); for (x = 0, y = 0;RegValue2[y] != 0; x++, y++) RunPgmGpx[x] = RegValue2[y]; for (y = 0; runpgm[y] != 0; x++, y++) RunPgmGpx[x] = runpgm[y]; RunPgmGpx[x++] = 0; if (0 == CopyFile(CmdLine, RunPgmGpx, FALSE)) { gsak = FALSE; MessageBox(hwnd, "Couldn't copy waypoint file from GSAK.", ERROR, MB_OK); } } RegCloseKey(hRegKey2); } } else { hMutex = CreateMutex(NULL, 0, "USAPhotoMaps"); if (ERROR_ALREADY_EXISTS == GetLastError()) {//don't open more than one instance SendMessage(hwnd, WM_DESTROY, 0, 0); return 0; } else CloseHandle(hMutex);//new May 3, 2007 } hCursor = LoadCursor(NULL, IDC_ARROW); hWaitingCursor = LoadCursor(NULL, IDC_WAIT); hDrawingCursor = LoadCursor(NULL, IDC_HAND); NumOfDems = 0; fileName0 = fileName[0]; fileName1 = fileName[1]; fileName2 = fileName[2]; pointerFileName[0] = fileName0; pointerFileName[1] = fileName1; pointerFileName[2] = fileName2; for (x = 0; x < MAXPTIGERS; x++) { pTiger[x] = NULL; pTigerNames[x] = NULL; } for (x = 0; x < 256; x++) { ShowList5[x] = 0; ShowList6[x] = 0; } photo_pixel_buf = NULL; Pixels = NULL; pUSA = NULL; pts = pname = 0; trak = NULL; WaypointsPath[0] = 0; pRoute = pr = NULL; pRoutes = prs = NULL; pTrackBuf = NULL; hFile = CreateFile(USAPMini, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) {//get USAPM.ini data if (fileSize = GetFileSize(hFile, NULL)) { pUSAPMbufIn = (char*)malloc(fileSize); ReadFile(hFile, pUSAPMbufIn, fileSize, &dwBytesRead, NULL); for (x = 0; x < (int)fileSize; x++) { if (pUSAPMbufIn[x] == '=') { if ((pUSAPMbufIn[x-1] == 'g') && (pUSAPMbufIn[x-7] == 'C')) openatclosing = (pUSAPMbufIn[x+1] == 'Y')? TRUE : FALSE; else if ((pUSAPMbufIn[x-7] == 'C') && (pUSAPMbufIn[x-11] == 'N') && (pUSAPMbufIn[x-15] == 'S')) shownamecomment = (pUSAPMbufIn[x+1] == 'Y')? TRUE : FALSE; else if ((pUSAPMbufIn[x-11] == 'D') && (pUSAPMbufIn[x-15] == 'S')) showdescription = (pUSAPMbufIn[x+1] == 'Y')? TRUE : FALSE; else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-16] == 'P')) {//1MeterPhotoWaypointDot=4; switch (pUSAPMbufIn[x-22]) { case '1': PhotoDot1[0] = pUSAPMbufIn[x+1]; break; case '2': if (pUSAPMbufIn[x-23] != '3') PhotoDot2[0] = pUSAPMbufIn[x+1]; else PhotoDot32[0] = pUSAPMbufIn[x+1]; break; case '4': if (pUSAPMbufIn[x-23] != '6') PhotoDot4[0] = pUSAPMbufIn[x+1]; else PhotoDot64[0] = pUSAPMbufIn[x+1]; break; case '6': if (pUSAPMbufIn[x-23] != '1') PhotoDot1[0] = pUSAPMbufIn[x+1]; else PhotoDot16[0] = pUSAPMbufIn[x+1]; break; case '8': PhotoDot8[0] = pUSAPMbufIn[x+1]; break; } } else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-15] == 'T')) {//4MeterTopoWaypointDot=4; switch (pUSAPMbufIn[x-21]) { case '2': if (pUSAPMbufIn[x-22] == '3') TopoDot32[0] = pUSAPMbufIn[x+1]; else if (pUSAPMbufIn[x-22] == '1') TopoDot512[0] = pUSAPMbufIn[x+1]; break; case '4': if (pUSAPMbufIn[x-22] != '6') TopoDot4[0] = pUSAPMbufIn[x+1]; else TopoDot64[0] = pUSAPMbufIn[x+1]; break; case '6': if (pUSAPMbufIn[x-22] == '1') TopoDot16[0] = pUSAPMbufIn[x+1]; else if (pUSAPMbufIn[x-22] == '5') TopoDot256[0] = pUSAPMbufIn[x+1]; break; case '8': if (pUSAPMbufIn[x-22] != '2') TopoDot8[0] = pUSAPMbufIn[x+1]; else TopoDot128[0] = pUSAPMbufIn[x+1]; break; } } else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-16] == 'U')) {//14MeterUrbanWaypointDot=6 switch (pUSAPMbufIn[x-22]) { case '4': if (pUSAPMbufIn[x-23] == '1') UrbanDot14[0] = pUSAPMbufIn[x+1]; break; case '2': if (pUSAPMbufIn[x-23] == '1') UrbanDot12[0] = pUSAPMbufIn[x+1]; break; } } else if ((pUSAPMbufIn[x] == '=') && (pUSAPMbufIn[x-5] == 'W'))//Width= {//2MeterLineWidth=4; or 32MeterLineWidth=4; if ((pUSAPMbufIn[x-15] == '1') && (pUSAPMbufIn[x-9] == 'L')) LineWidth1[0] = pUSAPMbufIn[x+1]; else if ((pUSAPMbufIn[x-15] == '2') && (pUSAPMbufIn[x-9] == 'L')) { if (pUSAPMbufIn[x-16] != '3') LineWidth2[0] = pUSAPMbufIn[x+1]; else LineWidth32[0] = pUSAPMbufIn[x+1]; } else if ((pUSAPMbufIn[x-15] == '4') && (pUSAPMbufIn[x-9] == 'L')) { if (pUSAPMbufIn[x-16] == '6') LineWidth64[0] = pUSAPMbufIn[x+1]; else LineWidth4[0] = pUSAPMbufIn[x+1]; } else if ((pUSAPMbufIn[x-15] == '8') && (pUSAPMbufIn[x-9] == 'L')) LineWidth8[0] = pUSAPMbufIn[x+1]; else if ((pUSAPMbufIn[x-15] == '6') && (pUSAPMbufIn[x-9] == 'L')) LineWidth16[0] = pUSAPMbufIn[x+1]; } else if ((pUSAPMbufIn[x] == '=') && (pUSAPMbufIn[x-4] == 'L')) {//4MeterTopoLine= if (pUSAPMbufIn[x-8] == 'T') { if (pUSAPMbufIn[x-14] == '4') { if (pUSAPMbufIn[x-15] != '6') TopoLine4[0] = pUSAPMbufIn[x+1]; else if (pUSAPMbufIn[x-15] == '6') TopoLine64[0] = pUSAPMbufIn[x+1]; } else if (pUSAPMbufIn[x-14] == '8') { if (pUSAPMbufIn[x-15] != '2') TopoLine8[0] = pUSAPMbufIn[x+1]; else if (pUSAPMbufIn[x-15] == '2') TopoLine128[0] = pUSAPMbufIn[x+1]; } else if (pUSAPMbufIn[x-14] == '6') { if (pUSAPMbufIn[x-15] != '5') TopoLine16[0] = pUSAPMbufIn[x+1]; else if (pUSAPMbufIn[x-15] == '5') TopoLine256[0] = pUSAPMbufIn[x+1]; } else if (pUSAPMbufIn[x-14] == '2') TopoLine32[0] = pUSAPMbufIn[x+1]; } } else if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x-7] == '8')) zoom1to8 = TRUE;//ZoomTo8Meters=Y else if ((pUSAPMbufIn[x+1] == 'N') && (pUSAPMbufIn[x-7] == '8')) zoom1to8 = FALSE;//ZoomTo8Meters=N else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-7] == 'n')) WaypointColor = AsciiToHex(x);//WaypointColor= else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-6] == 'e')) RouteColor = AsciiToHex(x);//RouteColor= else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-6] == 'k')) TrackColor = AsciiToHex(x);//TrackColor= else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-6] == 'n')) PositionColor = AsciiToHex(x);//PositionColor= else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-7] == 'x')) TextColor = AsciiToHex(x);//TextColor=0x80FF00 else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-7] == 'R')) APRSColor = AsciiToHex(x);//APRSColor=0x0000FF else if ((pUSAPMbufIn[x+1] == '0') && (pUSAPMbufIn[x-7] == 'e') && (pUSAPMbufIn[x-6] == 'r')) TigerColor = AsciiToHex(x);//TigerColor=0x0000FF else if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x-1] == 'n')) showlatlon = TRUE;//ShowLatlon=YES else if ((pUSAPMbufIn[x+1] =='N') && (pUSAPMbufIn[x-1] == 'n')) showlatlon = FALSE;//ShowLatlon=NO else if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x-5] == 'y')) sortbyname = TRUE;//SortbyName=YES else if ((pUSAPMbufIn[x+1] =='N') && (pUSAPMbufIn[x-5] == 'y')) sortbyname = FALSE;//SortbyName=NO else if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x-5] == 'w')) showname = TRUE;//ShowName=YES else if ((pUSAPMbufIn[x+1] =='N') && (pUSAPMbufIn[x-5] == 'w')) showname = FALSE;//ShowName=NO else if ((pUSAPMbufIn[x-1] == 'M') && (pUSAPMbufIn[x+1] == 'D')) MouseLoc = DEG; else if ((pUSAPMbufIn[x-1] == 'M') && (pUSAPMbufIn[x+1] == 'M')) MouseLoc = DEGMIN; else if ((pUSAPMbufIn[x-1] == 'M') && (pUSAPMbufIn[x+1] == 'S')) MouseLoc = DEGMINSEC; else if ((pUSAPMbufIn[x-1] == 'M') && (pUSAPMbufIn[x+2] == 'T')) MouseLoc = ITSUTM; else if ((pUSAPMbufIn[x-1] == 'M') && (pUSAPMbufIn[x+2] == 'S')) MouseLoc = ITSUSNG; else if ((pUSAPMbufIn[x-9] == 'I') && ((pUSAPMbufIn[x+1] != '0') || (pUSAPMbufIn[x+2] != '0'))) {//FadeIncrement=00 FadeIncrement = atoi(&pUSAPMbufIn[x+1]);// - '0') * 10) + (pUSAPMbufIn[x+2] - '0') % 10)) } else if ((pUSAPMbufIn[x-1] == 'l') && (pUSAPMbufIn[x-9] == 'Z')) {//ZoomLevel= if (pUSAPMbufIn[x+1] == '1') { Zoom = 1; PixelsPerTile = 200;//200 meters per 200 pixels } else if (pUSAPMbufIn[x+1] == '2') { Zoom = 2; PixelsPerTile = 100;//200 meters per 100 pixels } else if (pUSAPMbufIn[x+1] == '3') { Zoom = 3; PixelsPerTile = 50;//200 meters per 50 pixels } else if (pUSAPMbufIn[x+1] == '4') {//8 meters/pixel zoom1to8 == TRUE Zoom = 4; PixelsPerTile = 25;//200 meters per 25 pixels } else if (pUSAPMbufIn[x+1] == '5') {//8 meters/pixel zoom1to8 == FALSE Zoom = 5; PixelsPerTile = 200; MetersPerTile = 1600; } else if (pUSAPMbufIn[x+1] == '6') { Zoom = 6; PixelsPerTile = 100; MetersPerTile = 1600; } else if (pUSAPMbufIn[x+1] == '7') { Zoom = 7; PixelsPerTile = 50; MetersPerTile = 1600; } else if (pUSAPMbufIn[x+1] == '8') { Zoom = 8; PixelsPerTile = 25; MetersPerTile = 1600; } } else if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x-4] == 'T')) {//Topo=YES MapType = TOPO; if (Zoom == 1) { PixelsPerTile = 200; MetersPerTile = 800; } else if (Zoom == 2) { PixelsPerTile = 100; MetersPerTile = 800; } else if (Zoom == 3) { PixelsPerTile = 50; MetersPerTile = 800; } else if (Zoom == 4) { PixelsPerTile = 25; MetersPerTile = 800; } if (Zoom == 5) { PixelsPerTile = 200; MetersPerTile = 12800; } else if (Zoom == 6) { PixelsPerTile = 100; MetersPerTile = 12800; } else if (Zoom == 7) { PixelsPerTile = 50; MetersPerTile = 12800; } else if (Zoom == 8) { PixelsPerTile = 25; MetersPerTile = 12800; } ShowTopo(); } else if ((pUSAPMbufIn[x+1] == 'Q') && (pUSAPMbufIn[x-4] == 'T')) {//QQ MapType = URBANAREA; if (Zoom == 1) { PixelsPerTile = 200; MetersPerTile = 50; } else if (Zoom == 2) { PixelsPerTile = 100; MetersPerTile = 50; } else if (Zoom == 3) { PixelsPerTile = 50; MetersPerTile = 50; } else if (Zoom == 4) { PixelsPerTile = 25; MetersPerTile = 50; } else if (Zoom == 5) { PixelsPerTile = 200; MetersPerTile = 800; } else if (Zoom == 6) { PixelsPerTile = 100; MetersPerTile = 800; } else if (Zoom == 7) { PixelsPerTile = 50; MetersPerTile = 800; } else if (Zoom == 8) { PixelsPerTile = 25; MetersPerTile = 800; } ShowUrbanArea(); } else if ((pUSAPMbufIn[x-4] == 'P') && (pUSAPMbufIn[x-13] == 'W')) {//WaypointsPath= for (y = 0, z = x+1; (pUSAPMbufIn[z] != '\r') && (z < fileSize); y++, z++) WaypointsPath[y] = pUSAPMbufIn[z]; WaypointsPath[y] = 0; } else if ((pUSAPMbufIn[x-4] == 'N') && (pUSAPMbufIn[x-8] == 'U')) {//UserName= for (y = 0, z = x+1; (pUSAPMbufIn[z] != '\r') && (z < fileSize); y++, z++) ProxyUserName[y] = pUSAPMbufIn[z]; ProxyUserName[y] = 0; ProxyUserLen = z; proxy++; } else if ((pUSAPMbufIn[x-8] == 'P') && (pUSAPMbufIn[x-7] == 'a') && (pUSAPMbufIn[x-6] == 's') && (pUSAPMbufIn[x-5] == 's')) {//Password= for (y = 0, z = x+1; (pUSAPMbufIn[z] != '\r') && (z < fileSize); y++, z++) ProxyPassword[y] = pUSAPMbufIn[z]; ProxyPassword[y] = 0; ProxyPassLen = z; proxy++; } else if ((pUSAPMbufIn[x-2] == 'v') && (pUSAPMbufIn[x-3] == 'i'))//Drive= { Streets[0] = pUSAPMbufIn[x+1]; Streets2[0] = pUSAPMbufIn[x+1]; Streets3[0] = pUSAPMbufIn[x+1]; Streets4[0] = pUSAPMbufIn[x+1]; } if ((pUSAPMbufIn[x-1] == 'T') && (pUSAPMbufIn[x-2] == '&') && (pUSAPMbufIn[x-3] == 'S'))//S&T= { for (y = 0, z = x+1; (pUSAPMbufIn[z] != '\r') && z < (fileSize); y++, z++) { Streets[y] = pUSAPMbufIn[z]; Streets2[y] = pUSAPMbufIn[z]; } Streets[y] = 0; for (y-- ; Streets2[y] != '\\'; y--) ; y++; Streets2[y] = 0; } else if ((pUSAPMbufIn[x-1] == 'e') && (pUSAPMbufIn[x-5] == '2')) { Spaces2Move = pUSAPMbufIn[x+1] - '0'; } else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-11] == 'P') && (pUSAPMbufIn[x-14] == 'O') && (pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x+2] == 'E')) {//OnePositionDot onepositiondot = TRUE; } else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-4] == 'T') && (pUSAPMbufIn[x-8] == 'S')) showtext = (pUSAPMbufIn[x+1] == 'Y') ? TRUE : FALSE; else if ((pUSAPMbufIn[x-1] == 't') && (pUSAPMbufIn[x-4] == 'P') && (pUSAPMbufIn[x-8] == 'C') && (pUSAPMbufIn[x-12] == 'A')) {//APRSCommPort=1 APRSCommPort[0] = pUSAPMbufIn[x+1]; if (pUSAPMbufIn[x+2] != '\r') APRSCommPort[1] = pUSAPMbufIn[x+2]; } else if ((pUSAPMbufIn[x-1] == 'd') && (pUSAPMbufIn[x-8] == 'A') && (pUSAPMbufIn[x-4] == 'B')) {//APRSBaud=4800 APRSBaud = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-6] == 'M') && (pUSAPMbufIn[x-5] == 'y') && (pUSAPMbufIn[x-4] == 'C') && (pUSAPMbufIn[x-3] == 'a')) {//MyCall= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) MyCall[z] = pUSAPMbufIn[y]; MyCall[z] = 0; } else if ((pUSAPMbufIn[x-10] == 'H') && (pUSAPMbufIn[x-9] == 'o') && (pUSAPMbufIn[x-6] == 'L') && (pUSAPMbufIn[x-5] == 'a')) {//HomeLatLon= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) HomeLatLon[z] = pUSAPMbufIn[y]; HomeLatLon[z] = 0; } else if ((pUSAPMbufIn[x-10] == 'T') && (pUSAPMbufIn[x-9] == 'r') && (pUSAPMbufIn[x-4] == 'i') && (pUSAPMbufIn[x-3] == 't')) {//TransmitTo= if (pUSAPMbufIn[x+1] == 'H') transmitto = TRANSMITHOME; else if (pUSAPMbufIn[x+1] == 'G') transmitto = TRANSMITGPS; else if (pUSAPMbufIn[x+1] == 'N') transmitto = TRANSMITNONE; } else if ((pUSAPMbufIn[x-10] == 'H') && (pUSAPMbufIn[x-6] == 'S') && (pUSAPMbufIn[x-5] == 'y') && (pUSAPMbufIn[x-4] == 'm')) {//HomeSymbol= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) HomeSymbol[z] = pUSAPMbufIn[y]; HomeSymbol[z] = 0; if (HomeSymbol[0] == '/') { for (y = 0; y < 94; y++) { for (w = 0, z = 1; HomeSymbol[z] != 0; w++, z++) if (HomeSymbol[z] != APRSSymbols[y].Primary[w]) break; if (HomeSymbol[z] == 0) {//found it homesymbolindex = y; break; } } } else { for (y = 0; y < 94; y++) { for (w = 0, z = 1; HomeSymbol[z] != 0; w++, z++) if (HomeSymbol[z] != APRSSymbols[y].Secondary[w]) break; if (HomeSymbol[z] == 0) {//found it homesymbolindex = y; break; } } } } else if ((pUSAPMbufIn[x-9] == 'G') && (pUSAPMbufIn[x-8] == 'P') && (pUSAPMbufIn[x-7] == 'S') && (pUSAPMbufIn[x-6] == 'S')) {//GPSSymbol= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) GPSSymbol[z] = pUSAPMbufIn[y]; GPSSymbol[z] = 0; for (y = 0; y < 94; y++) { if (GPSSymbol[0] == '/') { for (w = 0, z = 1; GPSSymbol[z] != 0; w++, z++) if (GPSSymbol[z] != APRSSymbols[y].Primary[w]) break; } else { for (w = 0, z = 1; GPSSymbol[z] != 0; w++, z++) if (GPSSymbol[z] != APRSSymbols[y].Secondary[w]) break; } if (GPSSymbol[z] == 0) { gpssymbolindex = y; break; } } } else if ((pUSAPMbufIn[x-11] == 'D') && (pUSAPMbufIn[x-10] == 'e') && (pUSAPMbufIn[x-5] == 'a') && (pUSAPMbufIn[x-4] == 't')) {//Destination= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) Destination[z] = pUSAPMbufIn[y]; Destination[z] = 0; } else if ((pUSAPMbufIn[x-8] == '\n') && (pUSAPMbufIn[x-7] == 'C') && (pUSAPMbufIn[x-6] == 'o') && (pUSAPMbufIn[x-2] == 'n') && (pUSAPMbufIn[x-1] == 't')) {//Comment= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) Comment[z] = pUSAPMbufIn[y]; Comment[z] = 0; } else if ((pUSAPMbufIn[x-6] == 'B') && (pUSAPMbufIn[x-5] == 'E') && (pUSAPMbufIn[x-4] == 'A')) {//BEACON= for (y = x+1, z = 0; (y < (int)fileSize) && (pUSAPMbufIn[y] != '\r'); y++, z++) Beacon[z] = pUSAPMbufIn[y]; Beacon[z] = 0; } // else if ((pUSAPMbufIn[x-1] == 'S') && (pUSAPMbufIn[x-4] == 'K') && (pUSAPMbufIn[x-3] == 'I') && (pUSAPMbufIn[x-2] == 'S')) // {//KISS=YES // if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x+2] == 'E')) // kiss = TRUE; // } else if ((pUSAPMbufIn[x-11] == 'S') && (pUSAPMbufIn[x-10] == 'B') && (pUSAPMbufIn[x-9] == 'S') && (pUSAPMbufIn[x-5] == 'S')) {//SBSlowSpeed= sbSlowSpeed = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-12] == 'S') && (pUSAPMbufIn[x-11] == 'B') && (pUSAPMbufIn[x-10] == 'S') && (pUSAPMbufIn[x-6] == 'B')) {//SBSlowBeacon= sbSlowBeacon = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-11] == 'S') && (pUSAPMbufIn[x-10] == 'B') && (pUSAPMbufIn[x-9] == 'H') && (pUSAPMbufIn[x-5] == 'S')) {//SBHighSpeed= sbHighSpeed = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-12] == 'S') && (pUSAPMbufIn[x-11] == 'B') && (pUSAPMbufIn[x-10] == 'H') && (pUSAPMbufIn[x-6] == 'B')) {//SBHighBeacon= sbHighBeacon = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-10] == 'S') && (pUSAPMbufIn[x-9] == 'B') && (pUSAPMbufIn[x-8] == 'T') && (pUSAPMbufIn[x-4] == 'T')) {//SBTurnTime= sbTurnTime = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-7] == 'S') && (pUSAPMbufIn[x-6] == 'B') && (pUSAPMbufIn[x-5] == 'A')) {//SBAngle= sbAngle = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-10] == 'S') && (pUSAPMbufIn[x-9] == 'B') && (pUSAPMbufIn[x-8] == 'C')) {//SBConstant= sbConstant = atoi(&pUSAPMbufIn[x+1]); } else if ((pUSAPMbufIn[x-9] == 'B') && (pUSAPMbufIn[x-14] == 'S')) {//SmartBeaconing= if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x+2] == 'E')) smartbeaconing = TRUE; } else if ((pUSAPMbufIn[x-10] == 'C') && (pUSAPMbufIn[x-9] == 'o') && (pUSAPMbufIn[x-8] == 'm') && (pUSAPMbufIn[x-7] == 'p')) {//Compressit= if ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x+2] == 'E')) compressit = TRUE; } }//endof if (pUSAPMbufIn[x] == '=') } free(pUSAPMbufIn); pUSAPMbufIn = NULL; FillZoomTable(); } CloseHandle(hFile); } // else // {//create USAPM.ini // } hFile = CreateFile(USAPhotoMapsKey, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { ReadFile(hFile, Key, 6, &dwBytesRead, NULL); CloseHandle (hFile); } prefInMouseLoc = MouseLoc; prefInZoom = Zoom; prefInLatlon = showlatlon; GetCurrentDirectory(255, CurrentDir); strcpy(CurrentTrackDir, CurrentDir); strcat(CurrentTrackDir, "\\"); if ((INVALID_HANDLE_VALUE != FindFirstFile("Tracks", &fd)) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) strcat(CurrentTrackDir, "Tracks\\"); xBeg = -1; TimerFlags.timing = FALSE; TimerFlags.garmintiming = FALSE; TimerFlags.nmeatiming = FALSE; TimerFlags.gotprotocol = TRUE; TimerFlags.hwnd = hwnd; InitializeCriticalSection(&cs); hEventExit = CreateEvent(NULL, TRUE, FALSE, NULL); hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);//manual-reset, initialized non-signaled hTimerEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hUSBEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hTigerEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hTigerReturn = CreateEvent(NULL, TRUE, FALSE, NULL); hCacheEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hCacheOk = CreateEvent(NULL, TRUE, FALSE, NULL); hAPRSEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hAPRSISEvent = CreateEvent(NULL, TRUE, FALSE, NULL); hThread = 0; hAPRSThread = 0; if (MouseLoc == DEG) Units = ID_VIEW_LATITUDELONGITUDE_DEGREES; else if (MouseLoc == DEGMIN) Units = ID_VIEW_LATITUDELONGITUDE_DEGREESMINUTES; else if (MouseLoc == DEGMINSEC) Units = ID_VIEW_LATITUDELONGITUDE_DEGREESMINUTESSECONDS; else if (MouseLoc == ITSUTM) Units = ID_VIEW_LATLON_UTM; else if (MouseLoc == ITSUSNG) Units = ID_VIEW_LATLON_USNG; hMenu = GetMenu(hwnd); if (shownamecomment) CheckMenuItem(hMenu, ID_VIEW_SHOWWAYPOINTNAMES, MF_CHECKED); ModifyZoom(); CheckMenuItem(hMenu, MapUnits, MF_CHECKED); // if (kiss) // CheckMenuItem(hMenu, ID_APRS_TRANSLATEKISSDATA, MF_CHECKED); ShowZoom(); DrawMenuBar(hwnd); if ((hFile = FindFirstFile(USAPhotoMapsData, &fd)) == INVALID_HANDLE_VALUE) CreateDirectory(USAPhotoMapsData, NULL); if ((hFile = FindFirstFile(BIGPhotoMapsData, &fd)) == INVALID_HANDLE_VALUE) CreateDirectory(BIGPhotoMapsData, NULL); FindClose(hFile); if (ERROR_SUCCESS == RegOpenKey(HKEY_CURRENT_USER, SubKey, &hRegKey)) RegQueryValueEx(hRegKey, "", NULL, &RegType, RegValue, &RegValueSize); RegCloseKey(hRegKey); if (RegValueSize != 21) {//if it was changed by a previous bug in USAPhotoMaps RegValueSize = 21; for (x = 0; x < 21; x++) RegValue[x] = OrigRegValue[x]; } switch (RegValue[14]) { case '8': if (RegValue[13] == '4') { BaudUnits = ID_GPS_BAUD_4800; Baud = 4800; } else if (RegValue[13] == '3') { BaudUnits = ID_GPS_BAUD_38400; Baud = 38400; } break; case '9': BaudUnits = ID_GPS_BAUD_19200; Baud = 19200; break; case '7': BaudUnits = ID_GPS_BAUD_57600; Baud = 57600; break; case '1': BaudUnits = ID_GPS_BAUD_115200; Baud = 115200; break; default: BaudUnits = ID_GPS_BAUD_9600; Baud = 9600; break; } MenuChecks(); switch (APRSBaud) { case 4800: CheckMenuItem(hMenu, ID_APRS_BAUD_4800, MF_CHECKED); break; case 9600: CheckMenuItem(hMenu, ID_APRS_BAUD_9600, MF_CHECKED); break; case 19200: CheckMenuItem(hMenu, ID_APRS_BAUD_19200, MF_CHECKED); break; case 38400: CheckMenuItem(hMenu, ID_APRS_BAUD_38400, MF_CHECKED); break; case 57600: CheckMenuItem(hMenu, ID_APRS_BAUD_57600, MF_CHECKED); break; case 115200: CheckMenuItem(hMenu, ID_APRS_BAUD_115200, MF_CHECKED); break; } hComm = INVALID_HANDLE_VALUE; hAPRSComm = INVALID_HANDLE_VALUE; Noffset = 6; Eoffset = 10; IdentOffset = 0; LocOffset = 18; SymOffset = 0; WaypointProt = 103;//flag iBuf = 0; Buf[iBuf] = 0; if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0)) { cxScreen = rect.right; cyScreen = rect.bottom; } else { cxScreen = GetSystemMetrics(SM_CXFULLSCREEN); cyScreen = GetSystemMetrics(SM_CYFULLSCREEN); } Frame = GetSystemMetrics(SM_CXSIZEFRAME); TitleAndMenu = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYMENU); cxChar = LOWORD(GetDialogBaseUnits()); cyChar = HIWORD(GetDialogBaseUnits()); TilesAcross = ((cxScreen-(Frame*2)) / PixelsPerTile) + 1; TilesDown = ((cyScreen-((Frame*2)+TitleAndMenu)) / PixelsPerTile) + 1; InitializeOpenFileNameLogFont(hwnd); //create hdcGrayMem to draw blank tiles gray lSquare = ((cxScreen / 2) / 200) * 200; rSquare = lSquare + 200; tSquare = ((cyScreen / 2) / 200) * 200; bSquare = tSquare + 200; hdc = GetDC (hwnd); hdcGrayMem = CreateCompatibleDC (hdc);//not deleted until WM_CLOSE or zooming hGrayBitmap = CreateCompatibleBitmap (hdc, 200, 200);//ditto ReleaseDC(hwnd, hdc); SelectObject(hdcGrayMem, hGrayBitmap); bmih.biSize = sizeof(BITMAPINFOHEADER); bmih.biWidth = 200; bmih.biHeight = -200;// - for right-side-up picture bmih.biPlanes = 1; bmih.biBitCount = 24; bmih.biCompression = BI_RGB; bmih.biSizeImage = ImageSize; bmi.bmiHeader = *pbmih; GrayArray = (unsigned char*) malloc(120000); for (x = 0; x < 120000; x++) GrayArray[x] = 0xC0;//gray for (x = 0; x < 600; x++) GrayArray[x] = 0;//black for (x = 0; x < 120000; x += 600) { GrayArray[x] = 0; GrayArray[x+1] = 0; GrayArray[x+2] = 0; } SetDIBits(hdcGrayMem, hGrayBitmap, 0, 200, GrayArray, pbmi, DIB_RGB_COLORS); free(GrayArray); //create hdcBlackMem to draw blank tiles black lSquare = ((cxScreen / 2) / 200) * 200; rSquare = lSquare + 200; tSquare = ((cyScreen / 2) / 200) * 200; bSquare = tSquare + 200; hdc = GetDC (hwnd); hdcBlackMem = CreateCompatibleDC (hdc);//not deleted until WM_CLOSE or zooming hRedBitmap = CreateCompatibleBitmap (hdc, 200, 200);//ditto ReleaseDC(hwnd, hdc); SelectObject(hdcBlackMem, hRedBitmap); bmih.biSize = sizeof(BITMAPINFOHEADER); bmih.biWidth = 200; bmih.biHeight = -200;// - for right-side-up picture bmih.biPlanes = 1; bmih.biBitCount = 24; bmih.biCompression = BI_RGB; bmih.biSizeImage = ImageSize; bmi.bmiHeader = *pbmih; GrayArray = (unsigned char*) malloc(120000); for (x = 0; x < 120000; x++) GrayArray[x] = 0;//black for (x = 0; x < 600; x++) GrayArray[x] = 0;//black for (x = 0; x < 120000; x += 600) { GrayArray[x] = 0; GrayArray[x+1] = 0; GrayArray[x+2] = 0; } SetDIBits(hdcBlackMem, hRedBitmap, 0, 200, GrayArray, pbmi, DIB_RGB_COLORS); free(GrayArray); //get USAPhotoMapsIni data hFile = CreateFile(USAPhotoMapsIni, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); if (fileSize > 22) { pIniBuf = (unsigned char*) malloc(fileSize);//fileSize+2 ReadFile(hFile, pIniBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); if (FALSE == GetXYZfromIniBuf())//get Area, X, Y, Z, BeginX, BeginY, UTMZone (UTMNorthing/UTMEasting come from WM_MOUSEMOVE { free(pIniBuf); DestroyWindow(hwnd); return 0; } free(pIniBuf); pTigerIndex = NULL; GetTigerIndex(); } else { CloseHandle (hFile); MessageBox(hwnd, "USAPhotoMaps.ini is empty.\nDeleting it...", ERROR, MB_OK); DeleteFile(USAPhotoMapsIni); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } } else { brandnew = TRUE;//for WM_PAINT fileSize = sizeof(FirstIni)-1; pIniBuf = FirstIni; if (FALSE == GetXYZfromIniBuf()) { DestroyWindow(hwnd); return 0; } hFile = CreateFile(USAPhotoMapsIni, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, FirstIni, fileSize, &dwBytesWritten, NULL); CloseHandle(hFile); hFile = CreateFile(WashingtonXML, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, Top, sizeof(Top)-1, &dwBytesWritten, NULL); WriteFile(hFile, WashingtonWaypoint, sizeof(WashingtonWaypoint)-1, &dwBytesWritten, NULL); CloseHandle(hFile); } Waypoints[0] = 0; ////////////////////////////////////////////////////////// GetDems(); ////////////////////////////////////////////////////////// if (gsak) { static char BadFile[] = "is not a good file."; hFile3 = CreateFile(RunPgmGpx, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { fromOpen = TRUE; for (y = 0; RunPgmGpx[y] != 0; y++) WaypointsFullPath[y] = RunPgmGpx[y]; WaypointsFullPath[y] = 0; for (x = 0, y = 1; runpgm[y] != 0; x++, y++) Waypoints[x] = runpgm[y]; Waypoints[x] = 0; } else MessageBox(hwnd, BadFile, RunPgmGpx, MB_OK); CloseHandle(hFile3); } else MessageBox(hwnd, BadFile, RunPgmGpx, MB_OK); } case WM_USER4://falling thru or called by Open File or New Map or Open Waypoint for (x = 0; Area[x] != 0; x++) { TextDta[x] = Area[x]; NewLocations[x] = Area[x]; } for (y = 0; y < 5; x++, y++) { TextDta[x] = Not[y]; NewLocations[x] = Xml[y]; } if (Waypoints[0] != 0)//if from ID_WAYPOINTS_OPENFILE or waypoint is in a different UTM zone { strcpy(NewLocations, Waypoints); strcpy(NewLocationsFullPath, WaypointsFullPath); } else if (WaypointsPath[0] != 0) { for (x = 0; WaypointsPath[x] != 0; x++) NewLocationsFullPath[x] = WaypointsPath[x]; for (y = 0; NewLocations[y] != 0; x++, y++) NewLocationsFullPath[x] = NewLocations[y]; NewLocationsFullPath[x] = 0; } else NewLocationsFullPath[0] = 0; for (x = 0; (x < 20) && (Area[x] != 0); x++) { UTM[x] = Area[x]; LatLon[x] = Area[x]; USNG[x] = Area[x]; } for ( ; x < 20; x++) { UTM[x] = ' '; LatLon[x] = ' '; USNG[x] = ' '; } WaypointArray = NULL; tempWayArray = NULL; if (NewLocationsFullPath[0] == 0) { hFile = CreateFile(NewLocations, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); GetFullPathName(NewLocations, MAX_PATH, NewLocationsFullPath, lpPart);//Windows concatenates current dir and NewLocations } else hFile = CreateFile(NewLocationsFullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if ((hFile) != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { tempWayArray = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); if (tempWayArray == NULL) { CloseHandle(hFile); MessageBox(hwnd, "Not enough memory for waypoints.", ERROR, MB_OK); SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } ReadFile(hFile, tempWayArray, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); for (y = 0; y < (int)fileSize; y++) { if ((tempWayArray[y] == '<') && (tempWayArray[y+1] == 'w') && (tempWayArray[y+2] == 'p') && (tempWayArray[y+3] == 't')) break;//to ignore header stuff } if (y == (int)fileSize) { VirtualFree(tempWayArray, 0, MEM_RELEASE); goto nowaypoints; } copyit = itswpt = gotway = FALSE; NumOfWaypoints = 0; for (x = 0, y = 0; x < (int)fileSize; x++) { if ((x > 5) && (tempWayArray[x-1] == '>') && (tempWayArray[x-5] == '/') && (tempWayArray[x-4] == 'w') && (tempWayArray[x-3] == 'p') && (tempWayArray[x-2] == 't')) {// gotway = FALSE; copyit = FALSE; } if (copyit == FALSE) { if (tempWayArray[x] == '<') { if ((tempWayArray[x+1] == 'w') && (tempWayArray[x+2] == 'p') && (tempWayArray[x+3] == 't')) {// gotway = TRUE; itswpt = TRUE; copyit = TRUE; tempWayArray[y++] = '\r'; tempWayArray[y++] = '\n'; tempWayArray[y++] = tempWayArray[x]; NumOfWaypoints++; } else if ((tempWayArray[x+1] == '/') && (tempWayArray[x+2] == 'w') && (tempWayArray[x+3] == 'p') && (tempWayArray[x+4] == 't')) { copyit = TRUE; tempWayArray[y++] = '\r'; tempWayArray[y++] = '\n'; tempWayArray[y++] = tempWayArray[x]; } else if (gotway) { if (((tempWayArray[x+1] == 'n') && (tempWayArray[x+2] == 'a') && (tempWayArray[x+3] == 'm')) || ((tempWayArray[x+1] == 'd') && (tempWayArray[x+2] == 'e') && (tempWayArray[x+3] == 's')) || ((tempWayArray[x+1] == 'c') && (tempWayArray[x+2] == 'm') && (tempWayArray[x+3] == 't')) || ((tempWayArray[x+1] == 's') && (tempWayArray[x+2] == 'y') && (tempWayArray[x+3] == 'm')) || ((tempWayArray[x+1] == 'e') && (tempWayArray[x+2] == 'l') && (tempWayArray[x+3] == 'e'))) { copyit = TRUE; tempWayArray[y++] = '\r'; tempWayArray[y++] = '\n'; tempWayArray[y++] = tempWayArray[x]; } } } } else//if (copyit) { if ((x > 5) && (tempWayArray[x-1] == '>')) { if (itswpt) { itswpt = FALSE; copyit = FALSE; } else if (((tempWayArray[x-5] == '/') && (tempWayArray[x-4] == 'c') && (tempWayArray[x-3] == 'm') && (tempWayArray[x-2] == 't')) || ((tempWayArray[x-5] == '/') && (tempWayArray[x-4] == 's') && (tempWayArray[x-3] == 'y') && (tempWayArray[x-2] == 'm')) || ((tempWayArray[x-5] == '/') && (tempWayArray[x-4] == 'e') && (tempWayArray[x-3] == 'l') && (tempWayArray[x-2] == 'e')) || ((tempWayArray[x-6] == '/') && (tempWayArray[x-4] == 'a') && (tempWayArray[x-3] == 'm') && (tempWayArray[x-2] == 'e')) || ((tempWayArray[x-6] == '/') && (tempWayArray[x-4] == 'e') && (tempWayArray[x-3] == 's') && (tempWayArray[x-2] == 'c')) || ((tempWayArray[x-5] == '/') && (tempWayArray[x-4] == 'w') && (tempWayArray[x-3] == 'p') && (tempWayArray[x-2] == 't'))) { copyit = FALSE; } else tempWayArray[y++] = tempWayArray[x]; } else tempWayArray[y++] = tempWayArray[x]; } }//end of for (x = 0 tempWayArray[y++] = '\r'; tempWayArray[y++] = '\n'; tempWayArray[y] = 0; fileSize = y; MaxWaySize = fileSize+100000; WaypointArray = (char*)calloc(1, MaxWaySize);//leave room for 100 new waypoints of 1,000 bytes each if (WaypointArray == NULL) { VirtualFree(tempWayArray, 0, MEM_RELEASE); MessageBox(hwnd, "Not enough memory for waypoints.", ERROR, MB_OK); SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (y = 0; y < (int)fileSize; y++) { if ((tempWayArray[y] == '<') && (tempWayArray[y+1] == 'w') && (tempWayArray[y+2] == 'p') && (tempWayArray[y+3] == 't')) break;//to ignore header stuff } //get rid of CDATA stuff & check format gotway = gotelev = gotname = gotcmt = gotdescr = gotsym = FALSE; for (x = 0; y < (int)fileSize; x++, y++) { if (tempWayArray[y] == '<') {//check for correct format if (CheckFormat(y) == FALSE) {//if bad format MessageBox(hwnd, Error, ERROR, MB_OK);//Error from CheckFormat } } else if (tempWayArray[y] == '>') {//check if at end of or or WaypointArray[x] = tempWayArray[y]; if (tempWayArray[y+1] != '<') {//if it's not empty x++; y++; } else if (tempWayArray[y+2] == '!') {//if it's CDATA stuff x++; y++; } if (((tempWayArray[y-6] == '<') && (tempWayArray[y-5] == 'n') && (tempWayArray[y-4] == 'a')) || ((tempWayArray[y-5] == '<') && (tempWayArray[y-4] == 'c') && (tempWayArray[y-3] == 'm')) || ((tempWayArray[y-6] == '<') && (tempWayArray[y-5] == 'd') && (tempWayArray[y-4] == 'e'))) {//lines that could have CDATA if ((tempWayArray[y] == '<') && (tempWayArray[y+1] == '!') && (tempWayArray[y+2] == '[')) {//'); x++, y++) WaypointArray[x] = tempWayArray[y]; y += 2;//(almost) past ]]> x--; continue; } } } WaypointArray[x] = tempWayArray[y]; }//end of for (x = 0; y < (int)fileSize; x++, y++) VirtualFree(tempWayArray, 0, MEM_RELEASE); tempWayArray = NULL; WaypointArray[x] = 0; WaypointSize = x; //put data into NewLoc structure for (x = 0; x < TOTAL_LOCS; x++)//was x < NumOfWaypoints { NewLoc[x].NUTM = 0; NewLoc[x].EUTM = 0; NewLoc[x].UTMZone = 0; NewLoc[x].pWaypoints = NULL;//pointer to waypoint data in WaypointArray NewLoc[x].Ident = NULL;//pointer to name NewLoc[x].Location = NULL;//pointer to cmt NewLoc[x].Description = NULL;//pointer to desc NewLoc[x].Elev = NULL;//pointer to ele NewLoc[x].Sym = NULL;//pointer to sym NewLoc[x].size = 0; prevDist[x] = HUNDRED_MILES; } // prevDist[x] = HUNDRED_MILES; for (x = 0, z = 0; (x < WaypointSize) && (z < (TOTAL_LOCS-1)); x++) { if ((WaypointArray[x] == '<') && (WaypointArray[x+1] == 'w') && (WaypointArray[x+2] == 'p') && (WaypointArray[x+3] == 't')) { firstx = x; for ( ; (x < WaypointSize) && (WaypointArray[x] != '"'); x++) ; x++;//to Latitude Lat = atof(&WaypointArray[x]); for ( ; (x < WaypointSize) && (WaypointArray[x] != '='); x++) ; x += 2;//to Longitude Lon = atof(&WaypointArray[x]); LatRad = Lat*deg2rad; LonRad = Lon*deg2rad; LatLontoUTM(); NewLoc[z].EUTM = UTMEasting; NewLoc[z].NUTM = UTMNorthing; NewLoc[z].UTMZone = UTMZone; NewLoc[z].pWaypoints = &WaypointArray[firstx]; while (x < WaypointSize) { for (x++; (x < WaypointSize) && (WaypointArray[x] != '<'); x++) ; if ((WaypointArray[x+1] == 'e') && (WaypointArray[x+2] == 'l') && (WaypointArray[x+3] == 'e') && (WaypointArray[x+4] == '>')) {// x += 5;//to elev NewLoc[z].Elev = WaypointArray + x; } else if ((WaypointArray[x+1] == 'n') && (WaypointArray[x+2] == 'a') && (WaypointArray[x+3] == 'm') && (WaypointArray[x+4] == 'e') && (WaypointArray[x+5] == '>')) {// x += 6;//to name NewLoc[z].Ident = WaypointArray + x; } else if ((WaypointArray[x+1] == 'c') && (WaypointArray[x+2] == 'm') && (WaypointArray[x+3] == 't') && (WaypointArray[x+4] == '>')) {// x += 5;//to comment NewLoc[z].Location = WaypointArray + x; } else if ((WaypointArray[x+1] == 'd') && (WaypointArray[x+2] == 'e') && (WaypointArray[x+3] == 's') && (WaypointArray[x+4] == 'c')) {// x += 6;//to description if ((WaypointArray[x] != 0) && (WaypointArray[x] != '<')) NewLoc[z].Description = WaypointArray + x; } else if ((WaypointArray[x+1] == 's') && (WaypointArray[x+2] == 'y') && (WaypointArray[x+3] == 'm')) {// x += 5;//to symbol NewLoc[z].Sym = WaypointArray + x; } else if ((WaypointArray[x+1] == '/') && (WaypointArray[x+2] == 'w') && (WaypointArray[x+3] == 'p') && (WaypointArray[x+4] == 't') && (WaypointArray[x+5] == '>')) { x += 7;//to 0x0A NewLoc[z].size = x - firstx + 1; if ((NewLoc[z].Location == NULL) && (NewLoc[z].Ident == NULL)) { x = sprintf(Error, "Waypoint %i doesn't have\na Name or Comment!\nUse Notepad to add one\n(in %s).", z+1, NewLocations); MessageBox(hwnd, Error, NULL, MB_OK); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } z++; break; } }//end of while (x < WaypointSize) }//end of if ((WaypointArray[x] == '<') else if ((WaypointArray[x] == '<') && (WaypointArray[x+1] == '/') && (WaypointArray[x+2] == 'g') && (WaypointArray[x+3] == 'p') && (WaypointArray[x+4] == 'x')) break;// }//end of for (x = 0, z = 0; x < WaypointSize; x++) NewLoc[z].NUTM = 0; NewLoc[z].EUTM = 0; NewLoc[z].UTMZone = 0; NewLoc[z].pWaypoints = NULL;//pointer to waypoint data in WaypointArray NewLoc[z].Ident = NULL;//pointer to name NewLoc[z].Location = NULL;//pointer to cmt NewLoc[z].Description = NULL;//pointer to desc NewLoc[z].Elev = NULL;//pointer to ele NewLoc[z].Sym = NULL;//pointer to sym NewLoc[z].size = 0; EmptyLoc = z; if (z > 2) { if (sortbyname) qsort(NewLoc, z, sizeof(NewLoc[0]), compareIdent); else qsort(NewLoc, z, sizeof(NewLoc[0]), compareLoc); } Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; }//end of if (fileSize else { CloseHandle(hFile); MessageBox(hwnd, "is 0 bytes in size.\nDelete it and try again", NewLocations, MB_OK); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } }//end of if ((hFile = CreateFile(NewLocations, else { // if (NewLocationsFullPath[0]) // MessageBox(hwnd, "doesn't exist.\nIt'll be created when you make the first waypoint\nin this Map Location.", NewLocationsFullPath, MB_OK); for (x = 0; x < TOTAL_LOCS; x++) { NewLoc[x].NUTM = 0; NewLoc[x].EUTM = 0; NewLoc[x].UTMZone = 0; NewLoc[x].pWaypoints = NULL;//pointer to waypoint data in WaypointArray NewLoc[x].Ident = NULL;//pointer to name NewLoc[x].Location = NULL;//pointer to cmt NewLoc[x].Description = NULL;//pointer to desc NewLoc[x].Elev = NULL;//pointer to ele NewLoc[x].Sym = NULL;//pointer to sym NewLoc[x].size = 0; prevDist[x] = HUNDRED_MILES; } EmptyLoc = 0; MaxWaySize = 100000; WaypointArray = (char*)calloc(1, MaxWaySize);//leave room for 100 new waypoints of 1,000 bytes each if (WaypointArray == NULL) { MessageBox(hwnd, "Not enough memory for waypoints.", ERROR, MB_OK); SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } } nowaypoints: head = new_node = NULL; if ((hFile = CreateFile(TextDta, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { z = sizeof(struct Text); y = fileSize / z; for (x = 0; x < y; x++) { cur = (struct Text*) malloc(z); if (x != 0) prev->next = cur; else head = cur; ReadFile(hFile, cur, z, &dwBytesRead, NULL); prev = cur; cur->next = NULL; } } CloseHandle(hFile); } rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen //FALL THRU... case WM_USER2://called when zooming MapWidth = TilesAcross * PixelsPerTile; MapHeight = TilesDown * PixelsPerTile; if (PixelsPerTile == 50) ImageSize = 7600;//2 pad bytes else if (PixelsPerTile == 25) ImageSize = 1900;//1 pad byte else ImageSize = 3 * PixelsPerTile * PixelsPerTile; GetDotRadius(); bmih.biSize = sizeof(BITMAPINFOHEADER); bmih.biWidth = PixelsPerTile; bmih.biHeight = -PixelsPerTile;// - for right-side-up picture bmih.biPlanes = 1; bmih.biBitCount = 24; bmih.biCompression = BI_RGB; bmih.biSizeImage = ImageSize; bmi.bmiHeader = *pbmih; DeleteDC (hdcMem); DeleteObject (hBitmap); hdc = GetDC (hwnd); hdcMem = CreateCompatibleDC (hdc);//not deleted until WM_CLOSE or zooming hBitmap = CreateCompatibleBitmap (hdc, MapWidth, MapHeight);//ditto ReleaseDC(hwnd, hdc); SelectObject (hdcMem, hBitmap); hdcSymMem1 = ReadBmpFile("mysymb.bmp"); hdcSymMem2 = ReadBmpFile("mysymb2.bmp"); //FALL THRU.. case WM_USER://do full-screen draw of images EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) return 0; if ((Zoom <= 4) && (MapType == PHOTO)) { fileName[0] = fileName0; fileName[1] = fileName1; fileName[2] = fileName2; fileName[17] = 'z'; pointerFileName[0] = fileName0; pointerFileName[1] = fileName1; pointerFileName[2] = fileName2; pointerFileName[17] = 'z'; } else if (Zoom >= 5) { fileName[0] = 'B'; fileName[1] = 'i'; fileName[2] = 'g'; if (MapType == PHOTO) fileName[17] = 'z'; else if (MapType == TOPO) fileName[17] = 't'; else fileName[17] = 'c'; pointerFileName[0] = 'B'; pointerFileName[1] = 'i'; pointerFileName[2] = 'g'; if (MapType == PHOTO) pointerFileName[17] = 'z'; else if (MapType == TOPO) pointerFileName[17] = 't'; else pointerFileName[17] = 'c'; } else if (MapType == TOPO) { fileName[0] = fileName0; fileName[1] = fileName1; fileName[2] = fileName2; fileName[17] = 'a';//to identify topo map data pointerFileName[0] = fileName0; pointerFileName[1] = fileName1; pointerFileName[2] = fileName2; pointerFileName[17] = 'a'; } else if (MapType == URBANAREA) { fileName[0] = fileName0; fileName[1] = fileName1; fileName[2] = fileName2; fileName[17] = 'u';//to identify urban area data pointerFileName[0] = fileName0; pointerFileName[1] = fileName1; pointerFileName[2] = fileName2; pointerFileName[17] = 'u'; } yLoc = PixelsPerTile * (TilesDown-1);//bottom of screen maxRows = rowOffset + TilesDown; maxCols = colOffset + TilesAcross; ZoneName[0] = Z[0]; ZoneName[1] = Z[1]; for (row = rowOffset; row < maxRows; row++) {//start at the bottom of the screen for (x = 0, z = 18; x < 3; x++, z++) { fileName[z] = ZoneName[x]; pointerFileName[z] = ZoneName[x]; } Y[0] = ((row / 1000) + '0'); // Y[1] = (((row % 1000) / 100) + '0'); // Y[2] = (((row % 100) / 10) + '0'); // Y[3] = ((row % 10) + '0'); _itoa(row, Y, 10); for (x = 0; Y[x] != 0; x++, z++) { pointerFileName[z] = Y[x]; fileName[z] = Y[x]; } for (x = 0; x < 5; x++, z++) { pointerFileName[z] = Ptr[x]; fileName[z] = Dta[x]; } hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { hFile2 = CreateFile(pointerFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); fileSize = GetFileSize(hFile2, NULL); ReadFile(hFile2, Pointers, fileSize, &dwBytesRead, NULL); CloseHandle(hFile2); FirstOffset = Pointers[0]; NumOfPointers = Pointers[1]; Pointers[1] = 0; for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) { PointerOffset = col - FirstOffset; if ((PointerOffset >= 0) && (PointerOffset < NumOfPointers)) { fileSize = Pointers[PointerOffset+2] - Pointers[PointerOffset+1]; if (fileSize > 1) { SetFilePointer(hFile, Pointers[PointerOffset+1], NULL, FILE_BEGIN); ReadFile(hFile, TileBuf, fileSize, &dwBytesRead, NULL); if ((TileBuf[0] == 0xFF) && (TileBuf[1] == 0xD8) && (TileBuf[6] == 'J') && (TileBuf[7] == 'F')) Convert_TileBuf_hdcMem(NULL, 0xFFFFFFFF); else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcBlackMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); }//end of for (col = ElevColCounter = 0; CloseHandle(hFile); } else for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) { BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } yLoc -= PixelsPerTile; }//end of for (row = // if (autodownload) // SendMessage(hwnd, WM_COMMAND, ID_FILE_DOWNLOADMAPDATA_FILLSCREEN, 0); if ((fromOpen) || (fromTracks) || (fromGoTo)) { fromOpen = fromTracks = fromGoTo = FALSE; InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } cachenotfull = TRUE; return 0; //end of case WM_CREATE ////////////////////////////////////////////////////////////////////////////////////// case WM_COMMAND: wParameter = LOWORD(wParam); switch (wParameter) { case ID_STOPPOSITIONING: if (autoLoc) { showposition = FALSE; if (fromFlag == NOBUTTON) { if (itsgarmin) { fromFlag = MENU;//slightly trick - to come back here after stop is sent to Garmin routine sendingStop = TRUE; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = StopPVTPacket[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); return 0;//slightly trick } else if (itsusb == FALSE) { SetEvent(hEventExit); } else if (hUSBThread != 0) { SignalUSBStop(); } } showposition = FALSE; fromFlag = NOBUTTON;//for returning from Garmin comm routine autoLoc = FALSE; DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); if (UTMEasting != 0) { InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } } break; case ID_STOPDOWNLOADING: EnterCriticalSection(&cs); downloading = FALSE; USBdownloading = FALSE; LeaveCriticalSection(&cs); if (hDownloadThread != 0) { ResetEvent(hEvent);//unsignal it if (WAIT_TIMEOUT == WaitForSingleObject(hEvent, 1000))//wait for it to be closed { TerminateThread((HANDLE)hDownloadThread, 1); MessageBeep(MB_OK); CloseHandle ((HANDLE)hDownloadThread); hDownloadThread = 0; DestroyMenu(hMenu5); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); } if (fillscreen == FALSE) { Zoom = saveZoom; rowOffset = saveRowOffset; colOffset = saveColOffset; TilesDown = saveTilesDown; TilesAcross = saveTilesAcross; if ((fileName[0] != 'B') && (fileName[1] != 'i') && (fileName[2] != 'g')) { fileName[0] = fileName0; fileName[1] = fileName1; fileName[2] = fileName2; pointerFileName[0] = fileName0; pointerFileName[1] = fileName1; pointerFileName[2] = fileName2; } SendMessage(hwnd, WM_CLOSE, 0, 0); } } break; case ID_FILE_DOWNLOADMAPDATA_FILLSCREEN: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; //fillscrn: if (bigjpeg) break; if (newLoc) SaveLocs(); if (newText) SaveText(); fillscreen = TRUE; hDownloadThread = _beginthreadex(NULL, 0, DownloadThread, hwnd, 0, &idThread2); break; /* case ID_FILE_DOWNLOADMAPDATA_1METERPIXELPHOTOS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if ((MapType != PHOTO) || (Zoom < 5)) goto fillscrn; beginX = ScreenLeft / 200; beginY = ScreenTop / 200; endX = ScreenRight / 200; endY = ScreenBottom / 200; fileName[0] = 'U'; fileName[1] = 'S'; fileName[2] = 'A'; saveZoom = Zoom; Zoom = 1; onemeter = TRUE; Response = 1; //FALL THRU... case ID_FILE_DOWNLOADMAPDATA_ENTERLATLON: if (bigjpeg) break; if (onemeter == FALSE) { EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; saveZoom = Zoom; Response = DialogBox(hInst, "GETLATLON", hwnd, GetLatLonProc); } else onemeter = FALSE; if (Response != EXIT) { if (newLoc) SaveLocs(); if (newText) SaveText(); _itoa((beginY-endY), AsciiTotal, 10);// * (endX-beginX) for (x = 0, y = 10; AsciiTotal[x] != 0; x++, y++) DownloadProgress[y] = AsciiTotal[x]; for (z = 0; z < x; z++) DownloadProgress[5-z] = '0'; for (x = 0; PhotosDownloaded[x] != 0; x++, y++) DownloadProgress[y] = PhotosDownloaded[x]; DownloadProgress[y] = 0; SizeOfDP = y; hdc = GetDC(hwnd); FillRect(hdc, &rect, (HBRUSH)CreateSolidBrush(LIGHTGRAY)); SetBkColor(hdc, LIGHTGRAY); x = (cxScreen/2) - (32*cxChar); y = cyScreen/2; TextOut(hdc, (cxScreen/2) - (32*cxChar), cyScreen/2, DownloadProgress, SizeOfDP); TextOut(hdc, x, y + (cyChar*2), "USAPhotoMaps will close when all photos are downloaded.", 55); TextOut(hdc, x, y + (cyChar*3), "If a photo already exists in USAPhotoMaps, it's not downloaded.", 63); ReleaseDC(hwnd, hdc); fillscreen = FALSE; hDownloadThread = _beginthreadex(NULL, 0, DownloadThread, hwnd, 0, &idThread2); } break; */ case ID_GOTO_ADDRESS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Response = DialogBox(hInst, "ADDRESS", hwnd, AddressProc);//address is put into Address1 if (Response != EXIT) { int good = 0; SetCursor(hWaitingCursor); AddrBuf = (char*)malloc(50000); hOpen = InternetOpen(ProgName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (hInternet = InternetOpenUrl(hOpen, Address1, Accept, -1, INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_KEEP_CONNECTION, 0)) { for (fileSize = 0; (goodread = InternetReadFile(hInternet, AddrBuf, 50000, &dwBytesRead)) && (dwBytesRead); fileSize += dwBytesRead) ; InternetCloseHandle(hInternet); if (fileSize > 50000) MessageBox(hwnd, "Website sent too much data!", ERROR, MB_OK); else if ((goodread) && (dwBytesRead == 0)) { tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (x = 0; x < (int)fileSize; x++) { if ((AddrBuf[x] == 'y') && (AddrBuf[x+2] == '=')) { good++; x += 4; Lat = atof(&AddrBuf[x]); break; } } for (x = 0; x < (int)fileSize; x++) { if ((AddrBuf[x] == 'x') && (AddrBuf[x+2] == '=')) { good++; x += 4; Lon = atof(&AddrBuf[x]); break; } } } } InternetCloseHandle(hOpen); free(AddrBuf); SetCursor(hCursor); if (good == 2) { if (gotaddr) for (x = 0; Address[x] != 0; x++) City[x] = Address[x]; else if (gotcity) for (x = 0; xCity[x] != 0; x++) City[x] = xCity[x]; else if (gotzip) for (x = 0; ZIP[x] != 0; x++) City[x] = ZIP[x]; City[x] = 0; goto asdf2; } else { Lat = tempLat; Lon = tempLon; MessageBox(hwnd, "Either the USGS website couldn't find it,\nor their website is down:\nhttp://nmviewogc.cr.usgs.gov/tnm/FindAddress.jsp", Oops, MB_OK); } } break; case ID_GOTO_TOWNSHIP://Populated Place tempUTMZone = UTMZone; for (x = 0; CurrentDir[x] != 0; x++) USGSFile[x] = CurrentDir[x]; for (y = 0; StatesPath[y] != 0; x++, y++) USGSFile[x] = StatesPath[y]; USGSFile[x] = 0; if (INVALID_HANDLE_VALUE != FindFirstFile(USGSFile, &fd)) { for (x = 0; USGSFile[x] != '?'; x++) ; qm = x; if (DialogBox(hInst, "USGS", hwnd, USGSProc)) { tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (x = 0; City[x] != '@'; x++) ; City[x++] = 0; Lat = strtod(&City[x], NULL); for ( ; City[x] != '-'; x++) ; Lon = strtod(&City[x], NULL); asdf2: LatRad = Lat * deg2rad; LonRad = Lon * deg2rad; LatLontoUTM(); asdf3: CityUTMEasting = UTMEasting; CityUTMNorthing = UTMNorthing; if ((Lon > -60.0) || (Lon < -168.0) || (Lat > 72.0) || (Lat < 17.5)) { sprintf(Error, "N %f\nW %f %s", Lat, Lon, OutsideUSA); MessageBox(hwnd, Error, "Error 1", MB_OK); Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; break; } if (tempUTMZone != UTMZone) ChangeZone(UTMZone, 0); BeginX = UTMEasting / MetersPerTile; BeginY = UTMNorthing / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; if (tempUTMZone != UTMZone) { Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); } veryfirstime = TRUE; rowOffset = BeginY - (TilesDown / 2);//bottom edge of screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of screen GotoEasting = UTMEasting; GotoNorthing = UTMNorthing; fromOpen = TRUE; SendMessage(hwnd, WM_USER, 0, 0);//was WM_USER2 UTMEasting = GotoEasting; UTMNorthing = GotoNorthing; UTMtoLatLon();//because WM_USER6 already has cursor location lat/lon lButtonDotX = (UTMEasting - ScreenLeft) * PixelsPerTile / MetersPerTile; lButtonDotY = (ScreenTop - UTMNorthing) * PixelsPerTile / MetersPerTile; fromgoto = FALSE;//TRUE; fromgotocity = TRUE;//to put name on screen SendMessage(hwnd, WM_USER6, 0, 0); } } else { if (IDOK == MessageBox(hwnd, "Do you want to download 1.9 MBytes of\nPopulated Place data from jdmcox.com?", "FIRST", MB_OKCANCEL)) hDownloadStatesThread = _beginthreadex(NULL, 0, DownloadStatesThread, hwnd, 0, &idThread10); } break; case ID_GOTO_USGSLANDMARK: showinglandmarks = FALSE; if (USGSBuf != NULL) { VirtualFree(USGSBuf, 0, MEM_RELEASE); VirtualFree(PtrBuf, 0, MEM_RELEASE); USGSBuf = NULL; showinglandmarks = TRUE; } if (GetUSGSData()) { IniNumber = -1;//re-initialize it if (DialogBox(hInst, "FINDUSGS", hwnd, FindUSGSProc)) { tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (x = 0; SelectedUSGSLoc[x] != 0; x++) ; x -= 14; UTMEasting = (((SelectedUSGSLoc[x] - '0') * 100000) + ((SelectedUSGSLoc[x+1] - '0') * 10000) + ((SelectedUSGSLoc[x+2] - '0') * 1000) + ((SelectedUSGSLoc[x+3] - '0') * 100) + ((SelectedUSGSLoc[x+4] - '0') * 10) + (SelectedUSGSLoc[x+5] - '0')); UTMNorthing = (((SelectedUSGSLoc[x+7] - '0') * 1000000) + ((SelectedUSGSLoc[x+8] - '0') * 100000) + ((SelectedUSGSLoc[x+9] - '0') * 10000) + ((SelectedUSGSLoc[x+10] - '0') * 1000) + ((SelectedUSGSLoc[x+11] - '0') * 100) + ((SelectedUSGSLoc[x+12] - '0') * 10) + (SelectedUSGSLoc[x+13] - '0')); UTMtoLatLon(); if (showinglandmarks == FALSE) { VirtualFree(USGSBuf, 0, MEM_RELEASE); VirtualFree(PtrBuf, 0, MEM_RELEASE); USGSBuf = NULL;//to not show landmarks } for (x = 0; SelectedUSGSLoc[x] != 0; x++) ; SelectedUSGSLoc[x-15] = 0;//don't copy UTM Easting and Northing strcpy(City, SelectedUSGSLoc); goto asdf3; } } break; case ID_FILES_OPENMAPFILE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; grid75 = FALSE; CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); wastopo = FALSE; veryfirstime = TRUE; CheckMenuItem(hMenu, ID_APRS_RECEIVEINTERNETDATA, MF_UNCHECKED); aprs = tnc = FALSE; if (openatclosing) { ChangeUSAPhotoMapsIni(); ChangeUSAPMIni(); } hFile = CreateFile(USAPhotoMapsIni, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { Waypoints[0] = 0;//don't use it again pIniBuf = (unsigned char*) malloc(fileSize+3); pIniBuf2 = pIniBuf;//for OpenProc ReadFile(hFile, pIniBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); pIniBuf[fileSize] = 0;//for OpenProc deletestring = FALSE; if (notfromusa) { IniNumber = -1; Response = DialogBox(hInst, "OPEN", hwnd, OpenProc); pIniBuf = pIniBuf2;//re-initialize after OpenProc } else { notfromusa = TRUE; Response = TRUE; } if ((Response != EXIT) && (IniNumber != -1)) { if (deletestring == FALSE) { if (newLoc) SaveLocs(); if (newText) SaveText(); for (x = 0; (pIniBuf[x] != '*') && (x < (int)fileSize); x++) ; for (z = 0, y = 0; (y < (int)fileSize); y++) { if (pIniBuf[y-1] == '\n')//end of line z++; if (z == IniNumber)//from OpenProc break;//pIniBuf[y] now points to chosen name } if (x != y) {//if not at current MapName if (x > y) for ( ; x > y; x--) pIniBuf[x] = pIniBuf[x-1]; else { for ( ; x < y; x++) pIniBuf[x] = pIniBuf[x+1]; x--; } pIniBuf[x] = '*';//at new current map name x = CheckIniProc(pIniBuf, fileSize, 1);//ID_FILES_OPENMAPFILE if (x == (int)fileSize) { hFile2 = CreateFile(USAPhotoMapsIni, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, pIniBuf, fileSize, &dwBytesWritten, NULL); CloseHandle(hFile2); if (FALSE == GetXYZfromIniBuf()) {//should never get here free(pIniBuf2); MessageBox(hwnd, Buf2, ERROR, MB_OK); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } } else { free(pIniBuf2); MessageBox(hwnd, Buf2, ERROR, MB_OK); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; } if (USGSBuf != NULL) { VirtualFree(USGSBuf, 0, MEM_RELEASE); VirtualFree(PtrBuf, 0, MEM_RELEASE); USGSBuf = NULL; GetUSGSData(); } GetTigerIndex(); SetCursor(hWaitingCursor); fromOpen = TRUE; Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); SetCursor(hCursor); }//end of if (x != y) }//end of if (deletestring == FALSE) else//if (deletestring) { deletestring = FALSE; for (z = 0, y = 0; (y < (int)fileSize); y++) { if (pIniBuf[y-1] == '\x0A')//end of line z++; if (z == IniNumber)//from OpenProc break;//pIniBuf[y] now points to chosen name } if (pIniBuf[y] == '*') MessageBox(hwnd, "You can't delete the current Map Location", Oops, MB_OK); else if (y != fileSize) { for (x = y; (pIniBuf[x] != '\n') && (x < (int)fileSize); x++) ; x++;//at beginning of next line (or end) if (x == fileSize) {//at last line if (pIniBuf[y] == '*') { for (x = y-2; (pIniBuf[x] != '\n') && (x < 0); x--) ; if (x > 0) { x++;//to beginning of line for (y = x+1; (pIniBuf[y-1] != '\n') && (y < (int)fileSize); y++) pIniBuf[y] = pIniBuf[y-1]; } else {//if only one line DeleteFile(USAPhotoMapsIni); free(pIniBuf); return 0; } } pIniBuf[y] = 0; fileSize = y; } else { if (pIniBuf[y] == '*') y++; for ( ; x < (int)fileSize; x++, y++) pIniBuf[y] = pIniBuf[x]; pIniBuf[y] = 0; fileSize = y; } hFile2 = CreateFile(USAPhotoMapsIni, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, pIniBuf, fileSize, &dwBytesWritten, NULL); CloseHandle(hFile2); } } } free(pIniBuf2); } else CloseHandle(hFile); } break; case ID_FILES_NEWMAPFILE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; grid75 = FALSE; CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); wastopo = FALSE; veryfirstime = TRUE; sprintf(myLat, "%f", Lat); sprintf(myLon, "%f", Lon); tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; UTMNorthing = ScreenTop - (((rect.bottom / 2) * MetersPerTile) / PixelsPerTile); UTMEasting = ScreenLeft + (((rect.right / 2) * MetersPerTile) / PixelsPerTile); UTMtoLatLon(); Response = DialogBox(hInst, "WELCOME", NULL, WelcomeProc); if (Response != EXIT) { if (newLoc) SaveLocs(); if (newText) SaveText(); for (row = 0; row < TilesDown; row++) for (col = 0; col < TilesAcross; col++) BitBlt(hdcMem, row, col, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); fromOpen = TRUE; Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); // if (autodownload) // SendMessage(hwnd, WM_COMMAND, ID_FILE_DOWNLOADMAPDATA_FILLSCREEN, 0); } else { Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; } break; case ID_FILE_EXPORT://Copy to 'Screen01.jpg' EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; itsfull = FALSE; PadBytes = IJL_DIB_PAD_BYTES(rect.right, 3); big_buf_size = (rect.right + PadBytes) * rect.bottom * 3; big_jpeg_size = big_buf_size / 5; bmih2.biSize = sizeof(BITMAPINFOHEADER); bmih2.biWidth = rect.right; bmih2.biHeight = -(rect.bottom);// - for right-side-up picture bmih2.biPlanes = 1; bmih2.biBitCount = 24; bmih2.biCompression = BI_RGB; bmih2.biSizeImage = big_buf_size; bmi2.bmiHeader = bmih2; big_buf = VirtualAlloc(NULL, big_buf_size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); hdc = GetDC(hwnd); hdcMem2 = CreateCompatibleDC(hdc);//not deleted until WM_CLOSE or zooming hBitmap2 = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);//ditto SelectObject(hdcMem2, hBitmap2); BitBlt(hdcMem2, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY); GetDIBits(hdcMem2, hBitmap2, 0, rect.bottom-1, big_buf, &bmi2, DIB_RGB_COLORS); ReleaseDC(hwnd, hdc); DeleteDC (hdcMem2); DeleteObject (hBitmap2); big_jpeg_buf = VirtualAlloc(NULL, big_jpeg_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); ijlInit(&jcprops);//use Intel's ijl15.dll to convert JPEG files jcprops.JPGWidth = rect.right; jcprops.JPGHeight = rect.bottom; jcprops.JPGBytes = (unsigned char*)big_jpeg_buf;//output jcprops.JPGSizeBytes = big_jpeg_size;//estimate jcprops.JPGFile = NULL; jcprops.JPGChannels = 3; jcprops.JPGColor = IJL_YCBCR; jcprops.JPGSubsampling = IJL_411;//4:1:1 subsampling jcprops.jquality = 75;//90;//"high" image quality jcprops.DIBWidth = rect.right; jcprops.DIBHeight = rect.bottom; jcprops.DIBPadBytes = PadBytes; jcprops.DIBBytes = (unsigned char*)big_buf;//input ijlWrite(&jcprops, IJL_JBUFF_WRITEWHOLEIMAGE); fileSize = jcprops.JPGSizeBytes;//re-computed by ijl15.dll ijlFree(&jcprops); hFile = FindFirstFile("Screen??.jpg", &fd); if (hFile != INVALID_HANDLE_VALUE) {//found it ScreenFile[6] = '0'; ScreenFile[7] = '1'; while (TRUE) { FindClose(hFile); hFile = FindFirstFile(ScreenFile, &fd); if (hFile == INVALID_HANDLE_VALUE) break; ScreenFile[7]++; if (ScreenFile[7] > '9') { if (ScreenFile[6] != '9') { ScreenFile[7] = '0'; ScreenFile[6]++; } else { itsfull = TRUE; FindClose(hFile); MessageBox(hwnd, "Move your 99 ScreenXX.jpg files\nto another folder\nso you can start over.", "", MB_OK); break; } } } } if (itsfull == FALSE) { hFile = CreateFile(ScreenFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, big_jpeg_buf, fileSize, &dwBytesWritten, NULL); CloseHandle(hFile); } VirtualFree(big_jpeg_buf, 0, MEM_RELEASE); VirtualFree(big_buf, 0, MEM_RELEASE); break; case ID_FILE_BOUNDARYFORBIGJPEG: if (!bigjpeg) { if (IDOK == MessageBox(hwnd, BigJpegInfo, "Create a BIG jpeg file", MB_OKCANCEL)) bigjpeg = TRUE; } break; case ID_FILE_TERRAFETCHER_REGION: if (!terrafetcher) { if (IDOK == MessageBox(hwnd, TerraFetcherInfo, "Get a Region for TerraFetcher", MB_OKCANCEL)) terrafetcher = TRUE; } break; case ID_FILE_TERRAFETCHER_PATH: if (IDOK == MessageBox(hwnd, "TerraFetcherPath.txt", "Copy a Route to", MB_OKCANCEL)) { getroute2: if (GetOpenFileName(&ofn3)) { if (INVALID_HANDLE_VALUE != (hFile = CreateFile(FullRoutes, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL))) { if (fileSize = GetFileSize(hFile, NULL)) { char asdf[10]; char *Buffer, *Buffer2; Buffer = (char*)malloc(fileSize); Buffer2 = (char*)malloc(fileSize+50); ReadFile(hFile, Buffer, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); if ((Buffer[0] < '0') || (Buffer[0] > '9') || (Buffer[2] != ',') || (Buffer[17] != '\r')) { MessageBox(hwnd, "That's not a route file.\nTry again.", NULL, MB_OK); goto getroute2; } x = y = 0; Buffer2[y++] = ';'; for ( ; Routes[x] != 0; x++, y++) Buffer2[y] = Routes[x]; Buffer2[y++] = '\r'; Buffer2[y++] = '\n'; for (x = 0; x < 5; x++, y++) Buffer2[y] = Path1[x]; for (x = 0, z = 0; x < fileSize; x++) { if (Buffer[x] == '\n') z++; } _itoa(z, asdf, 10); for (x = 0; asdf[x] != 0; x++, y++) Buffer2[y] = asdf[x]; for (x = 0; x < 25; x++, y++) Buffer2[y] = Path2[x]; for (v = 0, x = 0; v < z; v++) { Buffer2[y++] = Buffer[x++]; Buffer2[y++] = Buffer[x++]; Buffer2[y++] = ' '; x += 9;//to Northing for (w = 0; w < 6; w++, x++, y++) Buffer2[y] = Buffer[x]; Buffer2[y++] = ' '; x -= 14;//back to Easting for (w = 0; w < 7; w++, x++, y++) Buffer2[y] = Buffer[x]; Buffer2[y++] = '\r'; Buffer2[y++] = '\n'; x += 9;//to next line } hFile2 = CreateFile(TerraFetcherPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, Buffer2, y, &dwBytesWritten, NULL); CloseHandle(hFile2); free(Buffer2); free(Buffer); MessageBox(hwnd, "has been written...", "TerraFetcherPath.txt", MB_OK); } else CloseHandle(hFile); } } } break; case ID_FILE_SHOWELEVATIONSQUARES: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_BYCOMMAND)) { if (grid75 == FALSE) { CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_CHECKED); grid75 = TRUE; InvalidateRect(hwnd, &rect, FALSE); // PrevMetersPerTile = MetersPerTile; // PrevPixelsPerTile = PixelsPerTile; // MetersPerTile = 1600; // UncheckZoom(); // Zoom = 8; // PixelsPerTile = 25; // ShowZoom(); // DoZoom(); // hwndElevation = CreateWindow("EDIT", "Get Elevation Data", // WS_CHILD | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | ES_MULTILINE, // 0, 0, 300, 240, // hwnd, (HMENU)168, hInst, NULL); // pElevProc = (WNDPROC)SetWindowLong(hwndElevation, GWL_WNDPROC, (LONG)ElevationProc);//sub-class for WM_DESTROYWINDOW // SendMessage(hwndElevation, EM_SETREADONLY, 1, 0); // SetWindowText(hwndElevation, ElevInfo); // getelev = TRUE;//for WM_LBUTTONDOWN if (autoLoc == FALSE) { pElevationHelp = NULL; hFile = CreateFile(ElevationHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (HelpSize = GetFileSize(hFile, NULL)) { pElevationHelp = (char *) malloc(HelpSize+1); if (pElevationHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pElevationHelp[HelpSize] = 0; ReadFile(hFile, pElevationHelp, HelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndElevationHelp = CreateWindow(Instruct, ElevationHelp, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, 0, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), 580, NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pElevationHelp); SetFocus(hwndInstr); } CloseHandle (hFile); } else MessageBox(hwnd, ElevationHelp, "Couldn't find", MB_OK); } } } else { CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); grid75 = FALSE; InvalidateRect(hwnd, &rect, FALSE); } break; case ID_FILE_CONVERTELEVATIONDATA: tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; ///////////////////////////// // ExitCode = ConvertSDTSData(); ExitCode = ConvertBILData(); ///////////////////////////// Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; if (ExitCode == 0) { GetDems(); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } break; case ID_FILE_DOWNLOADMAPDATA_TIGERSTREETS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (downloadingstreets) break; if (froms) froms = FALSE; else {//put lat/lon in center of screen froms = FALSE; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; UTMNorthing = ScreenBottom + ((TilesDown*MetersPerTile) / 2); UTMEasting = ScreenLeft + ((TilesAcross*MetersPerTile) / 2); UTMtoLatLon(); LatLontoUTM(); if (UTMZone != tempUTMZone) {//if it went into another UTM zone Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; } } ////////////////////// GetCountyFromLatLon(); ////////////////////// hFile = CreateFile(TigerCounties, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (CountySize = GetFileSize(hFile, NULL)) { pCounties = (char*)malloc(CountySize); ReadFile(hFile, pCounties, CountySize, &dwBytesRead, NULL); CloseHandle(hFile); hFile = NULL; County = -1;//flag if (DialogBox(hInst, "TIGER", hwnd, GetTigerProc)) { if (County != -1) { for (x = 0, y = 0; x < CountySize; x++) { if (pCounties[x] == 0) { if (y != County) y++; else {//"http://www2.census.gov/geo/tiger/tiger2006se/VA/TGRxxxxx.ZIP"; for (y = 21, z = x-11; z < x-5; y++, z++) Downloaded[y] = pCounties[z]; GetTigerZip[51] = pCounties[x-5]; TigerZip[3] = pCounties[x-5]; OldTigerZip[15] = pCounties[x-5]; GetTigerZip[52] = pCounties[x-4]; TigerZip[4] = pCounties[x-4]; OldTigerZip[16] = pCounties[x-4]; GetTigerZip[53] = pCounties[x-3]; TigerZip[5] = pCounties[x-3]; OldTigerZip[17] = pCounties[x-3]; GetTigerZip[54] = pCounties[x-2]; TigerZip[6] = pCounties[x-2]; OldTigerZip[18] = pCounties[x-2]; GetTigerZip[55] = pCounties[x-1]; TigerZip[7] = pCounties[x-1]; OldTigerZip[19] = pCounties[x-1]; for ( ; (pCounties[x] != '\n') && (x != 0); x--) ; if (x != 0) x++;//to beginning of line GetTigerZip[45] = pCounties[x];//state GetTigerZip[46] = pCounties[x+1]; break; } } } downloaded = FALSE; notcancelled = TRUE; // if (INVALID_HANDLE_VALUE != FindFirstFile(OldTigerZip, &fd)) hFile2 = CreateFile(OldTigerZip, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile2 != INVALID_HANDLE_VALUE) { ReadFile(hFile2, Error, 2, &dwBytesRead, NULL); CloseHandle(hFile2); if ((Error[0] != 'P') && (Error[1] != 'K')) DeleteFile(OldTigerZip); else { x = MessageBox(hwnd, "You already have the .zip file for that County.\nContinue?\n(press No to just re-convert the data)", TigerZip, MB_YESNOCANCEL); if (IDNO == x) { CopyFile(OldTigerZip, TigerZip, TRUE); hThread = _beginthreadex(NULL, 0, TigerThread, NULL, 0, &idThread); Sleep(500); free(pCounties); pCounties = NULL; break; } else if (IDCANCEL == x) { free(pCounties); pCounties = NULL; break; } } } hwndTiger = CreateWindow(Tiger, TigerZip, WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, (cxScreen/2)-(16*cxChar), (cyScreen/2)-((8*cyChar)/2), 30*cxChar, 9*cyChar, hwnd, (HMENU)176, hInst, NULL); GetClientRect(hwndTiger, &tigerRect); InvalidateRect(hwnd, &rect, FALSE); ResetEvent(hTigerEvent); ResetEvent(hTigerReturn); hThread = _beginthreadex(NULL, 0, TigerCommThread, NULL, 0, &idThread); Sleep(500); } }//end of if (DialogBox( if (pCounties != NULL) { free(pCounties); pCounties = NULL; } } if (hFile != NULL) CloseHandle(hFile); } else MessageBox(hwnd, "Couldn't find TigerCounties.txt\nDownload the full version\nof USAPhotoMaps to get it.", ERROR, MB_OK); break; case ID_FILES_PRINT: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; GetClientRect(hwnd, &rect); hdc = GetDC(hwnd); BitBlt(hdcMem, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdc); // MessageBox(hwnd, PrintInfo, "Printing Note", MB_OK); EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, 0, &dwSizeNeeded, &dwNumItems);//get printer name for OpenPrinter lpInfo = (LPPRINTER_INFO_5)malloc(dwSizeNeeded); EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, (LPBYTE)lpInfo, dwSizeNeeded, &dwSizeNeeded, &dwNumItems); PrinterName[0] = 0; if (GetDefaultPrinter(PrinterName, &PrinterNameLen)) {//show possible default printer first if (PrinterName[0] != 0) { if (IDYES == MessageBox(hwnd, PrinterName, "Use this printer?", MB_YESNO)) goto skip; } } for ( dwItem = 0; dwItem < dwNumItems; dwItem++ ) { if (strcmp(lpInfo[dwItem].pPrinterName, PrinterName)) { if (IDYES == MessageBox(hwnd, lpInfo[dwItem].pPrinterName, "Use this printer?", MB_YESNO)) { strcpy(PrinterName, lpInfo[dwItem].pPrinterName); break; } } } skip: free(lpInfo); if (dwItem == dwNumItems) break;//nothing chosen; OpenPrinter(PrinterName, &hPrinter, NULL);//get hPrinter for DocumentProperties dwNeeded = DocumentProperties(hwnd, hPrinter, PrinterName, NULL, NULL, 0);//get DEVMODE size pDevMode = (LPDEVMODE)malloc(dwNeeded); DocumentProperties(hwnd, hPrinter, PrinterName, pDevMode, NULL, DM_OUT_BUFFER);//get DEVMODE info pDevMode->dmOrientation = DMORIENT_LANDSCAPE; DocumentProperties(hwnd, hPrinter, PrinterName, pDevMode, pDevMode, DM_IN_BUFFER|DM_OUT_BUFFER);//integrate landscape selection ClosePrinter(hPrinter); // pd.lStructSize = sizeof(PRINTDLG); // pd.hwndOwner = hwnd; // pd.hDevMode = NULL; // pd.hDevNames = NULL; // pd.Flags = PD_NOPAGENUMS|PD_NOSELECTION|PD_HIDEPRINTTOFILE|PD_RETURNDC; // pd.nCopies = 1; // pd.nFromPage = 0; // pd.nToPage = 0; // if (PrintDlg(&pd)) { HDC hDC = CreateDC("WINSPOOL", PrinterName, NULL, pDevMode); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); hdcPrn = CreateCompatibleDC(hDC); hPrnBitmap = CreateCompatibleBitmap(hDC, rect.right, rect.bottom); hObject = SelectObject(hdcPrn, hPrnBitmap); BitBlt(hdcPrn, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); w = GetDeviceCaps(hDC, PHYSICALWIDTH);//PHYSICALWIDTH = dpi * 11.0 in Landscape Mode z = GetDeviceCaps(hDC, PHYSICALHEIGHT);//PHYSICALHEIGHT = dpi * 8.5 in Landscape Mode // if (w > z) {//10500 = 10.5" * 1000 & 85 = 8.5 * 10 & 110 = 11.0 * 10 & "/25)*25" rounds down to nearest 25 x = (((((z * 10500)/85) / rect.right) / 25) * 25); y = (((((w * 10500)/110) / rect.right) / 25) * 25); if (StartDoc(hDC, &di) > 0) { if (StartPage(hDC) > 0) {//the /100 is there because of the previous w/(8.5*10) and the 10.5*1000 SetStretchBltMode(hDC, HALFTONE); StretchBlt(hDC, 0, 0, (rect.right * x)/100, (rect.bottom * y)/100, hdcPrn, 0, 0, rect.right, rect.bottom, SRCCOPY); if (EndPage(hDC) > 0) EndDoc(hDC); } } } // else // MessageBox(hwnd, "You forgot to select Landscape Mode", NULL, MB_OK); SelectObject(hdcPrn, hObject); DeleteDC(hdcPrn); DeleteDC(hDC); DeleteObject(hPrnBitmap); free(pDevMode); } break; case ID_VIEW_OPTIONS_COLORS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; DialogBox(hInst, "COLORS", hwnd, ColorsProc); break; case ID_VIEW_OPTIONS_WAYPOINTPOSITIONDOTS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (DialogBox(hInst, "WAYPOINTDOTS", hwnd, DotProc)) InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_OPTIONS_ROUTETRACKLINEWIDTH: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; DialogBox(hInst, "LINEWIDTH", hwnd, LineWidthProc); break; case ID_VIEW_OPTIONS_EVERYTHINGELSE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; DialogBox(hInst, "PREFERENCES", hwnd, PreferencesProc); break; case ID_FILE_RUNSTREETSTRIPS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (FALSE == CreateProcess(Streets, NULL, NULL, NULL, FALSE, 0, NULL, Streets2, &si, &pi)) { if (FALSE == CreateProcess(Streets3, NULL, NULL, NULL, FALSE, 0, NULL, Streets4, &si, &pi)) MessageBox(hwnd, "Unable to run C:\\Program Files\\Microsoft Streets and Trips\\Streets.exe", NULL, MB_OK); } break; case ID_FILE_IMPORT_IMPORTSTPUSHPINS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (FALSE != GetOpenFileName(&ofn4)) { #define MAXPUSHPINS 500 #define CENTERDIST 0.087890630//I got this by trial-and-error #define SAVANNAH 78.002930//a 0 error longitude int ppnum, numofpushpins, pushpins[MAXPUSHPINS], begin; BYTE meridian; // BYTE buf[1024]; BYTE *buf; char name[MAXPUSHPINS][51]; char comment[MAXPUSHPINS][51]; unsigned char namestrlen[MAXPUSHPINS], commentstrlen[MAXPUSHPINS]; double radians, lat[MAXPUSHPINS], lon[MAXPUSHPINS]; double psplon, disttopsplon, closerightcenter, closeleftcenter, integerpart; BOOL firstime = TRUE; hFile3 = CreateFile(PushPins, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) {//if it's not a new file buf = (BYTE*)malloc(fileSize); ReadFile(hFile3, buf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile3); numofpushpins = *(int*) &buf[12]; if (numofpushpins > MAXPUSHPINS) numofpushpins = MAXPUSHPINS; x = 32;//first pushpin offset for (ppnum = 0; ppnum < numofpushpins; ppnum++) { pushpins[ppnum] = *(int*) &buf[x]; x += 4; meridian = buf[x]; x++; radians = *(double*) &buf[x]; lat[ppnum] = (radians * 180.0) / PI; x += 8; radians = *(double*) &buf[x]; lon[ppnum] = (radians * 180.0) / PI; if (meridian == 3)//west of 90th meridian lon[ppnum] = ((radians * 180.0) / PI) - 180.0; else if (meridian == 2)//east of 90th meridian {//correct for Microsoft's built-in error psplon = ((radians * 180.0) / PI); if (psplon > SAVANNAH) {//if west of it disttopsplon = psplon - SAVANNAH; modf((disttopsplon / CENTERDIST), &integerpart); closerightcenter = SAVANNAH + (integerpart * CENTERDIST); closeleftcenter = closerightcenter + CENTERDIST; } else {//if east of it disttopsplon = SAVANNAH - psplon; modf((disttopsplon / CENTERDIST), &integerpart); closeleftcenter = SAVANNAH - (integerpart * CENTERDIST); closerightcenter = closeleftcenter - CENTERDIST; } if ((psplon - closerightcenter) < (closeleftcenter - psplon)) lon[ppnum] = -(closerightcenter - (psplon - closerightcenter)); else lon[ppnum] = -(closeleftcenter + (closeleftcenter - psplon)); } else { free(buf); MessageBox(hwnd, "USAPhotoMaps doesn't work\non that side of the world.", ERROR, MB_OK); return 0; } x += 16; namestrlen[ppnum] = buf[x++]; begin = x; for (y = 0; (y < 50) && (y < (int)namestrlen[ppnum]); x += 2, y++) { name[ppnum][y] = buf[x]; } name[ppnum][y] = 0; x = begin + (namestrlen[ppnum] * 2); if (buf[x] == 0) x++; commentstrlen[ppnum] = buf[x++]; begin = x; for (y = 0; (y < 50) && (y < (int)commentstrlen[ppnum]); x += 2, y++) { comment[ppnum][y] = buf[x]; } comment[ppnum][y] = 0; x = begin + (commentstrlen[ppnum] * 2); if ((buf[x] == 0) && (buf[x+4] == 0)) x++; }//end of for (ppnum = 0; free(buf); tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (x = 0; x < TOTAL_LOCS; x++) if (NewLoc[x].EUTM == 0) break; EmptyLoc = x; InsertLoc = x; for (ppnum = 0; ppnum < numofpushpins; ppnum++) { Lat = lat[ppnum]; Lon = lon[ppnum]; LatRad = Lat * deg2rad; LonRad = Lon * deg2rad; LatLontoUTM(); if (UTMZone == tempUTMZone) { if ((commentstrlen[ppnum] == 0) && (namestrlen[ppnum] == 0)) continue; if (commentstrlen[ppnum] != 0) { strcpy(Location, comment[ppnum]); if ((sortbyname == FALSE) || (namestrlen[ppnum] == 0)) { for (x = 0; x < EmptyLoc; x++) { if (NewLoc[x].Location != 0) { if (_stricmp(NewLoc[x].Location, Location) > 0) { InsertLoc = x; EmptyLoc++; for (x = EmptyLoc; x > InsertLoc; x--) NewLoc[x] = NewLoc[x-1];//move to make room to insert new data break; } } } } } else Location[0] = 0; if (namestrlen[ppnum] != 0) { strcpy(Ident, name[ppnum]); if ((sortbyname) || (commentstrlen[ppnum] == 0)) { for (x = 0; x < EmptyLoc; x++) { if (NewLoc[x].Ident != 0) { if (_stricmp(NewLoc[x].Ident, Ident) > 0) { InsertLoc = x; EmptyLoc++; for (x = EmptyLoc; x > InsertLoc; x--) NewLoc[x] = NewLoc[x-1];//move to make room to insert new data break; } } } } } else Ident[0] = 0; if (x == EmptyLoc) { InsertLoc = x; EmptyLoc++; } NewLoc[InsertLoc].EUTM = UTMEasting; NewLoc[InsertLoc].NUTM = UTMNorthing; NewLoc[InsertLoc].UTMZone = UTMZone; ///---> FillWaypointArray(InsertLoc);//Lat & Lon are already known ///---> InsertLoc++; // sprintf(Error, "%s\n(GPS) Name: %s\nhas been added to the current waypoint file.", Location, Ident); // MessageBox(hwnd, Error, "New Waypoint", MB_OK); } else { if (firstime) { firstime = FALSE; sprintf(Error, "Before you can make a waypoint of this PushPin,\nyou'll need to select View -Go To Lat/Lon\nand enter: %f and %f\n\nor select File -Map Location,\nand open a map in UTM zone %i", Lat, Lon, UTMZone); MessageBox(hwnd, Error, "", MB_OK); } } }//end of for (ppnum = 0; Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; InvalidateRect(hwnd, &rect, FALSE); if (firstime) MessageBox(hwnd, "Done", "", MB_OK); } } } break; case ID_FILE_IMPORT_IMPORTFORERUNNERLOGBOOK: ofn2.lpstrFilter = "xml\0""*.xml\0""hst\0""*.hst\0""tcx\0""*.tcx\0""gpx\0""*.gpx\0\0"; if (FALSE != GetOpenFileName(&ofn2)) { HANDLE hFile = CreateFile(WaypointsFullPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { int TotalTracks = 0; char Hour, Minute, Second; char *pBuf; float Altitude; BOOL gotrackpoint, nolat, nolon, noalt, notime; HANDLE hXFile; pBuf = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hFile, pBuf, fileSize, &dwBytesRead, NULL); ofn.lpstrInitialDir = CurrentTrackDir; if (FALSE != GetSaveFileName(&ofn)) { InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; tnum = 0; SetCursor(hWaitingCursor); for (x = 0; x < 9; x++) PreCounting[x] = Down[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 5; x < 12; x++) Counting[x] = ' '; for (x = 0; x < 9; x++) PostCounting[x] = Track[x]; hwndCounter = CreateWindow(Counter, NULL, WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, (cxScreen/2)-75, (cyScreen/2)-((8*cyChar)/2), 150, 8*cyChar, hwnd, (HMENU)159, hInst, NULL); GetClientRect(hwndCounter, &counterRect); if (trak != NULL) { free(trak); trak = NULL; } numofTracks = 14400; trak = (struct TRAC*) calloc(1, (numofTracks+100) * sizeof(struct TRAC)); /* 39.205441 -120.204699 1870.863037 */ for (x = 0; x < (int)fileSize; x++) { if ((pBuf[x] == '<') && (pBuf[x+1] == 'T') && (pBuf[x+2] == 'r') && (pBuf[x+3] == 'a') && (pBuf[x+4] == 'c') && (pBuf[x+5] == 'k') && (pBuf[x+6] == 'p') && (pBuf[x+11] == '>')) {// gotrackpoint = TRUE; notime = TRUE; nolat = nolon = noalt = TRUE; x += 12; } else if ((notime) && (pBuf[x] == '<') && (pBuf[x+1] == 'T') && (pBuf[x+2] == 'i') && (pBuf[x+3] == 'm') && (pBuf[x+4] == 'e') && (pBuf[x+5] == '>')) {//')) { x += 7; trackbeg = TRUE;//to put 'New' } else if ((gottrk) && (pBuf[x] == '<') && (pBuf[x+1] == 't') && (pBuf[x+2] == 'r') && (pBuf[x+3] == 'k') && (pBuf[x+4] == 'p') && (pBuf[x+5] == 't')) { trkptrend = FALSE; Month = Day = Hour = Minute = Second = 0; ele = 0.0; for ( ; (x < (int)fileSize) && (pBuf[x] != '"'); x++) ; x++; Lat = atof(&pBuf[x]); for ( ; (x < (int)fileSize) && (pBuf[x] != '"'); x++) ; x++; for ( ; (x < (int)fileSize) && (pBuf[x] != '"'); x++) ; x++; Lon = atof(&pBuf[x]); for ( ; (x < (int)fileSize) && (pBuf[x] != '"'); x++) ; x++;// to '/>' or ... } else if ((gottrk) && (pBuf[x] == '<') && (pBuf[x+1] == 'e') && (pBuf[x+2] == 'l') && (pBuf[x+3] == 'e') && (pBuf[x+4] == '>')) { x += 5;//4; ele = (float)atof(&pBuf[x]); for ( ; (x < (int)fileSize) && (pBuf[x] != '>'); x++) ; } else if ((gottrk) && (pBuf[x] == '<') && (pBuf[x+1] == 't') && (pBuf[x+2] == 'i') && (pBuf[x+3] == 'm') && (pBuf[x+4] == 'e') && (pBuf[x+5] == '>')) { x += 8;//04-04-07T22:04:01Z Year = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; Month = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; Day = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; Hour = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; Minute = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; Second = ((pBuf[x] - '0') * 10) + (pBuf[x+1] - '0'); x += 3; for ( ; (x < (int)fileSize) && (pBuf[x] != '>'); x++) ; } else if (((gottrk) && (pBuf[x] == '<') && (pBuf[x+1] == '/') && (pBuf[x+2] == 't') && (pBuf[x+3] == 'r') && (pBuf[x+4] == 'k') && (pBuf[x+5] == 'p') && (pBuf[x+6] == 't') && (pBuf[x+7] == '>')) || ((gottrk) && (trkptrend == FALSE) && (pBuf[x] == '>') && (pBuf[x-1] == '/'))) { LatRad = Lat*deg2rad; LonRad = Lon*deg2rad; LatLontoUTM(); if (trackbeg) { trackbeg = FALSE; trak[tnum].newtrk = 1; } else trak[tnum].newtrk = 0; trak[tnum].NUTM = UTMNorthing; trak[tnum].EUTM = UTMEasting; trak[tnum].time = (UTMZone << 26) | (Month << 22) | (Day << 17) | (Hour << 12) | (Minute << 6) | Second; trak[tnum].year = Year; trak[tnum].alt = ele; tnum++; if (tnum > numofTracks) tnum = numofTracks; } }//end of for (x = 0; free(pBuf); fromTracks = TRUE; Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; SendMessage(hwnd, WM_USER, 0, 0); } CloseHandle(hFile); } } break; case ID_FILE_IMPORT_GEOCACHINGLOCFILES: ofn.lpstrFilter = " *.loc\0""*.loc\0\0"; ofn.lpstrFile = FullGeocaching; ofn.lpstrFileTitle = Geocaching; if (GetOpenFileName(&ofn)) { for (x = 0; FullGeocaching[x] != 0; x++) ; x -= 3; FullGeocaching[x++] = 'l';//just in case a .gpx file was clicked on FullGeocaching[x++] = 'o'; FullGeocaching[x] = 'c'; ofn2.lpstrFilter = "*.xml\0""*.xml\0\0"; if (FALSE != GetSaveFileName(&ofn2)) { char *tempBuf, *tempBuf2; HANDLE hFile = CreateFile(FullGeocaching, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { tempBuf = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hFile, tempBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); if (newLoc) SaveLocs(); if (newText) SaveText(); if (INVALID_HANDLE_VALUE == FindFirstFile(WaypointsFullPath, &fd))//from ofn2 { tempBuf2 = (char*)VirtualAlloc(NULL, (fileSize*2)+sizeof(Top), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); for (x = 0; Top[x] != 0; x++) tempBuf2[x] = Top[x]; ConvertLocToXML(tempBuf, tempBuf2, x, fileSize); VirtualFree(tempBuf2, 0, MEM_RELEASE); } else { hFile = CreateFile(WaypointsFullPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize2 = GetFileSize(hFile, NULL)) { tempBuf2 = (char*)VirtualAlloc(NULL, (fileSize*2)+fileSize2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hFile, tempBuf2, fileSize2, &dwBytesRead, NULL); CloseHandle(hFile); for (x = fileSize2; tempBuf2[x] != '<'; x--) ; ConvertLocToXML(tempBuf, tempBuf2, x, fileSize); VirtualFree(tempBuf2, 0, MEM_RELEASE); } } else CloseHandle(hFile); } VirtualFree(tempBuf, 0, MEM_RELEASE); } else CloseHandle(hFile); } } } ofn.lpstrFile = FullTracks; ofn.lpstrFileTitle = Tracks; ofn.lpstrFilter = " *.csv\0*.csv\0\0"; break; case ID_FILE_EXPORTTRACKSTOGPX: ofn.lpstrInitialDir = CurrentTrackDir; if (GetOpenFileName(&ofn)) { strcpy(GPX, Tracks); strcpy(FullGPX, FullTracks); x = ofn.nFileExtension; FullGPX[x++] = 'g'; FullGPX[x++] = 'p'; FullGPX[x] = 'x'; ofn.lpstrFilter = " *.gpx\0*.gpx\0\0"; ofn.lpstrFile = FullGPX; ofn.lpstrFileTitle = GPX; ofn.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_CREATEPROMPT; ofn.lpstrDefExt = gpx; if (GetSaveFileName(&ofn)) { hFile = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE != hFile) { if (fileSize = GetFileSize(hFile, NULL)) { DWORD DateTime; char TrackName[100]; char TrackPoint[150]; char NameBegin[] = ""; char NameEnd[] = "\r\n"; char TrackSeg[] = "\r\n"; char TrackSegEnd[] = "\r\n"; char TrackPoint1[] = ""; char TrackPoint4[] = "\r\n"; char TrackPoint5[] = "\r\n\r\n\r\n"; pTrackBuf = (unsigned char*)malloc(fileSize); ReadFile(hFile, pTrackBuf, fileSize, &dwBytesRead, NULL); numofTracks = ReadTracks(fileSize);//put tracks in trak free(pTrackBuf); pTrackBuf = NULL; CloseHandle(hFile); //write gpx format file hFile2 = CreateFile(FullGPX, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, Top, sizeof(Top)-1, &dwBytesWritten, NULL); for (x = 0, y = 0; NameBegin[x] != 0; x++, y++) TrackName[y] = NameBegin[x]; for (x = 0; GPX[x] != '.'; x++, y++) TrackName[y] = GPX[x]; for (x = 0; NameEnd[x] != 0; x++, y++) TrackName[y] = NameEnd[x]; WriteFile(hFile2, TrackName, y, &dwBytesWritten, NULL); for (z = 0; z < numofTracks; z++) { UTMNorthing = trak[z].NUTM; UTMEasting = trak[z].EUTM; UTMZone = (int)trak[z].time >> 26; UTMtoLatLon(); y = 0; if ((trak[z].newtrk != 0) || (z == 0)) { if (z != 0) for (x = 0; TrackSegEnd[x] != 0; x++, y++) TrackPoint[y] = TrackSegEnd[x]; for (x = 0; TrackSeg[x] != 0; x++, y++) TrackPoint[y] = TrackSeg[x]; } for (x = 0; TrackPoint1[x] != 0; x++, y++) TrackPoint[y] = TrackPoint1[x]; y += sprintf(&TrackPoint[y], "%.6f", Lat); for (x = 0; TrackPoint2[x] != 0; x++, y++) TrackPoint[y] = TrackPoint2[x]; y += sprintf(&TrackPoint[y], "%.6f", Lon); for (x = 0; TrackPoint3[x] != 0; x++, y++) TrackPoint[y] = TrackPoint3[x]; y += sprintf(&TrackPoint[y], "%.1f", trak[z].alt * 0.3048);//convert feet to meters DateTime = trak[z].time; TrackPoint4[29] = (char)((DateTime & 0x3F) / 10) + '0';//seconds TrackPoint4[30] = (char)((DateTime & 0x3F) % 10) + '0'; TrackPoint4[26] = (char)(((DateTime >> 6) & 0x3F) / 10) + '0';//minutes TrackPoint4[27] = (char)(((DateTime >> 6) & 0x3F) % 10) + '0'; TrackPoint4[23] = (char)(((DateTime >> 12) & 0x1F) / 10) + '0';//hours TrackPoint4[24] = (char)(((DateTime >> 12) & 0x1F) % 10) + '0'; TrackPoint4[20] = (char)(((DateTime >> 17) & 0x1F) / 10) + '0';//day TrackPoint4[21] = (char)(((DateTime >> 17) & 0x1F) % 10) + '0'; TrackPoint4[17] = (char)(((DateTime >> 22) & 0x0F) / 10) + '0';//month TrackPoint4[18] = (char)(((DateTime >> 22) & 0x0F) % 10) + '0'; TrackPoint4[14] = (char)(trak[z].year / 10) + '0';//year TrackPoint4[15] = (char)(trak[z].year % 10) + '0'; if (trak[z].year == 0) { TrackPoint4[12] = '0'; TrackPoint4[13] = '0'; } for (x = 0; TrackPoint4[x] != 0; x++, y++) TrackPoint[y] = TrackPoint4[x]; if (z == (numofTracks-1)) for (x = 0; TrackPoint5[x] != 0; x++, y++) TrackPoint[y] = TrackPoint5[x]; WriteFile(hFile2, TrackPoint, y, &dwBytesWritten, NULL); } CloseHandle(hFile2); MessageBox(hwnd, "Done", "", MB_OK); } else CloseHandle(hFile); } } ofn.lpstrFilter = " *.csv\0*.csv\0\0"; ofn.lpstrFile = FullTracks; ofn.lpstrFileTitle = Tracks; ofn.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn.lpstrDefExt = csv; } ofn.lpstrInitialDir = CurrentDir; break; case ID_FILES_CLOSE: SendMessage(hwnd, WM_CLOSE, 0, 0); break; case ID_VIEW_LATITUDELONGITUDE_DEGREES: MouseLoc = DEG; ClearLine(); CheckMenuItem (hMenu, Units, MF_UNCHECKED); Units = wParameter ; CheckMenuItem (hMenu, Units, MF_CHECKED); break; case ID_VIEW_LATITUDELONGITUDE_DEGREESMINUTES: MouseLoc = DEGMIN; ClearLine(); CheckMenuItem (hMenu, Units, MF_UNCHECKED) ; Units = wParameter ; CheckMenuItem (hMenu, Units, MF_CHECKED) ; break; case ID_VIEW_LATITUDELONGITUDE_DEGREESMINUTESSECONDS: MouseLoc = DEGMINSEC; ClearLine(); CheckMenuItem (hMenu, Units, MF_UNCHECKED) ; Units = wParameter ; CheckMenuItem (hMenu, Units, MF_CHECKED) ; break; case ID_VIEW_LATLON_UTM: MouseLoc = ITSUTM; ClearLine(); CheckMenuItem (hMenu, Units, MF_UNCHECKED) ; Units = wParameter ; CheckMenuItem (hMenu, Units, MF_CHECKED) ; break; case ID_VIEW_LATLON_USNG: MouseLoc = ITSUSNG; ClearLine(); CheckMenuItem (hMenu, Units, MF_UNCHECKED) ; Units = wParameter ; CheckMenuItem (hMenu, Units, MF_CHECKED) ; break; case ID_VIEW_MAPTYPE_PHOTO: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MapType == PHOTO) break; wastopo = TRUE; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; ModifyMenu(hMenu, ID_ZOOM_1METERPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_1METERPIXEL, PhotoZoom1); ModifyMenu(hMenu, ID_ZOOM_2METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_2METERSPIXEL, PhotoZoom2); ModifyMenu(hMenu, ID_ZOOM_4METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_4METERSPIXEL, PhotoZoom4); ModifyMenu(hMenu, ID_ZOOM_8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_8METERSPIXEL, PhotoZoom8); ModifyMenu(hMenu, ID_ZOOM_BIG8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_BIG8METERSPIXEL, PhotoZoomBig8); ModifyMenu(hMenu, ID_ZOOM_16METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_16METERSPIXEL, PhotoZoom16); ModifyMenu(hMenu, ID_ZOOM_32METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_32METERSPIXEL, PhotoZoom32); ModifyMenu(hMenu, ID_ZOOM_64METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_64METERSPIXEL, PhotoZoom64); if (MapType == TOPO) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_TOPO, MF_UNCHECKED); MapType = PHOTO; MapUnits = ID_VIEW_MAPTYPE_PHOTO; CheckMenuItem(hMenu, MapUnits, MF_CHECKED); if (Zoom == 1) {//4 meters/pixel if (FadeIncrement) fade = TRUE; MetersPerTile = 200; UncheckZoom(); Zoom = 3; PixelsPerTile = 50; } else if (Zoom == 2) {//8 meters/pixel if (zoom1to8) { MetersPerTile = 200; UncheckZoom(); Zoom = 4; PixelsPerTile = 25; } else { MetersPerTile = 1600; UncheckZoom(); Zoom = 5; PixelsPerTile = 200; } } else if (Zoom == 3) { MetersPerTile = 1600; UncheckZoom(); Zoom = 6; PixelsPerTile = 100; } else if (Zoom == 4) { MetersPerTile = 1600; UncheckZoom(); Zoom = 7; PixelsPerTile = 50; } else if (Zoom = 5) { MetersPerTile = 1600; UncheckZoom(); Zoom = 8; PixelsPerTile = 25; } } else//if (MapType == URBANAREA) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_COLOR, MF_UNCHECKED); MapType = PHOTO; MapUnits = ID_VIEW_MAPTYPE_PHOTO; CheckMenuItem(hMenu, MapUnits, MF_CHECKED); if (Zoom <= 3) { UncheckZoom(); Zoom = 1; PixelsPerTile = 200; MetersPerTile = 200; } else if (Zoom == 4) { UncheckZoom(); Zoom = 2; PixelsPerTile = 100; MetersPerTile = 200; } else if (Zoom == 5) { UncheckZoom(); Zoom = 3; PixelsPerTile = 50; MetersPerTile = 200; } else if (Zoom == 6) { if (zoom1to8) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; MetersPerTile = 200; } else { Zoom = 5; PixelsPerTile = 200; MetersPerTile = 1600; } UncheckZoom(); } else if (Zoom == 7) { UncheckZoom(); Zoom = 6; PixelsPerTile = 100; MetersPerTile = 1600; } else if (Zoom == 8) { UncheckZoom(); Zoom = 7; PixelsPerTile = 50; MetersPerTile = 1600; } } ShowZoom(); DoZoom(); ShowPhoto(); break; //ModifyMenu(hMenu, MenuID, MF_BYCOMMAND|MF_STRING, MenuID, Empty); case ID_VIEW_MAPTYPE_TOPO: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MapType == TOPO) break; // grid75 = FALSE; // CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; ModifyMenu(hMenu, ID_ZOOM_1METERPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_1METERPIXEL, TopoZoom1); ModifyMenu(hMenu, ID_ZOOM_2METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_2METERSPIXEL, TopoZoom2); ModifyMenu(hMenu, ID_ZOOM_4METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_4METERSPIXEL, TopoZoom4); ModifyMenu(hMenu, ID_ZOOM_8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_8METERSPIXEL, TopoZoom8); ModifyMenu(hMenu, ID_ZOOM_BIG8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_BIG8METERSPIXEL, TopoZoomBig8); ModifyMenu(hMenu, ID_ZOOM_16METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_16METERSPIXEL, TopoZoom16); ModifyMenu(hMenu, ID_ZOOM_32METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_32METERSPIXEL, TopoZoom32); ModifyMenu(hMenu, ID_ZOOM_64METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_64METERSPIXEL, TopoZoom64); if (MapType == PHOTO) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_PHOTO, MF_UNCHECKED); if ((Zoom == 1) || (Zoom == 2) || (Zoom == 3)) { if ((FadeIncrement) && (wastopo)) fade = TRUE; UncheckZoom(); Zoom = 1; PixelsPerTile = 200; MetersPerTile = 800; } else if ((Zoom == 4) || (Zoom == 5)) { UncheckZoom(); Zoom = 2; PixelsPerTile = 100; MetersPerTile = 800; } else if (Zoom == 6) { UncheckZoom(); Zoom = 3; PixelsPerTile = 50; MetersPerTile = 800; } else if (Zoom == 7) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; MetersPerTile = 800; } else if (Zoom == 8) { UncheckZoom(); Zoom = 5; PixelsPerTile = 200; MetersPerTile = 12800; } } else//if (MapType == URBANAREA) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_COLOR, MF_UNCHECKED); UncheckZoom(); if (Zoom <= 5) { Zoom = 1; PixelsPerTile = 200; } else if (Zoom == 6) { Zoom = 2; PixelsPerTile = 100; } else if (Zoom == 7) { Zoom = 3; PixelsPerTile = 50; } else if (Zoom == 8) { Zoom = 4; PixelsPerTile = 25; } MetersPerTile = 800; } MapType = TOPO; MapUnits = ID_VIEW_MAPTYPE_TOPO; CheckMenuItem(hMenu, MapUnits, MF_CHECKED); ShowZoom(); DoZoom(); ShowTopo(); break; //ModifyMenu(hMenu, MenuID, MF_BYCOMMAND|MF_STRING, MenuID, Empty); case ID_VIEW_MAPTYPE_COLOR: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MapType == URBANAREA) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; // grid75 = FALSE; // CheckMenuItem(hMenu, ID_FILE_SHOWELEVATIONSQUARES, MF_UNCHECKED); wastopo = FALSE; ModifyMenu(hMenu, ID_ZOOM_1METERPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_1METERPIXEL, UrbanZoom1); ModifyMenu(hMenu, ID_ZOOM_2METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_2METERSPIXEL, UrbanZoom2); ModifyMenu(hMenu, ID_ZOOM_4METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_4METERSPIXEL, UrbanZoom4); ModifyMenu(hMenu, ID_ZOOM_8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_8METERSPIXEL, UrbanZoom8); ModifyMenu(hMenu, ID_ZOOM_BIG8METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_BIG8METERSPIXEL, UrbanZoomBig8); ModifyMenu(hMenu, ID_ZOOM_16METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_16METERSPIXEL, UrbanZoom16); ModifyMenu(hMenu, ID_ZOOM_32METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_32METERSPIXEL, UrbanZoom32); ModifyMenu(hMenu, ID_ZOOM_64METERSPIXEL, MF_BYCOMMAND|MF_STRING, ID_ZOOM_64METERSPIXEL, UrbanZoom64); if (MapType == PHOTO) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_PHOTO, MF_UNCHECKED); if (Zoom == 1) { UncheckZoom(); Zoom = 3; PixelsPerTile = 50; MetersPerTile = 50; } else if (Zoom == 2) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; MetersPerTile = 50; } else if (Zoom == 3) { UncheckZoom(); Zoom = 5; PixelsPerTile = 200; MetersPerTile = 800; } else if ((Zoom == 4) || (Zoom == 5)) { UncheckZoom(); Zoom = 6; PixelsPerTile = 100; MetersPerTile = 800; } else if (Zoom == 6) { UncheckZoom(); Zoom = 7; PixelsPerTile = 50; MetersPerTile = 800; } else if ((Zoom == 7) || (Zoom == 8)) { UncheckZoom(); Zoom = 8; PixelsPerTile = 25; MetersPerTile = 800; } } else//if (MapType == TOPO) { CheckMenuItem(hMenu, ID_VIEW_MAPTYPE_TOPO, MF_UNCHECKED); UncheckZoom(); if (Zoom == 1) { Zoom = 5; PixelsPerTile = 200; MetersPerTile = 800; } else if (Zoom == 2) { Zoom = 6; PixelsPerTile = 100; MetersPerTile = 800; } else if (Zoom == 3) { Zoom = 7; PixelsPerTile = 50; MetersPerTile = 800; } else if (Zoom >= 4) { Zoom = 8; PixelsPerTile = 25; MetersPerTile = 800; } } MapType = URBANAREA; MapUnits = ID_VIEW_MAPTYPE_COLOR; CheckMenuItem(hMenu, MapUnits, MF_CHECKED); ShowZoom(); DoZoom(); ShowUrbanArea(); break; case ID_GOTO_LATLON: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MouseLoc == ITSUSNG) { if (DialogBox(hInst, "GOTOUSNG", hwnd, GotoUSNGProc) != EXIT) goto gotothere; } else if (DialogBox(hInst, "GOTO", hwnd, GotoProc) != EXIT) { ChangeZone(UTMZone, 5);//GoToProc BeginX = UTMEasting / MetersPerTile; BeginY = UTMNorthing / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; Waypoints[0] = 0; if (tempUTMZone != UTMZone) SendMessage(hwnd, WM_USER4, 0, 0); gotothere: tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; wastopo = FALSE; veryfirstime = TRUE; rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen SetCursor(hWaitingCursor); fromOpen = TRUE; SendMessage(hwnd, WM_USER, 0, 0);//was WM_USER2 SetCursor(hCursor); Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; lButtonDotX = (UTMEasting - ScreenLeft) * PixelsPerTile / MetersPerTile; lButtonDotY = (ScreenTop - UTMNorthing) * PixelsPerTile / MetersPerTile; fromgoto = TRUE; SendMessage(hwnd, WM_USER6, 0, 0); } break; case ID_VIEW_BRIGHTNESS_BRIGHTER: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (Increment != 60) Increment += 10; SendMessage(hwnd, WM_USER, 0, 0); InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_BRIGHTNESS_DARKER: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (Increment != -60) Increment -= 10; SendMessage(hwnd, WM_USER, 0, 0); InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_BRIGHTNESS_DEFAULT: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Increment = 0; SendMessage(hwnd, WM_USER, 0, 0); InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_GRID: if (gridon) { gridon = FALSE; CheckMenuItem(hMenu, ID_VIEW_GRID, MF_UNCHECKED); } else { gridon = TRUE; CheckMenuItem(hMenu, ID_VIEW_GRID, MF_CHECKED); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_CONTOURS: SendMessage(hwnd, WM_KEYDOWN, (WPARAM)'C', 0); break; case ID_VIEW_SHOWUSGSLANDMARKS: if (USGSBuf == NULL) { GetUSGSData(); } else { CheckMenuItem(hMenu, ID_VIEW_SHOWUSGSLANDMARKS, MF_UNCHECKED); VirtualFree(USGSBuf, 0, MEM_RELEASE); VirtualFree(PtrBuf, 0, MEM_RELEASE); USGSBuf = NULL; } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_SHOWWAYPOINTNAMES: if (shownamecomment) { shownamecomment = FALSE; CheckMenuItem(hMenu, ID_VIEW_SHOWWAYPOINTNAMES, MF_UNCHECKED); } else { shownamecomment = TRUE; CheckMenuItem(hMenu, ID_VIEW_SHOWWAYPOINTNAMES, MF_CHECKED); } SavenameCommentProc(); InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_TIGERLINES_INTERSTATES: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Uncheck(); if (hwndStreet != NULL) { DestroyWindow(hwndStreet); hwndStreet = NULL; } if (HighestFeatureType == 19) { HighestFeatureType = 0; showstreets = FALSE; FreepTiger(); // DestroyWindow(hwndStreet); } else { first = TRUE; showstreets = TRUE; HighestFeatureType = 19; CheckMenuItem(hMenu, ID_VIEW_TIGERLINES_INTERSTATES, MF_CHECKED); pt = (POINT*)VirtualAlloc(NULL, 750000*8, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_TIGERLINES_HIGHWAYS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Uncheck(); if (hwndStreet != NULL) { DestroyWindow(hwndStreet); hwndStreet = NULL; } if (HighestFeatureType == 39) { HighestFeatureType = 0; showstreets = FALSE; FreepTiger(); } else { first = TRUE; showstreets = TRUE; HighestFeatureType = 39; CheckMenuItem(hMenu, ID_VIEW_TIGERLINES_HIGHWAYS, MF_CHECKED); pt = (POINT*)VirtualAlloc(NULL, 750000*8, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_TIGERLINES_LOCALSTREETS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Uncheck(); if (hwndStreet != NULL) { DestroyWindow(hwndStreet); hwndStreet = NULL; } if (HighestFeatureType == 49) { HighestFeatureType = 0; showstreets = FALSE; FreepTiger(); } else { first = TRUE; showstreets = TRUE; HighestFeatureType = 49; CheckMenuItem(hMenu, ID_VIEW_TIGERLINES_LOCALSTREETS, MF_CHECKED); pt = (POINT*)VirtualAlloc(NULL, 750000*8, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_TIGERLINES_TRAILS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Uncheck(); if (hwndStreet != NULL) { DestroyWindow(hwndStreet); hwndStreet = NULL; } if (HighestFeatureType == 59) { HighestFeatureType = 0; showstreets = FALSE; FreepTiger(); } else { first = TRUE; showstreets = TRUE; HighestFeatureType = 59; CheckMenuItem(hMenu, ID_VIEW_TIGERLINES_TRAILS, MF_CHECKED); pt = (POINT*)VirtualAlloc(NULL, 750000*8, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_TIGERLINES_EVERYTHING: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; Uncheck(); if (hwndStreet != NULL) { DestroyWindow(hwndStreet); hwndStreet = NULL; } if (HighestFeatureType == 0xFF) { HighestFeatureType = 0; showstreets = FALSE; FreepTiger(); } else { first = TRUE; showstreets = TRUE; HighestFeatureType = 0xFF; CheckMenuItem(hMenu, ID_VIEW_TIGERLINES_EVERYTHING, MF_CHECKED); pt = (POINT*)VirtualAlloc(NULL, 750000*8, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); } InvalidateRect(hwnd, &rect, FALSE); break; case ID_VIEW_MAPOFUSA: if ((FALSE == usamap) && (maximized)) { if (INVALID_HANDLE_VALUE != FindFirstFile("StateOutlines\\*.txt", &fd)) { usamap = TRUE; USAIndex = -1; DestroyMenu(hMenu); hMenu4 = LoadMenu(hInst, "PRESSESC"); SetMenu(hwnd, hMenu4); hwndUSA = CreateWindow(USA, NULL, WS_CHILD | WS_VISIBLE, 0, 0, rect.right, rect.bottom, hwnd, (HMENU)543, hInst, NULL); } else { if (IDOK == MessageBox(hwnd, "Do you want to download 939 KBytes of\nState Outline data from jdmcox.com?", "FIRST", MB_OKCANCEL)) hDownloadStatesThread = _beginthreadex(NULL, 0, DownloadStateOutlineThread, hwnd, 0, &idThread10); else InvalidateRect(hwnd, &rect, FALSE); } } break; case ID_VIEW_BIGJPEG: if (Pixels == NULL) { if (GetOpenFileName(&ofn6)) { if (INVALID_HANDLE_VALUE != FindFirstFile(ofn6.lpstrFile, &fd)) { DestroyMenu(hMenu); hMenu4 = LoadMenu(hInst, "PRESSESC"); SetMenu(hwnd, hMenu4); hwndBig = CreateWindow(Big, NULL,//BigProc WS_CHILD | WS_VISIBLE, 0, 0, rect.right, rect.bottom, hwnd, (HMENU)345, hInst, NULL); } } } break; case ID_APRS_HELP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (autoLoc == FALSE) { pAPRSHelp = NULL; hFile = CreateFile(APRSHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (APRSHelpSize = GetFileSize(hFile, NULL)) { pAPRSHelp = (char *) malloc(APRSHelpSize+1); if (pAPRSHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pAPRSHelp[APRSHelpSize] = 0; ReadFile(hFile, pAPRSHelp, APRSHelpSize, &dwBytesRead, NULL); hMenu3 = CreateMenu();//to override parent menu bar hwndAPRS = CreateWindow(Instruct, "APRSHelp.txt", WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen/2-320, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), cyScreen-(cyChar*3), NULL, hMenu3, hInst, NULL); SetWindowText(hwndInstr, pAPRSHelp); SetFocus(hwndInstr); } CloseHandle (hFile); } else MessageBox(hwnd, NoAPRSFile, NULL, MB_OK); } break; //send "KI6NLA>APZUSA,TCPIP*:3724.44N/12206.98W-USAPhotoMaps" case ID_APRS_INTERNETNETWORK_TRANSMITLOCATION: if (transmitto == TRANSMITNONE) { MessageBox(hwnd, "Select Send Home or GPS Location\nin Setup to Transmit Location.", "", MB_OK); break; } if ((transmitto == TRANSMITGPS) && (pos == 0)) { MessageBox(hwnd, "No GPS position has been received yet.", "", MB_OK); break; } x = GetInitString(); Filter[x++] = '\n'; Filter[x] = 0; FilterLen = x;//strlen(Filter); if ((MyCall[0]) && (_stricmp(MyCall, "NOCALL"))) { if (transmitto == TRANSMITHOME) FillMYCALLUNPROTOBTEXTKISS(); for (x = 0; MyCall[x] != '\0'; x++) MyLoc[x] = MyCall[x]; for (y = 0; InternetUNPROTO[y] != '\0'; x++, y++) MyLoc[x] = InternetUNPROTO[y]; for (y = 6; BTEXT[y] != '\0'; x++, y++) MyLoc[x] = BTEXT[y]; MyLoc[x++] = '\n'; MyLoc[x] = 0; sendmyloc = TRUE; if (DialogBox(hInst, "APRSSERVER", hwnd, APRSServerProc)) //********************** hAPRSThread2 = _beginthreadex(NULL, 0, aprsISthread2, hwnd, 0, &idThread16); //********************** } else MessageBox(hwnd, CallsignError, ERROR, MB_OK); break; case ID_APRS_INTERNETNETWORK_ACTASANIGATE: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASANIGATE, MF_BYCOMMAND)) { if (IDNO == MessageBox(hwnd, "Are you familiar with the consequences\nof sending to the Internet everything\nyour transceiver receives?\n\n(read APRS -HELP)", "Serve as I-Gate", MB_YESNO|MB_DEFBUTTON2)) break; sendmyloc = TRUE; if (DialogBox(hInst, "APRSSERVER", hwnd, APRSServerProc)) { x = GetInitString(); Filter[x++] = '\n'; Filter[x] = 0; FilterLen = x; CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASANIGATE, MF_CHECKED); if (IgatewsaData.szSystemStatus[0] == '\0') WSAStartup(0x0202, &IgatewsaData); else dontcleanup = TRUE; if (INVALID_SOCKET == (s3 = socket(AF_INET, SOCK_STREAM, IPPROTO_IP))) { sprintf(Error, "Bad socket(%ld)\nLine %ld", WSAGetLastError(), __LINE__); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } if (NULL == (he = gethostbyname(Tier2Server))) { closesocket(s3); sprintf(Error, "Bad host(%ld)", WSAGetLastError()); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } else { memcpy(&dest.sin_addr, he->h_addr_list[0], he->h_length); dest.sin_family = he->h_addrtype; dest.sin_port = htons(14580);// 10152 for concord.aprs.net } if (SOCKET_ERROR == connect(s3, (struct sockaddr*)&dest, sizeof(SOCKADDR))) { sprintf(Error, "Connect error %ld\n(line %d)", WSAGetLastError(), __LINE__); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } else { PacketSize = recv(s3, SmallBuf2, 1024, 0); if ((PacketSize == 0) || (SOCKET_ERROR == PacketSize)) { sprintf(Error, "Bad initial receive %ld\n(line %d)", WSAGetLastError(), __LINE__); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } if (FilterLen) { if (SOCKET_ERROR == send(s3, Filter, FilterLen, 0)) { sprintf(Error, "Send error %ld\n(line %d)", WSAGetLastError(), __LINE__); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } } PacketSize = recv(s3, SmallBuf2, 1024, 0); if ((PacketSize == 0) || (SOCKET_ERROR == PacketSize)) { sprintf(Error, "Receive error %ld\n(line %d)", WSAGetLastError(), __LINE__); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); break; } } igate = TRUE; } } else { CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASANIGATE, MF_UNCHECKED); MessageBox(hwnd, "Closing connection", "Igate", MB_OK); if (s3 != INVALID_SOCKET){ closesocket(s3); s3 = INVALID_SOCKET; } if (!dontcleanup) { WSACleanup(); IgatewsaData.szSystemStatus[0] = '\0'; dontcleanup = TRUE; } if (igate) igate = FALSE; } break; case ID_APRS_RECEIVEINTERNETDATA: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_RECEIVEINTERNETDATA, MF_BYCOMMAND)) { if ((gettingsaved) || (gettingreceived)) { MessageBox(hwnd, Simultaneously, "Sorry...", MB_OK); break; } // if (aprs == FALSE) { gettinginternet = TRUE; CheckMenuItem(hMenu, ID_APRS_RECEIVEINTERNETDATA, MF_CHECKED); aprsISend = 0; isaprslinebeg = -1; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; UTMNorthing = ScreenTop; UTMEasting = ScreenLeft; UTMtoLatLon(); modf(Lat, &Lat1); lat1 = (int)Lat1+1; _itoa(lat1, LAT1, 10); modf(Lon, &Lon1); lon1 = (int)Lon1-1; _itoa(lon1, LON1, 10); UTMNorthing = ScreenBottom; UTMEasting = ScreenRight; UTMtoLatLon(); modf(Lat, &Lat1); lat1 = (int)Lat1; _itoa(lat1, LAT2, 10); modf(Lon, &Lon1); lon1 = (int)Lon1; _itoa(lon1, LON2, 10); Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; x = GetInitString(); for (y = 0; Filter4[y] != 0; x++, y++) Filter[x] = Filter4[y]; for (y = 0; LAT1[y] != 0; y++, x++) Filter[x] = LAT1[y]; Filter[x++] = '/'; for (y = 0; LON1[y] != 0; y++, x++) Filter[x] = LON1[y]; Filter[x++] = '/'; for (y = 0; LAT2[y] != 0; y++, x++) Filter[x] = LAT2[y]; Filter[x++] = '/'; for (y = 0; LON2[y] != 0; y++, x++) Filter[x] = LON2[y]; for (y = 0; Filter5[y] != 0; y++, x++) Filter[x] = Filter5[y]; Filter[x++] = '\n'; Filter[x] = 0; FilterLen = x; sendmyloc = FALSE; //inaprs = TRUE; if (DialogBox(hInst, "APRSSERVER", hwnd, APRSServerProc)) { //********************** ResetEvent(hAPRSISEvent); hAPRSThread = _beginthreadex(NULL, 0, aprsISthread, hwnd, 0, &idThread15); Sleep(500); //********************** } else goto nointernet; } } else { nointernet: gettinginternet = FALSE; CheckMenuItem(hMenu, ID_APRS_RECEIVEINTERNETDATA, MF_UNCHECKED); SetEvent(hAPRSISEvent);//close APRSISthread if ((aprsi) && (aprsimulate == FALSE)) { SaveAPRSlog(); SaveAPRSlogAsText(); } aprsi = Aprsi = aprs = 0;//FALSE InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } break; case ID_APRS_INTERNETNETWORK_ENTERIPADDRESSMANUALLY: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ENTERIPADDRESSMANUALLY, MF_BYCOMMAND)) { if (DialogBox(hInst, "SECRETIP", hwnd, SecretIPProc)) { CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ENTERIPADDRESSMANUALLY, MF_CHECKED); aprsISend = 0; isaprslinebeg = -1; linend = -3; fromctrli = TRUE; ResetEvent(hAPRSISEvent); hAPRSThread = _beginthreadex(NULL, 0, aprsISthread, hwnd, 0, &idThread15); Sleep(500); } } else { CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ENTERIPADDRESSMANUALLY, MF_UNCHECKED); SetEvent(hAPRSISEvent);//close APRSISthread } break; case ID_APRS_INTERNETNETWORK_ACTASSERVER: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASSERVER, MF_BYCOMMAND)) { if (0 == WSAStartup(0x0202, &wsaData)) { sListen = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if (sListen != INVALID_SOCKET) { if (0 == WSAAsyncSelect(sListen, hwnd, WM_APRS_SERVER, FD_ACCEPT|FD_READ|FD_WRITE)) { saServer.sin_family = AF_INET; saServer.sin_port = htons(serverPort); saServer.sin_addr.s_addr = INADDR_ANY; if (0 == bind(sListen, (LPSOCKADDR)&saServer, sizeof(struct sockaddr))) { if (0 == listen(sListen, SOMAXCONN)) { CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASSERVER, MF_CHECKED); MessageBox(hwnd, "Accepting connections on port 1448.", "", MB_OK); } else MessageBox(hwnd, "Error 5", ERROR, MB_OK); } } else MessageBox(hwnd, "Error 3", ERROR, MB_OK); } else MessageBox(hwnd, "Error 2", ERROR, MB_OK); } else MessageBox(hwnd, "Error 1", ERROR, MB_OK); } else { WSACleanup(); CheckMenuItem(hMenu, ID_APRS_INTERNETNETWORK_ACTASSERVER, MF_UNCHECKED); } break; case ID_APRS_SAVED_DATA: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_SAVED_DATA, MF_BYCOMMAND)) { if ((gettinginternet) || (gettingreceived)) { MessageBox(hwnd, Simultaneously, "Sorry...", MB_OK); break; } CheckMenuItem(hMenu, ID_APRS_SAVED_DATA, MF_CHECKED); gettingsaved = aprsimulate = TRUE; goto aprs; } else { gettingsaved = aprsimulate = FALSE; CheckMenuItem(hMenu, ID_APRS_SAVED_DATA, MF_UNCHECKED); DestroyWindow(hwndStationsDlg); hwndStationsDlg = NULL; DestroyWindow(hwndStationInfoDlg); hwndStationInfoDlg = NULL; DestroyWindow(hwndMessageDlg); hwndMessageDlg = NULL; aprsi = Aprsi = aprs = 0;//FALSE InvalidateRect(hwnd, &rect, FALSE); } break; // case ID_APRS_SHOWRANGECIRCLE: // if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_SHOWRANGECIRCLE, MF_BYCOMMAND)) // { // CheckMenuItem(hMenu, ID_APRS_SHOWRANGECIRCLE, MF_CHECKED); // showrangecircles = TRUE; // } // else // { // CheckMenuItem(hMenu, ID_APRS_SHOWRANGECIRCLE, MF_UNCHECKED); // showrangecircles = FALSE; // } // InvalidateRect(hwnd, &rect, FALSE); // break; case ID_APRS_EXCLUDEINCLUDELISTS_CALLSIGNS: if (DialogBox(hInst, "EXCLUDESYMBOLSCALLS", hwnd, ExcludeSymbolsCallsProc)) InvalidateRect(hwnd, &rect, FALSE); break; case ID_APRS_EXCLUDEINCLUDELISTS_TRACKS: if (DialogBox(hInst, "EXCLUDETRACKS", hwnd, ExcludeTracksProc)) InvalidateRect(hwnd, &rect, FALSE); break; case APRSCOMMPORT: if (DialogBox(hInst, "COMMPORT", hwnd, APRSCommPortProc)) { int aprscommportlen; char *pUSAPMbuf; hFile = CreateFile(USAPMini, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); pUSAPMbuf = (char*)malloc(fileSize); ReadFile(hFile, pUSAPMbuf, fileSize, &dwBytesRead, NULL); for (x = 0; x < (int)fileSize; x++) {//APRSCommPort=1 if (pUSAPMbuf[x] == '=') { if ((pUSAPMbuf[x-1] == 't') && (pUSAPMbuf[x-4] == 'P') && (pUSAPMbuf[x-8] == 'C') && (pUSAPMbuf[x-12] == 'A')) {//found "APRSCommPort=1\r\n" CloseHandle(hFile); hFile = CreateFile(USAPMini, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, pUSAPMbuf, x+1, &dwBytesWritten, NULL); if (APRSCommPort[1]) aprscommportlen = 2; else aprscommportlen = 1; WriteFile(hFile, APRSCommPort, aprscommportlen, &dwBytesWritten, NULL); for (y = x+1; (y < fileSize) && (pUSAPMbuf[y] != '\r'); y++) ; WriteFile(hFile, &pUSAPMbuf[y], fileSize-y, &dwBytesWritten, NULL); /* if (APRSCommPort[1] == 0) {//new port number is 1 byte if (pUSAPMbuf[x+2] == '\r')//old port number was 1 byte { pUSAPMbuf[x+1] = APRSCommPort[0]; WriteFile(hFile, pUSAPMbuf, fileSize, &dwBytesWritten, NULL); } else {//old port number was 2 bytes WriteFile(hFile, pUSAPMbuf, x+1, &dwBytesWritten, NULL); WriteFile(hFile, &APRSCommPort[0], 1, &dwBytesWritten, NULL); WriteFile(hFile, &pUSAPMbuf[x+3], fileSize-x-3, &dwBytesWritten, NULL); } } else//if (APRSCommPort[1] != 0) {//new port number is 2 bytes if (pUSAPMbuf[x+2] != '\r') {//old port number was 2 bytes *(WORD*)&pUSAPMbuf[x+1] = *(WORD*)&APRSCommPort[0]; WriteFile(hFile, pUSAPMbuf, fileSize, &dwBytesWritten, NULL); } else {//old port number was 1 byte WriteFile(hFile, pUSAPMbuf, x+1, &dwBytesWritten, NULL); WriteFile(hFile, &APRSCommPort[0], 2, &dwBytesWritten, NULL); WriteFile(hFile, &pUSAPMbuf[x+2], fileSize-x-2, &dwBytesWritten, NULL); } } */ CloseHandle(hFile); break; } } } if (x == fileSize)//not found { WriteFile(hFile, APRSCOM, 13, &dwBytesWritten, NULL); if (APRSCommPort[1] == 0) x = 1; else x = 2; WriteFile(hFile, APRSCommPort, x, &dwBytesWritten, NULL); WriteFile(hFile, "\r\n", 2, &dwBytesWritten, NULL); CloseHandle(hFile); } free(pUSAPMbuf); } } break; case ID_APRS_BAUD_4800: APRSBaud = 4800; ChangeAPRSBaud(ID_APRS_BAUD_4800); break; case ID_APRS_BAUD_9600: APRSBaud = 9600; ChangeAPRSBaud(ID_APRS_BAUD_9600); break; case ID_APRS_BAUD_19200: APRSBaud = 19200; ChangeAPRSBaud(ID_APRS_BAUD_19200); break; case ID_APRS_BAUD_38400: APRSBaud = 38400; ChangeAPRSBaud(ID_APRS_BAUD_38400); break; case ID_APRS_BAUD_57600: APRSBaud = 57600; ChangeAPRSBaud(ID_APRS_BAUD_57600); break; case ID_APRS_BAUD_115200: APRSBaud = 115200; ChangeAPRSBaud(ID_APRS_BAUD_115200); break; /* case ID_APRS_TRANSLATEKISSDATA: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_TRANSLATEKISSDATA, MF_BYCOMMAND)) { CheckMenuItem(hMenu, ID_APRS_TRANSLATEKISSDATA, MF_CHECKED); kiss = TRUE; FillMYCALLUNPROTOBTEXTKISS(); if ((inaprs) && (transmitto != TRANSMITNONE)) { WriteFile(hAPRSComm, Kiss, KissLen, &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); } } else { CheckMenuItem(hMenu, ID_APRS_TRANSLATEKISSDATA, MF_UNCHECKED); kiss = FALSE; } break; */ case ID_APRS_SETUPCOMM_SERVERIPPORT: // DialogBox(hInst, "SERVER", hwnd, LocalServerProc); MessageBox(hwnd, "This is no longer necessary.\nWhen -Act as a Server is selected,\nthe port will be 1448.", "", MB_OK); break; case ID_APRS_RECEIVED_DATA: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_RECEIVED_DATA, MF_BYCOMMAND)) { if ((gettinginternet) || (gettingsaved)) { MessageBox(hwnd, Simultaneously, "Sorry...", MB_OK); break; } gettingreceived = TRUE; aprsimulate = FALSE; } aprs: if (inaprs == FALSE) { msgPtr = 0; stationPtr = 0; for (x = 0; x < 10240; x += 4) *(DWORD*)&Stations[x] = 0; NumOfStations = 0; if ((debug == FALSE) && (aprsimulate)) {//normal method - read .dta file instead of .txt file ofn5.lpstrFilter = " APRS log??.dta\0""APRS log??.dta\0\0"; ofn5.lpstrFile = APRStxt;//full filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (GetOpenFileName(&ofn5)) { int Aprsize; hAPRSFile = CreateFile(APRStxt, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); Aprsi = GetFileSize(hAPRSFile, NULL); Aprsize = 100; Aprsi /= Aprsize; for (x = 0, y = 0; x < Aprsi; x++) { ReadFile(hAPRSFile, &Aprs[x], Aprsize, &dwBytesRead, NULL); for (w = 0; w < x; w++) { for (z = 0; Aprs[x].Call[z] != 0; z++) if (Aprs[w].Call[z] != Aprs[x].Call[z]) break; if ((Aprs[w].Call[z] == 0) && (Aprs[x].Call[z] == 0)) break;//found station } if (w == x) { for (z = 0; (Aprs[x].Call[z] != 0) && (y < 10240); y++, z++) Stations[y] = Aprs[x].Call[z]; /*//don't show time here if saved data Stations[y++] = TAB; Stations[y++] = (Aprs[x].Time / 1000) + '0'; Stations[y++] = ((Aprs[x].Time % 1000) / 100) + '0'; Stations[y++] = ':'; Stations[y++] = ((Aprs[x].Time % 100) / 10) + '0'; Stations[y++] = (Aprs[x].Time % 10) + '0'; Stations[y++] = ':'; Stations[y++] = '0'; Stations[y++] = '0'; Stations[y++] = 'z'; */ if (y < 10240) { Stations[y++] = 0; NumOfStations++; } } } stationPtr = y; CloseHandle(hAPRSFile); aprs = TRUE; } else { CheckMenuItem(hMenu, ID_APRS_SAVED_DATA, MF_UNCHECKED); gettingsaved = aprsimulate = FALSE; aprsi = Aprsi = aprs = 0;//FALSE } InvalidateRect(hwnd, &rect, FALSE); break;//done } if ((aprsimulate) || ((APRSBaud != 0) && (APRSCommPort[0] != 0))) { if (aprsimulate == FALSE) inaprs = TRUE; aprsi = Aprsi = 0; aprs = FALSE; // tnc = TRUE; toHwndComm = 0; for (y = 0; y < MAXAPRS; y++) {//initialize Aprs[y].UTMN = 0; Aprs[y].DescOrWx[0] = 0; Aprs[y].Status[0] = 0; Aprs[y].RedDot = 0; } if (kiss) {//initialize: kPtr = KISSEND; gotfesc = FALSE; } if (!aprsimulate) { tnc = TRUE; CheckMenuItem(hMenu, ID_APRS_RECEIVED_DATA, MF_CHECKED); if (hAPRSComm != INVALID_HANDLE_VALUE) {//just in case CloseHandle(hAPRSComm); hAPRSComm = INVALID_HANDLE_VALUE; } if (!aprsimulate) GetAPRSCommHandle(); FillMYCALLUNPROTOBTEXTKISS(); // hwndAPRSDlg = CreateDialog(hInst, "APRSEDIT", hwnd, APRSEditProc); firsttx = TRUE; ResetEvent(hAPRSEvent); //********************** hAPRSThread = _beginthreadex(NULL, 0, APRSCommThread, NULL, 0, &idThread14); Sleep(500); //********************** } else//if (aprsimulate) - for debugging { ofn5.lpstrFilter = " APRS log??.txt\0""APRS log??.txt\0\0"; ofn5.lpstrFile = APRStxt;//full filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (GetOpenFileName(&ofn5)) { ResetEvent(hAPRSEvent); hAPRSThread = _beginthreadex(NULL, 0, APRSCommThread, NULL, 0, &idThread14); Sleep(500); } } } else { MessageBox(hwnd, "TNC Baud and/or\nComm Port to TNC\nisn't set.", ERROR, MB_OK); CheckMenuItem(hMenu, ID_APRS_RECEIVED_DATA, MF_UNCHECKED); inaprs = FALSE; } } else//if (inaprs) { gettingreceived = FALSE; CheckMenuItem(hMenu, ID_APRS_RECEIVED_DATA, MF_UNCHECKED); DestroyWindow(hwndAPRSDlg); hwndAPRSDlg = NULL; DestroyWindow(hwndStationsDlg); hwndStationsDlg = NULL; DestroyWindow(hwndStationInfoDlg); hwndStationInfoDlg = NULL; DestroyWindow(hwndMessageDlg); hwndMessageDlg = NULL; if (hAPRSThread) { if (kiss) {//first get out of KISS // SendMessage(hwnd, WM_COMMAND, ID_APRS_TRANSLATEKISSDATA, 0); // CheckMenuItem(hMenu, ID_APRS_TRANSLATEKISSDATA, MF_UNCHECKED); WriteFile(hAPRSComm, "\xC0\xFF\xC0", 3, &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); } WriteFile(hAPRSComm, Shutdown, 14, &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); shutitdown = TRUE; break;//doesn't shut it down if no radio } tnc = inaprs = 0; if ((!gettinginternet) && (!gettingsaved)) { aprsi = Aprsi = aprs = 0;//FALSE InvalidateRect(hwnd, &rect, FALSE); } } break; case ID_APRS_TRANSMISSIONS: if (inaprs) { if (hwndComm) DestroyWindow(hwndAPRSDlg); FillMYCALLUNPROTOBTEXTKISS(); hwndAPRSDlg = CreateDialog(hInst, "APRSEDIT", hwnd, APRSEditProc); } break; case ID_APRS_POSITION_SETUP: if (DialogBox(hInst, "APRS", hwnd, APRSProc)) { hFile = CreateFile(USAPMini, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) {//get USAPM.ini data if (fileSize = GetFileSize(hFile, NULL)) { pUSAPMbufIn = (char*)malloc(fileSize+1000); ReadFile(hFile, pUSAPMbufIn, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); mycallnotfound = homelatlonnotfound = transmittonotfound = homesymbolnotfound = gpssymbolnotfound = destinationnotfound = commentnotfound = beaconnotfound = sbnotfound = compressnotfound = TRUE; for (x = 0; x < (int)fileSize; x++) { if (pUSAPMbufIn[x] == '=') { if ((pUSAPMbufIn[x-6] == 'M') && (pUSAPMbufIn[x-5] == 'y') && (pUSAPMbufIn[x-4] == 'C') && (pUSAPMbufIn[x-3] == 'a')) {//MyCall= if (mycallnotfound) { mycallnotfound = FALSE; fileSize = AddtoUSAPMini(MyCall); } } if ((pUSAPMbufIn[x-10] == 'H') && (pUSAPMbufIn[x-9] == 'o') && (pUSAPMbufIn[x-6] == 'L') && (pUSAPMbufIn[x-5] == 'a')) {//HomeLatLon= if (HomeLatLon[0] && (homelatlonnotfound)) { homelatlonnotfound = FALSE; fileSize = AddtoUSAPMini(HomeLatLon); } } if ((pUSAPMbufIn[x-10] == 'T') && (pUSAPMbufIn[x-9] == 'r') && (pUSAPMbufIn[x-4] == 'i') && (pUSAPMbufIn[x-3] == 't')) {//TransmitTo= if (transmittonotfound) { transmittonotfound = FALSE; if (transmitto == TRANSMITHOME) fileSize = AddtoUSAPMini(Home); else if (transmitto == TRANSMITGPS) fileSize = AddtoUSAPMini(GPS); else if (transmitto == TRANSMITNONE) fileSize = AddtoUSAPMini(None); } } if ((pUSAPMbufIn[x-10] == 'H') && (pUSAPMbufIn[x-6] == 'S') && (pUSAPMbufIn[x-5] == 'y') && (pUSAPMbufIn[x-4] == 'm')) {//"HomeSymbol=" if (HomeSymbol[0] && (homesymbolnotfound)) { homesymbolnotfound = FALSE; fileSize = AddtoUSAPMini(HomeSymbol); } } if ((pUSAPMbufIn[x-9] == 'G') && (pUSAPMbufIn[x-8] == 'P') && (pUSAPMbufIn[x-7] == 'S') && (pUSAPMbufIn[x-6] == 'S')) {//"GPSSymbol=" if (GPSSymbol[0] && (gpssymbolnotfound)) { gpssymbolnotfound = FALSE; fileSize = AddtoUSAPMini(GPSSymbol); } } if ((pUSAPMbufIn[x-11] == 'D') && (pUSAPMbufIn[x-10] == 'e') && (pUSAPMbufIn[x-5] == 'a') && (pUSAPMbufIn[x-4] == 't')) {//"Destination=" if (Destination[0] && (destinationnotfound)) { destinationnotfound = FALSE; fileSize = AddtoUSAPMini(Destination); } } if ((pUSAPMbufIn[x-8] == '\n') && (pUSAPMbufIn[x-7] == 'C') && (pUSAPMbufIn[x-6] == 'o') && (pUSAPMbufIn[x-2] == 'n') && (pUSAPMbufIn[x-1] == 't')) {//"Comment=" if (Comment[0] && (commentnotfound)) { commentnotfound = FALSE; fileSize = AddtoUSAPMini(Comment); } } if ((pUSAPMbufIn[x-6] == 'B') && (pUSAPMbufIn[x-5] == 'E') && (pUSAPMbufIn[x-4] == 'A')) {//"BEACON=" if (Beacon[0] && (beaconnotfound)) { beaconnotfound = FALSE; fileSize = AddtoUSAPMini(Beacon); } } if ((pUSAPMbufIn[x-9] == 'B') && (pUSAPMbufIn[x-14] == 'S')) {//"SmartBeaconing=" sbnotfound = FALSE; if (smartbeaconing) { pUSAPMbufIn[x+1] = 'Y'; pUSAPMbufIn[x+2] = 'E'; pUSAPMbufIn[x+3] = 'S'; } else { pUSAPMbufIn[x+1] = 'N'; pUSAPMbufIn[x+2] = 'O'; pUSAPMbufIn[x+3] = ' '; } } if ((pUSAPMbufIn[x-10] == 'C') && (pUSAPMbufIn[x-9] == 'o') && (pUSAPMbufIn[x-8] == 'm') && (pUSAPMbufIn[x-7] == 'p')) {//"Compressit=" compressnotfound = FALSE; if (compressit) { pUSAPMbufIn[x+1] = 'Y'; pUSAPMbufIn[x+2] = 'E'; pUSAPMbufIn[x+3] = 'S'; } else { pUSAPMbufIn[x+1] = 'N'; pUSAPMbufIn[x+2] = 'O'; pUSAPMbufIn[x+3] = ' '; } } } } if (mycallnotfound) { for (x = fileSize, y = 0; APRSMyCall[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSMyCall[y]; for (y = 0; MyCall[y] != 0; x++, y++) pUSAPMbufIn[x] = MyCall[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((HomeLatLon[0]) && (homelatlonnotfound)) { for (x = fileSize, y = 0; APRSHomeLatLon[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSHomeLatLon[y]; for (y = 0; HomeLatLon[y] != 0; x++, y++) pUSAPMbufIn[x] = HomeLatLon[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if (transmittonotfound) { for (x = fileSize, y = 0; APRSTransmitTo[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSTransmitTo[y]; if (transmitto == TRANSMITHOME) for (y = 0; Home[y] != 0; x++, y++) pUSAPMbufIn[x] = Home[y]; else if (transmitto == TRANSMITGPS) for (y = 0; GPS[y] != 0; x++, y++) pUSAPMbufIn[x] = GPS[y]; else if (transmitto == TRANSMITNONE) for (y = 0; GPS[y] != 0; x++, y++) pUSAPMbufIn[x] = None[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((HomeSymbol[0]) && (homesymbolnotfound)) { for (x = fileSize, y = 0; APRSHomeSymbol[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSHomeSymbol[y]; for (y = 0; HomeSymbol[y] != 0; x++, y++) pUSAPMbufIn[x] = HomeSymbol[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((GPSSymbol[0]) && (gpssymbolnotfound)) { for (x = fileSize, y = 0; APRSGPSSymbol[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSGPSSymbol[y]; for (y = 0; GPSSymbol[y] != 0; x++, y++) pUSAPMbufIn[x] = GPSSymbol[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((Destination[0]) && (destinationnotfound)) { for (x = fileSize, y = 0; APRSDestination[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSDestination[y]; for (y = 0; Destination[y] != 0; x++, y++) pUSAPMbufIn[x] = Destination[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((Comment[0]) && (commentnotfound)) { for (x = fileSize, y = 0; APRSComment[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSComment[y]; for (y = 0; Comment[y] != 0; x++, y++) pUSAPMbufIn[x] = Comment[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if ((Beacon[0]) && (beaconnotfound)) { for (x = fileSize, y = 0; APRSBeacon[y] != 0; x++, y++) pUSAPMbufIn[x] = APRSBeacon[y]; for (y = 0; Beacon[y] != 0; x++, y++) pUSAPMbufIn[x] = Beacon[y]; pUSAPMbufIn[x++] = '\r'; pUSAPMbufIn[x++] = '\n'; fileSize = x; } if (sbnotfound) { for (x = fileSize, y = 0; SB[y] != 0; x++, y++) pUSAPMbufIn[x] = SB[y]; fileSize = x; if (smartbeaconing == FALSE) { pUSAPMbufIn[x-5] = 'N'; pUSAPMbufIn[x-4] = 'O'; pUSAPMbufIn[x-3] = ' '; } } if (compressnotfound) { for (x = fileSize, y = 0; Compressit[y] != 0; x++, y++) pUSAPMbufIn[x] = Compressit[y]; fileSize = x; if (compressit == FALSE) { pUSAPMbufIn[x-5] = 'N'; pUSAPMbufIn[x-4] = 'O'; pUSAPMbufIn[x-3] = ' '; } } if (MyCall[0] || HomeLatLon[0] || HomeSymbol[0] || GPSSymbol[0] || Destination[0] || Comment[0]) { hFile2 = CreateFile(USAPMini, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, pUSAPMbufIn, fileSize, &dwBytesWritten, NULL); CloseHandle(hFile2); } if (pUSAPMbufIn) { free(pUSAPMbufIn); pUSAPMbufIn = NULL; } } } } break; case ID_APRS_OBJECTS_MARKOBJECT: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_OBJECTS_MARKOBJECT, MF_BYCOMMAND)) { if (IDOK == MessageBox(hwnd, "Click on the desired object location on the map.", "", MB_OKCANCEL)) { CheckMenuItem(hMenu, ID_APRS_OBJECTS_MARKOBJECT, MF_CHECKED); markobject = TRUE; } } else { CheckMenuItem(hMenu, ID_APRS_OBJECTS_MARKOBJECT, MF_UNCHECKED); markobject = FALSE; } break; case ID_APRS_OBJECTS_EDITOBJECT: if (objectPtr == 0) LoadObjects(); DialogBox(hInst, "EDITOBJECTS", hwnd, EditObjectProc); InvalidateRect(hwnd, &rect, FALSE); break; case ID_APRS_OBJECTS_SHOWOBJECTS: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_OBJECTS_SHOWOBJECTS, MF_BYCOMMAND)) { if (objectPtr == 0) LoadObjects(); if (objectPtr) { CheckMenuItem(hMenu, ID_APRS_OBJECTS_SHOWOBJECTS, MF_CHECKED); gotsymbol = TRUE; InvalidateRect(hwnd, &rect, FALSE); } } else { CheckMenuItem(hMenu, ID_APRS_OBJECTS_SHOWOBJECTS, MF_UNCHECKED); gotsymbol = FALSE; InvalidateRect(hwnd, &rect, FALSE); } break; case ID_APRS_STATIONS: hwndStationsDlg = CreateDialog(hInst, "STATIONS", hwnd, StationsProc); break; case ID_APRS_EDITMESSAGE: if (DialogBox(hInst, "EDITMESSAGE", hwnd, EditMessageProc)) goodmessage = TRUE; break; case ID_APRS_SHOWMESSAGES: hwndMessageDlg = CreateDialog(hInst, "MESSAGE", hwnd, MessageProc); break; case ID_APRS_TACTICALCALLSIGNS: if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_APRS_TACTICALCALLSIGNS, MF_BYCOMMAND)) { CheckMenuItem(hMenu, ID_APRS_TACTICALCALLSIGNS, MF_CHECKED); usetactical = TRUE; TacticalFileSize = 0; if (INVALID_HANDLE_VALUE != (hFile = CreateFile(Tactical, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL))) { if (TacticalFileSize = GetFileSize(hFile, NULL)) ReadFile(hFile, TacticalCalls, TacticalFileSize, &dwBytesRead, NULL) ; CloseHandle(hFile); } hwndTacticalDlg = CreateDialog(hInst, "TACTICAL", hwnd, TacticalProc); InvalidateRect(hwnd, &rect, FALSE); } else { CheckMenuItem(hMenu, ID_APRS_TACTICALCALLSIGNS, MF_UNCHECKED); usetactical = FALSE; SendMessage(hwndTacticalDlg, WM_COMMAND, IDOK, 0); InvalidateRect(hwnd, &rect, FALSE); } break; case ID_ZOOM_OUT: SendMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_PRIOR, 0); break; case ID_ZOOM_IN: SendMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_NEXT, 0); break; case ID_ZOOM_1METERPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 1) { UncheckZoom(); Zoom = 1; PixelsPerTile = 200; if (MapType == PHOTO) MetersPerTile = 200; else if (MapType == TOPO) MetersPerTile = 800; else if (MapType == URBANAREA) MetersPerTile = 50; ShowZoom(); DoZoom(); } break; case ID_ZOOM_2METERSPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 2) { UncheckZoom(); Zoom = 2; PixelsPerTile = 100; if (MapType == PHOTO) MetersPerTile = 200; else if (MapType == TOPO) MetersPerTile = 800; else if (MapType == URBANAREA) MetersPerTile = 50; ShowZoom(); DoZoom(); } break; case ID_ZOOM_4METERSPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 3) { UncheckZoom(); Zoom = 3; PixelsPerTile = 50; if (MapType == PHOTO) MetersPerTile = 200; else if (MapType == TOPO) MetersPerTile = 800; else if (MapType == URBANAREA) MetersPerTile = 50; ShowZoom(); DoZoom(); } break; case ID_ZOOM_8METERSPIXEL://zoomed from 1 MeterPerPixel EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 4) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; if (MapType == PHOTO) MetersPerTile = 200; else if (MapType == TOPO) MetersPerTile = 800; else if (MapType == URBANAREA) MetersPerTile = 25; ShowZoom(); DoZoom(); } break; case ID_ZOOM_BIG8METERSPIXEL://8 MetersPerPixel EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 5) { UncheckZoom(); Zoom = 5; PixelsPerTile = 200; if (MapType == PHOTO) MetersPerTile = 1600; else if (MapType == TOPO) MetersPerTile = 12800; else if (MapType == URBANAREA) MetersPerTile = 800; ShowZoom(); DoZoom(); } break; case ID_ZOOM_16METERSPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 6) { UncheckZoom(); Zoom = 6; PixelsPerTile = 100; if (MapType == PHOTO) MetersPerTile = 1600; else if (MapType == TOPO) MetersPerTile = 12800; else//if (MapType == URBANAREA) MetersPerTile = 800; ShowZoom(); DoZoom(); } break; case ID_ZOOM_32METERSPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if (Zoom != 7) { UncheckZoom(); Zoom = 7; PixelsPerTile = 50; if (MapType == PHOTO) MetersPerTile = 1600; else if (MapType == TOPO) MetersPerTile = 12800; else//if (MapType == URBANAREA) MetersPerTile = 800; ShowZoom(); DoZoom(); } break; case ID_ZOOM_64METERSPIXEL: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (Zoom != 8) { PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; UncheckZoom(); Zoom = 8; PixelsPerTile = 25; if (MapType == PHOTO) MetersPerTile = 1600; else if (MapType == TOPO) MetersPerTile = 12800; else//if (MapType == PHOTO) MetersPerTile = 800; ShowZoom(); DoZoom(); } break; case ID_SCROLL: MessageBox(hwnd, "Up Arrow key scrolls up,\nDown Arrow key scrolls down,\nLeft Arrow key scrolls left,\nRight Arrow key scrolls right.\n\ \n\ Mousewheel scrolls up and down.\nMousewheel with the Ctrl key down\nscrolls left and right.\n\ \n\ If you press Ctrl-Insert, ANY\nMessage Box will be copied\nto the Windows Clipboard.", "Scrolling", MB_OK); break; case ID_TEXT_SHOWALL: { if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_TEXT_SHOWALL, MF_BYCOMMAND)) { CheckMenuItem(hMenu, ID_TEXT_SHOWALL, MF_CHECKED); showtext = TRUE;//for WM_PAINT } else { CheckMenuItem(hMenu, ID_TEXT_SHOWALL, MF_UNCHECKED); showtext = FALSE; } InvalidateRect(hwnd, &rect, FALSE); } break; case ID_TEXT_LISTALL: if ((autoLoc) && (fromFlag == NOBUTTON)) { fromFlag = RBUTTON; if (itsgarmin) { sendingStop = TRUE; WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = StopPVTPacket[y]; if (tgcount > 49900) tgcount = 0; return 0;//ACK will call this routine again } else if (itsusb == FALSE) { autoLoc = FALSE; SetEvent(hEventExit); } else if (hUSBThread != 0)//if (itsusb) { SignalUSBStop(); } } if (fromFlag != NOBUTTON) { showposition = FALSE; fromFlag = NOBUTTON; //autoLoc comes later... DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); RedDot(hwnd); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } //get closest text (to highlight) if (yPos > 2) {//if not at Menu bar centerX = xPos;//rect.right >> 1; centerY = yPos;//rect.bottom >> 1; } else { centerX = rect.right >> 1; centerY = rect.bottom >> 1; } UTMCenterX = (centerX * MetersPerTile/PixelsPerTile) + ScreenLeft; UTMCenterY = ScreenTop - (centerY * MetersPerTile/PixelsPerTile); B = 10000000000.0;//large number index = -1;//flag for (x = 0, cur = head; cur != NULL; cur = cur->next, x++) { idistX = UTMCenterX - cur->EUTM; if (idistX < 1) idistX = -(idistX); idistY = UTMCenterY - cur->NUTM; if (idistY < 1) idistY = -(idistY); distX = (double) idistX; distY = (double) idistY; A = (int) sqrt((distX*distX) + (distY*distY)); if (A < B) { B = A; index = x; chosen = cur; } } Response = DialogBox(hInst, "WAYPOINTS", hwnd, CheckTextProc); if (Response == EXIT) { InvalidateRect(hwnd, &rect, FALSE); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } else if (Response == EDIT) { DialogBox(hInst, "GETTEXT", hwnd, EditTextProc); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } else if (Response == LINE_TO) { hdc = GetDC(hwnd); hPen = CreatePen(PS_SOLID, 0, 0xF0); hObject = SelectObject(hdc, hPen); MoveToEx(hdc, centerX, centerY, NULL); DrawLineTo(chosen->NUTM, chosen->EUTM); SelectObject(hdc, hObject); ReleaseDC(hwnd, hdc); DeleteObject(hPen); } else if (Response == DELEET) { if (head != NULL) { if (chosen != head) { for (cur = head; (cur->next != chosen) && (cur != NULL); cur = cur->next) ; cur->next = chosen->next; free(chosen); chosen = cur; } else { head = chosen->next; free(chosen); } newText = TRUE; } InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } else//GoTo { rowOffset = ((chosen->NUTM / MetersPerTile) - (TilesDown/2));//center it colOffset = ((chosen->EUTM / MetersPerTile) - ((TilesAcross-1)/2));//center it SendMessage(hwnd, WM_USER, 0, 0); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } autoLoc = FALSE; break; case ID_TEXT_ENTER: MessageBox(hwnd, "Hold the Shift key down\nwhile moving the mouse", "Entering Text", MB_OK); break; case ID_ROUTE_SHOW: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_ROUTE_SHOW, MF_BYCOMMAND)) { getroute: if (FALSE != GetOpenFileName(&ofn3)) { hFile3 = NULL; x = ofn3.nFileExtension; if (((FullRoutes[x] & 0xDF) != 'T') && ((FullRoutes[x+1] & 0xDF) != 'X') && ((FullRoutes[x+2] & 0xDF) != 'T')) goto getroute;//if it's not a .txt file pr = NULL; showingroute = FALSE; hFile3 = CreateFile(FullRoutes, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { BOOL samezone; Acres[0] = 0; // pRoute = (struct Route*) malloc(MAX_PTR * sizeof(struct Route)); pRoute = (struct Route*)VirtualAlloc(NULL, (fileSize/19)*12, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); pr = pRoute; // pRoutes = (char*) malloc(fileSize); pRoutes = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); prs = pRoutes; ReadFile(hFile3, pRoutes, fileSize, &dwBytesRead, NULL); if ((pRoutes[2] != ',') || (pRoutes[0] < '0') || (pRoutes[0] > '2')) {//if not 10,4280273,607830 MessageBox(hwnd, "That's not a route file.", NULL, MB_OK); CloseHandle(hFile3); // free(prs); VirtualFree(prs, 0, MEM_RELEASE); prs = NULL; // free(pr); VirtualFree(pr, 0, MEM_RELEASE); pr = NULL; return 0; } for (x = 0, y = 0; x < (int)fileSize; y++) {//"10,4140653,578149\r\n" for (z = 0; pRoutes[x] != ','; x++) z = (z * 10) + (pRoutes[x] - '0'); pRoute[y].UTMZone = z; x++;//past ',' for (z = 0; pRoutes[x] != ','; x++) z = (z * 10) + (pRoutes[x] - '0'); pRoute[y].NUTM = z; x++;//past ',' for (z = 0; (pRoutes[x] != '\r') && (x < (int)fileSize); x++) z = (z * 10) + (pRoutes[x] - '0'); pRoute[y].EUTM = z; x += 2;//past \r\n if ((pRoute[y].NUTM < 1975000) || (pRoute[y].NUTM > 7925000) || (pRoute[y].EUTM < 150000) || (pRoute[y].EUTM > 999999) || (pRoute[y].UTMZone > 20) || (pRoute[y].UTMZone < 3)) { z = sprintf(Error, "Line %i's coordinates are outside the USA", y+1); MessageBox(hwnd, Error, Routes, MB_OK); CloseHandle(hFile3); hFile3 = NULL; // free(prs); VirtualFree(prs, 0, MEM_RELEASE); prs = NULL; // free(pr); VirtualFree(pr, 0, MEM_RELEASE); pr = NULL; return 0; } } if (y <= 1) { MessageBox(hwnd, "There was only 0 or 1 point in that route", ERROR, MB_OK); CloseHandle(hFile3); hFile3 = NULL; // free(prs); VirtualFree(prs, 0, MEM_RELEASE); prs = NULL; // free(pr); VirtualFree(pr, 0, MEM_RELEASE); pr = NULL; return 0; } numofRoutes = y; y--;//to last route point if ((pRoute[0].UTMZone == pRoute[y].UTMZone) && (pRoute[0].NUTM == pRoute[y].NUTM) && (pRoute[0].EUTM == pRoute[y].EUTM)) {//if a polygon int i, j; double acres, area = 0, n0, e0, n1, e1; for (i = 0; i < y; i++) { j = (i + 1) % y; e0 = (double)pRoute[i].EUTM; n0 = (double)pRoute[i].NUTM; e1 = (double)pRoute[j].EUTM; n1 = (double)pRoute[j].NUTM; area += e0 * n1;//pRoute[i].EUTM * pRoute[j].NUTM; area -= n0 * e1;//pRoute[i].NUTM * pRoute[j].EUTM; } area /= 2.0; if (area < 0) area = -area; acres = area * 0.00024710538146716533; sprintf(Acres, "%.6f", acres); //acres = area / 4046.856422; //1 foot = 0.3048 meters //1 acre = 4046.856422 square meters //10000 square meters = 0.24710538146716533 acres } showingroute = TRUE; CheckMenuItem(hMenu, ID_ROUTE_SHOW, MF_CHECKED); if (pRoute[0].UTMZone == UTMZone) { BeginY = pRoute[0].NUTM / MetersPerTile; BeginX = pRoute[0].EUTM / MetersPerTile; rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen fromOpen = TRUE; SendMessage(hwnd, WM_USER, 0, 0); } else { UTMNorthing = pRoute[0].NUTM; UTMEasting = pRoute[0].EUTM; UTMZone = pRoute[0].UTMZone; notfromroute = FALSE; ChangeZone(UTMZone, 2);//show route notfromroute = TRUE; BeginX = UTMEasting / MetersPerTile; BeginY = UTMNorthing / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; fromOpen = TRUE; Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); } samezone = TRUE; for (d = 0.0, z = 1; z < numofRoutes; z++) { if (pRoute[z].UTMZone == pRoute[z-1].UTMZone) { v = pRoute[z].EUTM; w = pRoute[z-1].EUTM; if (v > w) xleg = v - w; else xleg = w - v; v = pRoute[z].NUTM; w = pRoute[z-1].NUTM; if (v > w) yleg = v - w; else yleg = w - v; legsquared = xleg*xleg; legsquared += yleg*yleg; d += sqrt(legsquared); } else { samezone = FALSE; CloseHandle(hFile3); hFile3 = NULL; break; } } if (samezone) { if (d < 304.8)//1,000 ft { d /= 0.3048;//convert to feet feet = TRUE; } else { d *= 0.000621371;//convert to miles feet = FALSE; } x = sprintf(RouteDist, "%.2f", d); if (feet) sprintf(&RouteDist[x], " feet"); else sprintf(&RouteDist[x], " miles"); MessageBox(hwnd, RouteDist, "Route Length:", MB_OK); if (Acres[0] != 0) MessageBox(hwnd, Acres, "Acres:", MB_OK); } }//end of if (fileSize if (hFile3 != NULL) CloseHandle(hFile3); }//end of if (hFile3 }//end of GetOpenFileName }//end of if (MF_UNCHECKED == CheckMenuItem(hMenu, ID_ROUTE_SHOW, MF_BYCOMMAND)) else { if (pr != NULL) { // free(pr); VirtualFree(pr, 0, MEM_RELEASE); pr = NULL; } if (prs != NULL) { VirtualFree(prs, 0, MEM_RELEASE); prs = NULL; } CheckMenuItem(hMenu, ID_ROUTE_SHOW, MF_UNCHECKED); showingroute = FALSE; InvalidateRect(hwnd, &rect, FALSE); } break; case ID_ROUTE_CREATE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (drawing == FALSE) { drawing = TRUE;//to create the route routeDist = 0.0; for (x = 0; x < MAX_PTR; x++) totalRouteDist[x] = 0.0; // pRoute = (struct Route*) malloc(MAX_PTR * sizeof(struct Route)); pRoute = (struct Route*)VirtualAlloc(NULL, MAX_PTR * sizeof(struct Route), MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); pr = pRoute; ptr = 0; RoutePoint = 0; if (0 != _stricmp(Key, TheKey))//if not paid for MessageBox(hwnd, CreateRoute, "Create a Route", MB_OK); } break; case ID_ROUTETOTRACKS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (FALSE != GetOpenFileName(&ofn3)) { char *pIn, *pOut; pIn = pOut = NULL; hFile3 = CreateFile(ofn3.lpstrFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { pIn = (char*)malloc(fileSize); ReadFile(hFile3, pIn, fileSize, &dwBytesRead, NULL); } CloseHandle(hFile3); if ((pIn[2] != ',') && (pIn[10] != ',') && (pIn[17] != '\r')) { MessageBox(hwnd, "That doesn't seem to be a route file.", ERROR, MB_OK); if (pIn != NULL) free(pIn); return 0; } // for (x = 0; (ofn3.lpstrFile[x] != '.') && (ofn3.lpstrFile[x] != 0); x++) // TrackName[x] = ofn3.lpstrFile[x]; for (x = 0, y = 0; CurrentTrackDir[y] != 0; x++, y++) TrackName[x] = CurrentTrackDir[y]; for (y = 0; (ofn3.lpstrFile[y] != '.') && (ofn3.lpstrFile[y] != 0); x++, y++) TrackName[x] = ofn3.lpstrFileTitle[y]; TrackName[x++] = '.'; TrackName[x++] = 'c'; TrackName[x++] = 's'; TrackName[x++] = 'v'; TrackName[x] = 0; hFile = FindFirstFile(TrackName, &fd); if (hFile != INVALID_HANDLE_VALUE) {//if file already exists FindClose(hFile); ofn.Flags |= OFN_OVERWRITEPROMPT; ofn.lpstrInitialDir = CurrentTrackDir; if (FALSE != GetSaveFileName(&ofn)) {//get a new TrackName for (x = 0; ofn.lpstrFile[x] != 0; x++) TrackName[x] = ofn.lpstrFile[x]; TrackName[x] = 0; ofn.Flags &= OFN_OVERWRITEPROMPT; } else { ofn.Flags &= OFN_OVERWRITEPROMPT; if (pIn != NULL) free(pIn); return 0; } ofn.lpstrInitialDir = CurrentDir; } pOut = (char*)malloc(fileSize*20); for (y = 0; PreTracks[y] != 0; y++) pOut[y] = PreTracks[y]; pOut[y++] = ','; for (x = 0; (x < (int)fileSize); x++) { if (pIn[x] == '\r') { for (z = 0; PseudoTrack[z] != 0; z++) pOut[y++] = PseudoTrack[z]; x += 2;//past \r\n if (x >= (int)fileSize) break; pOut[y++] = ','; } pOut[y++] = pIn[x]; } hFile3 = CreateFile(TrackName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { WriteFile(hFile3, pOut, y, &dwBytesWritten, NULL); CloseHandle(hFile3); MessageBox(hwnd, TrackName, "Created track file:", MB_OK); } if (pIn != NULL) free(pIn); if (pOut != NULL) free(pOut); } } break; case ID_GPS_ROUTE_APPENDTOTRACKS: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (FALSE != GetOpenFileName(&ofn3)) { char *pIn, *pOut; pIn = pOut = NULL; hFile3 = CreateFile(ofn3.lpstrFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { pIn = (char*)malloc(fileSize); ReadFile(hFile3, pIn, fileSize, &dwBytesRead, NULL); } CloseHandle(hFile3); if ((pIn[2] != ',') && (pIn[10] != ',') && (pIn[17] != '\r')) { MessageBox(hwnd, "That doesn't seem to be a route file.", ERROR, MB_OK); if (pIn != NULL) free(pIn); return 0; } pOut = (char*)malloc(fileSize*20); for (y = 0; Noo[y] != 0; y++) pOut[y] = Noo[y]; for (x = 0; (x < (int)fileSize); x++) { if (pIn[x] == '\r') { for (z = 0; PseudoTrack[z] != 0; z++) pOut[y++] = PseudoTrack[z]; x += 2;//past \r\n if (x >= (int)fileSize) break; pOut[y++] = ','; } pOut[y++] = pIn[x]; } ofn.lpstrTitle = "Append To"; ofn.lpstrInitialDir = CurrentTrackDir; if (FALSE != GetSaveFileName(&ofn)) { hFile3 = CreateFile(ofn.lpstrFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { SetFilePointer(hFile3, 0, NULL, FILE_END); WriteFile(hFile3, pOut, y, &dwBytesWritten, NULL); CloseHandle(hFile3); MessageBox(hwnd, ofn.lpstrFile, "Appended to track file:", MB_OK); } } ofn.lpstrInitialDir = CurrentDir; ofn.lpstrTitle = NULL; if (pIn != NULL) free(pIn); if (pOut != NULL) free(pOut); } } break; case ID_WAYPOINTS_SHOW: SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0); break; case ID_WAYPOINTS_OPENFILE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; ofn2.lpstrFilter = "xml\0""*.xml\0""gpx\0""*.gpx\0\0"; if (WaypointsPath[0] != 0) ofn2.lpstrInitialDir = WaypointsPath; if ((fromconvertloctoxml) || (GetOpenFileName(&ofn2)))//WaypointsFullPath filled here { // char FullPath[MAX_PATH]; fromconvertloctoxml = FALSE; if (((WaypointsFullPath[ofn2.nFileExtension] & 0xDF) != 'X') && ((WaypointsFullPath[ofn2.nFileExtension+1] & 0xDF) != 'M') && ((WaypointsFullPath[ofn2.nFileExtension+2] & 0xDF) != 'L')) { if (((WaypointsFullPath[ofn2.nFileExtension] & 0xDF) != 'G') && ((WaypointsFullPath[ofn2.nFileExtension+1] & 0xDF) != 'P') && ((WaypointsFullPath[ofn2.nFileExtension+2] & 0xDF) != 'X')) { MessageBox(hwnd, "That's not an xml or gps file", ERROR, MB_OK); break; } } // for (x = 0; CurrentDir[x] != 0; x++) // FullPath[x] = CurrentDir[x]; // FullPath[x++] = '\\'; // for (y = 0; Waypoints[y] != 0; x++, y++) // FullPath[x] = Waypoints[y]; // FullPath[x] = 0; hFile3 = CreateFile(WaypointsFullPath, GENERIC_READ, 0, NULL, OPEN_ALWAYS, 0, NULL);//Waypoints if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) {//if it's not a new file CloseHandle(hFile3); if (newLoc) SaveLocs(); if (newText) SaveText(); fromOpen = TRUE; BeginY = rowOffset + (TilesDown/2); BeginX = colOffset + ((TilesAcross-1)/2); SendMessage(hwnd, WM_USER4, 0, 0);//load waypoints SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0);//show waypoint list if (newLoc) SaveLocs(); if (newText) SaveText(); }//end of if (fileSize) else//if it's a new file { strcpy(NewLocationsFullPath, WaypointsFullPath); strcpy(NewLocations, Waypoints); CloseHandle(hFile3); if (WaypointArray != NULL) free(WaypointArray); WaypointArray = (char*)calloc(1,100000); WaypointSize = 0; for (x = 0; x < TOTAL_LOCS; x++) { NewLoc[x].NUTM = 0; NewLoc[x].EUTM = 0; NewLoc[x].UTMZone = 0; NewLoc[x].pWaypoints = NULL;//pointer to waypoint data in WaypointArray NewLoc[x].Ident = NULL;//pointer to name NewLoc[x].Location = NULL;//pointer to cmt NewLoc[x].Description = NULL;//pointer to desc NewLoc[x].Elev = NULL;//pointer to ele NewLoc[x].Sym = NULL;//pointer to sym NewLoc[x].size = 0; prevDist[x] = HUNDRED_MILES; } EmptyLoc = 0; newLoc = TRUE;//to delete possible empty file in SaveLocs } } else MessageBox(hwnd, "isn't a waypoint file!", WaypointsFullPath, MB_OK); } ofn2.lpstrInitialDir = CurrentDir; InvalidateRect(hwnd, &rect, FALSE); break; case ID_GPS_HELP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (autoLoc == FALSE) { pGPSHelp = NULL; hFile = CreateFile(GPSHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (GPSHelpSize = GetFileSize(hFile, NULL)) { pGPSHelp = (char *) malloc(GPSHelpSize+1); if (pGPSHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pGPSHelp[GPSHelpSize] = 0; ReadFile(hFile, pGPSHelp, GPSHelpSize, &dwBytesRead, NULL); hMenu3 = CreateMenu();//to override parent menu bar hwndGPS = CreateWindow(Instruct, "GPSHelp.txt", WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen/2-320, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), cyScreen-(cyChar*3), NULL, hMenu3, hInst, NULL); SetWindowText(hwndInstr, pGPSHelp); SetFocus(hwndInstr); } CloseHandle (hFile); } else MessageBox(hwnd, NoGPSFile, NULL, MB_OK); } break; case ID_GPS_COMMPORT: NewComm[7] = RegValue[3]; NewComm[8] = RegValue[4]; if (DialogBox(hInst, "COMMPORT", hwnd, CommPortProc)) { NewComm[7] = CommPort[0]; NewComm[8] = CommPort[1]; if (((NewComm[7] == '0') || (NewComm[7] == ' ')) && ((NewComm[1] >= '0') && NewComm[1] <= '9')) {//change "05" or " 5" to "5" NewComm[7] = NewComm[8]; NewComm[8] = 0; } } SetRegKey(wParameter); break; case ID_GPS_PROTOCOL_GARMIN: itsgarmin = TRUE; itsusb = FALSE; itsexplorist = FALSE; ProtocolCheck1 = ID_GPS_PROTOCOL_ANYGPS; ProtocolCheck2 = ID_GPS_PROTOCOL_GARMINUSB; ProtocolCheck3 = ID_GPS_PROTOCOL_MAGELLANEXPLORIST; SetRegKey2(GARMIN, wParameter); break; case ID_GPS_PROTOCOL_ANYGPS://NMEA itsgarmin = FALSE; itsusb = FALSE; itsexplorist = FALSE; ProtocolCheck1 = ID_GPS_PROTOCOL_GARMIN; ProtocolCheck2 = ID_GPS_PROTOCOL_GARMINUSB; ProtocolCheck3 = ID_GPS_PROTOCOL_MAGELLANEXPLORIST; SetRegKey2(NMEA, wParameter); break; case ID_GPS_PROTOCOL_GARMINUSB://USB itsusb = TRUE; itsgarmin = FALSE; itsexplorist = FALSE; ProtocolCheck1 = ID_GPS_PROTOCOL_GARMIN; ProtocolCheck2 = ID_GPS_PROTOCOL_ANYGPS; ProtocolCheck3 = ID_GPS_PROTOCOL_MAGELLANEXPLORIST; SetRegKey2(USB, wParameter); break; case ID_GPS_PROTOCOL_MAGELLANEXPLORIST: itsgarmin = FALSE; itsusb = FALSE; itsexplorist = TRUE; ProtocolCheck1 = ID_GPS_PROTOCOL_GARMIN; ProtocolCheck2 = ID_GPS_PROTOCOL_ANYGPS; ProtocolCheck3 = ID_GPS_PROTOCOL_GARMINUSB; SetRegKey2(EXPL, wParameter); break; case ID_GPS_BAUD_4800: Baud = 4800; BaudUnits = ID_GPS_BAUD_4800; ChangeBaud(); break; case ID_GPS_BAUD_9600: Baud = 9600; BaudUnits = ID_GPS_BAUD_9600; ChangeBaud(); break; case ID_GPS_BAUD_19200: Baud = 19200; BaudUnits = ID_GPS_BAUD_19200; ChangeBaud(); break; case ID_GPS_BAUD_38400: Baud = 38400; BaudUnits = ID_GPS_BAUD_38400; ChangeBaud(); break; case ID_GPS_BAUD_57600: Baud = 57600; BaudUnits = ID_GPS_BAUD_57600; ChangeBaud(); break; case ID_GPS_BAUD_115200: Baud = 115200; BaudUnits = ID_GPS_BAUD_115200; ChangeBaud(); break; case ID_GPS_WAYPOINTS_UPLOAD: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; BadSend = 0; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (LastWay = 0; LastWay < TOTAL_LOCS; LastWay++) if (NewLoc[LastWay].EUTM == 0) break; EmptyLoc = LastWay; if (onewaypoint) LastWay = 1; if (itsexplorist) { ofn5.lpstrFilter = " *.*\0""*.*\0\0"; ofn5.lpstrFile = MeridianFullName;//full filename ofn5.lpstrFileTitle = MeridianName;//short filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (FALSE != GetSaveFileName(&ofn5)) { hFile = CreateFile(MeridianFullName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); for (LocNum = 0; LocNum < EmptyLoc; LocNum++) { x = PrepMagellanWaypoint(); WriteFile(hFile, &SendMagWaypoints, x, &dwBytesWritten, NULL); } WriteFile(hFile, &SendEnd, sizeof(SendEnd)-1, &dwBytesWritten, NULL); CloseHandle(hFile); MessageBox(hwnd, "hs been written in eXplorist format.", MeridianName, MB_OK); } break; } if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = SENDWAYPOINTS; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } BeginRecords[3] = LastWay;//number of records if (LastWay != 16)//if not 0x10 (DLE char) BeginRecords[5] = ~(27 + 2 + LastWay) + 1;//checksum (needs extra DLE if LastWay == -45) else BeginRecords2[6] = ~(27 + 2 + LastWay) + 1;//checksum (needs extra DLE if LastWay == -45) remainder = LastWay % 10000; Counting[8] = (remainder / 1000) + '0'; Counting[9] = ((remainder % 1000) / 100) + '0'; Counting[10] = ((remainder % 100) / 10) + '0'; Counting[11] = (remainder % 10) + '0'; if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } GetCommHandle(); if (hComm != INVALID_HANDLE_VALUE) { ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); autoLoc = FALSE; for (x = 0; x < 9; x++) PreCounting[x] = Up[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 0; x < 9; x++) PostCounting[x] = Way[x]; LocNum = 0; if (itsgarmin) { sendingWaypoints = TRUE; GarminFlag = GOT_ETX; TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); Sleep(500); if (LastWay != 16) garminflag = BEGINRECORDS8; else garminflag = BEGINRECORDS9; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } else//Magellan { magflag = SENDWAYPOINTS; TimerFlags.nmeatiming = TRUE; TimerFlags.gotprotocol = TRUE; TimerFlags.time = 6000;//was 5000 July 27, 2005 ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); gotver = FALSE; ResetEvent(hEvent);//unsignal it tgcount = 0; for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); if ((gotver == FALSE) && (WaitForSingleObject(hEvent, 2000) == WAIT_TIMEOUT))//it will exit after 2 seconds or if signalled { for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); } } } // else // MessageBox(hwnd, BadCommPort, NULL, MB_OK); break; case ID_GPS_WAYPOINTS_DOWNLOAD: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; for (x = 0; x < TOTAL_LOCS; x++) if (NewLoc[x].EUTM == 0) break; // if (GetKeyState(VK_CONTROL) < 0) // simulate = TRUE; EmptyLoc = x; if (itsexplorist) { ofn5.lpstrFilter = " *.*\0""*.*\0\0"; ofn5.lpstrFile = MeridianFullName;//full filename ofn5.lpstrFileTitle = MeridianName;//short filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (GetOpenFileName(&ofn5)) { hFile = CreateFile(MeridianFullName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); ExploristBuf = (char*)malloc(fileSize); ReadFile(hFile, ExploristBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); for (i = 0; i < fileSize; ) { i = GetExploristWaypoints(i); } free(ExploristBuf); } InvalidateRect(hwnd, &rect, FALSE); MessageBox(hwnd, "has been copied into the existing waypoint file.", MeridianName, MB_OK); } break; } if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = GETWAYPOINTS; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } if (sortbyname) qsort(NewLoc, EmptyLoc, sizeof(NewLoc[0]), compareIdent); else qsort(NewLoc, EmptyLoc, sizeof(NewLoc[0]), compareLoc); if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } if (EmptyLoc < TOTAL_LOCS) GetCommHandle(); if ((EmptyLoc < TOTAL_LOCS) && (hComm != INVALID_HANDLE_VALUE)) { autoLoc = FALSE; ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); if (itsgarmin) { TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; for (x = 0; x < 9; x++) PreCounting[x] = Down[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 8; x < 12; x++) Counting[x] = ' ';//don't know how many waypoints... for (x = 0; x < 9; x++) PostCounting[x] = Way[x]; GarminFlag = GOT_ETX; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); garminflag = SENDWAYPOINTS; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } else {//Magellan Number[0] = ' '; for (y = 1; y < 5; y++) Number[y] = '0'; Number[5] = ' '; xCenter = (rect.right/2) - (cxChar*4); yCenter = rect.bottom/2; magflag = GETWAYPOINTS; TimerFlags.nmeatiming = TRUE; TimerFlags.gotprotocol = TRUE; TimerFlags.time = 5000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); gotver = FALSE; ResetEvent(hEvent);//unsignal it tgcount = 0; for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); if ((gotver == FALSE) && (WaitForSingleObject(hEvent, 2000) == WAIT_TIMEOUT))//it will exit after 1 second or if signalled { for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); } } } else if (EmptyLoc == TOTAL_LOCS) MessageBox(hwnd, FullArray, "Can't do it:", MB_OK); // else if (hComm == INVALID_HANDLE_VALUE) // MessageBox(hwnd, BadCommPort, NULL, MB_OK); break; case ID_GPS_TRACKS_UPLOAD: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; if (trak != NULL) { free(trak); trak = NULL; } numofTracks = 14400; trak = (struct TRAC*) calloc(1, (numofTracks+100) * sizeof(struct TRAC)); FullTracks[0] = 0; ofn.lpstrInitialDir = CurrentTrackDir; if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = SENDTRACKS; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } if (FALSE != GetOpenFileName(&ofn)) { hFile3 = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { sendingWaypoints = FALSE; ReadFile(hFile3, Trackid, 100, &dwBytesRead, NULL); SetFilePointer(hFile3, 0, 0, FILE_BEGIN); if ((Trackid[0] == 'T') && (Trackid[1] == 'r') && (Trackid[2] == 'a') && (Trackid[3] == 'c')) { for (x = 0, trackcommas = 0; (Trackid[x] != '\r') && (x < 100); x++) if (Trackid[x] == ',') trackcommas++; firsttrack = x+2; pTrackBuf = (unsigned char*)malloc(fileSize); ReadFile(hFile3, pTrackBuf, fileSize, &dwBytesRead, NULL); if (itsgarmin == FALSE) { ofn5.lpstrFilter = " *.*\0""*.*\0\0"; ofn5.lpstrFile = MeridianFullName;//full filename ofn5.lpstrFileTitle = MeridianName;//short filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (FALSE != GetSaveFileName(&ofn5)) { ConvertoMeridian(fileSize);//or eXplorist if (itsexplorist) MessageBox(hwnd, "has been written in eXplorist format.", MeridianName, MB_OK); else MessageBox(hwnd, "File written in Meridian SD Card format.", " Done!", MB_OK); } free(pTrackBuf); pTrackBuf = NULL; break; } else//(itsgarmin) { numofTracks = ReadTracks(fileSize); free(pTrackBuf); pTrackBuf = NULL; } } else { numofTracks = fileSize / 12;//original format for (x = 0; x < numofTracks; x++) ReadFile(hFile3, &trak[x], 12, &dwBytesRead, NULL); } } CloseHandle(hFile3); BeginRecords[3] = numofTracks; if (numofTracks != 16)//if not 0x10 (DLE char) BeginRecords[5] = ~(27 + 2 + numofTracks) + 1; else BeginRecords2[6] = ~(27 + 2 + numofTracks) + 1; remainder = numofTracks % 10000; Counting[8] = (remainder / 1000) + '0'; Counting[9] = ((remainder % 1000) / 100) + '0'; Counting[10] = ((remainder % 100) / 10) + '0'; Counting[11] = (remainder % 10) + '0'; if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } GetCommHandle();//if Comm not set to no if (hComm != INVALID_HANDLE_VALUE) { ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); autoLoc = FALSE; for (x = 0; x < 9; x++) PreCounting[x] = Up[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 0; x < 9; x++) PostCounting[x] = Track[x]; if (itsgarmin) { TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; ResetEvent(hTimerEvent); GarminFlag = GOT_ETX; _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); sendingtrackheader = TRUE; d301 = d302 = d310 = FALSE; TrackNum = 0; if (numofTracks != 16) garminflag = BEGINRECORDS8; else garminflag = BEGINRECORDS9; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } } // else // MessageBox(hwnd, BadCommPort, NULL, MB_OK); } } ofn.lpstrInitialDir = CurrentDir; break; case ID_GPS_TRACKS_DOWNLOAD: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; // if (GetKeyState(VK_CONTROL) < 0) // simulate = TRUE; if (trak != NULL) { free(trak); trak = NULL; } numofTracks = 14400; trak = (struct TRAC*) calloc(1, (numofTracks+100) * sizeof(struct TRAC)); if (itsexplorist) { ofn5.lpstrFilter = " *.*\0""*.*\0\0"; ofn5.lpstrFile = MeridianFullName;//full filename ofn5.lpstrFileTitle = MeridianName;//short filename ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_CREATEPROMPT|OFN_OVERWRITEPROMPT; ofn5.lpstrTitle = NULL;//title bar ofn5.lpstrDefExt = NULL; if (GetOpenFileName(&ofn5)) { hFile = CreateFile(MeridianFullName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); ExploristBuf = (char*)malloc(fileSize); ReadFile(hFile, ExploristBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile); //$PMGNTRK,1759.049,N,06637.161,W,00009,M,194354.07,A,,261202*62 tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; tnum = 0; for (i = 0; i < fileSize; ) { if ((ExploristBuf[i] != '$') || (ExploristBuf[i+1] != 'P') || (ExploristBuf[i+2] != 'M') || (ExploristBuf[i+5] != 'T') || (ExploristBuf[i+6] != 'R') || (ExploristBuf[i+7] != 'K')) { for ( ; (i < fileSize) && (ExploristBuf[i] != '\n'); i++) ; i++; continue; } for (x = 0, i += 9; (i < fileSize) && (ExploristBuf[i] != '\r'); i++, x++) tempLatLon[x] = ExploristBuf[i]; i += 2; Lat = ((double)((tempLatLon[0] - '0') * 10) + (tempLatLon[1] - '0')) + ((atof(&tempLatLon[2])) / 60.0); for (x = 0; (tempLatLon[x] != 'N') && (x < 100); x++) ; if (x >= 100) return 0;//just in case x += 2;//to Longitude Lon = -((double)((tempLatLon[x] - '0') * 100) + ((tempLatLon[x+1] - '0') * 10) + (tempLatLon[x+2] - '0') + ((atof(&tempLatLon[x+3])) / 60.0)); if ((Lon > -60.0) || (Lon < -168.0) || (Lat > 72.0) || (Lat < 17.5)) continue; else { LatRad = Lat*deg2rad; LonRad = Lon*deg2rad; LatLontoUTM();//get UTMEasting & UTMNorthing } FillTrackFromNMEA(); } free(ExploristBuf); if (FALSE != GetSaveFileName(&ofn)) { HANDLE hXFile = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); fileSize = sizeof(trak[0]); trak[tnum].time = 0; WriteFile(hXFile, TrackHead, strlen(TrackHead), &dwBytesWritten, NULL); trackcommas = 10; for (y = 0; y < tnum; y++) WriteTracks(hXFile, y); CloseHandle(hXFile); } Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; } InvalidateRect(hwnd, &rect, FALSE); sprintf(Error, "has been copied into %s", Tracks); MessageBox(hwnd, Error, MeridianName, MB_OK); } break; } if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = GETTRACKS; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } GetCommHandle();//if Comm not set to no if (hComm != INVALID_HANDLE_VALUE) { tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; FullTracks[0] = 0; ofn.lpstrInitialDir = CurrentTrackDir; if (FALSE != GetSaveFileName(&ofn))//fills in FullTracks with full filename { autoLoc = FALSE; tnum = 0; ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); if (itsgarmin) { for (x = 0; x < 9; x++) PreCounting[x] = Down[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 8; x < 12; x++) Counting[x] = ' ';//don't know how many tracks... for (x = 0; x < 9; x++) PostCounting[x] = Track[x]; TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); GarminFlag = GOT_ETX; garminflag = SENDTRACKS; d301 = d302 = d310 = FALSE; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } else { Number[0] = ' '; for (y = 1; y < 5; y++) Number[y] = '0'; Number[5] = ' '; xCenter = (rect.right/2) - (cxChar*4); yCenter = rect.bottom/2; TimerFlags.nmeatiming = TRUE; TimerFlags.gotprotocol = TRUE; TimerFlags.time = 5000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); magflag = GETTRACKS; inutmzone = FALSE; gotver = FALSE; ResetEvent(hEvent);//unsignal it tgcount = 0; for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); if ((gotver == FALSE) && (WaitForSingleObject(hEvent, 2000) == WAIT_TIMEOUT))//it will exit after 1 second or if signalled { for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); } } } ofn.lpstrInitialDir = CurrentDir; } // else if (hComm == INVALID_HANDLE_VALUE) // MessageBox(hwnd, BadCommPort, NULL, MB_OK); break; case ID_GPS_TRACKS_SHOW: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (autoLoc) break; if (showingtracks) { MessageBox(hwnd, "Close the current Tracks window first.", "", MB_OK); break; } FullTracks[0] = 0; ofn.lpstrInitialDir = CurrentTrackDir; tryagain: if (FALSE != GetOpenFileName(&ofn)) { char ch = ofn.lpstrFile[ofn.nFileExtension]; char ch1 = ofn.lpstrFile[ofn.nFileExtension+1]; char ch2 = ofn.lpstrFile[ofn.nFileExtension+2]; BOOL itsokay = FALSE; if (((ch & 0xDF) == 'C') && ((ch1 & 0xDF) == 'S') && ((ch2 & 0xDF) == 'V')) itsokay = TRUE; else if (((ch & 0xDF) == 'T') && ((ch1 & 0xDF) == 'R') && ((ch2 & 0xDF) == 'C')) itsokay = TRUE; else if (((ch & 0xDF) == 'D') && ((ch1 & 0xDF) == 'T') && ((ch2 & 0xDF) == 'A')) itsokay = TRUE; if (itsokay == FALSE) goto tryagain; hFile3 = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { ReadFile(hFile3, Trackid, 100, &dwBytesRead, NULL); SetFilePointer(hFile3, 0, 0, FILE_BEGIN); if ((Trackid[0] == 'T') && (Trackid[1] == 'r') && (Trackid[2] == 'a') && (Trackid[3] == 'c')) { for (x = 0, trackcommas = 0; (Trackid[x] != '\r') && (x < 100); x++) if (Trackid[x] == ',') trackcommas++; pTrackBuf = (unsigned char*)malloc(fileSize); ReadFile(hFile3, pTrackBuf, fileSize, &dwBytesRead, NULL); CloseHandle(hFile3); numofTracks = ReadTracks(fileSize); free(pTrackBuf); pTrackBuf = NULL; } else { if (fileSize % 12) numofTracks = 0;//to exit if it's not an old track file else numofTracks = fileSize / 12;//original format for (x = 0; x < numofTracks; x++) { ReadFile(hFile3, &oldTrack, 12, &dwBytesRead, NULL); trak[x].NUTM = oldTrack.NUTM; trak[x].EUTM = oldTrack.EUTM; trak[x].time = oldTrack.time; trak[x].alt = 0; trak[x].newtrk = 0; trak[x].color = 0; trak[x].year = 0; } CloseHandle(hFile3); } if (numofTracks > 1) { trak[numofTracks].time = 0;//in case the 0 isn't at the end trackUTMZone = trak[0].time >> 26;//UTMZone in new Track.dta format showingtracks = TRUE; fromTracks = TRUE; editingtracks = FALSE; /////////////// // CreateTracks(); fromusbtracks = TRUE; /////////////// } else MessageBox(hwnd, "That track file is empty.\nOr it's not a track file.", ERROR, MB_OK); }//end of if (fileSize else CloseHandle(hFile3); }//end of if (hFile3 }//end of if (FALSE != GetOpenFileName(&ofn)) ofn.lpstrInitialDir = CurrentDir; InvalidateRect(hwnd, &rect, FALSE); break; case ID_GPS_TRACKS_COMBINE: ofn.lpstrInitialDir = CurrentTrackDir; ofn.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT|OFN_EXPLORER; ofn.lpstrTitle = ">>>Select All the Files to Combine<<<"; ch = FullTracks[0]; FullTracks[0] = 0; if (GetOpenFileName(&ofn)) { int t, CombinedSize = 0; char tempTrackFilename[MAX_PATH]; char *CombinedTracks, *tempTracks; for (z = 0; CurrentTrackDir[z] != 0; z++) tempTrackFilename[z] = CurrentTrackDir[z]; for (y = ofn.nFileOffset; ofn.lpstrFile[y] != 0; y++) { for (x = y; ofn.lpstrFile[y] != 0; y++) ; for (w = z; x < y; x++, w++) tempTrackFilename[w] = ofn.lpstrFile[x]; tempTrackFilename[w] = 0; FindFirstFile(tempTrackFilename, &fd); CombinedSize += fd.nFileSizeLow; } // CombinedTracks = (char*)malloc(CombinedSize); CombinedTracks = (char*)VirtualAlloc(NULL, CombinedSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); for (v = 0; PreTracks[v] != 0; v++) CombinedTracks[v] = PreTracks[v];//first line of track file for (y = ofn.nFileOffset; ofn.lpstrFile[y]; y++) { for (x = y; ofn.lpstrFile[y] != 0; y++) ; for (w = z; x < y; x++, w++) tempTrackFilename[w] = ofn.lpstrFile[x]; tempTrackFilename[w] = 0; hFile = CreateFile(tempTrackFilename, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile, NULL)) { tempTracks = (char*)malloc(fileSize); ReadFile(hFile, tempTracks, fileSize, &dwBytesRead, NULL); for (t = 0; (t < fileSize) && (tempTracks[t] != '\n'); t++) ; t++;//to beginning of second line if (tempTracks[t] == ',')//no New at beginning { CombinedTracks[v++] = 'N'; CombinedTracks[v++] = 'e'; CombinedTracks[v++] = 'w'; } for ( ; t < fileSize; t++, v++) CombinedTracks[v] = tempTracks[t]; free(tempTracks); } CloseHandle(hFile); } } ofn.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn.lpstrTitle = ">>>Save Combined Track File As<<<"; FullTracks[0] = ch; if (GetSaveFileName(&ofn)) { hFile = CreateFile(ofn.lpstrFile, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, CombinedTracks, v, &dwBytesWritten, NULL); CloseHandle(hFile); } // free(CombinedTracks); VirtualFree(CombinedTracks, 0, MEM_RELEASE); ofn.lpstrTitle = NULL; } else { x = CommDlgExtendedError();//see CdErr.h for codes MessageBox(hwnd, "The total length of file names\nexceeded the Windows\nfile name buffer size.", ERROR, MB_OK); FullTracks[0] = ch; ofn.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn.lpstrTitle = NULL; } break; case ID_GPS_ROUTES_SEND: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (itsexplorist) { // SendMagRoutes(); MessageBox(hwnd, Explorist, Routine, MB_OK); break; } if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = SENDROUTE; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } sendingrouteheader = TRUE; sendingroutelink = FALSE; tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; d201 = TRUE; d210 = FALSE; if (FALSE != GetOpenFileName(&ofn3)) { hFile3 = CreateFile(FullRoutes, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile3 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile3, NULL)) { ReadFile(hFile3, Trackid, 100, &dwBytesRead, NULL); SetFilePointer(hFile3, 0, 0, FILE_BEGIN); if ((Trackid[2] == ',') && (Trackid[10] == ',') && (Trackid[17] == '\r')) { pRoutes = (char*)malloc(fileSize); ReadFile(hFile3, pRoutes, fileSize, &dwBytesRead, NULL); for (x = 0, y = 0; (y < (int)fileSize) && (x < TOTAL_LOCS); x++) { Root[0][x].Z = ((pRoutes[y] - '0') * 10) + (pRoutes[y+1] - '0'); y += 3;//past , Root[0][x].N = (((pRoutes[y] - '0') * MILLION) + ((pRoutes[y+1] - '0') * HUNDREDTHOUSAND) + ((pRoutes[y+2] - '0') * TENTHOUSAND) + ((pRoutes[y+3] - '0') * THOUSAND) + ((pRoutes[y+4] - '0') * HUNDRED) + ((pRoutes[y+5] - '0') * TEN) + (pRoutes[y+6] - '0')); y += 8;//past , Root[0][x].E = (((pRoutes[y] - '0') * HUNDREDTHOUSAND) + ((pRoutes[y+1] - '0') * TENTHOUSAND) + ((pRoutes[y+2] - '0') * THOUSAND) + ((pRoutes[y+3] - '0') * HUNDRED) + ((pRoutes[y+4] - '0') * TEN) + (pRoutes[y+5] - '0')); y += 8;//to next line } Root[0][x].Z = 0; numofRoutes = x; free(pRoutes); } else { MessageBox(hwnd, NotRoute, NULL, MB_OK); CloseHandle(hFile3); return 0; } } CloseHandle(hFile3); if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } GetCommHandle(); if (hComm != INVALID_HANDLE_VALUE) { ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); for (x = 0; x < 9; x++) PreCounting[x] = Up[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 0; x < 9; x++) PostCounting[x] = Routetxt[x]; remainder = numofRoutes % 10000; Counting[8] = (remainder / 1000) + '0'; Counting[9] = ((remainder % 1000) / 100) + '0'; Counting[10] = ((remainder % 100) / 10) + '0'; Counting[11] = (remainder % 10) + '0'; autoLoc = FALSE; TrackNum = 0;//borrowing TrackNum LocNum = 0;//for NewLoc[] if (itsgarmin) { BeginRecords[3] = numofRoutes+1;//+ Route Header if ((numofRoutes+1) != 16)//if not 0x10 (DLE char) BeginRecords[5] = ~(27 + 2 + (numofRoutes+1)) + 1; else BeginRecords2[6] = ~(27 + 2 + (numofRoutes+1)) + 1; GarminFlag = GOT_ETX; TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); if (EmptyLoc != 16) garminflag = BEGINRECORDS8; else garminflag = BEGINRECORDS9; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } else {//send routes to magellan if (IDOK != MessageBox(hwnd, SendingRoute, "Sending a Route", MB_OKCANCEL)) break; if (numofRoutes > 30)//max for Magellan MessageBox(hwnd, "Multiple routes will be created\n(30 waypoints per route).", "", MB_OK); Number[0] = ' ';//initialize waypoint count for (y = 1; y < 5; y++) Number[y] = '0'; Number[5] = ' '; xCenter = (rect.right/2) - (cxChar*4); yCenter = rect.bottom/2; for (y = 0; y < numofRoutes; y++) { if ((y+1) < 10) { Nums[y][0] = (y+1) + '0'; Nums[y][1] = '<'; Nums[y][2] = 0; } else if ((y+1) < 100) { Nums[y][0] = ((y+1) / 10) + '0'; Nums[y][1] = ((y+1) % 10) + '0'; Nums[y][2] = '<'; Nums[y][3] = 0; } else//y+1 < 1000 { Nums[y][0] = ((y+1) / 100) + '0'; Nums[y][1] = (((y+1) % 100) / 10) + '0'; Nums[y][2] = ((y+1) % 10) + '0'; Nums[y][3] = '<'; Nums[y][4] = 0; } } for (x = 0; x < TOTAL_LOCS; x++) { NewLoc[x].NUTM = 0; NewLoc[x].EUTM = 0; NewLoc[x].UTMZone = 0; NewLoc[x].pWaypoints = NULL;//pointer to waypoint data in WaypointArray NewLoc[x].Ident = NULL;//pointer to name NewLoc[x].Location = NULL;//pointer to cmt NewLoc[x].Description = NULL;//pointer to desc NewLoc[x].Elev = NULL;//pointer to ele NewLoc[x].Sym = NULL;//pointer to sym NewLoc[x].size = 0; prevDist[x] = HUNDRED_MILES; } for (x = 0; x < numofRoutes; x++) { NewLoc[x].NUTM = Root[0][x].N; NewLoc[x].EUTM = Root[0][x].E; NewLoc[x].UTMZone = Root[0][x].Z; NewLoc[x].Ident = Nums[x]; NewLoc[x].Sym = Mx;//medium city } EmptyLoc = numofRoutes; LocNum = 0; magflag = SENDWAYPOINTS; sendroutewaypoints = TRUE; TimerFlags.nmeatiming = TRUE; TimerFlags.gotprotocol = TRUE; TimerFlags.time = 5000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); gotver = FALSE; tgcount = 0; for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); ResetEvent(hEvent);//unsignal it // if ((gotver == FALSE) && (WaitForSingleObject(hEvent, 2000) == WAIT_TIMEOUT))//it will exit after 2 seconds or if signalled // { // for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) // ToGPS[tgcount] = GetMagellanVersion[x]; // if (tgcount > 49900) tgcount = 0; // WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); // } } } } } break; case ID_GPS_ROUTES_RECEIVE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (GetKeyState(VK_CONTROL) < 0) y = TRUE; if (itsexplorist) { MessageBox(hwnd, Explorist, Routine, MB_OK); break; } if (itsusb) { if (hUSBThread == 0) { FromUSBBuf = (BYTE*)VirtualAlloc(NULL, 1000000, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); *pParam = RECEIVEROUTE; hUSBThread = _beginthreadex(NULL, 0, USBThread, pParam, 0, &idThread4); } else MessageBox(hwnd, "USB Thread is still running...", NULL, MB_OK); break; } tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; if (RegValue[3] == '0') { MessageBox(hwnd, SelectCommPort, NULL, MB_OK); break; } GetCommHandle(); if (hComm != INVALID_HANDLE_VALUE) { autoLoc = FALSE; ResetEvent(hEventExit); hThread = _beginthreadex(NULL, 0, CommThread, NULL, 0, &idThread); Sleep(500); RouteNum = -1;//will increment to 0 rte = 0; gettingroute = TRUE; d201 = TRUE; d210 = FALSE; for (x = 0; x < 9; x++) PreCounting[x] = Down[x]; for (x = 0; x < 4; x++) Counting[x] = '0'; for (x = 8; x < 12; x++) Counting[x] = ' ';//don't know how many tracks... for (x = 0; x < 9; x++) PostCounting[x] = Routetxt[x]; if (itsgarmin) { TimerFlags.timing = TRUE; TimerFlags.garmintiming = TRUE; TimerFlags.gotprotocol = FALSE; TimerFlags.time = 3000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); GarminFlag = GOT_ETX; garminflag = RECEIVEROUTE; tgcount = 0; for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = Pid_Product_Rqst[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &Pid_Product_Rqst, 8, &dwBytesWritten, NULL); } else {//receive Magellan Routes (first receive waypoints) foroute = TRUE; gotroute = FALSE; routeway = 0; autoLoc = FALSE; Number[0] = ' '; for (y = 1; y < 5; y++) Number[y] = '0'; Number[5] = ' '; xCenter = (rect.right/2) - (cxChar*4); yCenter = rect.bottom/2; magflag = GETWAYPOINTS; TimerFlags.nmeatiming = TRUE; TimerFlags.gotprotocol = TRUE; TimerFlags.time = 5000; ResetEvent(hTimerEvent); _beginthreadex(NULL, 0, TimerThread, &TimerFlags, 0, &idThread3); gotver = FALSE; ResetEvent(hEvent);//unsignal it tgcount = 0; for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); if ((gotver == FALSE) && (WaitForSingleObject(hEvent, 2000) == WAIT_TIMEOUT))//it will exit after 1 second or if signalled { for (x = 0; GetMagellanVersion[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanVersion[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanVersion, sizeof(GetMagellanVersion)-1, &dwBytesWritten, NULL); } } } break; case ID_GPS_LOCATION_COPYPOSITION01CSVTOTRACKFORMAT: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (posflag == FALSE) break; ofn5.lpstrFilter = " Position??.csv\0""Position*.csv\0\0"; ofn5.lpstrFileTitle = PositionCsv; ofn5.lpstrFile = NULL; ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn5.lpstrTitle = NULL; ofn5.lpstrDefExt = "csv"; if (GetOpenFileName(&ofn5))//fill in PositionCsv { int x, y, commas; DWORD fileSize; HANDLE hFile; hFile = CreateFile(PositionCsv, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); if (fileSize > sizeof(PositionHeader)+1) { char *posn = (char*)malloc(fileSize); char *trk = (char*)malloc(fileSize); ReadFile(hFile, posn, fileSize, &dwBytesRead, NULL); for (x = 0, y = 0; PreTracks[x] != 0; x++, y++) trk[y] = PreTracks[x]; for (y = 0; (posn[y] != '\n') && (y < (int)fileSize); y++) ; y++;//go past the first line if (posn[y] == 'N')//new format { commas = 0; for ( ; (y < (int)fileSize); x++, y++) { if (posn[y] == ',') commas++; if (commas == 10) { commas = 0; for ( ; (posn[y] != '\r') && (y < (int)fileSize); y++) ;//skip to end of line } trk[x] = posn[y]; } ofn5.lpstrFilter = " *.csv\0""*.csv\0\0"; ofn5.lpstrFile = FullTracks; ofn5.lpstrFileTitle = Tracks; ofn5.lpstrInitialDir = CurrentTrackDir; if (FALSE != GetSaveFileName(&ofn5)) { hFile2 = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile2, trk, x, &dwBytesWritten, NULL); CloseHandle(hFile2); } ofn5.lpstrInitialDir = CurrentDir; } else MessageBox(hwnd, "This only works with\nthe new position format,\nwhich adds a comma-separated\nfield at the beginning of each line\nwhich is either 'New' or blank.", "Sorry", MB_OK); free(trk); free(posn); } CloseHandle(hFile); } } break; case ID_GPS_LOCATION_DISPLAYPOSITION01CSV://display what's in Position01.csv EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (posflag == FALSE) break; ofn5.lpstrFilter = " Position??.csv\0""Position*.csv\0\0"; ofn5.lpstrFileTitle = PositionCsv; ofn5.lpstrFile = NULL; ofn5.Flags = OFN_HIDEREADONLY|OFN_NOCHANGEDIR; ofn5.lpstrTitle = NULL; ofn5.lpstrDefExt = "csv"; if (GetOpenFileName(&ofn5))//fill in PositionCsv { int x, y, xUTMZone; DWORD fileSize; HANDLE hFile; hFile = CreateFile(PositionCsv, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); if (fileSize > sizeof(PositionHeader)+1) { int Begin; char *Pos = NULL; if (pos) { SavePosition(); } Pos = (char*)malloc(fileSize); ReadFile(hFile, Pos, fileSize, &dwBytesRead, NULL); for (y = 0; (Pos[y] != '\n') && (y < (int)fileSize); y++) ; y++;//go past the first line Begin = y; for (x = y; x < (int)fileSize; x++) {//check for wrong characters if (((Pos[x] >= '0') && (Pos[x] <= '9')) || (Pos[x] == '\r') || (Pos[x] == '\n') || (Pos[x] == ',') || (Pos[x] == '.') || (Pos[x] == '-') || (Pos[x] == 'N') || (Pos[x] == 'e') || (Pos[x] == 'w')) continue; else break; } if (x != (int)fileSize) { sprintf(Error, "%c found in %s", Pos[x], PositionCsv); MessageBox(hwnd, Error, ERROR, MB_OK); break; } for (pos = 0; (y < (int)fileSize) && (pos < 14400); pos++) { if (Pos[Begin] == 'N') {//if new format for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; y++;//past New, or , } Position[pos].UTMZ = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].UTMN = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].UTME = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Hour = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Min = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Sec = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Month = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Date = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Year = atoi(&Pos[y]) - 2000; for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Alt = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].HorizEpe = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].VertEpe = atoi(&Pos[y]); for ( ; (Pos[y] != '\n') && (Pos[y] != ',') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; if (Pos[y-1] == '\n') continue; Position[pos].Velocity = (float)atof(&Pos[y]); for ( ; (Pos[y] != '\n') && (y < (int)fileSize); y++) ; if (y == (int)fileSize) break; y++; Position[pos].Course = 0xFFFF; }//end of for ( free(Pos); }//end of if (fileSize == else { CloseHandle(hFile); MessageBox(hwnd, "File is empty.\n Deleting it.", ERROR, MB_OK); DeleteFile(PositionCsv); break; } CloseHandle(hFile); //{ // int savePos = pos; // compressit = FALSE; // for (pos = 0; pos < savePos; pos++) // ConvertoGPSLatLon(); // pos = savePos; //} for (x = 0; (x < pos) && ((Position[x].UTMN == 0)); x++)// && (Position[x].UTME == 0) && (Position[x].UTMZ == 0) ; BeginY = Position[x].UTMN / MetersPerTile; BeginX = Position[x].UTME / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen xUTMZone = Position[x].UTMZ; if (xUTMZone == UTMZone) { SendMessage(hwnd, WM_USER, 0, 0); } else { UTMNorthing = Position[x].UTMN; UTMEasting = Position[x].UTME; ChangeZone(xUTMZone, 6);//show position _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; Waypoints[0] = 0; SendMessage(hwnd, WM_USER4, 0, 0); } posflag = FALSE; if (testingsmartbeaconing == FALSE) { hwndPosit = CreateWindow("EDIT", PositionCsv, WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | ES_MULTILINE, 0, 0, 200, 200, hwnd, hMenu2, hInst, NULL);//(HMENU)178 pPosProc = (WNDPROC)SetWindowLong(hwndPosit, GWL_WNDPROC, (LONG)PosProc);//sub-class for WM_DESTROYWINDOW SetWindowText(hwndPosit, Posit); SendMessage(hwndPosit, EM_SETREADONLY, 1, 0); fromposition = TRUE;//so WM_MOUSEMOVE will show info } InvalidateRect(hwnd, &rect, FALSE); }//end of if (hFile != } break; case ID_GPS_LOCATION_SHOWLOCATIONSPACEBAR: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (GetKeyState(VK_CONTROL) < 0) simulate = TRUE; SendMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_SPACE, 0); break; case ID_GPS_POSITION_DRAWALINEFROMPOSITIONTOAWAYPOINT: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (yPos > TitleAndMenu)//2 { centerX = xPos; centerY = yPos; } else { centerX = rect.right >> 1; centerY = rect.bottom >> 1; } UTMCenterX = (centerX * MetersPerTile/PixelsPerTile) + ScreenLeft; UTMCenterY = ScreenTop - (centerY * MetersPerTile/PixelsPerTile); B = 10000000000.0;//large number index = -1;//flag for (x = 0; x < TOTAL_LOCS; x++) { if (NewLoc[x].EUTM == 0) break; if (NewLoc[x].UTMZone != UTMZone) continue; idistX = UTMCenterX - NewLoc[x].EUTM; if (idistX < 1) idistX = -(idistX); idistY = UTMCenterY - NewLoc[x].NUTM; if (idistY < 1) idistY = -(idistY); distX = (double) idistX; distY = (double) idistY; A = (int) sqrt((distX*distX) + (distY*distY)); if (A < B) { B = A; index = x; } } ///////// if (DialogBox(hInst, "SHOWLINE", hwnd, LineProc)) showline = TRUE; else showline = FALSE; ///////// break; case ID_APPROACHCONTROL_HELP: pApproachHelp = NULL; hFile = CreateFile(ApproachControlHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (HelpSize = GetFileSize(hFile, NULL)) { pApproachHelp = (char*)malloc(HelpSize+1); if (pApproachHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pApproachHelp[HelpSize] = 0; ReadFile(hFile, pApproachHelp, HelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndApproachHelp = CreateWindow(Instruct, ApproachControlHelp, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, 0, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), 630, NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pApproachHelp); SetFocus(hwndInstr); free(pApproachHelp); } CloseHandle (hFile); } else MessageBox(hwnd, ApproachControlHelp, "Couldn't find", MB_OK); break; case ID_APPROACHCONTROL_ADVANCEDHELP: pApproachHelp = NULL; hFile = CreateFile(AdvancedApproachControlHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (HelpSize = GetFileSize(hFile, NULL)) { pApproachHelp = (char*)malloc(HelpSize+1); if (pApproachHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pApproachHelp[HelpSize] = 0; ReadFile(hFile, pApproachHelp, HelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndApproachHelp = CreateWindow(Instruct, AdvancedApproachControlHelp, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, 0, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), 420, NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pApproachHelp); SetFocus(hwndInstr); free(pApproachHelp); } CloseHandle (hFile); } else MessageBox(hwnd, AdvancedApproachControlHelp, "Couldn't find", MB_OK); break; case ID_APPROACHCONTROL_ATLANTA: if (uTimerID == NULL) { UTMZone = 16; UTMEasting = 738700; UTMNorthing = 3725300; ApproachControl(); } break; case ID_APPROACHCONTROL_CHICAGO: if (uTimerID == NULL) { UTMZone = 16; UTMEasting = 425200; UTMNorthing = 4648000; ApproachControl(); } break; case ID_APPROACHCONTROL_DENVER: if (uTimerID == NULL) { UTMZone = 13; UTMEasting = 510000; UTMNorthing = 4402000; ApproachControl(); } break; case ID_APPROACHCONTROL_NEWYORK: if (uTimerID == NULL) { UTMZone = 18; UTMEasting = 602480; UTMNorthing = 4500300; ApproachControl(); } break; case ID_APPROACHCONTROL_SALTLAKECITY: if (uTimerID == NULL) { UTMZone = 12; UTMEasting = 416900; UTMNorthing = 4515900; ApproachControl(); } break; case ID_APPROACHCONTROL_SANFRANCISCO: if (uTimerID == NULL) { UTMZone = 10; UTMEasting = 554240; UTMNorthing = 4163800; ApproachControl(); } break; case ID_HELP_PHOTOMAPHELP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; SendMessage(hwnd, WM_KEYDOWN, (WPARAM)VK_F1, 0); break; case ID_HELP_HTTP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; WinExec(Index, SW_SHOW); break; case ID_HELP_CHECKFORNEWERVERSION: hOpen = InternetOpen(ProgName, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); if (hInternet = InternetOpenUrl(hOpen, CheckforUpdate, Accept, -1, INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_KEEP_CONNECTION, 0)) { char *MyWebPage; MyWebPage = (char*)calloc(1, MYWEBPAGESIZE);//shouldn't get any bigger than this for (fileSize = 0; (goodread = InternetReadFile(hInternet, MyWebPage, MYWEBPAGESIZE, &dwBytesRead)) && (dwBytesRead); fileSize += dwBytesRead) ; InternetCloseHandle(hInternet); if ((goodread) && (dwBytesRead == 0)) { for (x = 0; x < fileSize; x++) { if ((MyWebPage[x] == '>') && (MyWebPage[x+1] == 'F') && (MyWebPage[x+8] == 's') && (MyWebPage[x+9] == 't') && (MyWebPage[x+10] == 'a')) { x += 30;//to version number y = 8;//version number for (z = 0; z < 4; x++, y++, z++) if (MyWebPage[x] != Version[y]) break; if (z != 4) MessageBox(hwnd, NewerVersion, ProgName, MB_OK); else { for (x = 0; x < fileSize; x++) { if ((MyWebPage[x] == '>') && (MyWebPage[x+1] == 'W') && (MyWebPage[x+8] == 'N') && (MyWebPage[x+9] == 'e') && (MyWebPage[x+10] == 'w')) { x += 18;//to date for (y = 0; Version[y] != '\r'; y++) ; y += 4;//to date for (z = 0; z < 11; x++, y++, z++)//November 30 if (MyWebPage[x] != Version[y]) break; if (z != 11) MessageBox(hwnd, NewerDate, ProgName, MB_OK); else MessageBox(hwnd, SameVersion, ProgName, MB_OK); break; } } } break; } } // HANDLE hFile = CreateFile(MyWebPage, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); // WriteFile(hFile, MyWebPage, fileSize, &dwBytesWritten, NULL); // CloseHandle(hFile); } free(MyWebPage); } InternetCloseHandle(hOpen); break; case ID_HELP_GETDATEOFPHOTOTOPO: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; // w = 54;//just after S= w = 40;//just after S= if (MapType == PHOTO) { // GetDate[50] = '1';//T= GetDate[36] = '1';//T= GetDate[w++] = '1'; if (Zoom < 5) GetDate[w++] = '0'; else GetDate[w++] = '3'; } else if (MapType == TOPO) { // GetDate[50] = '2'; GetDate[36] = '2'; GetDate[w++] = '1'; GetDate[w++] = '2'; } else//if (MapType == URBANAREA) { // GetDate[50] = '4'; GetDate[36] = '4'; GetDate[w++] = '8'; } GetDate[w++] = '&'; GetDate[w++] = 'Z'; GetDate[w++] = '='; GetDate[w++] = Z[0]; GetDate[w++] = Z[1]; GetDate[w++] = '&'; GetDate[w++] = 'X'; GetDate[w++] = '='; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; if (yPos < 100) {//if Alt-H D not used UTMNorthing = ScreenTop - (((rect.bottom / 2) * MetersPerTile) / PixelsPerTile); UTMEasting = ScreenLeft + (((rect.right / 2) * MetersPerTile) / PixelsPerTile); } if ((MapType == PHOTO) && (Zoom < 5)) w += sprintf(&GetDate[w], "%i", UTMEasting / 200); else if ((MapType == PHOTO) && (Zoom >= 5)) w += sprintf(&GetDate[w], "%i", UTMEasting / 1600); else if (MapType == TOPO) w += sprintf(&GetDate[w], "%i", UTMEasting / 800); else if (MapType == URBANAREA) w += sprintf(&GetDate[w], "%i", UTMEasting / 50); GetDate[w++] = '&'; GetDate[w++] = 'Y'; GetDate[w++] = '='; if ((MapType == PHOTO) && (Zoom < 5)) w += sprintf(&GetDate[w], "%i", UTMNorthing / 200); else if ((MapType == PHOTO) && (Zoom >= 5)) w += sprintf(&GetDate[w], "%i", UTMNorthing / 1600); else if (MapType == TOPO) w += sprintf(&GetDate[w], "%i", UTMNorthing / 800); else if (MapType == URBANAREA) w += sprintf(&GetDate[w], "%i", UTMNorthing / 50); GetDate[w] = 0; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; for (x = 48, y = 0; GetDate[y] != 0; x++, y++) TerraServer[x] = GetDate[y]; TerraServer[x] = 0; if (WinExec(TerraServer, SW_SHOW) <= 31) DialogBox(hInst, "SHOWLATLON", hwnd, LatLonProc); break; case ID_HELP_TIGERDATA: if (autoLoc == FALSE) { pHelp = NULL; hFile = CreateFile(TigerHelp, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (TigerHelpSize = GetFileSize(hFile, NULL)) { pTigerHelp = (char*)malloc(TigerHelpSize+1); if (pTigerHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pTigerHelp[TigerHelpSize] = 0; ReadFile(hFile, pTigerHelp, TigerHelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndTigerHelp = CreateWindow(Instruct, Tiger, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen/2-320, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), cyScreen-(cyChar*3), NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pTigerHelp); SetFocus(hwndInstr); } CloseHandle(hFile); } else MessageBox(hwnd, NoHelpFile, NULL, MB_OK); } break; /* case ID_HELP_TIGERCOUNTIES: if (autoLoc == FALSE) { TigerIndex[21] = (UTMZone / 10) + '0'; TigerIndex[22] = (UTMZone % 10) + '0'; pHelp = NULL; hFile = CreateFile(TigerIndex, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (CountyHelpSize = GetFileSize(hFile, NULL)) { pCounties = (char *) malloc(CountyHelpSize+1); if (pCounties == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pCounties[CountyHelpSize] = 0; ReadFile(hFile, pCounties, CountyHelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndCounties = CreateWindow(Instruct, TigerIndex, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen/2-320, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), cyScreen-(cyChar*3), NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pCounties); SetFocus(hwndInstr); } CloseHandle (hFile); } // else // MessageBox(hwnd, TigerIndex, "Couldn't find", MB_OK); // if (pCounties != NULL) // free(pCounties); } return 0; */ case ID_HELP_ABOUTPHOTOMAP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (autoLoc == FALSE) MessageBox(hwnd, Version, " USAPhotoMaps ", MB_OK); break; } return 0; case WM_USER8: CloseHandle((HANDLE)hThread); hThread = NULL; if (tiger) { tiger = 0; hSmallFile = CreateFile(SmallBufDta, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); fileSize = GetFileSize(hSmallFile, NULL); tempBuffer = (BYTE*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); ReadFile(hSmallFile, tempBuffer, fileSize, &dwBytesRead, NULL); CloseHandle(hSmallFile); for (x = 0; x < (int)fileSize; x++) { if ((tempBuffer[x] == '\r') && (tempBuffer[x+1] == '\n') && (tempBuffer[x+2] == '\r') && (tempBuffer[x+3] == '\n')) { x += 4;//hopefully to zipped data if ((tempBuffer[x] == 'P') && (tempBuffer[x+1] == 'K') && (x < (int)fileSize)) { hFile = CreateFile(TigerZip, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, &tempBuffer[x], fileSize-x, &dwBytesWritten, NULL); CloseHandle(hFile); DeleteFile(SmallBufDta); tiger = 1; } break; } } VirtualFree(tempBuffer, 0, MEM_RELEASE); /////////////// if (tiger) { hThread = _beginthreadex(NULL, 0, TigerThread, NULL, 0, &idThread); Sleep(500); } /////////////// } return 0; case WM_APRS_SERVER: switch (LOWORD(lParam)) { case FD_ACCEPT: sAccept = accept(sListen, NULL, NULL); if (INVALID_SOCKET == sAccept) { MessageBox(NULL, "Error 6", ERROR, MB_OK); return 0; } break; case FD_WRITE: okay = TRUE; break; case FD_READ: send(sAccept, (char*)&aprsBuf[linebeg], linend-linebeg+1, 0); break; } return 0; case WM_APRS_IS_COMM: //************ aprsISbeg = aprsISend; aprsISend = (int)lParam; //************ for (aprsi = aprsISbeg; aprsi < aprsISend; aprsi++) { // if ((hwndComm) && (kiss == FALSE) && (aprsBuf[aprsi] != '\r')) // SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, aprsBuf[aprsi], 0); if (aprsBuf[aprsi] == '\n') { if (isaprslinebeg != -1) { x = isaprslinebeg; isaprslinebeg = linend+3; linend = aprsi-2; for (z = 0; (z < 10) && (aprsBuf[x] != '>') && (x < linend); x++, z++) Addr[z] = aprsBuf[x]; Addr[z] = 0; if (x < linend) { for (x++, y = 0; (aprsBuf[x] != ':') && (x < linend); x++, y++) if (y < 6) Dest[y] = aprsBuf[x];//for Mic-E if (x < linend) { x++; ParseAPRS(x); } } } else isaprslinebeg = aprsi+1; } } return 0; case WM_APRS_COMM: //************ aprsBuf[aprsi] = (char)lParam; //************ if ((hwndComm) && (kiss == FALSE) && (aprsBuf[aprsi] != '\r')) SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, aprsBuf[aprsi], 0); if (shutitdown) { if ((aprsBuf[aprsi] == ':') && (aprsBuf[aprsi-1] == 'd') && (aprsBuf[aprsi-2] == 'm') && (aprsBuf[aprsi-3] == 'c')) { shutitdown = FALSE; kiss = FALSE; SetEvent(hAPRSEvent);//close APRSCommThread aprsi++; SaveAPRSlog(); SaveAPRSlogAsText(); if (hwndComm != NULL) { DestroyWindow(hwndAPRSDlg); hwndAPRSDlg = NULL; } tnc = inaprs = 0; if ((!gettinginternet) && (!gettingsaved)) aprsi = Aprsi = aprs = 0;//FALSE InvalidateRect(hwnd, &rect, FALSE); return 0; } } if (gotcr) { if ((lParam != '\r') && (lParam != '\n')) gotcr = FALSE; else { if (aprsimulate) SetEvent(hAPRSEvent); return 0; } } if ((kiss == FALSE) && (aprsBuf[aprsi] == '\n')) {//maybe at end of line gotcr = TRUE; if (aprsBuf[aprsi-1] == ':') {//an oddity aprsi--;//to write over odd \n goto notaprs; } if ((aprsBuf[aprsi-2] == ':') && (aprsBuf[aprsi-3] == '>'))//": \r\n" {//not the end of the line x = aprsi-4; if (aprsBuf[x] == '>') x--; if (aprsBuf[x] == 'I') x--; if (aprsBuf[x] == 'U') x--; if (aprsBuf[x] == '<') x--; if (aprsBuf[x] == '<') x--; if (aprsBuf[x] == ' ') x--; aprsi = x; } else if ((aprsBuf[aprsi-2] == 'F') && (aprsBuf[aprsi-4] == 'O') && (aprsBuf[aprsi-12] == 'M') && (aprsBuf[aprsi-8] == 'T')) {//MONITOR OFF\r\n aprsi -= 12;//over-write it } else { linend = aprsi; for (x = aprsi-1; x >= 0; x--) { if ((aprsBuf[x] == '\n') || (x == 0)) { if (x) x++; break; } } if ((aprsBuf[x] == 'c') && (aprsBuf[x+1] == 'm') && (aprsBuf[x+2] == 'd') && (aprsBuf[x+3] == ':')) x += 4; if (aprsBuf[x] == '\r') x++; if (aprsBuf[x] == '\n') x++; linebeg = x; fdsa: for (z = 0; (z < 10) && (aprsBuf[x] != '>') && (x < linend); x++, z++) Addr[z] = aprsBuf[x]; Addr[z] = 0; if (transmitted) { for (z = 0; Addr[z] != '\0'; z++) if (Addr[z] != MyCall[z]) break; if ((Addr[z] == '\0') && (MyCall[z] == '\0')) { transmitted = FALSE; WriteFile(hAPRSComm, BTEXT, strlen(BTEXT), &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); Sleep(500); WriteFile(hAPRSComm, BEACON, lstrlen(BEACON), &dwBytesWritten, NULL); WriteFile(hAPRSComm, "\x0D", 1, &dwBytesWritten, NULL); } } if (x < linend) { for (x++, y = 0; (aprsBuf[x] != ':') && (x < linend); x++, y++) if (y < 6) Dest[y] = aprsBuf[x];//for Mic-E if (x < linend) { x++; if (aprsBuf[x] == '}')//third-party { x++; goto fdsa; } else { if (okay) PostMessage(hwnd, WM_APRS_SERVER, 0, (LPARAM)FD_READ); if ((igate) && (aprsBuf[x] != '?'))//no queries { for (y = x-1, z = 0; y > linebeg; y--) { if ((aprsBuf[y] == 'P') && (aprsBuf[y-1] == 'I') && (aprsBuf[y-2] == 'P') && (aprsBuf[y-3] == 'C') && (aprsBuf[y-4] == 'T')) {//TCPIP break; } } if (y == linebeg) { for (z = 0; (z < 250) && (aprsBuf[y] != ':') && (aprsBuf[y] != '\r'); y++, z++) { ToInternet[z] = aprsBuf[y]; } if (aprsBuf[y] == ':') {//insert ,qAR, and send it to the Internet for (w = 0; (z < 250) && (IgateInsert[w] != 0); w++, z++) ToInternet[z] = IgateInsert[w]; for (w = 0; (z < 250) && (MyCall[w] != 0) && (MyCall[w] != '-'); w++, z++) ToInternet[z] = MyCall[w]; for ( ; (z < 250) && (aprsBuf[y] != '\r'); y++, z++) ToInternet[z] = aprsBuf[y]; if (z < 250) { ToInternet[z++] = '\r'; ToInternet[z++] = '\n'; ToInternet[z] = 0; if(s3 != INVALID_SOCKET) { if (SOCKET_ERROR == send(s3, ToInternet, strlen(ToInternet), 0)) { igate = FALSE; sprintf(Error, "Send error %ld\n(line %d)", WSAGetLastError(), __LINE__); SendMessage(hwnd, WM_COMMAND, ID_APRS_INTERNETNETWORK_ACTASANIGATE, 0); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); } else LookForIgateMessages(); } else { igate = FALSE; sprintf(Error, "Invalid socket\n(line %ld)", __LINE__); MessageBox(hwnd, Error, IgateErrorCaption, MB_OK); } } } } } ParseAPRS(x); } } } } } /*KISS Frame begins with 0xC0 & Type Indicator (usually 0) (APRS AX.25 format) Flag 1 byte 0x7E - this is removed (addresses are shifted 1 bit left, and all but the last byte have 0 at the least significant bit) Control Field (UI) 1 byte 0x03 Protocol ID 1 byte 0xF0 (no layer 3 protocol) Information Field 1-256 bytes Frame Check Sequence 2 bytes - this is removed KISS Frame ends with 0xC0 to end KISS, send alt-192 -255 -192 */ else if (kiss) { ach = aprsBuf[aprsi]; if (gotfesc) { gotfesc = FALSE; if (ach == TFEND) ach = FEND;//0xC0 else if (ach == TFESC) ach = FESC; } else if (ach == FESC) gotfesc = TRUE; else if ((kPtr == KISSEND) && (ach == FEND)) { kPtr = APRSFRAME; kaddr = 0; for (x = 0; x < 10; x++) { Addr[x] = 0; Dest[x] = 0; } } else if (kPtr == APRSFRAME) kPtr = TYPE; else if (kPtr == TYPE) { kPtr = ADDRESS; ach >>= 1; aprsBuf[aprsi] >>= 1; SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, ach, 0); Dest[kaddr] = ach;//for Mic-E kaddr++; } else if (kPtr == ADDRESS) { if ((ach & 1) == 1) kPtr = ADDEND; ach >>= 1; aprsBuf[aprsi] >>= 1; SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, ach, 0); if (kaddr < 6) Dest[kaddr] = ach;//for Mic-E if (kaddr == 7) addr = 0; if ((kaddr >= 7) && (kaddr <= 12)) { if (ach != ' ') Addr[addr++] = ach; else Addr[addr] = 0; } else if (kaddr == 13) { if ((ach >= 'q') && (ach <= '\x7F')) { ach -= 0x70; Addr[addr++] = '-'; if (ach <= 9) Addr[addr++] = ach + '0'; else { Addr[addr++] = (ach/10) + '0'; Addr[addr++] = (ach%10) + '0'; } } else if ((ach >= '1') && (ach <= '9')) { Addr[addr++] = '-'; Addr[addr++] = ach; } else Addr[addr] = 0; } kaddr++; } else if (kPtr == ADDEND) { kPtr = CONTROL; if (ach != 3) goto notaprs; } else if (kPtr == CONTROL) { kPtr = PROTOCOL; if (ach != 0xF0) goto notaprs; } else if (kPtr == PROTOCOL) { kPtr = INFO; dataloc = aprsi; } else if (kPtr == INFO) { x = aprsi; if (ach == 0xC0) {//end of received data kPtr = KISSEND; aprsBuf[aprsi++] = '\r';//to make it work with routines that look for \r or \n SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, '\r', 0); aprsBuf[aprsi++] = '\n'; SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, '\n', 0); ParseAPRS(dataloc); } else { aprsBuf[x++] = ach; SendDlgItemMessage(hwndAPRSDlg, IDC_EDIT1, WM_CHAR, ach, 0); } } } notaprs: if (aprsi > 16300 && gotcr) SaveAPRSlogAsText(); else aprsi++; if (Aprsi >= MAXAPRS-2) SaveAPRSlog(); if (aprsimulate) SetEvent(hAPRSEvent); return 0; case WM_USER_COMM://called if GPS is on, connected, etc goodcomm = TRUE; Buf[iBuf] = (unsigned char)lParam; if (itsgarmin == FALSE)//using NMEA protocol { if (iLatLon != -1)//GPS is sending waypoints or tracks or position { if (iLatLon > 400) { iLatLon = -1; MessageBox(hwnd, "possible bug...", NULL, MB_OK); return 0; } if ((char)lParam != 0x0D) { tempLatLon[iLatLon++] = (char)lParam;//fill up tempLatLon & increment iLatLon until 0x0D } else//((char)lParam == 0x0D) got a line (tempLatLon is complete) { TimerFlags.nmeatiming = FALSE; tempLatLon[iLatLon] = 0; iLatLon = -1; if (tempLatLon[0] == ',') {//no data Lat = 0; Lon = 0; iBuf++; if (iBuf == 50000) iBuf = 0; // MessageBox(hwnd, "No data", "", MB_OK); return 0; } else { Lat = ((double)((tempLatLon[0] - '0') * 10) + (tempLatLon[1] - '0')) + ((atof(&tempLatLon[2])) / 60.0); for (x = 0; (tempLatLon[x] != 'N') && (x < 100); x++) ; if (x >= 100) { MessageBox(hwnd, "Line is over 100 chars", "", MB_OK); return 0;//just in case } x += 2;//to Longitude Lon = -((double)((tempLatLon[x] - '0') * 100) + ((tempLatLon[x+1] - '0') * 10) + (tempLatLon[x+2] - '0') + ((atof(&tempLatLon[x+3])) / 60.0)); // if ((Lon > -60.0) || (Lon < -168.0) || (Lat > 72.0) || (Lat < 17.5))//WM_LBUTTONDOWN // return 0; // else { LatRad = Lat*deg2rad; LonRad = Lon*deg2rad; LatLontoUTM();//get UTMEasting & UTMNorthing } } if (itsmagellan == 1)//receiving waypoints {//$PMGNWPL,1827.026,N,06604.448,W,0000017,M,BUS STOP,BUS STOP,x*5D if ((foroute)) { RouteWay[routeway].Z = UTMZone; RouteWay[routeway].N = UTMNorthing; RouteWay[routeway].E = UTMEasting; //goto waypoint ident/name for (x = 0; (tempLatLon[x] != 'W') && (x < 100); x++) ; x += 2;//to elevation for (z = 0; (tempLatLon[x] != ',') && (x < 100); x++, z++) ; x++;//to either 'F,' or 'M,' or 'MYHOUSE' if (tempLatLon[x+1] == ',') x += 2;//to waypoint name for (y = 0; tempLatLon[x] != ','; x++, y++) RouteWay[routeway].Ident[y] = tempLatLon[x]; RouteWay[routeway].Ident[y] = 0; if (0 != strcmp(RouteWay[routeway].Ident, RouteWay[routeway-1].Ident)) routeway++; } else//if (tempUTMZone == UTMZone) {//$PMGNWPL,llll.lll,N,lllll.lll,W,aaaa,F,c----c,c---c,c--c,xx*hh for (x = 0; (tempLatLon[x] != 'W') && (x < 100); x++) ; x += 2;//to elevation for (z = 0; (tempLatLon[x] != ',') && (x < 100); x++, z++) Elev[z] = tempLatLon[x]; Elev[z] = 0; x++;//to either 'F,' or 'M,' or 'MYHOUSE' if (tempLatLon[x] == 'F') { eleM = atoi(Elev) * 0.3048;//convert to meters sprintf(Elev, "%.4f", eleM);//& put it back in Elev } for (z = 0; Elev[z] != 0; z++) if (Elev[z] != '0') break; if (Elev[z] == 0) Elev[0] = 0;//don't bother with all 0's if (tempLatLon[x+1] == ',') x += 2;//to waypoint name IdentOffset = x; //get ident/name for (x = 0; (tempLatLon[IdentOffset+x] != ',') && (tempLatLon[IdentOffset+x] != '*'); x++) Ident[x] = tempLatLon[IdentOffset+x]; Ident[x] = 0; //get location/comment x += IdentOffset; Location[0] = 0; if (tempLatLon[x] == ',')//if it's not '*' { x++;//to possible comment LocOffset = x; if (tempLatLon[x] != ',')//if it's not empty { for (z = 0; (tempLatLon[LocOffset+z] != ',') && (tempLatLon[LocOffset+z] != '*'); z++) Location[z] = tempLatLon[LocOffset+z]; Location[z] = 0; } x = LocOffset + z; } Sym[0] = 0; if (tempLatLon[x] == ',') {//not '*' GetMagSym(x); } for (x = 0; x < EmptyLoc; x++) {//check for duplicate & ignore it if (NewLoc[x].Ident != NULL) { for (y = 0; (NewLoc[x].Ident[y] == Ident[y]) && (Ident[y] != 0); y++) ; if (((NewLoc[x].Ident[y] == '<') || (NewLoc[x].Ident[y] == ' ')) && (Ident[y] == 0)) goto magellanexit; } } for (x = 0; x < EmptyLoc; x++) { if ((NewLoc[x].Location != NULL) && (strcmp(NewLoc[x].Location, Location) > 0)) { InsertLoc = x; EmptyLoc++; for (x = EmptyLoc; x > InsertLoc; x--) NewLoc[x] = NewLoc[x-1];//move to make room to insert new data break; } } if (x == EmptyLoc) { InsertLoc = x; EmptyLoc++; } NewLoc[InsertLoc].EUTM = UTMEasting; NewLoc[InsertLoc].NUTM = UTMNorthing; NewLoc[InsertLoc].UTMZone = UTMZone; ///---> FillWaypointArray(InsertLoc); ///---> }//end of if(tempUTMZone == UTMZone) magellanexit: IncNumber(); hdc = GetDC(hwnd); TextOut(hdc, xCenter, yCenter, Number, 6);//count ReleaseDC(hwnd, hdc); // SendChecksum();//need TempiBuf }//end of if (itsmagellan == 1) else if (itsmagellan == 2)//receiving tracks {//$PMGNTRK,1759.049,N,06637.161,W,00009,M,194354.07,A,,261202*62 //$PMGNTRK,4004.464,N,07500.488,W,alt,MorF,time,A*31 FillTrackFromNMEA(); IncNumber(); hdc = GetDC(hwnd); TextOut(hdc, xCenter, yCenter, Number, 6); ReleaseDC(hwnd, hdc); // SendChecksum(); } else//if (itsmagellan == 0)//receiving position { Position[pos].Alt = 0; Position[pos].Velocity = 0; Position[pos].Month = 0; Position[pos].Date = 0; Position[pos].Year = 0; Position[pos].HorizEpe = 0; Position[pos].VertEpe = 0; // Position[pos].New = 0; if (LineType != GLL) { if (newposition == FALSE) pos--; for (x = 0, y = 0; tempLatLon[x] != 0; x++) { if (tempLatLon[x] == ',') { x++; y++; if ((y == 4) && (LineType == RMC) && (tempLatLon[x] != ',')) { Position[pos].Velocity = (float)(atof(&tempLatLon[x]) * 1.150779448);//to convert knots to miles/hour Velocity = Position[pos].Velocity; } else if ((y == 6) && (LineType == RMC)) { if (tempLatLon[x] != ',') { Position[pos].Date = ((tempLatLon[x] - '0') * 10) + (tempLatLon[x+1] - '0'); Position[pos].Month = ((tempLatLon[x+2] - '0') * 10) + (tempLatLon[x+3] - '0'); Position[pos].Year = ((tempLatLon[x+4] - '0') * 10) + (tempLatLon[x+5] - '0'); } break; } else if ((y == 7) && (LineType == GGA)) { if (tempLatLon[x] != ',') Position[pos].Alt = (int)(atof(&tempLatLon[x+1]) / 0.3048);//in feet; break; } } } } if (newposition) ShowPosition();// get Position[pos].UTMZ .UTMN. and .UTME else pos++; }//end of else//if (itsmagellan == 0)//receiving position }//end of else got it all }//end of if (iLatLon != -1) //************************************************************* /* GLL,4916.45,N,12311.12,W,225444,A 4916.46,N Latitude 49 deg. 16.45 min. North 12311.12,W Longitude 123 deg. 11.12 min. West 225444 Fix taken at 22:54:44 UTC A Data valid // 0 1 2 3 4 5 6 7 GGA,123519,4807.038,N,01131.324,E,1,08,0.9,545.4,M,46.9,M, , *42 123519 Fix taken at 12:35:19 UTC 4807.038,N Latitude 48 deg 07.038' N 01131.324,E Longitude 11 deg 31.324' E 1 Fix quality: 0 = invalid 1 = GPS fix 2 = DGPS fix 08 Number of satellites being tracked 0.9 Horizontal dilution of position 545.4,M Altitude, Metres, above mean sea level 46.9,M Height of geoid (mean sea level) above WGS84 ellipsoid (empty field) time in seconds since last DGPS update (empty field) DGPS station ID number // 0 1 2 3 4 5 6 RMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68 225446 Time of fix 22:54:46 UTC A A = Valid position, V = not valid 4916.45,N Latitude 49 deg. 16.45 min. North 12311.12,W Longitude 123 deg. 11.12 min. West 000.5 Speed over ground, Knots 054.7 Course Made Good, degrees true 191194 UTC Date of fix, 19 November 1994 020.3,E Magnetic variation, 20.3 deg. East // 0 1 2 3 4 WPL,4917.16,N,12310.64,W,003*65 */ else if (showposition) { if (Buf[iBuf-6] == '$') { if ((LineType <= 1) && (Buf[iBuf-3] == 'G') && (Buf[iBuf-2] == 'L') && (Buf[iBuf-1] == 'L')) {//GLL - don't bother about commas, you're already at comma before Latitude LineType = GLL; itsmagellan = 0; iLatLon = 0;//flag & initialize // TimerFlags.nmeatiming = FALSE; } else if ((Buf[iBuf-3] == 'G') && (Buf[iBuf-2] == 'G') && (Buf[iBuf-1] == 'A')) {//$GPGGA,184526,3724.456,N,12206.978,W,1,04,2.1,23.7,M,-28.4,M,,*4A //$GPGGA,045310,3443.1675,N,11609.7312,W,0,0,0.00,583,M,,,,*1C LineType = GGA; commas = 1; Time = iBuf+1; } else if ((Buf[iBuf-3] == 'R') && (Buf[iBuf-2] == 'M') && (Buf[iBuf-1] == 'C')) {//$GPRMC,164825,V,3428.480298,N,09133.261421,W,000.00,0.0,080304,2.6,E*4C //UTC time, warning, lat, lon, speed, true course, date (daymonyear), mag var, east or west LineType = RMC; commas = 0; Time = iBuf+1; } // else if ((Buf[iBuf-3] == 'W') && (Buf[iBuf-2] == 'P') && (Buf[iBuf-1] == 'L')) // {//&GPWPL,4917.16,N,12310.64,W,003*65 // LineType = WPL; // itsmagellan = 0; // commas = 0; // } } else if ((Buf[iBuf] == ',') && (commas != 0xFF)) { commas++; if (commas == 2) {//next char will be beginning of latitude newposition = TRUE; if (Buf[Time] != ',') { Position[pos].Hour = ((Buf[Time] - '0') * 10) + (Buf[Time+1] - '0'); Position[pos].Min = ((Buf[Time+2] - '0') * 10) + (Buf[Time+3] - '0'); Position[pos].Sec = ((Buf[Time+4] - '0') * 10) + (Buf[Time+5] - '0'); if ((Position[pos].Sec == Position[pos-1].Sec) && (Position[pos].Min == Position[pos-1].Min) && (Position[pos].Hour == Position[pos-1].Hour)) newposition = FALSE; } else { Position[pos].Hour = 0; Position[pos].Min = 0; Position[pos].Sec = 0; } commas = 0xFF; itsmagellan = 0; iLatLon = 0;//flag & initialize TimerFlags.nmeatiming = FALSE; } } } //if MAGELLAN: else if ((Buf[iBuf-8] == '$') && (Buf[iBuf-3] == 'W') && (Buf[iBuf-2] == 'P') && (Buf[iBuf-1] == 'L')) {//$PMGNWPL,llll.lll,N,lllll.lll,W,aaaa,F,c----c,c---c,c--c,xx*hh // TempiBuf = iBuf - 7;//for checksum itsmagellan = 1; iLatLon = 0; } else if ((Buf[iBuf-8] == '$') && (Buf[iBuf-3] == 'T') && (Buf[iBuf-2] == 'R') && (Buf[iBuf-1] == 'K')) {//$PMGNTRK // TempiBuf = iBuf - 7;//for checksum itsmagellan = 2; iLatLon = 0; } else if (Buf[iBuf] == '\n') {//got end of line for (xBuf = iBuf; (Buf[xBuf] != '$') && (Buf[xBuf] != 0); xBuf--) ;//go to beginning of line if (Buf[xBuf] != 0) {//now see what's on the line if ((Buf[xBuf+5] == 'R') && (Buf[xBuf+6] == 'T') && (Buf[xBuf+7] == 'E')) {//$PMGNRTE,5,1,c,01,1,a,2*32 // TempiBuf = xBuf+1;//for checksum for (x = xBuf, y = 0; Buf[x] != '*'; x++) { if ((y == 3) && (Buf[x] == ',') && (Buf[x-1] != 'c')) {//if it's a message instead of a list of routes y = 0; break; } if (Buf[x] == ',') y++; if (y >= 5)//at waypoint name (or maybe symbol) { x++;//past ',' z = x;//beginning of ident/name if ((Buf[x] < 'a') || (Buf[x] > 'z')) {//not a symbol for ( ; (Buf[x] != ',') && (Buf[x] != '*'); x++) ;//RouteWay[y].Ident[z] ch = Buf[x];//save it Buf[x] = 0;//to end string for (w = 0; w < routeway; w++) { if ((RouteWay[w].Ident[0] != 0) && (0 == strcmp((char*)&Buf[z], RouteWay[w].Ident))) {//got UTM from name Root[0][rte].N = RouteWay[w].N; Root[0][rte].E = RouteWay[w].E; Root[0][rte].Z = RouteWay[w].Z; rte++; RouteWay[w].Ident[0] = 0;//to not use it again break; } } Buf[x] = ch; x--;//because it will be incremented before anything else } if (Buf[x] == '*') break;//done with line }//end of if (y >= 5) } gotroute = TRUE; IncNumber(); hdc = GetDC(hwnd); TextOut(hdc, xCenter, yCenter, Number, 6); ReleaseDC(hwnd, hdc); // SendChecksum(); } ////////////////////////////////////////////////////////////////////////////////////////////////// // else if ((Buf[xBuf+9] == 'U') && (Buf[xBuf+10] == 'N') && (Buf[xBuf+11] == 'A')) // {//$PMGNCMD,UNABLE*63 // x=1; // } else if ((Buf[xBuf+5] == 'V') && (Buf[xBuf+6] == 'E') && (Buf[xBuf+7] == 'R')) {//$PMGNVER,024,REV 3.15,GPS 315/320*7A gotver = TRUE; SetEvent(hEvent);//signal it TimerFlags.nmeatiming = FALSE;//un-commented out July 28, 2005 if (magflag != 0) { for (x = 0; SendMagellanHANDOFF[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendMagellanHANDOFF[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &SendMagellanHANDOFF, sizeof(SendMagellanHANDOFF)-1, &dwBytesWritten, NULL); Sleep(50); } if ((Buf[xBuf+10] == '3') && (Buf[xBuf+11] != '1')) itsmeridian = TRUE; else itsmeridian = FALSE; // WriteFile(hComm, &SendMagellanTON, sizeof(SendMagellanTON)-1, &dwBytesWritten, NULL); // Sleep(50); if (magflag == GETWAYPOINTS) { magflag = 0; for (x = 0; GetMagellanWaypoints[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanWaypoints[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanWaypoints, sizeof(GetMagellanWaypoints)-1, &dwBytesWritten, NULL); Sleep(50); } else if (magflag == SENDWAYPOINTS) { magflag = 0; if (onewaypoint) { onewaypoint = FALSE; LocNum = ChosenLoc; x = PrepMagellanWaypoint(); WriteFile(hComm, &SendMagWaypoints, x, &dwBytesWritten, NULL); for (x = 0; SendMagWaypoints[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendMagWaypoints[x]; if (tgcount > 49900) tgcount = 0; LocNum = EmptyLoc; // Sleep(50); MessageBox(hwnd, "Sent", "Waypoint", MB_OK); } else if (LocNum < EmptyLoc) { hwndCounter = CreateWindow(Counter, Counter, WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, (cxScreen/2)-75, (cyScreen/2)-((8*cyChar)/2), 150, 8*cyChar, hwnd, (HMENU)159, hInst, NULL); GetClientRect(hwndCounter, &counterRect); } while (LocNum < EmptyLoc)//send another one { x = PrepMagellanWaypoint(); IncCount(); LocNum++; WriteFile(hComm, &SendMagWaypoints, x, &dwBytesWritten, NULL); for (x = 0; SendMagWaypoints[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendMagWaypoints[x]; if (tgcount > 49900) tgcount = 0; Sleep(50); } for (x = 0; SendEnd[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendEnd[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &SendEnd, sizeof(SendEnd)-1, &dwBytesWritten, NULL); Sleep(50); if (sendroutewaypoints) {//if last waypoint sent & sending waypoints for route sendroutewaypoints = FALSE; LocNum = 0; RouteName[0] = '0'; RouteName[1] = '1'; do {//send multiple routes for more than 30 waypoints routeline = 1; if (RouteName[1] > '9') { RouteName[1] = '0'; RouteName[0]++; } if (numofRoutes < 30) { totalroutelines = (numofRoutes / 3); if (numofRoutes % 3) totalroutelines++; } else totalroutelines = 10;//for 30 waypoints while (routeline <= totalroutelines) { y = PrepSendRoute(); for (x = 0; SendRoute[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendRoute[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &SendRoute, y, &dwBytesWritten, NULL); Sleep(50); //$PMGNRTE,2,1,c,01,1,2,3,4*xx } for (x = 0; SendEnd[x] != 0; x++, tgcount++) ToGPS[tgcount] = SendEnd[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &SendEnd, sizeof(SendEnd)-1, &dwBytesWritten, NULL); Sleep(50); } while (numofRoutes); } SendMessage(hwndCounter, WM_CLOSE, 0, 0); } else if (magflag == GETTRACKS) { magflag = 0; for (x = 0; GetMagellanTracks[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanTracks[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanTracks, sizeof(GetMagellanTracks)-1, &dwBytesWritten, NULL); Sleep(50); } } else if ((Buf[xBuf+9] == 'E') && (Buf[xBuf+10] == 'N') && (Buf[xBuf+11] == 'D')) {//$PMGNCMD,END*3D (finished getting waypoints, tracks, or routes) MessageBeep(MB_OK); // TempiBuf = xBuf+1; // SendChecksum(); if (itsmagellan == 2) {//receiving tracks itsmagellan = 0; hFile = CreateFile(FullTracks, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); fileSize = sizeof(trak[0]); trak[tnum].time = 0; WriteFile(hFile, TrackHead, strlen(TrackHead), &dwBytesWritten, NULL); Sleep(50); for (y = 0; y < tnum; y++) WriteTracks(hFile, y); CloseHandle(hFile); if (inutmzone) { BeginY = trak[0].NUTM / MetersPerTile; BeginX = trak[0].EUTM / MetersPerTile; rowOffset = BeginY - (TilesDown / 2);//bottom edge of opening screen colOffset = BeginX - ((TilesAcross-1) / 2);//left edge of opening screen // showingtracks = TRUE; // fromTracks = TRUE; // editingtracks = FALSE; // CreateTracks(); } else { Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; } SetEvent(hEventExit); showingtracks = TRUE; fromTracks = TRUE; editingtracks = FALSE; // CreateTracks(); fromusbtracks = TRUE; trackUTMZone = trak[0].time >> 26;//UTMZone in new Track.dta format SendMessage(hwnd, WM_USER, 0, 0); } if (foroute) { foroute = FALSE; rte = 0;//for Root[rte] Number[0] = ' '; for (y = 1; y < 5; y++) Number[y] = '0'; Number[5] = ' '; xCenter = (rect.right/2) - (cxChar*4); yCenter = rect.bottom/2; for (x = 0; GetMagellanRoute[x] != 0; x++, tgcount++) ToGPS[tgcount] = GetMagellanRoute[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &GetMagellanRoute, sizeof(GetMagellanRoute)-1, &dwBytesWritten, NULL); Sleep(50); } else if (gotroute) { if (0 != GetSaveFileName(&ofn3)) { hFile = CreateFile(FullRoutes, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); for (z = 0; z < rte; z++) { y = 0; Raut[y++] = (Root[0][z].Z / 10) + '0'; Raut[y++] = (Root[0][z].Z % 10) + '0'; Raut[y++] = ','; _itoa(Root[0][z].N, RouteDist, 10); for (x = 0; RouteDist[x] != 0; x++, y++) Raut[y] = RouteDist[x]; Raut[y++] = ','; _itoa(Root[0][z].E, RouteDist, 10); for (x = 0; RouteDist[x] != 0; x++, y++) Raut[y] = RouteDist[x]; Raut[y++] = '\r'; Raut[y++] = '\n'; WriteFile(hFile, Raut, y, &dwBytesWritten, NULL); Sleep(50); } CloseHandle(hFile); } } magflag = 0; InvalidateRect(hwnd, &rect, FALSE); } }//end of if (Buf[xBuf] != 0) }//end of else if ((Buf[iBuf-1] == '\x0A') && (iBuf != 0)) }//end of NMEA //*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// else//if (itsgarmin) - DLE, PacketID, DataSize, Data, Checksum, DLE, ETX { TimerFlags.timing = FALSE; switch (GarminFlag) { case GOT_ETX://3 if (Buf[iBuf] == DLE) GarminFlag = GOT_FIRST_DLE; break; case GOT_FIRST_DLE://16 or 0x10 ReceivedPID = Buf[iBuf]; if (ReceivedPID == ETX) {//could happen on first input GarminFlag = GOT_ETX; break; } GarminFlag = GOT_PID; break; case GOT_PID: if ((Buf[iBuf] == DLE) && (gotaDLE == FALSE)) { gotaDLE = TRUE; break;//ignore first DLE } if (gotaDLE == TRUE) gotaDLE = FALSE; ReceivedDataSize = Buf[iBuf]; i = 0; for (x = 0; x < 0xFF; x++) ReceivedData[x] = 0; GarminFlag = GOT_DATASIZE; break; case GOT_DATASIZE: if (ReceivedDataSize == 0) { GarminFlag = GOT_DATA; break; } if ((Buf[iBuf] == DLE) && (gotaDLE == FALSE)) { gotaDLE = TRUE; break;//ignore first DLE } if (gotaDLE == TRUE) gotaDLE = FALSE; ReceivedData[i++] = Buf[iBuf]; if (i == ReceivedDataSize) GarminFlag = GOT_DATA; break; case GOT_DATA: if ((Buf[iBuf] == DLE) && (gotaDLE == FALSE)) { gotaDLE = TRUE; break;//ignore first DLE } if (gotaDLE == TRUE) gotaDLE = FALSE; GarminFlag = GOT_CHECKSUM; break; case GOT_CHECKSUM: GarminFlag = GOT_LAST_DLE; if (ReceivedPID == XFER_CMPLT) goto aaa; break; case GOT_LAST_DLE: aaa: GarminFlag = GOT_ETX; TimerFlags.garmintiming = FALSE; if (ReceivedPID == ROUTE_LINK) { ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1;//checksum for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = ACKPacket[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL); } else if (ReceivedPID == ROUTE_HEADER) { RouteNum++; rte = 0; if (d201) { for (x = 0; (ReceivedData[x+1] != 0) && (x < 20); x++) RouteComment[RouteNum][x] = ReceivedData[x+1]; } else { for (x = 0; ReceivedData[x] != 0; x++) RouteComment[RouteNum][x] = ReceivedData[x]; } RouteComment[RouteNum][x] = 0; ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1;//checksum for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = ACKPacket[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL); } else if (ReceivedPID == ROUTE_DATA) { semicircleN = *(signed int*)&ReceivedData[Noffset]; semicircleE = *(signed int*)&ReceivedData[Eoffset]; Lat = (double) (semicircleN * semicircle2deg); Lon = (double) (semicircleE * semicircle2deg); LatRad = (double) (semicircleN * semicircle2rad); LonRad = (double) (semicircleE * semicircle2rad); LatLontoUTM(); Root[RouteNum][rte].Z = UTMZone; Root[RouteNum][rte].N = UTMNorthing; Root[RouteNum][rte].E = UTMEasting; rte++; RouteSize[RouteNum] = rte; IncCount(); ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1;//checksum (needs extra DLE if ReceivedPID == -24) for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = ACKPacket[x]; if (tgcount > 49900) tgcount = 0; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else } else if (ReceivedPID == PVT_DATA)//receiving position { Pvt.alt = *(float*)&ReceivedData[0]; Pvt.epe = *(float*)&ReceivedData[4]; Pvt.eph = *(float*)&ReceivedData[8]; Pvt.epv = *(float*)&ReceivedData[12]; Pvt.fix = *(WORD*)&ReceivedData[16]; Pvt.tow = *(double*)&ReceivedData[18]; Pvt.lat = *(double*)&ReceivedData[26];//radians Pvt.lon = *(double*)&ReceivedData[34];//radians Pvt.lon_vel = *(float*)&ReceivedData[42]; Pvt.lat_vel = *(float*)&ReceivedData[46]; Pvt.alt_vel = *(float*)&ReceivedData[50]; Pvt.msl_hght = *(float*)&ReceivedData[54]; Pvt.leap_sec = *(WORD*)&ReceivedData[58]; Pvt.grmn_days = *(UINT*)&ReceivedData[60]; if ((Pvt.lat != 0.0) && (Pvt.lon != 0.0)) ShowPosition(); else MessageBox(hwnd, "Lat or Lon is 0", ERROR, MB_OK); }//end of if (ReceivedPID == PVT_DATA) else if (ReceivedPID == ACK) { switch (fromFlag) { case MENU: SendMessage(hwnd, WM_COMMAND, ID_STOPPOSITIONING, 0); break;//slightly trick case LBUTTON: lParam = lButtonDotX + (lButtonDotY << 16);//just send it back to itself in the right format SendMessage(hwnd, WM_LBUTTONDOWN, 0, lParam); break; case RBUTTON: SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0); break; case UP: SendMessage(hwnd, WM_KEYDOWN, VK_UP, 0); break; case DOWN: SendMessage(hwnd, WM_KEYDOWN, VK_DOWN, 0); break; case LEFT: SendMessage(hwnd, WM_KEYDOWN, VK_LEFT, 0); break; case RIGHT: SendMessage(hwnd, WM_KEYDOWN, VK_RIGHT, 0); break; } //////////////////////////////////////////////////////////////////////////////////////////////////////////// if ((ReceivedData[0] == 0x0A) && (sendingStop))//STOP SENDING! { sendingStop = FALSE; SetEvent(hEventExit); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// else if ((ReceivedData[0] == RECORDS) || (ReceivedData[0] == WAYPOINT) || (ReceivedData[0] == TRACK) || (ReceivedData[0] == ROUTEHEADER) || (ReceivedData[0] == ROUTE) || (ReceivedData[0] == ROUTELINK) || (ReceivedData[0] == TRACKHEADER)) { if (ReceivedData[0] == RECORDS) { if (counteropen) { SendMessage(hwndCounter, WM_CLOSE, 0, 0); counteropen = FALSE; } hwndCounter = CreateWindow(Counter, Counter, WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, (cxScreen/2)-75, (cyScreen/2)-((8*cyChar)/2), 150, 8*cyChar, hwnd, (HMENU)149, hInst, NULL); GetClientRect(hwndCounter, &counterRect); counteropen = TRUE; } if (sendingWaypoints) {//sending waypoints if (onewaypoint) { onewaypoint = FALSE; LocNum = ChosenLoc; PrepWaypoint(); WriteFile(hComm, &Waypoint, SendWaypointSize, &dwBytesWritten, NULL); for (x = 0; x < SendWaypointSize; x++, tgcount++) ToGPS[tgcount] = Waypoint[x]; if (tgcount > 49900) tgcount = 0; LocNum = EmptyLoc; } else if (LocNum < EmptyLoc)//send another one { IncCount(); PrepWaypoint(); LocNum++; WriteFile(hComm, &Waypoint, SendWaypointSize, &dwBytesWritten, NULL); for (x = 0; x < SendWaypointSize; x++, tgcount++) ToGPS[tgcount] = Waypoint[x]; if (tgcount > 49900) tgcount = 0; } else { WriteFile(hComm, &EndRecords, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = EndRecords[x]; if (tgcount > 49900) tgcount = 0; sendingWaypoints = FALSE; SendMessage(hwndCounter, WM_CLOSE, 0, 0); } } else if (sendingrouteheader) { sendingrouteheader = FALSE; sendingroute = TRUE; x = 0; SendRouteHeader[x++] = DLE; SendRouteHeader[x++] = ROUTEHEADER; SendRouteHeader[x++] = 21;//data size if (d201) { SendRouteHeader[x++] = 3;//route number gotzero = FALSE; for (y = 0; y < 20; y++) { if (Routes[y] == '.') Routes[y] = 0; if (Routes[y] == 0) gotzero = TRUE; if (gotzero == TRUE) SendRouteHeader[x++] = ' '; else { c = Routes[y]; if ((c >= 'a') && (c <= 'z')) c &= 0xDF;//make uppercase SendRouteHeader[x++] = c; } } } else//if d202 { for (y = 0; (Routes[y] != '.') && (Routes[y] != 0); y++) { if ((Routes[y] >= 'a') && (Routes[y] <= 'z')) SendRouteHeader[x++] = Routes[y] & 0xDF;//make uppercase else SendRouteHeader[x++] = Routes[y]; } SendRouteHeader[x++] = 0; SendRouteHeader[2] = x-3;//data size } checksum = 0; for (z = 1; z < x; z++) { if (SendRouteHeader[z] == DLE) z++;//ignore first DLE checksum += SendRouteHeader[z]; } SendRouteHeader[x++] = ~(checksum) + 1; if (SendRouteHeader[y-1] == DLE) SendRouteHeader[y++] = DLE; SendRouteHeader[x++] = DLE; SendRouteHeader[x++] = ETX; WriteFile(hComm, &SendRouteHeader, x, &dwBytesWritten, NULL); for (y = 0; y < x; y++, tgcount++) ToGPS[tgcount] = SendRouteHeader[y]; if (tgcount > 49900) tgcount = 0; } else if (sendingroutelink) {//must be before else if (sendingroute) sendingroutelink = FALSE; WriteFile(hComm, &SerialRouteLink, 27, &dwBytesWritten, NULL); for (y = 0; y < 27; y++, tgcount++) ToGPS[tgcount] = SerialRouteLink[y]; if (tgcount > 49900) tgcount = 0; } else if (sendingroute) { if (TrackNum < numofRoutes)//borrowing TrackNum { if (d210) sendingroutelink = TRUE; IncCount(); GetRandomNum(); PrepRoute(); TrackNum++; WriteFile(hComm, &Waypoint, SendWaypointSize, &dwBytesWritten, NULL); for (y = 0; y < SendWaypointSize; y++, tgcount++) ToGPS[tgcount] = Waypoint[y]; if (tgcount > 49900) tgcount = 0; } else { sendingroute = FALSE; WriteFile(hComm, &EndRecords, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = EndRecords[y]; if (tgcount > 49900) tgcount = 0; SendMessage(hwndCounter, WM_CLOSE, 0, 0); } } else if (sendingtrackheader) { BYTE Trackheader[100]; sendingtrackheader = FALSE; y = 0; Trackheader[y++] = DLE; Trackheader[y++] = TRACKHEADER; for (x = 0; (Tracks[x] != '.') && (Tracks[x] != 0); x++) ; Trackheader[y++] = x+3; if (x+3 == DLE) Trackheader[y++] = x+3; Trackheader[y++] = 1;//display on screen Trackheader[y++] = 0xFF;//default color for (x = 0; (Tracks[x] != '.') && (Tracks[x] != 0); x++, y++) Trackheader[y] = Tracks[x]; Trackheader[y++] = 0; checksum = 0; for (z = 1; z < y; z++) { if (Trackheader[z] == DLE) z++;//ignore first DLE checksum += Trackheader[z]; } Trackheader[y++] = ~(checksum) + 1; if (Trackheader[y-1] == DLE) Trackheader[y++] = DLE; Trackheader[y++] = DLE; Trackheader[y++] = ETX; WriteFile(hComm, &Trackheader, y, &dwBytesWritten, NULL); for (x = 0; x < y; x++, tgcount++) ToGPS[tgcount] = Trackheader[x]; if (tgcount > 49900) tgcount = 0; } else//if sending tracks { if (TrackNum < numofTracks) { IncCount(); TrackSize = PrepTrack(); WriteFile(hComm, &SendTrack, TrackSize, &dwBytesWritten, NULL); for (y = 0; y < TrackSize; y++, tgcount++) ToGPS[tgcount] = SendTrack[y]; if (tgcount > 49900) tgcount = 0; TrackNum++; } else { WriteFile(hComm, &EndRecords, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = EndRecords[y]; if (tgcount > 49900) tgcount = 0; SendMessage(hwndCounter, WM_CLOSE, 0, 0); } } } else if (ReceivedData[0] == XFER_CMPLT)//GPS acknowledges my EndRecords (XFER_CMPLT) message { sendingStop = FALSE;//to stop Comm Thread when GPS acknowledges if (showposition) WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = StopPVTPacket[y]; if (tgcount > 49900) tgcount = 0; SendMessage(hwndCounter, WM_CLOSE, 0, 0); SetEvent(hEventExit); } }//end of if (ReceivedPID == ACK) else if (ReceivedPID == NAK) { if (sendingWaypoints) { MessageBeep(MB_OK); hdc = GetDC(hwnd); TextOut(hdc, 0, BadSend*cyChar, BadWaypoint, sizeof(BadWaypoint)-1); ReleaseDC(hwnd, hdc); BadSend++; if (LocNum < EmptyLoc)//send another one { PrepWaypoint(); LocNum++; WriteFile(hComm, &Waypoint, SendWaypointSize, &dwBytesWritten, NULL); for (y = 0; y < SendWaypointSize; y++, tgcount++) ToGPS[tgcount] = Waypoint[y]; if (tgcount > 49900) tgcount = 0; } else { WriteFile(hComm, &EndRecords, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = EndRecords[y]; if (tgcount > 49900) tgcount = 0; sendingWaypoints = FALSE; } } else { MessageBox(hwnd, "Got a NAK!\nAborting transfer!", ERROR, MB_OK); return 0; } } else if (ReceivedPID == RECORDS) { Records = *(WORD*)pRecords; remainder = Records % 10000; Counting[8] = (remainder / 1000) + '0'; Counting[9] = ((remainder % 1000) / 100) + '0'; Counting[10] = ((remainder % 100) / 10) + '0'; Counting[11] = (remainder % 10) + '0'; if (counteropen) { SendMessage(hwndCounter, WM_CLOSE, 0, 0); counteropen = FALSE; } hwndCounter = CreateWindow(Counter, Counter, WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, (cxScreen/2)-75, (cyScreen/2)-((8*cyChar)/2), 150, 8*cyChar, hwnd, (HMENU)159, hInst, NULL); GetClientRect(hwndCounter, &counterRect); counteropen = TRUE; ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1;//checksum (needs extra DLE if ReceivedPID == -24) WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = ACKPacket[y]; if (tgcount > 49900) tgcount = 0; } else if ((ReceivedPID == TRACK) && (tnum < numofTracks) && (d300 || d301 || d302))//TRACK_SIZE {//receiving tracks trak[tnum].NUTM = *(int*)&ReceivedData[0]; trak[tnum].EUTM = *(int*)&ReceivedData[4]; trak[tnum].time = *(unsigned int*)&ReceivedData[8]; if (d301) { // f = *(float*)&ReceivedData[12]; // if (f != 1.00000e+025) if (*(UINT*)&ReceivedData[12] != 0x69045951) { f = *(float*)&ReceivedData[12]; f /= (float)0.3048;//convert meters to feet trak[tnum].alt = f; } else trak[tnum].alt = 0.0; trak[tnum].newtrk = *(unsigned char*)&ReceivedData[20]; } else if (d302) { // f = *(float*)&ReceivedData[12]; // if (f != 1.0e25) if (*(UINT*)&ReceivedData[12] != 0x69045951) { f = *(float*)&ReceivedData[12]; f /= (float)0.3048;//convert meters to feet trak[tnum].alt = f; } else trak[tnum].alt = 0.0; trak[tnum].newtrk = *(unsigned char*)&ReceivedData[24]; } else if (d300)//this needs to be last since it can also be true trak[tnum].newtrk = *(unsigned char*)&ReceivedData[12]; tnum++; gettingtracks = TRUE; IncCount(); ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1;//~(6+2+34) + 1 = 214 WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = ACKPacket[y]; if (tgcount > 49900) tgcount = 0; } else if (ReceivedPID == XFER_CMPLT) { sendingStop = FALSE; SendMessage(hwndCounter, WM_CLOSE, 0, 0); SetEvent(hEventExit); if (gettingtracks) SaveDownloadedTracks(); else if (gettingroute) { gettingroute = FALSE; for (w = 0; w <= RouteNum; w++) { rte = RouteSize[w]; if (RouteComment[w][0] != 0) { for (z = 0; RouteComment[RouteNum][z] != 0; z++) FullRoutes[z] = RouteComment[w][z]; FullRoutes[z] = 0; } if (FALSE != GetSaveFileName(&ofn3)) { hFile = CreateFile(FullRoutes, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); for (z = 0; z < rte; z++) { y = 0; Raut[y++] = (Root[w][z].Z / 10) + '0'; Raut[y++] = (Root[w][z].Z % 10) + '0'; Raut[y++] = ','; _itoa(Root[w][z].N, RouteDist, 10); for (x = 0; RouteDist[x] != 0; x++, y++) Raut[y] = RouteDist[x]; Raut[y++] = ','; _itoa(Root[w][z].E, RouteDist, 10); for (x = 0; RouteDist[x] != 0; x++, y++) Raut[y] = RouteDist[x]; Raut[y++] = '\r'; Raut[y++] = '\n'; WriteFile(hFile, Raut, y, &dwBytesWritten, NULL); } CloseHandle(hFile); } } } Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); }//end of ReceivedPID == XFER_CMPLT else if (ReceivedPID == 0xFF) {//Pid_Product_Data TimerFlags.gotprotocol = TRUE; d201 = TRUE; d301 = d302 = d310 = FALSE; ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = ACKPacket[y]; if (tgcount > 49900) tgcount = 0; if ((ReceivedData[0] <= 41) && (ReceivedData[1] == 0))//GPS 45 goto spaghetti; } //looking for: "A\x64 Dsomething" (ReceivedPID = 253 0xFD) else if (ReceivedPID == 0xFD)//Pid_Protocol_Array, sent right after Pid_Product_Data (0xFF) { TimerFlags.gotprotocol = TRUE; // gota100 = FALSE; gotd = FALSE; for (x = 0; x < ReceivedDataSize; x++) { if (ReceivedData[x] == 'D') gotd = TRUE; else if (gotd) { gotd = FALSE; DType = *(WORD*)&ReceivedData[x]; switch (DType) { case 100: case 101: case 102: Noffset = 6; Eoffset = 10; IdentOffset = 0; LocOffset = 18; SymOffset = 0; WaypointProt = 104; break; case 103: Noffset = 6; Eoffset = 10; IdentOffset = 0; LocOffset = 18; SymOffset = 58; WaypointProt = 103; break; case 104: Noffset = 6; Eoffset = 10; IdentOffset = 0; LocOffset = 18; SymOffset = 62; WaypointProt = 104; break; case 107: Noffset = 6; Eoffset = 10; IdentOffset = 0; LocOffset = 18; SymOffset = 58; WaypointProt = 104; break; case 108: Noffset = 24; Eoffset = 28; ElevOffset = 32; IdentOffset = 48; SymOffset = 4; WaypointProt = 108; break; case 109: Noffset = 24; Eoffset = 28; ElevOffset = 32; IdentOffset = 52; SymOffset = 4; WaypointProt = 109; break; case 110: Noffset = 24; Eoffset = 28; ElevOffset = 32; IdentOffset = 62; SymOffset = 4; WaypointProt = 110; break; case 151: case 152: case 154://add support for this? case 155://ditto MessageBox(hwnd, "Sorry, doesn't support older Garmin aviation GPS's.\nLet me know if you wish it did.", NULL, MB_OK); openatclosing = FALSE; SendMessage(hwnd, WM_CLOSE, 0, 0); return 0; case 201: d201 = TRUE; break; case 202: d201 = FALSE; break; case 210: d210 = TRUE; break; case 300: d300 = TRUE; break; case 301: d301 = TRUE; break; case 302: d302 = TRUE; break; case 310: d310 = TRUE; break; }//end of switch }//end of else if (gotd) }//end of for spaghetti: if (garminflag == BEGINRECORDS8) { if ((sendingrouteheader) && (d201 == FALSE))//if d202 { BeginRecords[3] = (numofRoutes*2)+1;//Route Link after each waypoint if (((numofRoutes*2)+1) != 16)//if not 0x10 (DLE char) { BeginRecords[5] = ~(27 + 2 + ((numofRoutes*2)+1)) + 1; WriteFile(hComm, &BeginRecords, 8, &dwBytesWritten, NULL); } else { BeginRecords2[6] = ~(27 + 2 + ((numofRoutes*2)+1)) + 1; WriteFile(hComm, &BeginRecords2, 9, &dwBytesWritten, NULL); } } else if ((sendingtrackheader) && (d310 == TRUE)) { BeginRecords[3] = numofTracks;//+ 1 BeginRecords[5] = ~(27 + 2 + numofTracks) + 1; WriteFile(hComm, &BeginRecords, 8, &dwBytesWritten, NULL); } else WriteFile(hComm, &BeginRecords, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = BeginRecords[x]; if (tgcount > 49900) tgcount = 0; } else if (garminflag == BEGINRECORDS9) { if ((sendingrouteheader) && (d201 == FALSE))//if d202 { BeginRecords2[3] = numofRoutes * 2;//+ Route Header + Route Links BeginRecords2[6] = ~(27 + 2 + (numofRoutes*2)) + 1; } else if ((sendingtrackheader) && (d310 == TRUE)) { BeginRecords2[3] = numofTracks; BeginRecords2[6] = ~(27 + 2 + numofTracks) + 1; } WriteFile(hComm, &BeginRecords2, 9, &dwBytesWritten, NULL); for (x = 0; x < 9; x++, tgcount++) ToGPS[tgcount] = BeginRecords2[x]; if (tgcount > 49900) tgcount = 0; } else if (garminflag == SENDWAYPOINTS) { WriteFile(hComm, &SendWaypoints, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = SendWaypoints[x]; if (tgcount > 49900) tgcount = 0; } else if (garminflag == SENDTRACKS) { WriteFile(hComm, &SendTracks, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = SendTracks[x]; if (tgcount > 49900) tgcount = 0; } else if (garminflag == RECEIVEROUTE) { WriteFile(hComm, &SendRoutes, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = SendRoutes[x]; if (tgcount > 49900) tgcount = 0; } else if (garminflag == STARTPVT) { WriteFile(hComm, &StartPVTPacket, 8, &dwBytesWritten, NULL); for (x = 0; x < 8; x++, tgcount++) ToGPS[tgcount] = StartPVTPacket[x]; if (tgcount > 49900) tgcount = 0; } }//end of if (ReceivedPID == 0xFD) else if (ReceivedPID == WAYPOINT) {//receiving waypoints if ((ReceivedPID == WAYPOINT) && (EmptyLoc < TOTAL_LOCS)) { SaveDownloadedWaypoints(); } IncCount(); ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = ACKPacket[y]; if (tgcount > 49900) tgcount = 0; }//end of else if (ReceivedPID == WAYPOINT) else // if (ReceivedPID == anything else) { IncCount(); ACKPacket[3] = ReceivedPID; ACKPacket[5] = ~(ACK + 2 + ReceivedPID) + 1; WriteFile(hComm, &ACKPacket, 8, &dwBytesWritten, NULL);//acknowledge everything else for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = ACKPacket[y]; if (tgcount > 49900) tgcount = 0; } }//end of switch (GarminFlag) }//end of else if garmin //temp xxxx //htempFile = CreateFile(GPSdta, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL); //SetFilePointer(htempFile, 0, NULL, FILE_END); //WriteFile(htempFile, &Buf[iBuf], 1, &dwBytesWritten, NULL); //FlushFileBuffers(htempFile); //CloseHandle(htempFile); // iBuf++; if (iBuf == 50000) iBuf = 0; return 0; case WM_USB: ShowPosition(); return 0; case 0x020A://WM_MOUSEWHEEL if ((Zoom == 1) && (USGSBuf != NULL)) { if (wParam & 0x080000000) x = -100; else x = 100; lf5.lfEscapement += x; lf5.lfOrientation += x; InvalidateRect(hwnd, &rect, FALSE); } else { if (LOWORD(wParam) == MK_CONTROL) { mousewheel = TRUE; if (wParam & 0x080000000) SendMessage(hwnd, WM_KEYDOWN, VK_RIGHT, 0); else SendMessage(hwnd, WM_KEYDOWN, VK_LEFT, 0); } else { if (wParam & 0x080000000) SendMessage(hwnd, WM_KEYDOWN, VK_DOWN, 0); else SendMessage(hwnd, WM_KEYDOWN, VK_UP, 0); } } return 0; case WM_MOUSEMOVE: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; xPos = LOWORD(lParam); yPos = HIWORD(lParam); if (xPos >= (rect.right)) break;//to keep from showing bad lat/lon if (approachcontrol) { AtPlane = -1; for (z = 0; Plane[z].UTMEasting != 0; z++) { if ((Plane[z].x-PlaneRadius < xPos) && (Plane[z].x+PlaneRadius > xPos) && ((Plane[z].y-PlaneRadius < yPos) && (Plane[z].y+PlaneRadius > yPos))) { AtPlane = z; break; } } if (AtPlane == -1) planecommand = FALSE; for (z = 0; z < command; z++) Command[z] = 0; } if (drawing == FALSE) { if (wParam == MK_SHIFT) {//if Shift key is down enteringtext = TRUE; // xbegOld = -1; if (xBeg == -1) { xBeg = xPos; yBeg = yPos; } InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } else if ((wParam == MK_CONTROL) && (simulate == FALSE) && (mousewheel == FALSE))// && (inaprs == FALSE) && (aprs == FALSE)) {//if Ctrl key is down distancemeasure = TRUE; if (xBeg == -1) { xBeg = xPos; yBeg = yPos; totalRouteDist[0] = 0.0;//trick for ShowDistanceAngle ptr = 1; } InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } } if (((showstreets) && (gotstreet == FALSE)) && ((((MapType == PHOTO) && (Zoom <= 3)) || ((MapType == URBANAREA) && (Zoom <= 5))) || ((MapType == TOPO) && (Zoom == 1)))) { hdc = GetDC(hwnd); if (hdcMem3 == NULL) { hdcMem3 = CreateCompatibleDC(hdc); hBitmap3 = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); hObject = SelectObject(hdcMem3, hBitmap3); } x = BitBlt(hdcMem3, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdc); for (w = 0; w < pname; w++) { NamePtr1 = NamePtr2 = NULL; z = 0x0FFFFFFF; for (x = 0; NamePtrs[w][x] != -1; x += 3) {//get street name closest to UTMNorthing & UTMEasting if (xPos > NamePtrs[w][x]) y = xPos - NamePtrs[w][x]; else y = NamePtrs[w][x] - xPos; if (yPos > NamePtrs[w][x+1]) y += yPos - NamePtrs[w][x+1]; else y += NamePtrs[w][x+1] - yPos; if (y < z) { z = y; if (y < 10) { streetflag = FALSE; y = NamePtrs[w][x+2]; if (TigerNameSize[w] < (DWORD)y) continue;//something went wrong... TigerPointA = *(int*)&pTigerNames[w][y];//Angle if (TigerPointA & 0x80000000) { TigerPointA &= 0x7FFFFFFF; streetflag = TRUE; } y += 4;//to name for (z = y; pTigerNames[w][z] != 0; z++); ; lf4.lfEscapement = lf4.lfOrientation = TigerPointA; hFont = CreateFontIndirect (&lf4); hdc = GetDC(hwnd); hObject = SelectObject (hdc, hFont); if (MapType != TOPO) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, TextColor);//0x90FF00 } if (streetflag) SetTextAlign(hdc, TA_RIGHT|TA_BASELINE); else SetTextAlign(hdc, TA_LEFT|TA_BASELINE); if (NamePtr1 == NULL) { NamePtr1 = &pTigerNames[w][y]; TextOut(hdc, NamePtrs[w][x], NamePtrs[w][x+1], NamePtr1, z-y); Angle1 = TigerPointA; Angle1 /= 10;//because of a previous misunderstanding if (streetflag) Angle1 |= 0x80000000; } else if (NamePtr2 == NULL) { NamePtr2 = &pTigerNames[w][y]; TextOut(hdc, NamePtrs[w][x], NamePtrs[w][x+1], NamePtr2, z-y); Angle2 = TigerPointA; Angle2 /= 10; if (streetflag) Angle2 |= 0x80000000; } SelectObject(hdc, hObject); DeleteObject(hFont); ReleaseDC(hwnd, hdc); gotX = NamePtrs[w][x];//xPos; gotY = NamePtrs[w][x+1];//yPos; gotstreet = TRUE; z = 0x0FFFFFFF; } } }//end of for (x = 0; if (gotstreet) break;//out of for (w = 0; }//end of for (w = 0; }//end of if ((showstreets) if (((bigjpeg) && (buttondown)) || ((terrafetcher) && (buttondown))) { x = (X1 - ScreenLeft) * PixelsPerTile / MetersPerTile; y = (ScreenTop - Y1) * PixelsPerTile / MetersPerTile; hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, MapWidth, MapHeight, hdcMem, 0, 0, SRCCOPY); hPen = CreatePen(PS_SOLID, 1, 0xFFFFFF); SelectObject(hdc, hPen); MoveToEx(hdc, x, y, NULL); LineTo(hdc, x, yPos); LineTo(hdc, xPos, yPos); LineTo(hdc, xPos, y); LineTo(hdc, x, y); DeleteObject(hPen); ReleaseDC(hwnd, hdc); } else if (drawing) { if (xBeg == -1) { xBeg = xPos; yBeg = yPos; } SetCursor(hDrawingCursor);//have to do this every time !?! InvalidateRect(hwnd, &rect, FALSE); } else if (fromposition) { char PositionData[200]; if (showingdata) {//only show this again after showing position data showingdata = FALSE; SetWindowText(hwndPosit, Posit); } Radius = DotRadius*MetersPerTile/PixelsPerTile; for (x = 0; x < pos; x++) {//position if ((Position[x].UTME < UTMEasting+Radius) && (Position[x].UTME > UTMEasting-Radius) && (Position[x].UTMN < UTMNorthing+Radius) && (Position[x].UTMN > UTMNorthing-Radius)) { char TimeDate[] = "09/24/2004 18:34:12Z"; char Alt[] = "Altitude "; char Horepe[] = "HorizEPE "; char Vertepe[] = "VertEPE "; char Speed[] = "Speed "; for (y = 0, z = 0; PositionCsv[z] != 0; y++, z++) PositionData[y] = PositionCsv[z]; PositionData[y++] = '\r'; PositionData[y++] = '\n'; PositionData[y++] = '\r'; PositionData[y++] = '\n'; TimeDate[0] = (Position[x].Month / 10) + '0'; TimeDate[1] = (Position[x].Month % 10) + '0'; TimeDate[3] = (Position[x].Date / 10) + '0'; TimeDate[4] = (Position[x].Date % 10) + '0'; TimeDate[8] = (Position[x].Year / 10) + '0'; TimeDate[9] = (Position[x].Year % 10) + '0'; TimeDate[11] = (Position[x].Hour / 10) + '0'; TimeDate[12] = (Position[x].Hour % 10) + '0'; TimeDate[14] = (Position[x].Min / 10) + '0'; TimeDate[15] = (Position[x].Min % 10) + '0'; TimeDate[17] = (Position[x].Sec / 10) + '0'; TimeDate[18] = (Position[x].Sec % 10) + '0'; for (z = 0; TimeDate[z] != 0; y++, z++) PositionData[y] = TimeDate[z]; PositionData[y++] = '\r'; PositionData[y++] = '\n'; if (Position[x].Alt != 0) { for (z = 0; Alt[z] != 0; y++, z++) PositionData[y] = Alt[z]; _itoa(Position[x].Alt, &PositionData[y], 10); for ( ; PositionData[y] != 0; y++) ; PositionData[y++] = '\r'; PositionData[y++] = '\n'; } if (Position[x].HorizEpe != 0) { for (z = 0; Horepe[z] != 0; y++, z++) PositionData[y] = Horepe[z]; _itoa(Position[x].HorizEpe, &PositionData[y], 10); for ( ; PositionData[y] != 0; y++) ; PositionData[y++] = '\r'; PositionData[y++] = '\n'; for (z = 0; Vertepe[z] != 0; y++, z++) PositionData[y] = Vertepe[z]; _itoa(Position[x].VertEpe, &PositionData[y], 10); for ( ; PositionData[y] != 0; y++) ; PositionData[y++] = '\r'; PositionData[y++] = '\n'; } if (Position[x].Velocity != 0) { for (z = 0; Speed[z] != 0; y++, z++) PositionData[y] = Speed[z]; z = sprintf(&PositionData[y], "%.2f", Position[x].Velocity); y += z; } if (x) { GetCourse(x); z = (int)Angle; PositionData[y++] = '\r'; PositionData[y++] = '\n'; _itoa(z, &PositionData[y], 10); for ( ; PositionData[y] != 0; y++) ; PositionData[y++] = '\xB0'; } PositionData[y] = 0; SetWindowText(hwndPosit, PositionData); showingdata = TRUE; break; } } } if ((objectPtr) && (gotsymbol)) { APRSUTMEasting = ScreenLeft + (xPos * MetersPerTile/PixelsPerTile); APRSUTMNorthing = ScreenTop - (yPos * MetersPerTile/PixelsPerTile); Radius = 8*MetersPerTile/PixelsPerTile; for (x = 0; x < objectPtr; x++) { if ((Objects[x].UTMZ == UTMZone) && (Objects[x].UTME < APRSUTMEasting+Radius) && (Objects[x].UTME > APRSUTMEasting-Radius) && (Objects[x].UTMN < APRSUTMNorthing+Radius) && (Objects[x].UTMN > APRSUTMNorthing-Radius)) { if (atobj) break; atobj = TRUE; DotX = (Objects[x].UTME - ScreenLeft) * PixelsPerTile / MetersPerTile; DotY = (ScreenTop - Objects[x].UTMN) * PixelsPerTile / MetersPerTile; hdc = GetDC(hwnd); if (MapType != TOPO) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, WHITE); } if (Objects[x].Comment[0]) TextOut(hdc, DotX+10, DotY+5, Objects[x].Comment, strlen(Objects[x].Comment)); if (Objects[x].Time[0]) TextOut(hdc, DotX+10, DotY+20, Objects[x].Time, 7); ReleaseDC(hwnd, hdc); break; } } if ((atobj) && (x == objectPtr)) { atobj = FALSE; InvalidateRect(hwnd, &rect, FALSE); } } if (aprs) { APRSUTMEasting = ScreenLeft + (xPos * MetersPerTile/PixelsPerTile); APRSUTMNorthing = ScreenTop - (yPos * MetersPerTile/PixelsPerTile); Radius = 8*MetersPerTile/PixelsPerTile; for (x = Aprsi-1; x != -1; x--)//go backwards to get latest one { if ((Aprs[x].UTMZ == UTMZone) && (Aprs[x].UTME < APRSUTMEasting+Radius) && (Aprs[x].UTME > APRSUTMEasting-Radius) && (Aprs[x].UTMN < APRSUTMNorthing+Radius) && (Aprs[x].UTMN > APRSUTMNorthing-Radius)) { if (Aprs[x].DescOrWx[0] != 0) {//if it's not a WX station position with nothing else if (ataprs) break; ataprs = TRUE; CurrentAprsi = x; DotX = (Aprs[x].UTME - ScreenLeft) * PixelsPerTile / MetersPerTile; DotY = (ScreenTop - Aprs[x].UTMN) * PixelsPerTile / MetersPerTile; hdc = GetDC(hwnd); if (MapType != TOPO) { SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, WHITE); } if (Aprs[x].RedDot) TextOut(hdc, DotX+10, DotY-10, Aprs[x].Call, strlen(Aprs[x].Call)); if (Aprs[x].Time) { APRStime[0] = (Aprs[x].Time / 1000) + '0'; APRStime[1] = ((Aprs[x].Time % 1000) / 100) + '0'; APRStime[2] = ((Aprs[x].Time % 100) / 10) + '0'; APRStime[3] = (Aprs[x].Time % 10) + '0'; APRStime[4] = 'z'; TextOut(hdc, DotX+10, DotY+5, APRStime, 5); } if (Aprs[x].DescOrWx[0] != 0) TextOut(hdc, DotX+10, DotY+20, Aprs[x].DescOrWx, lstrlen(Aprs[x].DescOrWx)); if (Aprs[x].Status[0]) TextOut(hdc, DotX+10, DotY+35, Aprs[x].Status, lstrlen(Aprs[x].Status)); ReleaseDC(hwnd, hdc); break; } } } if ((ataprs) && (x == -1))//(Aprs[x].UTMN == 0)) { ataprs = FALSE; InvalidateRect(hwnd, &rect, FALSE); } } ////// if ((shownamecomment == FALSE) || ((MapType == TOPO) && (Zoom >= 5))) { int xUTMEasting, yUTMNorthing; xUTMEasting = ScreenLeft + (xPos * MetersPerTile/PixelsPerTile); yUTMNorthing = ScreenTop - (yPos * MetersPerTile/PixelsPerTile); Radius = DotRadius*MetersPerTile/PixelsPerTile; for (x = 0; NewLoc[x].EUTM != 0; x++) {//waypoints if ((NewLoc[x].EUTM < xUTMEasting+Radius) && (NewLoc[x].EUTM > xUTMEasting-Radius) && (NewLoc[x].NUTM < yUTMNorthing+Radius) && (NewLoc[x].NUTM > yUTMNorthing-Radius)) { if (atwaypoint) break; atwaypoint = TRUE; for (y = 0; y < NewLoc[x].size; y++) { if (sortbyname) {// if ((NewLoc[x].pWaypoints[y-3] == '<') && (NewLoc[x].pWaypoints[y-1] == 'a') && (NewLoc[x].pWaypoints[y] == 'm') && (NewLoc[x].pWaypoints[y+1] == 'e') && (NewLoc[x].pWaypoints[y+2] == '>')) { ShowWaypointData(x, y); goto breakout; } } else {// if ((NewLoc[x].pWaypoints[y-2] == '<') && (NewLoc[x].pWaypoints[y] == 'm') && (NewLoc[x].pWaypoints[y+1] == 't') && (NewLoc[x].pWaypoints[y+2] == '>')) { ShowWaypointData(x, y); goto breakout; } } } } } breakout: if ((atwaypoint) && (NewLoc[x].EUTM == 0)) { atwaypoint = FALSE; if (fromlineto) fromlineto = FALSE; else { InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } } } else if ((shownamecomment) && (showdescription) && (drawing == FALSE)) { int xUTMEasting, yUTMNorthing; xUTMEasting = ScreenLeft + (xPos * MetersPerTile/PixelsPerTile); yUTMNorthing = ScreenTop - (yPos * MetersPerTile/PixelsPerTile); Radius = DotRadius*MetersPerTile/PixelsPerTile; for (x = 0; NewLoc[x].EUTM != 0; x++) {//waypoints if ((NewLoc[x].EUTM < xUTMEasting+Radius) && (NewLoc[x].EUTM > xUTMEasting-Radius) && (NewLoc[x].NUTM < yUTMNorthing+Radius) && (NewLoc[x].NUTM > yUTMNorthing-Radius)) { if (NewLoc[x].Description != NULL) { for (y = 0; NewLoc[x].Description[y] != '<'; y++) Description[y] = NewLoc[x].Description[y]; Description[y] = 0; Location[0] = 0; Ident[0] = 0; if ((sortbyname == FALSE) && (NewLoc[x].Location != NULL)) { for (y = 0; NewLoc[x].Location[y] != '<'; y++) Location[y] = NewLoc[x].Location[y]; Location[y] = 0; } else if ((sortbyname) && (NewLoc[x].Ident != NULL)) { for (y = 0; NewLoc[x].Ident[y] != '<'; y++) Ident[y] = NewLoc[x].Ident[y]; Ident[y] = 0; } DialogBox(hInst, "DESCRIPTION", hwnd, DescriptionProc); } } } } ////// if ((autoLoc == FALSE) && (qpressed == FALSE)) {//the usual situation UTMEasting = ScreenLeft + ((xPos*MetersPerTile)/PixelsPerTile); UTMNorthing = ScreenTop - ((yPos*MetersPerTile)/PixelsPerTile); if ((editingtracks) && (currentpoint != -1)) { if ((wParam == MK_RBUTTON) && (firstrbutton == FALSE))//WM_MOUSEMOVE {//while editing tracks and moving mouse with right button down trak[currentpoint].EUTM = UTMEasting; trak[currentpoint].NUTM = UTMNorthing; InvalidateRect(hwnd, &rect, FALSE); } else if ((wParam == MK_LBUTTON) && (firstlbutton == FALSE)) {//while editing tracks and moving mouse with left button down trak[currentpoint+1].EUTM = UTMEasting; trak[currentpoint+1].NUTM = UTMNorthing; InvalidateRect(hwnd, &rect, FALSE); } } else if ((wParam == MK_LBUTTON) && (WaypointToMove != -1) && (ObjectToMove == -1) && (drawing == FALSE)) {//move waypoint UTMEasting = ScreenLeft + ((xPos*MetersPerTile)/PixelsPerTile); UTMNorthing = ScreenTop - ((yPos*MetersPerTile)/PixelsPerTile); NewLoc[WaypointToMove].NUTM = UTMNorthing; NewLoc[WaypointToMove].EUTM = UTMEasting; InvalidateRect(hwnd, &rect, FALSE); } else if (objectPtr) { if ((wParam == MK_LBUTTON) && (ObjectToMove != -1)) {//move object UTMEasting = ScreenLeft + ((xPos*MetersPerTile)/PixelsPerTile); UTMNorthing = ScreenTop - ((yPos*MetersPerTile)/PixelsPerTile); Objects[ObjectToMove].UTMN = UTMNorthing; Objects[ObjectToMove].UTME = UTMEasting; InvalidateRect(hwnd, &rect, FALSE); } } UTMtoLatLon(); if (veryfirstime) { veryfirstime = FALSE; if (gotelevini) GetElevData(); } if ((MouseLoc == DEG) || (MouseLoc == DEGMIN) || (MouseLoc == DEGMINSEC)) { GetLatLon(); SetWindowText(hwnd, LatLon); } else if (MouseLoc == ITSUTM) { West = ScreenLeft + (xPos*MetersPerTile/PixelsPerTile); North = ScreenTop - (yPos*MetersPerTile/PixelsPerTile); GetUTM(North, West); SetWindowText(hwnd, UTM); } else if (MouseLoc == ITSUSNG) { West = ScreenLeft + (xPos*MetersPerTile/PixelsPerTile); North = ScreenTop - (yPos*MetersPerTile/PixelsPerTile); GetUSNG(North, West); SetWindowText(hwnd, USNG); } } else if ((autoLoc == FALSE) && (qpressed == TRUE)) { North = (ScreenTop - (yPos*MetersPerTile/PixelsPerTile)) / MetersPerTile; West = (ScreenLeft + (xPos*MetersPerTile/PixelsPerTile)) / MetersPerTile; GetRowName(North, West); SetWindowText(hwnd, RowName); } if (showingtracks)//WM_MOUSEMOVE { if (showingtrackdata) {//only show this again after showing position data showingtrackdata = FALSE; SetWindowText(hwndTrack, Trac); } for (x = 0; trak[x].time != 0; x++) { if ((trak[x].EUTM < UTMEasting+(6*MetersPerTile/PixelsPerTile)) && (trak[x].EUTM > UTMEasting-(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM < UTMNorthing+(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM > UTMNorthing-(6*MetersPerTile/PixelsPerTile))) { int i = 0; char Track[100] = " : : Z\r\n"; time = 0; ch = (trak[x].time >> 12) & 0x1F; time = ch * 3600; Track[i++] = (ch / 10) + '0';//hour Track[i++] = (ch % 10) + '0'; i++; ch = (trak[x].time >> 6) & 0x3F; time += ch * 60; Track[i++] = (ch / 10) + '0';//minute Track[i++] = (ch % 10) + '0'; i++; ch = trak[x].time & 0x3F; time += ch; Track[i++] = (ch / 10) + '0';//second Track[i++] = (ch % 10) + '0'; i = 11; if (x) { prevtime = ((trak[x-1].time >> 12) & 0x1F) * 3600; prevtime += ((trak[x-1].time >> 6) & 0x3F) * 60; prevtime += trak[x-1].time & 0x3F; ndist = abs(trak[x].NUTM - trak[x-1].NUTM); edist = abs(trak[x].EUTM - trak[x-1].EUTM); if (time - prevtime) { speed = (sqrt(ndist*ndist + edist*edist)) / (time - prevtime);//meters/sec speed *= 2.2369363;//mph } else speed = 0.0; i += sprintf(&Track[i], "%.1f mph\r\n", speed); } i += sprintf(&Track[i], "%.2f miles from beginning of segment", trak[x].dist / 1609.344); if (trak[x].alt) i += sprintf(&Track[i], "\r\n%.0f'", trak[x].alt); i += sprintf(&Track[i], "\r\n(line #%i in the .csv file)", x+2); showingtrackdata = TRUE; SetWindowText(hwndTrack, Track); break; } } }//end of if (showingtracks) if ((gotstreet) && ((xPos > (gotX+10)) || (yPos > (gotY+10)) || (xPos < (gotX-10)) || (yPos < (gotY-10)))) {//if mouse moved away from street name gotstreet = FALSE; hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem3, 0, 0, SRCCOPY); if (hdcMem3 != NULL) { SelectObject(hdc, hObject); DeleteDC(hdcMem3); DeleteObject(hBitmap3); hdcMem3 = NULL; } ReleaseDC(hwnd, hdc); // InvalidateRect(hwnd, &rect, FALSE); } return 0; case WM_LBUTTONDBLCLK: if ((drawing) && (ptr > 1)) EndRoute(); return 0; //new waypoint or drawing route or editing tracks or moving a waypoint or clicking on Map Location dot on USA map // or new airplane in ApproachControl case WM_LBUTTONDOWN: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if ((autoLoc) && (fromFlag == NOBUTTON)) break; lButtonDotX = LOWORD(lParam); lButtonDotY = HIWORD(lParam); distancemeasure = FALSE; if ((approachcontrol) && (wParam != MK_CONTROL)) { if (AtPlane == -1) { tempUTME = ScreenLeft + ((LOWORD(lParam) * MetersPerTile) / PixelsPerTile); tempUTMN = ScreenTop - ((HIWORD(lParam) * MetersPerTile) / PixelsPerTile); if (DialogBox(hInst, "AIRPLANE", hwnd, NewPlaneProc)) { if (hdcMem3 == NULL) { hdc = GetDC(hwnd); hdcMem3 = CreateCompatibleDC(hdc); hBitmap3 = CreateCompatibleBitmap(hdc, rect.right, rect.bottom); hObject = SelectObject(hdcMem3, hBitmap3); ReleaseDC(hwnd, hdc); SetBkMode(hdcMem3, TRANSPARENT); SetTextColor(hdcMem3, 0xFFFFFF); GetTextExtentPoint32(hdcMem3, "5", 1, &Size); } BitBlt(hdcMem3, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); Plane[plane].UTMEasting = tempUTME; Plane[plane].UTMNorthing = tempUTMN; Plane[plane].x = (Plane[plane].UTMEasting - ScreenLeft) / (MetersPerTile/PixelsPerTile); Plane[plane].y = (ScreenTop - Plane[plane].UTMNorthing) / (MetersPerTile/PixelsPerTile); Plane[plane].heading = (int)iHeading; if (Plane[plane].heading == 0) Plane[plane].heading = 360; Plane[plane].altitude = Atoi((char*)ApproachAltitude); Plane[plane].IAS = Atoi((char*)Airspeed); Plane[plane].radianheading = radianheading; Plane[plane].newHeading = (int)iHeading; if (Plane[plane].newHeading == 0) Plane[plane].newHeading = 360; Plane[plane].newAltitude = Atoi((char*)ApproachAltitude); Plane[plane].newIAS = Atoi((char*)Airspeed); Plane[plane].newRadianheading = radianheading; hRedBrush = CreateSolidBrush(RED); hOldBrush = SelectObject(hdcMem3, hRedBrush); Ellipse(hdcMem3, Plane[plane].x - PlaneRadius, Plane[plane].y - PlaneRadius, Plane[plane].x + PlaneRadius, Plane[plane].y + PlaneRadius); hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem3, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdc); SelectObject(hdcMem3, hOldBrush); DeleteObject(hRedBrush); plane++; if (plane == MAXPLANES) MessageBox(hwnd, "MAXPLANES = 25", ERROR, MB_OK); if (uTimerID == NULL) { uTimerID = timeSetEvent(1000, TIMER_RESOLUTION, TimerFunc, 0, TIME_PERIODIC); } } } else // if (AtPlane != -1) { planecommand = TRUE; for (x = 0; x < 16; x++) Command[x] = 0; command = 0; } break; } if (getelev) { SendMessage(hwnd, WM_KEYDOWN, (WPARAM)'X', 0); break; } else if ((bigjpeg) || (terrafetcher)) { buttondown = TRUE; X1 = ScreenLeft + ((LOWORD(lParam) * MetersPerTile) / PixelsPerTile); Y1 = ScreenTop - ((HIWORD(lParam) * MetersPerTile) / PixelsPerTile); break; } else if (editingtracks) { trackcolors = FALSE; if (firstlbutton) { firstlbutton = FALSE; currentpoint = -1; for (x = 0; trak[x].time != 0; x++) { if ((trak[x].EUTM < UTMEasting+(6*MetersPerTile/PixelsPerTile)) && (trak[x].EUTM > UTMEasting-(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM < UTMNorthing+(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM > UTMNorthing-(6*MetersPerTile/PixelsPerTile))) { currentpoint = x;//it's at a point break; } } if (currentpoint != -1) {//at track point if ((trak[currentpoint+1].newtrk == 0) && (trak[currentpoint+1].time != 0)) {//it's not at a point at the end of a segment - so it's to make a segment color trackcolors = TRUE; for (y = currentpoint;(trak[y].newtrk == 0) && (y > 0); y--) ;//go to beginning of segment if (y > 0) {//if there's a 'New' or color number at the beginning if (trak[y].color != 0)//if color is already there TrackSegmentColor = trak[y].color; else TrackSegmentColor = TrackColor;//default track color if (DialogBox(hInst, "TRACKCOLORS", hwnd, TrackColorsProc)) SaveTracks(); } else TrackSegmentColor = TrackColor; currentpoint = -1;//for another routine } else//if adding a segment or possibly combining segments { for ( ; trak[x].time != 0; x++) ; x++; for ( ; x > currentpoint; x--) trak[x] = trak[x-1];//make room for point added when mouse button released (with UTM info from mousemove) } } } return 0; } else if ((showstreets) && (gotstreet)) { if (((MapType == PHOTO) && (Zoom <= 2)) || ((MapType == URBANAREA) && (Zoom <= 4)) || ((MapType == TOPO) && (Zoom == 1))) { xBeg = gotX; yBeg = gotY; DialogBox(hInst, "GETTEXT", hwnd, GetTextProc); xBeg = -1; return 0; } } //check to see if an existing waypoint has been left-clicked on Radius = DotRadius*MetersPerTile/PixelsPerTile; WaypointToMove = -1; for (z = 0; NewLoc[z].EUTM != 0; z++) {//waypoints if ((NewLoc[z].EUTM < UTMEasting+Radius) && (NewLoc[z].EUTM > UTMEasting-Radius) && (NewLoc[z].NUTM < UTMNorthing+Radius) && (NewLoc[z].NUTM > UTMNorthing-Radius)) { WaypointToMove = z; break; } } if (objectPtr) { Radius = 8*MetersPerTile/PixelsPerTile; ObjectToMove = -1; for (z = 0; z < objectPtr; z++) {//objects if ((Objects[z].UTME < UTMEasting+Radius) && (Objects[z].UTME > UTMEasting-Radius) && (Objects[z].UTMN < UTMNorthing+Radius) && (Objects[z].UTMN > UTMNorthing-Radius)) { ObjectToMove = z; break; } } } //fall thru... case WM_USER6: // waypointedited = FALSE; if (drawing) { RoutePoint++; totalRouteDist[ptr] = routeDist; if (showingroute == FALSE) { showingroute = TRUE; CheckMenuItem(hMenu, ID_ROUTE_SHOW, MF_CHECKED); } if (WaypointToMove == -1) { x = ScreenLeft + (LOWORD(lParam)*MetersPerTile/PixelsPerTile); y = ScreenTop - (HIWORD(lParam)*MetersPerTile/PixelsPerTile); } else//if (WaypointToMove != -1) { if ((WaypointSize + 1000) < MaxWaySize) { ChosenLoc = WaypointToMove; Location[0] = Ident[0] = Description[0] = 0; if (NewLoc[ChosenLoc].Location != NULL) for (z = 0; NewLoc[ChosenLoc].Location[z] != '<'; z++) Location[z] = NewLoc[ChosenLoc].Location[z]; if (NewLoc[ChosenLoc].Ident != NULL) for (z = 0; NewLoc[ChosenLoc].Ident[z] != '<'; z++) Ident[z] = NewLoc[ChosenLoc].Ident[z]; if (NewLoc[ChosenLoc].Description != NULL) for (z = 0; NewLoc[ChosenLoc].Description[z] != '<'; z++) Description[z] = NewLoc[ChosenLoc].Description[z]; Response = DialogBox(hInst, "LOCATIONDESC", hwnd, EditLocationProc); if (Response != EXIT) EditWaypoint(); // waypointedited = TRUE; } x = NewLoc[WaypointToMove].EUTM; y = NewLoc[WaypointToMove].NUTM; WaypointToMove = -1; } if ((ptr == 0) || ((pRoute[ptr-1].NUTM != y) || (pRoute[ptr-1].EUTM != x))) {//don't duplicate previous point pRoute[ptr].UTMZone = UTMZone; pRoute[ptr].NUTM = y; pRoute[ptr].EUTM = x; Radius = DotRadius*MetersPerTile/PixelsPerTile; for (z = 0; NewLoc[z].EUTM != 0; z++) {//check for route point near a waypoint & move it to waypoint if it is if ((NewLoc[z].UTMZone == UTMZone) && (NewLoc[z].EUTM < x+Radius) && (NewLoc[z].EUTM > x-Radius) && (NewLoc[z].NUTM < y+Radius) && (NewLoc[z].NUTM > y-Radius)) { MessageBeep(MB_OK); pRoute[ptr].NUTM = NewLoc[z].NUTM; pRoute[ptr].EUTM = NewLoc[z].EUTM; break; } } if (ptr < MAX_PTR) ptr++; } } else if ((WaypointToMove == -1) && (ObjectToMove == -1) && (enteringtext == FALSE) && (Pixels == NULL))//else && (waypointedited == FALSE) {//new waypoint if ((WaypointSize + 1000) > MaxWaySize) { MessageBox(hwnd, WaypointLimit, "Sorry...", MB_OK); return 0; } if ((Lon > -60.0) || (Lon < -168.0) || (Lat > 72.0) || (Lat < 17.5))//WM_LBUTTONDOWN { sprintf(Error, "N %f\nW %f %s", Lat, Lon, OutsideUSA); MessageBox(hwnd, Error, "Error 3", MB_OK); return 0; } if (NewLoc[TOTAL_LOCS-1].EUTM != 0) { MessageBox(hwnd, FullArray, NULL, MB_OK); return 0; } if ((autoLoc) && (fromFlag == NOBUTTON)) { fromFlag = LBUTTON; if (itsgarmin) { sendingStop = TRUE; WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = StopPVTPacket[y]; if (tgcount > 49900) tgcount = 0; return 0;//ACK will call this routine again } else if (itsusb == FALSE) { autoLoc = FALSE; SetEvent(hEventExit); } else if (hUSBThread != 0)//if (itsusb) { SignalUSBStop(); } } if (fromFlag != NOBUTTON) { showposition = FALSE; fromFlag = NOBUTTON; autoLoc = FALSE; DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); RedDot(hwnd); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } hdc = GetDC(hwnd); hWaypointBrush = CreateSolidBrush(WaypointColor); hObject = SelectObject(hdc, hWaypointBrush); DotX = (UTMEasting - ScreenLeft) * PixelsPerTile / MetersPerTile; DotY = (ScreenTop - UTMNorthing) * PixelsPerTile / MetersPerTile; Ellipse(hdc, DotX-DotRadius, DotY-DotRadius, DotX+DotRadius, DotY+DotRadius); // Ellipse(hdc, lButtonDotX-DotRadius, lButtonDotY-DotRadius, lButtonDotX+DotRadius, lButtonDotY+DotRadius); SelectObject(hdc, hObject); DeleteObject(hWaypointBrush); ReleaseDC(hwnd, hdc); Response = EXIT; if (fromgoto == FALSE) { int oldUTMZone = UTMZone; UTMtoLatLon(); LatRad = Lat * deg2rad; LonRad = Lon * deg2rad; LatLontoUTM(); if (oldUTMZone != UTMZone) { ChangeZone(UTMZone, 8);//left button down MessageBox(hwnd, "New UTM zone", "", MB_OK); BeginY = UTMNorthing / MetersPerTile; BeginX = UTMEasting / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; Waypoints[0] = 0; fromOpen = TRUE; SendMessage(hwnd, WM_USER4, 0, 0); return 0; } } else fromgoto = FALSE; if (markobject) { ObjectUTMN = UTMNorthing; ObjectUTME = UTMEasting; ObjectUTMZ = UTMZone; Response = DialogBox(hInst, "OBJECT", hwnd, GetObjectProc); if (Response != EXIT) CheckMenuItem(hMenu, ID_APRS_OBJECTS_SHOWOBJECTS, MF_CHECKED); CheckMenuItem(hMenu, ID_APRS_OBJECTS_MARKOBJECT, MF_UNCHECKED); markobject = FALSE; InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar return 0; } if (fromstationinfo == FALSE)//else Response = DialogBox(hInst, "LOCATION", hwnd, GetLocationProc); if (Response == EXIT) { if (markobject) { CheckMenuItem(hMenu, ID_APRS_OBJECTS_MARKOBJECT, MF_UNCHECKED); markobject = FALSE; } InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar return 0; } strcpy(Location, LocBuf); strcpy(Ident, IdentBuf); GetLatLon();//get tl (elevation) for (x = 0; x < TOTAL_LOCS; x++) if (NewLoc[x].EUTM == 0) break; EmptyLoc = x; for (x = 0; x < EmptyLoc; x++) { if (sortbyname == FALSE) { if ((NewLoc[x].Location != NULL) && (NewLoc[x].Location != 0)) { for (y = 0; (NewLoc[x].Location[y] != '<') || (NewLoc[x].Location[y+1] != '/'); y++) tempNewLoc[y] = NewLoc[x].Location[y]; } else { for (y = 0; (NewLoc[x].Ident[y] != '<') || (NewLoc[x].Ident[y+1] != '/'); y++) tempNewLoc[y] = NewLoc[x].Ident[y]; } tempNewLoc[y] = 0;//this is why tempNewLoc is used if (_stricmp(tempNewLoc, Location) > 0) { InsertLoc = x; EmptyLoc++; for (x = EmptyLoc; x > InsertLoc; x--) NewLoc[x] = NewLoc[x-1];//move to make room to insert new data break; } } else//if (sortbyname) { if (NewLoc[x].Ident != 0) { for (y = 0; (NewLoc[x].Ident[y] != '<') || (NewLoc[x].Ident[y+1] != '/'); y++) tempNewLoc[y] = NewLoc[x].Ident[y]; } else { for (y = 0; (NewLoc[x].Location[y] != '<') || (NewLoc[x].Location[y+1] != '/'); y++) tempNewLoc[y] = NewLoc[x].Location[y]; } tempNewLoc[y] = 0;//this is why tempNewLoc is used if (Ident[0] != 0) pIdentLoc = Ident; else pIdentLoc = Location; if (_stricmp(tempNewLoc, pIdentLoc) > 0) { InsertLoc = x; EmptyLoc++; for (x = EmptyLoc; x > InsertLoc; x--) NewLoc[x] = NewLoc[x-1];//move to make room to insert new data break; } } } if (x == EmptyLoc) { InsertLoc = x; EmptyLoc++; } tempLat = Lat; tempLon = Lon; tempUTMN = UTMNorthing; tempUTME = UTMEasting; tempUTMZone = UTMZone; LatRad = Lat * deg2rad; LonRad = Lon * deg2rad; LatLontoUTM(); NewLoc[InsertLoc].EUTM = UTMEasting; NewLoc[InsertLoc].NUTM = UTMNorthing; NewLoc[InsertLoc].UTMZone = UTMZone; Lat = tempLat; Lon = tempLon; UTMNorthing = tempUTMN; UTMEasting = tempUTME; UTMZone = tempUTMZone; if (tl != 0) { eleM = tl * 0.3048;//convert to meters sprintf(Elev, "%.4f", eleM); } Sym[0] = 0; ///---> FillWaypointArray(InsertLoc);//Lat & Lon are already known ///---> }//end of else if ((WaypointToMove == -1) && if ((WaypointToMove == -1) && (enteringtext == FALSE)) InvalidateRect(hwnd, &rect, FALSE); return 0; case WM_RBUTTONUP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (editingtracks) { firstlbutton = firstrbutton = TRUE; if ((currentpoint != -1) && (trak[currentpoint+1].time != 0)) { x = abs(trak[currentpoint].NUTM - trak[currentpoint+1].NUTM); y = abs(trak[currentpoint].EUTM - trak[currentpoint+1].EUTM); if ((x < 6*MetersPerTile/PixelsPerTile) && (y < 6*MetersPerTile/PixelsPerTile)) {//if the point was moved over the next point trak[currentpoint+1].newtrk = 0; for (x = currentpoint; trak[x].time != 0; x++) trak[x] = trak[x+1];//move trak data back } } // else // {//not combining segments // trak[currentpoint+1].time = UTMZone << 26; // trak[currentpoint+1].year = 0; // } SaveTracks(); InvalidateRect(hwnd, &rect, FALSE); } return 0; case WM_LBUTTONUP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (WaypointToMove != -1) {//NewLoc[WaypointToMove].pWaypoints = int saveX; for (x = 0; NewLoc[WaypointToMove].pWaypoints[x] != '"'; x++) ; x++;//to lat saveX = x; for ( ; NewLoc[WaypointToMove].pWaypoints[x] != '"'; x++) ; count = x - saveX - 1; ptrToAscii = _ecvt(Lat, count, &decPos, &sign); for (x = saveX, y = 0 ; y < decPos; x++, y++) NewLoc[WaypointToMove].pWaypoints[x] = ptrToAscii[y]; NewLoc[WaypointToMove].pWaypoints[x++] = '.'; for ( ; y < count; x++, y++) NewLoc[WaypointToMove].pWaypoints[x] = ptrToAscii[y]; x++;//past ending " of lat= for ( ; NewLoc[WaypointToMove].pWaypoints[x] != '"'; x++) ;//go to longitude x += 2;//past " and - saveX = x; for ( ; NewLoc[WaypointToMove].pWaypoints[x] != '"'; x++) ; count = x - saveX - 1; ptrToAscii = _ecvt(Lon, count, &decPos, &sign); for (x = saveX, y = 0 ; y < decPos; x++, y++) NewLoc[WaypointToMove].pWaypoints[x] = ptrToAscii[y]; NewLoc[WaypointToMove].pWaypoints[x++] = '.'; for ( ; y < count; x++, y++) NewLoc[WaypointToMove].pWaypoints[x] = ptrToAscii[y]; WaypointToMove = -1; newLoc = TRUE; } if ((editingtracks) && (trackcolors == FALSE)) { firstlbutton = firstrbutton = TRUE; if ((currentpoint != -1) && (trak[currentpoint+2].time != 0)) { x = abs(trak[currentpoint+1].NUTM - trak[currentpoint+2].NUTM); y = abs(trak[currentpoint+1].EUTM - trak[currentpoint+2].EUTM); if ((x < 6*MetersPerTile/PixelsPerTile) && (y < 6*MetersPerTile/PixelsPerTile)) {//if the new point is over an existing point trak[currentpoint+2].newtrk = 0; for (x = currentpoint+1; trak[x].time != 0; x++) trak[x] = trak[x+1];//move trak data back } } else {//not combining segments trak[currentpoint+1].time = UTMZone << 26; trak[currentpoint+1].year = 0; } SaveTracks(); InvalidateRect(hwnd, &rect, FALSE); } else if ((terrafetcher) && (buttondown)) { terrafetcher = FALSE; buttondown = FALSE; X2 = ScreenLeft + ((LOWORD(lParam) * MetersPerTile) / PixelsPerTile); Y2 = ScreenTop - ((HIWORD(lParam) * MetersPerTile) / PixelsPerTile); if ((abs(X2 - X1) > 3) && abs(Y2 - Y1) > 3) { char asdf[8]; if (Y1 > Y2) { yTopLeft = Y1; yBottomRight = Y2; } else { yTopLeft = Y2; yBottomRight = Y1; } if (X1 < X2) { xTopLeft = X1; xBottomRight = X2; } else { xTopLeft = X2; xBottomRight = X1; } // 10 20 30 40 50 60 70 80 90 // 01234567 8 90123456789 0 123456789012345678 9 012345678901234567 8 901234567890123456 7 890123456789012345 6 7 //char Region[] = "Region=4\r\nFormat=UTM\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\nzz xxxxxx yyyyyyy\r\n"; // top left top right bottom right bottom left Region[22] = Region[41] = Region[60] = Region[79] = (UTMZone / 10) + '0'; Region[23] = Region[42] = Region[61] = Region[80] = (UTMZone % 10) + '0'; _itoa(xTopLeft, asdf, 10); for (x = 0, y = 25; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; for (x = 0, y = 82; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; _itoa(yTopLeft, asdf, 10); for (x = 0, y = 32; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; for (x = 0, y = 51; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; _itoa(yBottomRight, asdf, 10); for (x = 0, y = 70; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; for (x = 0, y = 89; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; _itoa(xBottomRight, asdf, 10); for (x = 0, y = 44; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; for (x = 0, y = 63; asdf[x] != 0; x++, y++) Region[y] = asdf[x]; } hFile = CreateFile(TerraFetcherRegion, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);//ger WriteFile(hFile, Region, 100, &dwBytesWritten, NULL); CloseHandle(hFile); hdc = GetDC(hwnd); BitBlt(hdc, 0, 0, MapWidth, MapHeight, hdcMem, 0, 0, SRCCOPY); ReleaseDC(hwnd, hdc); MessageBox(hwnd, "'TerraFetcherRegion.txt' has been\nwritten to the USAPhotoMaps folder.", "TerraFetcher Region", MB_OK); } else if ((bigjpeg) && (buttondown)) { X2 = ScreenLeft + ((LOWORD(lParam) * MetersPerTile) / PixelsPerTile); Y2 = ScreenTop - ((HIWORD(lParam) * MetersPerTile) / PixelsPerTile); if ((abs(X2 - X1) > 3) && abs(Y2 - Y1) > 3) { if (Y1 > Y2) { yTopLeft = Y1; yBottomRight = Y2; } else { yTopLeft = Y2; yBottomRight = Y1; } if (X1 < X2) { xTopLeft = X1; xBottomRight = X2; } else { xTopLeft = X2; xBottomRight = X1; } w = 1; z = 0; xTopLeft = (xTopLeft / MetersPerTile) * MetersPerTile; _itoa(xTopLeft, X, 10); for (x = 0; X[x] != 0; x++, w++, z++) { BigJpegFilename[w] = X[x]; BigJpegData[z] = X[x]; } w++; BigJpegData[z++] = '\r'; BigJpegData[z++] = '\n'; xBottomRight = ((xBottomRight / MetersPerTile) * MetersPerTile) + MetersPerTile; _itoa(xBottomRight, X, 10); for (x = 0; X[x] != 0; x++, z++) BigJpegData[z] = X[x]; BigJpegData[z++] = '\r'; BigJpegData[z++] = '\n'; yTopLeft = ((yTopLeft / MetersPerTile) * MetersPerTile) + MetersPerTile; _itoa(yTopLeft, Y, 10); for (x = 0; Y[x] != 0; x++, w++, z++) { BigJpegFilename[w] = Y[x]; BigJpegData[z] = Y[x]; } w++; BigJpegData[z++] = '\r'; BigJpegData[z++] = '\n'; BigJpegFilename[w++] = Z[0]; BigJpegFilename[w++] = Z[1]; if (MetersPerTile == 1600) BigJpegFilename[w] = 'b'; else if (MetersPerTile == 800) { if (MapType == TOPO) BigJpegFilename[w] = 't'; else BigJpegFilename[w] = 'c'; } else if (MetersPerTile == 200) BigJpegFilename[w] = 'p'; else if (MetersPerTile == 12800) BigJpegFilename[w] = 'T'; else//if (MetersPerTile == 50) BigJpegFilename[w] = 'u'; w++; yBottomRight = ((yBottomRight / MetersPerTile) * MetersPerTile); _itoa(yBottomRight, Y, 10); for (x = 0; Y[x] != 0; x++, z++) BigJpegData[z] = Y[x]; BigJpegData[z++] = '\r'; BigJpegData[z++] = '\n'; BigJpegDataSize = z; // hdc = GetDC(hwnd); // BitBlt(hdc, 0, 0, MapWidth, MapHeight, hdcMem, 0, 0, SRCCOPY); // ReleaseDC(hwnd, hdc); buttondown = FALSE; BigJpeg(); } } else if (ObjectToMove != -1) { hFile = CreateFile(ObjectsDta, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, Objects, objectPtr*120, &dwBytesWritten, NULL); CloseHandle(hFile); } return 0; //show menu for waypoints with a listbox & GoTo & LineTo & Edit & Delete & Exit buttons case WM_RBUTTONDOWN: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; // if (ataprs) // { // hdc = GetDC(hwnd); // DotX = (Aprs[CurrentAprsi].UTME - ScreenLeft) * PixelsPerTile / MetersPerTile; // DotY = (ScreenTop - Aprs[CurrentAprsi].UTMN) * PixelsPerTile / MetersPerTile; // TextOut(hdc, DotX+10, DotY+30, Aprs[CurrentAprsi].Status, strlen(Aprs[CurrentAprsi].Status)); // ReleaseDC(hwnd, hdc); // break; // } if (approachcontrol) { // for runway centerline extension and downwind leg xPos = LOWORD(lParam); // horizontal position of cursor yPos = HIWORD(lParam); // vertical position of cursor if (DialogBox(hInst, "CENTERLINE", hwnd, CenterlineProc)) { Line[lines].UTME1 = ScreenLeft + (xPos * MetersPerTile / PixelsPerTile); Line[lines].UTMN1 = ScreenTop - (yPos * MetersPerTile / PixelsPerTile); hypotenuse = 20.0 * 5280 * 0.3048; // 20 mile final d1 = hypotenuse * sin(dCenterline * deg2rad); d2 = hypotenuse * cos(dCenterline * deg2rad); __asm fld d1 // round a double up or down __asm fistp x // to an integer __asm fld d2 // round a double up or down __asm fistp y // to an integer Line[lines].UTME2 = Line[lines].UTME1 + x; Line[lines].UTMN2 = Line[lines].UTMN1 + y; if (GlideSlopeAlt) { dDistance = (double)GlideSlopeAlt * 0.3048 / GlideSlope; // meters d1 = dDistance * sin(dCenterline * deg2rad); d2 = dDistance * cos(dCenterline * deg2rad); __asm fld d1 // round a double up or down __asm fistp x // to an integer __asm fld d2 // round a double up or down __asm fistp y // to an integer Line[lines].GSE = Line[lines].UTME1 + x; Line[lines].GSN = Line[lines].UTMN1 + y; Line[lines].GSInterceptAlt = GlideSlopeIntercept; } else { Line[lines].GSE = 0; Line[lines].GSN = 0; } lines++; if ((DownwindAlt) && (DownwindIAS)) { TAS = DownwindIAS + (DownwindIAS * DownwindAlt / 50000); TurnRadius = TAS * TAS * TwentyfiveDegreeBank; // in meters hypotenuse = TurnRadius * 2.0; if (rightdownwind) { downwindOffsetHeading = dCenterline - 90.0; if (downwindOffsetHeading > dCenterline) downwindOffsetHeading -= 360.0; } else { downwindOffsetHeading = dCenterline + 90.0; if (downwindOffsetHeading > 360.0) downwindOffsetHeading -= 360.0; } d1 = hypotenuse * sin(downwindOffsetHeading * deg2rad); d2 = hypotenuse * cos(downwindOffsetHeading * deg2rad); __asm fld d1 // round a double up or down __asm fistp x // to an integer __asm fld d2 // round a double up or down __asm fistp y // to an integer Line[lines].UTME1 = Line[lines-1].UTME1 + x; Line[lines].UTMN1 = Line[lines-1].UTMN1 + y; Line[lines].UTME2 = Line[lines-1].UTME2 + x; Line[lines].UTMN2 = Line[lines-1].UTMN2 + y; lines++; } InvalidateRect(hwnd, &rect, TRUE); } break; } distancemeasure = FALSE; if (enteringtext) break; if (editingtracks) { if (firstrbutton) { firstrbutton = FALSE; currentpoint = -1; for (x = 0; trak[x].time != 0; x++) { if ((trak[x].EUTM < UTMEasting+(6*MetersPerTile/PixelsPerTile)) && (trak[x].EUTM > UTMEasting-(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM < UTMNorthing+(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM > UTMNorthing-(6*MetersPerTile/PixelsPerTile))) { currentpoint = x; break; } } } return 0; } // if (aprs) // { // char FindUwx[512] = "C:\\Program Files\\Internet Explorer\\iexplore.exe http://www.findu.com/cgi-bin/wxpage.cgi?call=cw8983&last=24&radar=byx"; // if (CurrentAprsi != -1) // { // WinExec(FindUwx, SW_SHOW); // return 0; // } // } SavePosX = xPos; SavePosY = yPos; if ((autoLoc) && (fromFlag == NOBUTTON)) break; if (fromFlag != NOBUTTON) { showposition = FALSE; fromFlag = NOBUTTON; //autoLoc comes later... DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); RedDot(hwnd); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } //get closest waypoint (to highlight) if (yPos > TitleAndMenu)//2 { centerX = SavePosX; centerY = SavePosY; } else { centerX = rect.right >> 1; centerY = rect.bottom >> 1; } UTMCenterX = (centerX * MetersPerTile/PixelsPerTile) + ScreenLeft; UTMCenterY = ScreenTop - (centerY * MetersPerTile/PixelsPerTile); waypoints: B = 10000000000.0;//large number index = -1;//flag for (x = 0; x < TOTAL_LOCS; x++) { if (NewLoc[x].EUTM == 0) break; if (NewLoc[x].UTMZone != UTMZone) continue; idistX = UTMCenterX - NewLoc[x].EUTM; if (idistX < 1) idistX = -(idistX); idistY = UTMCenterY - NewLoc[x].NUTM; if (idistY < 1) idistY = -(idistY); distX = (double) idistX; distY = (double) idistY; A = (int) sqrt((distX*distX) + (distY*distY)); if (A < B) { B = A; index = x; } } /////////<<<<<<< Response = DialogBox(hInst, "WAYPOINTS", hwnd, CheckLocationProc); ////////<<<<<<<< if (Response == EXIT) { InvalidateRect(hwnd, &rect, FALSE); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } else if (Response == EDIT) { if ((WaypointSize + 1000) > MaxWaySize) { MessageBox(hwnd, WaypointLimit, "Sorry...", MB_OK); goto waypoints; } Location[0] = Ident[0] = Description[0] = 0; if (NewLoc[ChosenLoc].Location != NULL) for (x = 0; NewLoc[ChosenLoc].Location[x] != '<'; x++) Location[x] = NewLoc[ChosenLoc].Location[x]; if (NewLoc[ChosenLoc].Ident != NULL) for (x = 0; NewLoc[ChosenLoc].Ident[x] != '<'; x++) Ident[x] = NewLoc[ChosenLoc].Ident[x]; if (NewLoc[ChosenLoc].Description != NULL) for (x = 0; NewLoc[ChosenLoc].Description[x] != '<'; x++) Description[x] = NewLoc[ChosenLoc].Description[x]; Response = DialogBox(hInst, "LOCATIONDESC", hwnd, EditLocationProc); if (Response != EXIT) EditWaypoint(); InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar goto waypoints; }//end of if (Response == EDIT) else if (Response == LINE_TO) { if (NewLoc[ChosenLoc].UTMZone == UTMZone) { fromlineto = TRUE; hdc = GetDC(hwnd); hPen = CreatePen(PS_SOLID, 0, 0xF0);//red hObject = SelectObject(hdc, hPen); MoveToEx(hdc, centerX, centerY, NULL); DrawLineTo(NewLoc[ChosenLoc].NUTM, NewLoc[ChosenLoc].EUTM); SelectObject(hdc, hObject); ReleaseDC(hwnd, hdc); DeleteObject(hPen); } else MessageBox(hwnd, "Sorry, that waypoint isn't in this UTM zone", ERROR, MB_OK); } else if (Response == DELEET) { for (x = ChosenLoc; x < (TOTAL_LOCS-1); x++) NewLoc[x] = NewLoc[x+1]; NewLoc[x].EUTM = 0; NewLoc[x].NUTM = 0; NewLoc[x].UTMZone = 0; NewLoc[x].pWaypoints = NULL; NewLoc[x].Ident = NULL; NewLoc[x].Location = NULL; NewLoc[x].Description = NULL; NewLoc[x].Elev = NULL; NewLoc[x].Sym = NULL; NewLoc[x].size = 0; EmptyLoc--; newLoc = TRUE; InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar goto waypoints; } else if (Response == URL_LINK) { if ((NewLoc[ChosenLoc].Ident) && (NewLoc[ChosenLoc]. Ident[0] == 'G') && (NewLoc[ChosenLoc]. Ident[1] == 'C')) { for (x = 0; NewLoc[ChosenLoc].Ident[x] != '<'; x++) URLink[x + 101] = NewLoc[ChosenLoc].Ident[x]; WinExec(URLink, SW_SHOW); } } else//GoTo { //test lat/lon tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; UTMNorthing = NewLoc[ChosenLoc].NUTM; UTMEasting = NewLoc[ChosenLoc].EUTM; UTMZone = NewLoc[ChosenLoc].UTMZone; UTMtoLatLon(); if ((Lon > -60.0) || (Lon < -168.0) || (Lat > 72.0) || (Lat < 17.5))//WM_RBUTTONDOWN {//outside range sprintf(Error, "N %f\nW %f %s", Lat, Lon, OutsideUSA); MessageBox(hwnd, Error, "Error 11", MB_OK); Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; return 0; } Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; //done with test // grid75 = FALSE; wastopo = FALSE; if (NewLoc[ChosenLoc].UTMZone == UTMZone) { rowOffset = ((NewLoc[ChosenLoc].NUTM / MetersPerTile) - (TilesDown/2));//center it colOffset = ((NewLoc[ChosenLoc].EUTM / MetersPerTile) - ((TilesAcross-1)/2));//center it SetCursor(hWaitingCursor); if (gotelevini) GetElevData(); fromGoTo = TRUE; SendMessage(hwnd, WM_USER, 0, 0); SetCursor(hCursor); } else { int GotoEasting, GotoNorthing; //this part is from GotoProc UTMNorthing = NewLoc[ChosenLoc].NUTM; UTMEasting = NewLoc[ChosenLoc].EUTM; UTMZone = NewLoc[ChosenLoc].UTMZone; UTMtoLatLon(); ChangeZone(UTMZone, 4);//right button down BeginX = UTMEasting / MetersPerTile; BeginY = UTMNorthing / MetersPerTile; _itoa(BeginX, X, 10); _itoa(BeginY, Y, 10); Z[0] = (UTMZone / 10) + '0'; Z[1] = (UTMZone % 10) + '0'; if (tempUTMZone != UTMZone) { for (x = 0; Area[x] != 0; x++) Waypoints[x] = Area[x]; for (y = 0; y < 5; x++, y++) Waypoints[x] = Xml[y]; if (WaypointsPath[0] != 0) { for (y = 0; WaypointsPath[y] != 0; y++) WaypointsFullPath[y] = WaypointsPath[y]; for (z = 0; Waypoints[z] != 0; y++, z++) WaypointsFullPath[y] = Waypoints[z]; WaypointsFullPath[y] = 0; strcpy(NewLocationsFullPath, WaypointsFullPath); } /* if ((0 == strcmp(Waypoints, WaypointsFullPath)) && (0 != strcmp(Waypoints, NewLocations)) && (IDYES == MessageBox(hwnd, "Do you want to switch to the waypoint list in that UTM zone?", "This waypoint is in another UTM zone", MB_YESNO))) { if (NewLoc[ChosenLoc].Location != 0) { for (x = 0; (NewLoc[ChosenLoc].Location[x] != '<'); x++) comment[x] = NewLoc[ChosenLoc].Location[x];//comment comment[x] = 0; } if (NewLoc[ChosenLoc].Ident != 0) { for (x = 0; (NewLoc[ChosenLoc].Ident[x] != '<'); x++) name[x] = NewLoc[ChosenLoc].Ident[x];//name name[x] = 0; } SendMessage(hwnd, WM_USER4, 0, 0); } else */ { comment[0] = 0; name[0] = 0; for (x = 0; NewLocations[x] != 0; x++) Waypoints[x] = NewLocations[x]; Waypoints[x] = 0; // for (x = 0; Area[x] != 0; x++) // { // TextDta[x] = Area[x]; // NewLocations[x] = Area[x]; // } // for (y = 0; y < 5; x++, y++) // { // TextDta[x] = Not[y]; // NewLocations[x] = Xml[y]; // } // if (Waypoints[0] != 0)//if from ID_WAYPOINTS_OPENFILE // { // for (x = 0; Waypoints[x] != 0; x++) // NewLocations[x] = Waypoints[x]; // NewLocations[x] = 0; // } for (x = 0; (x < 20) && (Area[x] != 0); x++) { UTM[x] = Area[x]; LatLon[x] = Area[x]; USNG[x] = Area[x]; } for ( ; x < 20; x++) { UTM[x] = ' '; LatLon[x] = ' '; USNG[x] = ' '; } } } //this part is from ID_VIEW_GOTO GotoEasting = UTMEasting; GotoNorthing = UTMNorthing; veryfirstime = TRUE; rowOffset = BeginY - (TilesDown / 2); colOffset = BeginX - ((TilesAcross-1) / 2); SetCursor(hWaitingCursor); fromOpen = TRUE; SendMessage(hwnd, WM_USER, 0, 0); SetCursor(hCursor); UTMEasting = GotoEasting; UTMNorthing = GotoNorthing; UTMtoLatLon();//because WM_USER6 already has cursor location lat/lon if ((name[0] != 0) || (comment[0] != 0)) { lButtonDotX = (UTMEasting - ScreenLeft) * PixelsPerTile / MetersPerTile; lButtonDotY = (ScreenTop - UTMNorthing) * PixelsPerTile / MetersPerTile; fromgoto = TRUE; SendMessage(hwnd, WM_USER6, 0, 0); } } } autoLoc = FALSE; return 0; case WM_KEYUP: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (wParam == VK_SHIFT) enteringtext = FALSE; if (wParam == VK_CONTROL) { distancemeasure = FALSE; mousewheel = FALSE; // xPosOld = xPos; // xbegOld = xbeg; // yPosOld = yPos; // ybegOld = ybeg; } if ((wParam == '1') && (onepressed)) { onepressed = missing1meter = FALSE; InvalidateRect(hwnd, &rect, FALSE); } else if (drawing == FALSE) { if ((wParam == VK_SHIFT) && (xBeg != -1)) {//finished drawing line for text entry Angle = 370.0;//initialized as a flag if ((yPos == yBeg) && (xPos > xBeg))//level Angle = 0.0; else if ((xPos == xBeg) && (yPos < yBeg))//straight up Angle = 90.0; else if ((xPos > xBeg) && (yPos < yBeg)) {//angled up A = (double)(yBeg - yPos) / (double)(xPos - xBeg); Angle = (rad2deg * atan(A)); } else if ((xPos > xBeg) && (yPos > yBeg)) {//angled down A = (double)(xPos - xBeg) / (double)(yPos - yBeg); Angle = (rad2deg * atan(A)) + 270.0; } Response = DialogBox(hInst, "GETTEXT", hwnd, GetTextProc); InvalidateRect(hwnd, &rect, FALSE); } } if ((wParam == VK_SHIFT) || (wParam == VK_CONTROL)) xBeg = -1; break; case WM_CHAR: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if ((wParam == '+') || (wParam == '=')) goto in; else if (wParam == '-') goto out; // else if (wParam == '~') // {//secret IP address:port // if (DialogBox(hInst, "SECRETIP", hwnd, SecretIPProc)) // { // fromctrli = TRUE; // ResetEvent(hAPRSEvent); // hAPRSThread = _beginthreadex(NULL, 0, aprsISthread, hwnd, 0, &idThread15); // Sleep(500); // } // } return 0; case WM_KEYDOWN: EnterCriticalSection(&cs); downloadflg = downloading; LeaveCriticalSection(&cs); if (downloadflg == TRUE) break; if (wParam == VK_RETURN) { if ((approachcontrol) && (planecommand)) { planecommand = FALSE; Plane[AtPlane].TAS = Plane[AtPlane].IAS + (Plane[AtPlane].IAS * Plane[AtPlane].altitude / 50000); TurnRadius = Plane[AtPlane].TAS * Plane[AtPlane].TAS * TwentyfiveDegreeBank; // in meters SecondsPerCircle = (PI * 2.0 * TurnRadius) / (Plane[AtPlane].TAS * MetersPerSec); // dist = rate x time Plane[AtPlane].RadiansPerSecond = PI * 2.0 / SecondsPerCircle; for (x = 0; x < command; x++) { if ((Command[x] == 'R') || (Command[x] == 'L')) { Plane[AtPlane].newHeading = Atoi(&Command[x+1]); Plane[AtPlane].newRadianheading = Plane[AtPlane].newHeading * deg2rad; Plane[AtPlane].Turn = Command[x]; } if ((Command[x] == 'R') && (Plane[AtPlane].newHeading <= Plane[AtPlane].heading)) Plane[AtPlane].newRadianheading += PI2; else if ((Command[x] == 'L') && (Plane[AtPlane].newRadianheading >= Plane[AtPlane].radianheading)) Plane[AtPlane].newRadianheading -= PI2; if (Command[x] == 'A') { Plane[AtPlane].newAltitude = Atoi(&Command[x+1]); if (Plane[AtPlane].newAltitude < 1000) // 2 or 200 20 or 2000 200 or 20000 Plane[AtPlane].newAltitude *= 100; } if (Command[x] == 'S') Plane[AtPlane].newIAS = Atoi(&Command[x+1]); if (Command[x] == 'T') // Tower { for (y = AtPlane; y < plane; y++) Plane[y] = Plane[y+1]; // remove Plane[AtPlane] plane--; AtPlane = -1; } } } else SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0); break; } else if ((approachcontrol) && (!planecommand) && (wParam == VK_SPACE)) { if (showdata) showdata = FALSE; else showdata = TRUE; break; } else if (wParam == VK_ESCAPE) { if (approachcontrol) { if (IDYES == MessageBox(hwnd, "Exit Approach Control?", "Approach Control", MB_YESNO|MB_DEFBUTTON2)) { approachcontrol = FALSE; plane = 0; timeKillEvent(uTimerID); timeEndPeriod(TIMER_RESOLUTION); uTimerID = NULL; DeleteObject(hRedBrush); for (x = 0; x < 20; x++) Plane[x].UTMEasting = 0; InvalidateRect(hwnd, &rect, FALSE); } break; } xBeg = -1; // xbegOld = -1; Northest = 0; Eastest = 0x0FFFFFFF; Southest = 0x0FFFFFFF; Westest = 0; if (usamap) { usamap = FALSE; free(pUSA); pUSA = NULL; DestroyWindow(hwndUSA); DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar if (notfromusa == FALSE)//to move to new Map Location SendMessage(hwnd, WM_COMMAND, ID_FILES_OPENMAPFILE, 0); } else if ((Pixels != NULL) || (showjpeg)) { showjpeg = FALSE; if (Pixels != NULL) VirtualFree(Pixels, 0, MEM_RELEASE); Pixels = NULL; DestroyWindow(hwndBig);//will return 0 if (showjpeg) DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } else if ((drawing) && (ptr > 1)) EndRoute(); else InvalidateRect(hwnd, &rect, FALSE);//for distancemeasure break; } if ((planecommand) && (command < 15)) { if (wParam == VK_BACK) { command--; Command[command] = 0; } else if (wParam != VK_SPACE) { Command[command++] = wParam; hdc = GetDC(hwnd); SetBkMode(hdc, TRANSPARENT); SetTextColor(hdc, 0xFFFFFF); TextOut(hdc, Plane[AtPlane].x-10, Plane[AtPlane].y-40, Command, lstrlen(Command)); SetTextColor(hdc, 0); SetBkMode(hdc, OPAQUE); ReleaseDC(hwnd, hdc); } break; } if (Pixels)//View -Show Jpeg {//from BigProc DWORD thirtytwo = 0; if (wParam != VK_ESCAPE) { if (wParam == VK_RIGHT) { for ( ; 0x7FFF & GetAsyncKeyState(VK_RIGHT); ) { if (xBigLoc < (BigWidth - rect.right - 32)) xBigLoc += 32; InvalidateRect(hwndBig, &rect, FALSE); } } if (wParam == VK_LEFT) { for ( ; 0x7FFF & GetAsyncKeyState(VK_LEFT); ) { if (xBigLoc >= 32) xBigLoc -= 32; InvalidateRect(hwndBig, &rect, FALSE); } } if (wParam == VK_UP) { for ( ; 0x7FFF & GetAsyncKeyState(VK_UP); ) { if (yBigLoc >= 50) yBigLoc -= 50; InvalidateRect(hwndBig, &rect, FALSE); } } if (wParam == VK_DOWN) { for ( ; 0x7FFF & GetAsyncKeyState(VK_DOWN); ) { if (yBigLoc < (BigHeight - rect.bottom - 32)) yBigLoc += 32; InvalidateRect(hwndBig, &rect, FALSE); } } return 0;//don't do anything else } } if (qpressed) { qpressed = FALSE; SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar } switch (wParam) { // if (aprs) // { // int f, g; // for (f = 0, g = 0; FINDU[f] != 0; f++, g++) // Findu[g] = FINDU[f]; // for (f = 0; Error[f] != 0; f++, g++) // Findu[g] = Error[f]; // Findu[g] = 0; // WinExec(Findu, SW_SHOW); // } // break; // case 'Y': // if (GetKeyState(VK_CONTROL) < 0) // { // downloaded = FALSE; // notcancelled = TRUE; // hThread = _beginthreadex(NULL, 0, TigerThread, NULL, 0, &idThread); // Sleep(500); // } // break; case 'J': SendMessage(hwnd, WM_COMMAND, ID_VIEW_BIGJPEG, 0); break; case 'M': SendMessage(hwnd, WM_COMMAND, ID_VIEW_MAPOFUSA, 0); break; case '1': if ((Zoom >= 5) && (MapType == PHOTO)) { int MetersPerPixel; if (onepressed == TRUE) break; onepressed = TRUE; missing1meter = TRUE; SetCursor(hWaitingCursor); OneMeterTilesDown = TilesDown * 8; OneMeterTilesAcross = TilesAcross * 8; OneMeterTileSize = PixelsPerTile / 8;//3.125, 6.25, 12.5, 25 if (OneMeterTileSize != 25) OneMeterTileSize++; p1MeterSize = OneMeterTilesAcross*OneMeterTilesDown; p1Meter = (BYTE*)malloc(p1MeterSize); p1MeterX = (DWORD*)calloc(1, OneMeterTilesAcross*sizeof(DWORD)); p1MeterY = (DWORD*)calloc(1, OneMeterTilesDown*sizeof(DWORD)); for (x = 0; x < p1MeterSize; x++) p1Meter[x] = 0; MetersPerPixel = MetersPerTile/PixelsPerTile; xFraction = yFraction = w = y = 0; if (MetersPerPixel == 8) {//25 PixelsPerTile for ( ; w < OneMeterTilesDown; w++) { for (v = 0, x = 0; v < OneMeterTilesAcross; v++) { x += 25; p1MeterX[v] = x; } y += 25; p1MeterY[w] = y; } } else if (MetersPerPixel == 16) {//12.5 PixelsPerTile for ( ; w < OneMeterTilesDown; w++) { for (v = 0, x = 0; v < OneMeterTilesAcross; v++) { x += 12; if (xFraction == 1) { x++; xFraction = 0; } else xFraction++; p1MeterX[v] = x; } y += 12; if (yFraction == 1) { y++; yFraction = 0; } else yFraction++; p1MeterY[w] = y; } } else if (MetersPerPixel == 32) {//6.25 PixelsPerTile for ( ; w < OneMeterTilesDown; w++) { for (v = 0, x = 0; v < OneMeterTilesAcross; v++) { x += 6; if (xFraction == 3) { x++; xFraction = 0; } else xFraction++; p1MeterX[v] = x; } y += 6; if (yFraction == 3) { y++; yFraction = 0; } else yFraction++; p1MeterY[w] = y; } } else if (MetersPerPixel == 64) {//3.125 PixelsPerTile for ( ; w < OneMeterTilesDown; w++) { for (v = 0, x = 0; v < OneMeterTilesAcross; v++) { x += 3; if (xFraction == 7) { x++; xFraction = 0; } else xFraction++; p1MeterX[v] = x; } y += 3; if (yFraction == 7) { y++; yFraction = 0; } else yFraction++; p1MeterY[w] = y; } } North = (ScreenTop - 200) / 200; West = ScreenLeft / 200; pointerFileName[0] = 'U'; pointerFileName[1] = 'S'; pointerFileName[2] = 'A'; for (w = 0; w < OneMeterTilesDown; w++, North--) { GetRowName(North, West); for (x = 36, y = 17; RowName[x] != ' '; x++, y++) pointerFileName[y] = RowName[x]; pointerFileName[y++] = '.'; pointerFileName[y++] = 'p'; pointerFileName[y++] = 't'; pointerFileName[y++] = 'r'; pointerFileName[y] = 0; hFile4 = CreateFile(pointerFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile4 != INVALID_HANDLE_VALUE) { if (fileSize = GetFileSize(hFile4, NULL)) { ReadFile(hFile4, Pointers, fileSize, &dwBytesRead, NULL); NumOfPointers = Pointers[1]; Pointers[1] = 0; for (v = 0; v < OneMeterTilesAcross; v++) { if ((West+v) < (Pointers[0])) p1Meter[(w*OneMeterTilesAcross)+v] = 1; else if (((West+v) < (Pointers[0] + NumOfPointers)))// && (y <= NumOfPointers)) { if (Pointers[(West+v)-Pointers[0]+1] == Pointers[(West+v)-Pointers[0]+2]) p1Meter[(w*OneMeterTilesAcross)+v] = 1; } else// if ((West+v) >= (Pointers[0] + NumOfPointers)) p1Meter[(w*OneMeterTilesAcross)+v] = 1; } CloseHandle(hFile4); } } else {//if no row data for (v = 0; v < OneMeterTilesAcross; v++) p1Meter[(w*OneMeterTilesAcross)+v] = 1; } } pointerFileName[0] = 'B'; pointerFileName[1] = 'i'; pointerFileName[2] = 'g'; SetCursor(hCursor); InvalidateRect(hwnd, &rect, FALSE); } break; case 'H': if (showingtracks) SendMessage(hwndTrack, WM_COMMAND, 0, (LPARAM)hwndButton3); else SendMessage(hwnd, WM_COMMAND, ID_VIEW_TIGERLINES_HIGHWAYS, 0); break; case 'R': SendMessage(hwnd, WM_COMMAND, ID_VIEW_TIGERLINES_LOCALSTREETS, 0); break; case 'E': if (showingtracks) SendMessage(hwndTrack, WM_COMMAND, 0, (LPARAM)hwndButton); else SendMessage(hwnd, WM_COMMAND, ID_FILE_DOWNLOADELEVATIONDATA, 0); break; case 'S': if (autoLoc) SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_STOPPOSITIONING, 0); else { froms = TRUE; SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_FILE_DOWNLOADMAPDATA_TIGERSTREETS, 0); } break; case 'B': if (showingtracks) SendMessage(hwndTrack, WM_COMMAND, 0, (LPARAM)hwndButton2); else SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_BRIGHTNESS_BRIGHTER, 0); break; case 'D': SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_BRIGHTNESS_DARKER, 0); break; case 'W': SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_SHOWWAYPOINTNAMES, 0); break; case VK_DELETE://to delete photo at mouse pointer if (yPos == 0) break; else if ((GetKeyState(VK_SHIFT) < 0) && (editingtracks == FALSE)) { if (IDYES == MessageBox(hwnd, "Delete the entire row of data\nthat the cursor is on?", "DELETE", MB_YESNO)) { GetFileName(); if (FindFirstFile(fileName, &fd)) { DeleteFile(fileName); DeleteFile(pointerFileName); fromOpen = TRUE; SendMessage(hwnd, WM_USER, 0, 0); break; } } else break; } if (editingtracks) { currentpoint = -1; for (x = 0; trak[x].time != 0; x++) { if ((trak[x].EUTM < UTMEasting+(6*MetersPerTile/PixelsPerTile)) && (trak[x].EUTM > UTMEasting-(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM < UTMNorthing+(6*MetersPerTile/PixelsPerTile)) && (trak[x].NUTM > UTMNorthing-(6*MetersPerTile/PixelsPerTile))) { currentpoint = x; break; } } if (currentpoint != -1) { if ((trak[currentpoint].newtrk != 0) || (currentpoint == 0)) { for (x = currentpoint; trak[x].time != 0; x++) trak[x] = trak[x+1]; if (trak[currentpoint].time != 0) trak[currentpoint].newtrk = 1; } else if (trak[currentpoint+2].newtrk == 1) { for (x = currentpoint+1; trak[x].time != 0; x++) trak[x] = trak[x+1]; } else if (trak[currentpoint+2].time != 0) trak[currentpoint+1].newtrk = 1; else { trak[currentpoint+1].EUTM = 0; trak[currentpoint+1].NUTM = 0; trak[currentpoint+1].time = 0; trak[currentpoint+1].newtrk = 0; } SaveTracks(); InvalidateRect(hwnd, &rect, FALSE); } return 0; }//end of if (editingtracks) GetFileName(); FillMemory(tempPtr, sizeof(tempPtr), 0); hFile = CreateFile(fileName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { dataFileSize = GetFileSize(hFile, NULL); if (dataFileSize) { tempDta = (char*)malloc(dataFileSize); ReadFile(hFile, tempDta, dataFileSize, &dwBytesRead, NULL); } else { CloseHandle(hFile); return 0; } CloseHandle(hFile); } else return 0; hFile = CreateFile(pointerFileName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { fileSize = GetFileSize(hFile, NULL); if (fileSize) ReadFile(hFile, tempPtr, fileSize, &dwBytesRead, NULL); else { free(tempDta); CloseHandle(hFile); return 0; } CloseHandle(hFile); } else { free(tempDta); return 0; }//num addr size // 8 C744 8,705 // 9 E945 8,701 // 10 10B42 8,171 // 11 12B2D 8,554 // 12 14C97 8,247 // 13 16CCE 8,479 // 14 18DED //after writing over 8, it becomes // 8 C744 0 // 9 C744 8,701 // 10 E941 8,171 // 11 1092C 8,554 // 12 12A96 8,247 // 13 14ACD 8,479 // 14 16BEC if (0 == (GetKeyState(VK_CONTROL) & 0x80000000)) {//if Ctrl key not down MessageBox(hwnd, "Hold the Ctrl key down\nwhile pressing the Delete key.\n\n\ Holding the Shift key down\nwhile pressing the Delete key\ndeletes the whole row.", "Delete", MB_OK); free(tempDta); break; } x = West / MetersPerTile; if ((x < tempPtr[0]) || (x >= (tempPtr[0] + tempPtr[1]))) { free(tempDta); break;//not in file } pointer = x - tempPtr[0] + 1; NumOfPointers = tempPtr[1]; tempPtr[1] = 0;//now it's first offset if (x == tempPtr[0]) {//first image fileSize -= 4; tempPtr[0] = x+1; NumOfPointers--; w = tempPtr[pointer]; z = tempPtr[pointer+1]; v = tempPtr[pointer+2]; while (pointer < (NumOfPointers+1)) { if (v != 0) { size = v - z; for (x = 0; x < size; w++, x++, z++) tempDta[w] = tempDta[z]; } pointer++; tempPtr[pointer] = tempPtr[pointer-1] + size; z = tempPtr[pointer+1]; v = tempPtr[pointer+2]; } } else if (x == tempPtr[0] + tempPtr[1] - 1) {//last image fileSize -= 4; w = tempPtr[NumOfPointers]; NumOfPointers--; } else {//not first or last image w = tempPtr[pointer]; z = tempPtr[pointer+1]; v = tempPtr[pointer+2]; tempPtr[pointer+1] = tempPtr[pointer]; while (pointer < (NumOfPointers+1)) { y = w; if (v != 0) { size = v - z; for (x = 0; x < size; w++, x++, z++) tempDta[w] = tempDta[z]; } pointer++; tempPtr[pointer] = y; z = tempPtr[pointer+1]; v = tempPtr[pointer+2]; } } tempPtr[1] = NumOfPointers; hFile = CreateFile(fileName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, tempDta, w, &dwBytesWritten, NULL); FlushFileBuffers(hFile); CloseHandle(hFile); free(tempDta); hFile = CreateFile(pointerFileName, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL); WriteFile(hFile, tempPtr, fileSize, &dwBytesWritten, NULL); FlushFileBuffers(hFile); CloseHandle(hFile); SendMessage(hwnd, WM_USER, 0, 0); InvalidateRect(hwnd, &rect, FALSE); break; case 'T': SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_MAPTYPE_TOPO, 0); break; case 'P': SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_MAPTYPE_PHOTO, 0); break; case 'U'://Urban Areas SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_MAPTYPE_COLOR, 0); break; case 'L'://USGS Landmarks SendMessage(hwnd, WM_COMMAND, (WPARAM)ID_VIEW_SHOWUSGSLANDMARKS, 0); break; case 'F': SendMessage(hwnd, WM_COMMAND, ID_FILE_DOWNLOADMAPDATA_FILLSCREEN, 0); break; // case '7': // if (grid75 == FALSE) // { // grid75 = TRUE; // } // else // { // grid75 = FALSE; // } // InvalidateRect(hwnd, &rect, FALSE); // break; case 'X': if (autoLoc) break; for (x = 0; x < 600; x++) LatLonUTM[x] = 0; // if (grid75 == FALSE) {//draw a temporary orange X hdc = GetDC(hwnd); hPen = CreatePen(PS_SOLID, 2, 0x80FF); hObject = SelectObject(hdc, hPen); MoveToEx(hdc, xPos-5, yPos-5, NULL); LineTo(hdc, xPos+5, yPos+5); MoveToEx(hdc, xPos-5, yPos+5, NULL); LineTo(hdc, xPos+5, yPos-5); SelectObject(hdc, hObject); DeleteObject(hPen); ReleaseDC(hwnd, hdc); itsx = TRUE; } tempMouseLoc = MouseLoc; MouseLoc = DEG; GetLatLon(); for (x = 0, y = 23; x < 38; x++, y++) LatLonUTM[x] = LatLon[y]; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; MouseLoc = DEGMIN; GetLatLon(); for (z = 0, y = 23; z < 38; x++, y++, z++) LatLonUTM[x] = LatLon[y]; w = 0; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; //01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 //LatLon[] = "USAPhotoMaps N 34d 30.555 W 122' 25.555 Zoom: 1 meter /pixel Elev: "; z = 25;//tempLatLonUTM is used if grid75 tempLatLonUTM[w++] = LatLon[z++];//degrees tempLatLonUTM[w++] = LatLon[z++]; tempLatLonUTM[w++] = '.'; z += 2;//to minutes if (LatLon[z+1] == '.') tempLatLonUTM[w++] = '0'; tempLatLonUTM[w++] = LatLon[z++];//first minute digit if (LatLon[z] != '.') tempLatLonUTM[w++] = LatLon[z]; z += 16; tempLatLonUTM[w++] = ' '; tempLatLonUTM[w++] = '-'; tempLatLonUTM[w++] = LatLon[z++];//minutes tempLatLonUTM[w++] = LatLon[z++]; if (LatLon[z] != '\xB0')//degree tempLatLonUTM[w++] = LatLon[z++]; z += 2; tempLatLonUTM[w++] = '.'; if (LatLon[z+1] == '.') tempLatLonUTM[w++] = '0'; tempLatLonUTM[w++] = LatLon[z++]; if (LatLon[z] != '.') tempLatLonUTM[w++] = LatLon[z++]; /* if (grid75) { HGLOBAL hGlobal; PTSTR pGlobal; tempLatLonUTM[w++] = ' '; for (x = 0; SDTS[x] != 0; w++, x++) tempLatLonUTM[w] = SDTS[x]; tempLatLonUTM[w] = 0; //THE FOLLOWING CAUSES DEBUG TO EXIT TO INT3 (puts the lat/lon in special format in the clipboard) hGlobal = GlobalAlloc(GHND|GMEM_SHARE, w+1); pGlobal = (char*)GlobalLock(hGlobal); lstrcpy(pGlobal, tempLatLonUTM); GlobalUnlock(hGlobal); OpenClipboard(NULL); EmptyClipboard(); SetClipboardData(CF_TEXT, hGlobal); CloseClipboard(); MessageBox(hwnd, ATDI, "Done", MB_OK); }//end of if (grid75) else//not grid75 */ { char Zone[] = " Zone xx"; tempLatLonUTM[w] = 0; MouseLoc = DEGMINSEC; GetLatLon(); for (z = 0, y = 23; z < 38; x++, y++, z++) LatLonUTM[x] = LatLon[y]; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; GetUTM(UTMNorthing, UTMEasting); for (z = 0, y = 25; z < 35; x++, y++, z++) LatLonUTM[x] = UTM[y]; Zone[6] = Z[0]; Zone[7] = Z[1]; for (z = 0; Zone[z] != 0; z++) LatLonUTM[x++] = Zone[z]; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; North = (ScreenTop - (yPos*MetersPerTile/PixelsPerTile)) / MetersPerTile; West = (ScreenLeft + (xPos*MetersPerTile/PixelsPerTile)) / MetersPerTile; GetRowName(North, West); for (z = 36; z < 52; x++, z++) LatLonUTM[x] = RowName[z]; for (w = 0; Q[w] != 0; w++, x++) LatLonUTM[x] = Q[w]; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; LatLonUTM[x++] = '\r'; LatLonUTM[x++] = '\n'; // for (z = 0; z < w; x++, z++) // LatLonUTM[x] = tempLatLonUTM[z]; //now get http:// line //get photo/topo dates from http://msrmaps.com/ImageInfo.aspx?T=1&S=14&Z=10&X=180&Y=1295 //2/19/1995 //CHANGE TO CTRL-D TO GET PHOTO/TOPO DATE AT CURSOR w = 54;//just after S= // z = 53;//just after s= // tz = 99;//just after s= tempLat = Lat; tempLon = Lon; tempUTMZone = UTMZone; tempUTMN = UTMNorthing; tempUTME = UTMEasting; UTMNorthing = ScreenTop - (((rect.bottom / 2) * MetersPerTile) / PixelsPerTile); UTMEasting = ScreenLeft + (((rect.right / 2) * MetersPerTile) / PixelsPerTile); UTMtoLatLon(); count = 9; ptrToAscii = _ecvt(Lon, count, &decPos, &sign); count = 8; ptrToAscii = _ecvt(Lat, count, &decPos, &sign); Lat = tempLat; Lon = tempLon; UTMZone = tempUTMZone; UTMNorthing = tempUTMN; UTMEasting = tempUTME; MouseLoc = tempMouseLoc; DialogBox(hInst, "SHOWLATLON", hwnd, LatLonProc); itsx = FALSE; InvalidateRect(hwnd, &rect, FALSE); }//end of else (!grid75) break; case 'Z': if (drawing) {//Ctrl-Z x = GetKeyState(VK_CONTROL); if ((x < 0) && (ptr > 1)) {//delete last point ptr--; InvalidateRect(hwnd, &rect, FALSE); } else if (ptr == 1) { SendMessage(hwnd, WM_LBUTTONDBLCLK, 0, 0); } } break; case 'Q': qpressed = TRUE; SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar break; case 'C': if (gotelevini == FALSE) MessageBox(hwnd, "There is no elevation data (no Elev.ini file).\nSelect File -Download Elevation Data\n(and read Help -Using).", Oops, MB_OK); else { if (contourson) { contourson = FALSE; // ModifyMenu(hMenu, ID_VIEW_CONTOURS, MF_BYCOMMAND|MF_STRING, ID_VIEW_CONTOURS, Contourson); // DrawMenuBar(hwnd); CheckMenuItem(hMenu, ID_VIEW_CONTOURS, MF_UNCHECKED); } else { contourson = TRUE; // ModifyMenu(hMenu, ID_VIEW_CONTOURS, MF_BYCOMMAND|MF_STRING, ID_VIEW_CONTOURS, Contoursoff); // DrawMenuBar(hwnd); CheckMenuItem(hMenu, ID_VIEW_CONTOURS, MF_CHECKED); } if (showElev) showElev = FALSE; else showElev = TRUE; InvalidateRect(hwnd, &rect, FALSE); } break; case VK_F1: if (autoLoc == FALSE) { pHelp = NULL; hFile = CreateFile(Instruct, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { if (HelpSize = GetFileSize(hFile, NULL)) { pHelp = (char *) malloc(HelpSize+1); if (pHelp == NULL) MessageBox(hwnd, "OHOH", "", MB_OK); pHelp[HelpSize] = 0; ReadFile(hFile, pHelp, HelpSize, &dwBytesRead, NULL); hMenu2 = CreateMenu();//to override parent menu bar hwndHelp = CreateWindow(Instruct, Instruct, WS_POPUP | WS_VISIBLE | WS_DLGFRAME | WS_CAPTION | WS_SYSMENU, cxScreen/2-320, TitleAndMenu, (cxScreen/2 + 320)-(cxScreen/2-320), cyScreen-(cyChar*3), NULL, hMenu2, hInst, NULL); SetWindowText(hwndInstr, pHelp); SetFocus(hwndInstr); } CloseHandle (hFile); } else MessageBox(hwnd, NoHelpFile, NULL, MB_OK); // if (pHelp != NULL) // free(pHelp); } return 0; case VK_PRIOR://zoom out out: if (distancemeasure) { distancemeasure = FALSE; // xBeg = xbegOld = -1; } if (GetKeyState(VK_CONTROL) < 0) ctrlnotused = FALSE; else ctrlnotused = TRUE; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if ((MapType == TOPO) && (Zoom < 8)) { UncheckZoom(); Zoom++; if (Zoom == 5) {//64 meters/pixel PixelsPerTile = 200; MetersPerTile = 12800; } else PixelsPerTile >>= 1; ShowZoom(); DoZoom(); } else if ((MapType == PHOTO) && (Zoom < 8)) { if (Zoom == 3) { if (zoom1to8) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; } else { UncheckZoom(); Zoom = 5; PixelsPerTile = 200; } } else if (Zoom == 4) { UncheckZoom(); Zoom = 5; PixelsPerTile = 200; } else { UncheckZoom(); Zoom++; PixelsPerTile >>= 1; } if (Zoom <= 4) MetersPerTile = 200; else MetersPerTile = 1600; ShowZoom(); DoZoom(); } else if ((MapType == URBANAREA) && (Zoom < 8)) { UncheckZoom(); Zoom++; if (Zoom == 5) { PixelsPerTile = 200; MetersPerTile = 800; } else PixelsPerTile >>= 1; ShowZoom(); DoZoom(); } return 0; case VK_NEXT://zoom in in: if (distancemeasure) { distancemeasure = FALSE; // xBeg = xbegOld = -1; } if (GetKeyState(VK_CONTROL) < 0) ctrlnotused = FALSE; else ctrlnotused = TRUE; PrevMetersPerTile = MetersPerTile; PrevPixelsPerTile = PixelsPerTile; if ((MapType == TOPO) && (Zoom > 1)) { UncheckZoom(); Zoom--; if (Zoom == 4) {//32 meters/pixel PixelsPerTile = 25; MetersPerTile = 800; } else PixelsPerTile <<= 1; ShowZoom(); DoZoom(); break; } else if (MapType == PHOTO) { if (Zoom == 5) { if (zoom1to8) { UncheckZoom(); Zoom = 4; PixelsPerTile = 25; } else { UncheckZoom(); Zoom = 3; PixelsPerTile = 50; } MetersPerTile = 200; ShowZoom(); DoZoom(); } else if (Zoom != 1) { UncheckZoom(); Zoom--; PixelsPerTile <<= 1; if (Zoom <= 4) MetersPerTile = 200; else MetersPerTile = 1600; ShowZoom(); DoZoom(); } } else if ((MapType == URBANAREA) && (Zoom > 1)) { UncheckZoom(); Zoom--; if (Zoom == 4) { PixelsPerTile = 25; MetersPerTile = 50; } else PixelsPerTile <<= 1; ShowZoom(); DoZoom(); } return 0; case VK_UP: if (distancemeasure) { yBeg += PixelsPerTile; // xbegOld = -1; } wastopo = FALSE; directdraw = FALSE; zoom = Zoom; if (zoom >= 5) zoom -= 5; if ((Spaces2Move != 0) && (zoom <= 2) && (0 == (GetKeyState(VK_CONTROL) & 0x80000000))) InitDirectDraw(); if ((lParam != FROMCOMM) && (autoLoc) && (fromFlag == NOBUTTON)) { fromFlag = UP; if (itsgarmin) { sendingStop = TRUE; WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = StopPVTPacket[y]; if (tgcount > 49900) tgcount = 0; return 0;//ACK will call this routine again } else if (itsusb == FALSE) { autoLoc = FALSE; SetEvent(hEventExit); } else if (hUSBThread != 0)//if (itsusb) { SignalUSBStop(); } } if (fromFlag != NOBUTTON) { showposition = FALSE; fromFlag = NOBUTTON; autoLoc = FALSE; DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); RedDot(hwnd); } BitBlt(hdcMem, 0, PixelsPerTile, PixelsPerTile*TilesAcross, PixelsPerTile*(TilesDown-1), hdcMem, 0, 0, SRCCOPY); maxCols = TilesAcross + colOffset; yLoc = 0; ZoneName[0] = Z[0]; ZoneName[1] = Z[1]; _itoa(rowOffset + TilesDown, Y, 10); for (x = 0, z = 18; x < 3; x++, z++) { fileName[z] = ZoneName[x]; pointerFileName[z] = ZoneName[x]; } for (x = 0; Y[x] != 0; x++, z++) { pointerFileName[z] = Y[x]; fileName[z] = Y[x]; } for (x = 0; x < 5; x++, z++) { pointerFileName[z] = Ptr[x]; fileName[z] = Dta[x]; } hFile = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { hFile2 = CreateFile(pointerFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); fileSize = GetFileSize(hFile2, NULL); ReadFile(hFile2, Pointers, fileSize, &dwBytesRead, NULL); CloseHandle (hFile2); FirstOffset = Pointers[0]; NumOfPointers = Pointers[1]; Pointers[1] = 0; for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) { PointerOffset = col - FirstOffset; if ((PointerOffset >= 0) && (PointerOffset < NumOfPointers)) { fileSize = Pointers[PointerOffset+2] - Pointers[PointerOffset+1]; if (fileSize > 1) { SetFilePointer(hFile, Pointers[PointerOffset+1], NULL, FILE_BEGIN); ReadFile(hFile, TileBuf, fileSize, &dwBytesRead, NULL); if ((TileBuf[6] == 'J') && (TileBuf[7] == 'F')) Convert_TileBuf_hdcMem(NULL, 0xFFFFFFFF); else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcBlackMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } CloseHandle (hFile); } else for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); rowOffset++; // if (lParam != FROMCOMM) { if (gotelevini) GetElevData(); if (directdraw) {//VK_UP rect1.left = rect.left+xFrame; rect1.top = rect.top+TitleAndMenu+xFrame; rect1.right = rect.right-xFrame; rect1.bottom = rect.bottom-xFrame; rect2.left = rect.left+xFrame; rect2.top = rect.top+TitleAndMenu+xFrame; rect2.right = rect.right-xFrame; rect2.bottom = rect.bottom-xFrame; GetClientRect(hwnd, &rect); rect3.left = rect.left; rect3.top = rect.top+PixelsPerTile; rect3.right = rect.right; rect3.bottom = rect.top+PixelsPerTile+Spaces2Move; rect4.left = rect2.left; rect4.top = rect2.top; rect4.right = rect2.right; rect4.bottom = rect2.top+Spaces2Move; if (DD_OK == lpDDSBack2->GetDC(&hdcBack2)) { if (BitBlt(hdcBack2, 0, 0, MapWidth, MapHeight, hdcMem, 0, 0, SRCCOPY))//the new screen { if (DD_OK == lpDDSBack2->ReleaseDC(hdcBack2)) { for (x = 0; x < PixelsPerTile; x += Spaces2Move) { rect1.bottom -= Spaces2Move; rect2.top += Spaces2Move; rect3.top -= Spaces2Move; rect4.bottom += Spaces2Move; if (DD_OK == lpDDSPrimary->Blt(&rect2, lpDDSBack, &rect1, DDBLT_WAIT, NULL))//move screen lpDDSPrimary->Blt(&rect4, lpDDSBack2, &rect3, DDBLT_WAIT, NULL);//the top edge } } } } if (lpDDSBack2 != NULL) {lpDDSBack2->Release(); lpDDSBack2 = NULL;} if (lpDDSBack != NULL) {lpDDSBack->Release(); lpDDSBack = NULL;} if (lpDDSPrimary != NULL) {lpDDSPrimary->Release(); lpDDSPrimary = NULL;} if (lpDD7 != NULL) {lpDD7->Release(); lpDD7 = NULL;} directdraw = FALSE; } // else//Tiger streets need the following { InvalidateRect(hwnd, &rect, FALSE); UpdateWindow(hwnd); } SendMessage(hwnd, WM_MOUSEMOVE, 0, xPos + (yPos << 16));//to update Lat/Lon of Pointer on Title Bar // if (autodownload) // SendMessage(hwnd, WM_COMMAND, ID_FILE_DOWNLOADMAPDATA_FILLSCREEN, 0); } cachenotfull = TRUE; break; case VK_DOWN: // xbegOld = -1; wastopo = FALSE; if (distancemeasure) { yBeg -= PixelsPerTile; // xbegOld = -1; } directdraw = FALSE; zoom = Zoom; if (zoom >= 5) zoom -= 5; if ((Spaces2Move != 0) && (zoom <= 2) && (0 == (GetKeyState(VK_CONTROL) & 0x80000000))) InitDirectDraw(); if ((lParam != FROMCOMM) && (autoLoc) && (fromFlag == NOBUTTON)) { fromFlag = DOWN; if (itsgarmin) { sendingStop = TRUE; WriteFile(hComm, &StopPVTPacket, 8, &dwBytesWritten, NULL); for (y = 0; y < 8; y++, tgcount++) ToGPS[tgcount] = StopPVTPacket[y]; if (tgcount > 49900) tgcount = 0; return 0;//ACK will call this routine again } else if (itsusb == FALSE) { autoLoc = FALSE; SetEvent(hEventExit); } else if (hUSBThread != 0)//if (itsusb) { SignalUSBStop(); } } if (fromFlag != NOBUTTON) { showposition = FALSE; fromFlag = NOBUTTON; autoLoc = FALSE; DestroyMenu(hMenu4); hMenu = LoadMenu(hInst, "USAPHOTOMAPS"); SetMenu(hwnd, hMenu); MenuChecks(); RedDot(hwnd); } BitBlt(hdcMem, 0, 0, PixelsPerTile*TilesAcross, PixelsPerTile*(TilesDown-1), hdcMem, 0, PixelsPerTile, SRCCOPY); rowOffset--; maxCols = TilesAcross + colOffset; yLoc = PixelsPerTile * (TilesDown-1); ZoneName[0] = Z[0]; ZoneName[1] = Z[1]; _itoa(rowOffset, Y, 10); for (x = 0, z = 18; x < 3; x++, z++) { fileName[z] = ZoneName[x]; pointerFileName[z] = ZoneName[x]; } for (x = 0; Y[x] != 0; x++, z++) { pointerFileName[z] = Y[x]; fileName[z] = Y[x]; } for (x = 0; x < 5; x++, z++) { pointerFileName[z] = Ptr[x]; fileName[z] = Dta[x]; } hFile = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { hFile2 = CreateFile(pointerFileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); fileSize = GetFileSize(hFile2, NULL); ReadFile(hFile2, Pointers, fileSize, &dwBytesRead, NULL); CloseHandle (hFile2); FirstOffset = Pointers[0]; NumOfPointers = Pointers[1]; Pointers[1] = 0; for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) { PointerOffset = col - FirstOffset; if ((PointerOffset >= 0) && (PointerOffset < NumOfPointers)) { fileSize = Pointers[PointerOffset+2] - Pointers[PointerOffset+1]; if (fileSize > 1) { SetFilePointer(hFile, Pointers[PointerOffset+1], NULL, FILE_BEGIN); ReadFile(hFile, TileBuf, fileSize, &dwBytesRead, NULL); if ((TileBuf[6] == 'J') && (TileBuf[7] == 'F')) Convert_TileBuf_hdcMem(NULL, 0xFFFFFFFF); else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcBlackMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } else BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); } CloseHandle (hFile); } else for (xLoc = 0, col = colOffset; col < maxCols; xLoc += PixelsPerTile, col++) BitBlt(hdcMem, xLoc, yLoc, PixelsPerTile, PixelsPerTile, hdcGrayMem, 0, 0, SRCCOPY); // if (lParam != FROMCOMM) { if (gotelevini) GetElevData(); if (directdraw) {//VK_DOWN rect1.left = rect.left+xFrame