/*
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_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_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_GOTO:
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_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_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 <winsock2.h>//put ws2_32.lib in Project/Settings/Link
#include <windows.h>//put msimg32.lib in Project/Settings/Link for TransparentBlt
#include <commctrl.h>//put comctl32.lib in Project/Settings/Link
#include "SetupAPI.h"//put setupapi.lib in Project/Settings/Link
#include <wininet.h>//put wininet.lib in Project/Settings/Link
#include <math.h>//for sqrt, etc
#include <stdio.h>//for sprintf
#include <process.h>//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 in Project/Settings/Link
#include "zconf.h"
#include <wingdi.h>//put gdi32.lib and msimg32.lib in Project/Settings/Link
//#include "mmsystem.h"//for PlaySound - put winmm.lib in Project/Settings/Link
#include <devguid.h>
#include "resource.h"
//#include <malloc.h>//for _msize
#include <ddraw.h>//? and put ddraw.lib and dxguid.lib in Project/Settings/Link

#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_USER4 WM_USER2 + 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 onetime0
#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)

char Version[] = "Version 2.77\r\n\r\nJune 30, 2008\r\n\r\nby Doug Cox\r\n";

BOOL debug = FALSE;

//BOOL autodownload = TRUE;

int PacketSize;
char ToInternet[128];
char IgateInsert[] = ",qAR,KI6NLA";
char Quit[] = "QUIT\n";
char BadISend[] = "bad send";
static BOOL dontcleanup = FALSE;

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[1024][1024];
int UTMEbilBuf[1024][1024];
int UTMN30Buf[1024*1024];
int UTME30Buf[1024*1024];
WORD UTMElevBuf[1024*1024];
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;
//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;
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 QRZ[28] = "http://www.QRZ.com/";
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 277 filter a/39/-123/36/-120\n";
char Filter1[] = "user NOCALL";
char Filter2[] = " pass ";
char Filter3[] = " vers usaphotomaps 277";
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 APRSlog[] = "APRS log01.dta";
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];//*aprsBuf;
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 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 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[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[] = "<![CDATA[";
char CdataEnd[] = "]]>";

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;

BOOL cachenotfull = TRUE;
BOOL right, top, xbeg, ybeg;
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;
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;
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 long hgunzipThread;
unsigned char *conus;
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[] = "3", PhotoDot4[] = "3", PhotoDot8[] = "3", PhotoDot16[] = "3", PhotoDot32[] = "3", PhotoDot64[] = "3";
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 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";
char TopoURLName[] = "http://terraserver-usa.com/tile.ashx?t=2&s=12&x=936&y=5435&z=10    ";//4,348,672 750,348
char ColorURLName[] = "http://terraserver-usa.com/tile.ashx?t=4&s=                          ";
//tile.ashx?t=4&s=8&x=11327&y=105600&z=10
//char URL[] = "\r\nhttp://terraserver-usa.com/GetImageArea.ashx?t=4&s=                                                    ";
//                                                                   10&lon=-77.444444&lat=38.888888&w=1024&h=768";
char GetDate[] = "http://terraserver.microsoft.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, 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;
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 {
	int NUTM;
	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[] = "\
<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>\r\n\
<gpx version=\"1.0\" creator=\"USAPhotoMaps - http://jdmcox.com\"\r\n\
 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n\
 xmlns=\"http://www.topografix.com/GPX/1/0\"\r\n\
 xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0\r\n\
 http://www.topografix.com/GPX/1/0/gpx.xsd\">\r\n";
char WashingtonWaypoint[] = "<wpt lat=\"38.889329\" lon=\"-77.046525\">\r\n<cmt>Washington</cmt>\r\n</wpt>\r\n</gpx>\r\n";

int temp, tempNUTM, tempEUTM, temp2UTMZone, longest;
char TheKey[] = "d9sa82";//no key";
char *tempWaypoints, *tempIdent, *tempLoc, *tempDesc, *tempElev, *tempSym;
char Bottom[] = "</gpx>\r\n";
char Name[] = "<name>";
char EndName[] = "</name>\r\n";//<cmt>";
char Cmt[] = "<cmt>";
char CmtEnd[] = "</cmt>\r\n";
char Desc[] = "<desc>";
char DescEnd[] = "</desc>\r\n";
char WptEnd[] = "</wpt>\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, 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;
HPEN hPen, hRoutePen, hTrackPen, hAPRSPen;
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;
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 BegProc(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);
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, int);
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 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);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	MSG          msg;
	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 "</cmt>" to "\0/cmt>"
		for (w = 0; ((struct newloc*)y)->Ident[w] != '<'; w++)
			;
		((struct newloc*)y)->Ident[w] = 0;//change "</cmt>" 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 "</cmt>"
		for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++)
			;
		((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "</cmt>"
		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 "</cmt>" to "\0/cmt>"
		}
		else
		{
			xIdent = TRUE;
			for (w = 0; ((struct newloc*)x)->Ident[w] != '<'; w++)
				;
			((struct newloc*)x)->Ident[w] = 0;//change "</cmt>" 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 "</cmt>" 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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++)
				;
			((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
		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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++)
				;
			((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
		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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++)
				;
			((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
		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 "</cmt>" to "\0/cmt>"
		for (w = 0; ((struct newloc*)y)->Location[w] != '<'; w++)
			;
		((struct newloc*)y)->Location[w] = 0;//change "</cmt>" 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 "</cmt>"
		for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++)
			;
		((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "</cmt>"
		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 "</cmt>" to "\0/cmt>"
		}
		else
		{
			xLoc = TRUE;
			for (w = 0; ((struct newloc*)x)->Location[w] != '<'; w++)
				;
			((struct newloc*)x)->Location[w] = 0;//change "</cmt>" 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 "</cmt>" 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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++)
				;
			((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
		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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Location[w] != 0; w++)
				;
			((struct newloc*)y)->Location[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
		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 "</cmt>"
			for (w = 0; ((struct newloc*)y)->Ident[w] != 0; w++)
				;
			((struct newloc*)y)->Ident[w] = '<';//change "\0/cmt>" to "</cmt>"
		}
	}
	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;
		}
	}
}

//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_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_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
//hDeviceFile = CreateFile("USBdebug.txt", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
		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;
		}
		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'))
						{
							if (pUSAPMbufIn[x+1] == 'Y')
								openatclosing = TRUE;
							else//if (pUSAPMbufIn[x+1] == 'N')
								openatclosing = FALSE;
						}

						else if ((pUSAPMbufIn[x-7] == 'C') && (pUSAPMbufIn[x-11] == 'N') && (pUSAPMbufIn[x-15] == 'S'))
						{
							if (pUSAPMbufIn[x+1] == 'Y')
								shownamecomment = TRUE;
							else if (pUSAPMbufIn[x+1] == 'N')
								shownamecomment = FALSE;
						}
						else if ((pUSAPMbufIn[x-11] == 'D') && (pUSAPMbufIn[x-15] == 'S'))
						{//ShowDescription=YES
							if (pUSAPMbufIn[x+1] == 'Y')
								showdescription = TRUE;
							else if (pUSAPMbufIn[x+1] == 'N')
								showdescription = 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
							if  ((pUSAPMbufIn[x+1] == 'Y') && (pUSAPMbufIn[x+2] == 'E'))
								showtext = TRUE;
							else
								showtext = 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++)
		{