📄 gpsdlg.cpp
字号:
// GPSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GPS.h"
#include "GPSDlg.h"
#include "SetDlg.h"
#include "ToolDlg.h"
#include "ErrorDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
SYSTEMTIME time0;
/////////////////////////////////////////////////////////////////////////////
HANDLE hBat;
HANDLE hBak;
CSetDlg set_dlg;
CToolDlg tool_dlg;
CErrorDlg error_dlg;
UCHAR chargeStau0=0;
#define IOCTL_GET_ACSTA 0x807
#define IOCTL_GET_SCALE 0x809
// CGPSDlg dialog
BOOL GpsCodeStart()
{
HANDLE hFile;
unsigned char rece;
unsigned char buf[100];
unsigned char baud[10];
int iBaudRate=0;
DWORD num;
int i=0;
hFile=CreateFile(TEXT("\\Storage Card\\GpsCmd.txt"),GENERIC_READ,0,NULL,
OPEN_EXISTING,0,NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
//CloseHandle(hWndFile);
//MessageBox(TEXT("Can't open file!"));
return FALSE;
}
while(1)//read baudrate from file
{
if(ReadFile(hFile, &rece, 1, &num, NULL))
{
if(rece==' ')
break;
else
{
baud[i]=rece;
i++;
if(i==9)//too long for baudrate
{
return FALSE;
}
}
}
else
return FALSE;
}
baud[i]=0;
int len1=i;//lenth fo baud
i=0;
while(1)//read command for codestart form file
{
if(ReadFile(hFile, &rece, 1, &num, NULL))
{
if(num==0)//reaches the end of the file
break;
if((rece==' ')||(rece=='\r')||(rece=='\n')||(rece==0))
break;
else
{
buf[i]=rece;
i++;
if(i==99)//too long for command
{
return FALSE;
}
}
}
else
return FALSE;
}
buf[i]=13;//<CR>
i++;
buf[i]=10;//<LF>
i++;
buf[i]=0;
int len2=i;
CloseHandle(hFile);
for(i=0;i<len1;i++)
{
iBaudRate=iBaudRate*10+(baud[i]-48);
}
//open COM1 for send command to GPS
HANDLE hPort;
DCB PortDCB;
COMMTIMEOUTS CommTimeouts;
hPort = CreateFile (TEXT("COM1:"), // Pointer to the name of the port
GENERIC_READ | GENERIC_WRITE,// Access (read-write) mode
0, // Share mode
NULL, // Pointer to the security attribute
OPEN_EXISTING,// How to open the serial port
0, // Port attributes
NULL); // Handle to port with attribute to copy
if(hPort==INVALID_HANDLE_VALUE)
{
//MessageBox(TEXT("Serial Open error!"),TEXT("ERROR"),MB_OK);
return FALSE;
}
// Initialize the DCBlength member.
PortDCB.DCBlength = sizeof (DCB);
// Get the default port setting information.
GetCommState (hPort, &PortDCB);
// Change the DCB structure settings.
PortDCB.BaudRate = iBaudRate; // Current baud
PortDCB.fBinary = TRUE; // Binary mode; no EOF check
PortDCB.fParity = FALSE; // Disable parity checking
PortDCB.fOutxCtsFlow = FALSE; // No CTS output flow control
PortDCB.fOutxDsrFlow = FALSE; // No DSR output flow control
PortDCB.fDtrControl = DTR_CONTROL_ENABLE;
// DTR flow control type
PortDCB.fDsrSensitivity = FALSE; // DSR sensitivity
PortDCB.fTXContinueOnXoff = TRUE; // XOFF continues Tx
PortDCB.fOutX = FALSE; // No XON/XOFF out flow control
PortDCB.fInX = FALSE; // No XON/XOFF in flow control
PortDCB.fErrorChar = FALSE; // Disable error replacement
PortDCB.fNull = FALSE; // Disable null stripping
PortDCB.fRtsControl = RTS_CONTROL_ENABLE;
// RTS flow control
PortDCB.fAbortOnError = FALSE; // Do not abort reads/writes on
// error
PortDCB.ByteSize = 8; // Number of bits/byte, 4-8
PortDCB.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
PortDCB.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
// Configure the port according to the specifications of the DCB
// structure.
if (!SetCommState (hPort, &PortDCB))
{
// Could not configure the serial port.
//dwError = GetLastError ();
//MessageBox (TEXT("Unable to configure the serial port"),
// TEXT("Error"), MB_OK);
CloseHandle(hPort);
return FALSE;
}
GetCommTimeouts (hPort, &CommTimeouts);
// Change the COMMTIMEOUTS structure settings.
CommTimeouts.ReadIntervalTimeout = 0;//MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;
CommTimeouts.WriteTotalTimeoutMultiplier = 10;
CommTimeouts.WriteTotalTimeoutConstant = 1000;
// Set the time-out parameters for all read and write operations
// on the port.
if (!SetCommTimeouts (hPort, &CommTimeouts))
{
// Could not set the time-out parameters.
//MessageBox (TEXT("Unable to set the time-out parameters"),
// TEXT("Error"), MB_OK);
//dwError = GetLastError ();
return FALSE;
}
//send command from COM1
DWORD dwNumBytesWritten;
WriteFile (hPort, // Port handle
buf, // Pointer to the data to write
len2, // Number of bytes to write
&dwNumBytesWritten, // Pointer to the number of bytes written
NULL // Must be NULL for Windows CE
);
CloseHandle(hPort);
return TRUE;
}
CGPSDlg::CGPSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGPSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGPSDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGPSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGPSDlg)
DDX_Control(pDX, IDC_BT4, m_BT4);
DDX_Control(pDX, IDC_BT3, m_BT3);
DDX_Control(pDX, IDC_BT2, m_BT2);
DDX_Control(pDX, IDC_BT1, m_BT1);
DDX_Control(pDX, IDC_BT0, m_BT0);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGPSDlg, CDialog)
//{{AFX_MSG_MAP(CGPSDlg)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_KEYDOWN()
ON_BN_CLICKED(IDC_BUTTON1, OnCancel)
ON_WM_TIMER()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_SUSPEND,OnSuspend)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPSDlg message handlers
BOOL CGPSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_Left=0;
m_Top=0;
m_Width=320;
m_Height=240;
::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,m_Left, m_Top,
m_Width, m_Height,SWP_SHOWWINDOW);
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_BackScreenBitmap.LoadBitmap(IDB_BKG);
SetToolRectangle();
m_prePick=-1;
m_currentPick =0 ;
m_bIsExecute=FALSE ;
m_NavRefresh = FALSE ;
PROCESS_INFORMATION info;
if(!(CreateProcess(TEXT("\\Windows\\usbcnect.exe"),NULL,NULL,NULL,NULL,CREATE_NEW_CONSOLE,
NULL,NULL,NULL, &info)))
{
//MessageBox(TEXT("Can't run !"),TEXT("Error"));
}
//open battery file to get battery power电池
hBat = CreateFile(TEXT("BAT1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,0);
if(INVALID_HANDLE_VALUE==hBat)
{
//MessageBox(TEXT("Can't open BAT1!"));
}
UCHAR out;
DeviceIoControl(hBat,IOCTL_GET_SCALE,NULL,0,&out,1,NULL,NULL);
ShowBattery(out);
//open backlite file to get AC state背光
hBak=CreateFile(TEXT("BAK1:"),GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
if(INVALID_HANDLE_VALUE==hBak)
{
//MessageBox(_T("CAN NOT OPEN BANK1!"));
//return FALSE;
}
Sleep(1000);
SetTimer(3,1000,NULL);
//开始播放音。
PlaySound(TEXT("startup.wav"),NULL,SND_FILENAME|SND_ASYNC);
GpsCodeStart();
// TODO: Add extra initialization here
SetFocus();
return TRUE; // return TRUE unless you set the focus to a control
}
void CGPSDlg::SetToolRectangle()
{
m_rect [0].SetRect(37,44,101,125);
m_rect [1].SetRect(134,43,195,125);
m_rect [2].SetRect(228,44,287,126);
m_rect [3].SetRect(29,131,101,216);
m_rect [4].SetRect(125,130,210,218);
m_rect [5].SetRect(225,127,289,214);
logo.SetRect(12,12,151,41);
}
BOOL CGPSDlg::OnEraseBkgnd(CDC* pDC)
{
BITMAP bmpInfo;
m_BackScreenBitmap.GetBitmap(&bmpInfo);
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&m_BackScreenBitmap);
// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
return true;
}
void CGPSDlg::OnCancel()
{
// TODO: Add your control notification handler code here
CDialog::OnCancel();
}
void CGPSDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
DrawInterface ( dc ) ;
//设透明字体
GetLocalTime(&time0);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(255,255,255));
CString str;
str.Format(_T(" %02d:%02d"),time0.wHour,time0.wMinute);
dc.ExtTextOut(220,16,ETO_CLIPPED,CRect(220,16,262,29),str,NULL);
}
void CGPSDlg::DrawInterface(CDC &dc)
{
CDC memDC ;
memDC.CreateCompatibleDC ( &dc ) ;
CBitmap* pBitmap ; //load all bitmap
CBitmap* pOldBitmap ; //save old bitmap temp
//.............................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if (m_NavRefresh || m_currentPick == 0)
{
//黑
pBitmap ->LoadBitmap ( IDB_GPS_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
else
{ //白
pBitmap ->LoadBitmap ( IDB_GPS_W) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
memDC.SelectObject ( pOldBitmap ) ;
//释放bitmap对象内存
delete pBitmap ;
//.............................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if ( m_currentPick == 1 )
{
pBitmap ->LoadBitmap ( IDB_MP3_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[1].TopLeft().x, m_rect[1].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
else
{
pBitmap ->LoadBitmap ( IDB_MP3_W ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[1].TopLeft().x, m_rect[1].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
memDC.SelectObject ( pOldBitmap ) ;
//释放bitmap对象内存
delete pBitmap ;
//...............................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if ( m_currentPick == 2 )
{
pBitmap ->LoadBitmap ( IDB_MP4_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[2].TopLeft().x, m_rect[2].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
else
{
pBitmap ->LoadBitmap ( IDB_MP4_W ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[2].TopLeft().x, m_rect[2].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
memDC.SelectObject ( pOldBitmap ) ;
//释放bitmap对象内存
delete pBitmap ;
//................................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if ( m_currentPick == 3 )
{
pBitmap ->LoadBitmap ( IDB_PICTURE_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[3].TopLeft().x, m_rect[3].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
else
{
pBitmap ->LoadBitmap ( IDB_PICTURE_W ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -