?? stdafx.cpp
字號:
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1997 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
// stdafx.cpp : source file that includes just the standard includes
// stdafx.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
#include "math.h"
//#include <sstream>
//using namespace std;
//**************************************************************
//創建并打開一個ADO連接
//輸入:ppadoConection Ado Connection 對象指針的指針
//輸出:如果創建且打開Ado connection 成功,則返回該指針
//返回: HRESULT類型 S_OK 成功,E_FAIL 失敗
//**************************************************************
/*
HRESULT OpenConnection(LPDISPATCH* ppadoConnection_out,tagDsnInfo pDsnInfo)
{
HRESULT hr;
BSTR bstrDSN;
_ConnectionPtr padoConnection;
WCHAR wszDSNBuffer[50];
hr = padoConnection.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
return hr;
if (FAILED(hr = padoConnection->put_CursorLocation(adUseClient)))
return hr;
// set an infinite connection timeout
if (FAILED(hr = padoConnection->put_ConnectionTimeout(0)))
return hr;
if (FAILED(hr = padoConnection->put_CommandTimeout(30000)))
return hr;
//use Kagera
memset((void*)wszDSNBuffer,0,sizeof(wszDSNBuffer));
swprintf(wszDSNBuffer,L"DSN=MSSQL;UID=sa;PWD=");
bstrDSN = ::SysAllocString(wszDSNBuffer);
//hr = padoConnection->Open("MSSQL","sa","",-1);
hr = padoConnection->Open(pDsnInfo.dsn,pDsnInfo.user,pDsnInfo.pwd,-1);
::SysFreeString( bstrDSN );
if (FAILED(hr))
return hr;
// all went well
// note - don't Release padoConnection, our caller will do that later
padoConnection->QueryInterface(IID_IDispatch,(void **)ppadoConnection_out);
return S_OK;
}
*/
//錯誤處理
void ErrorRaise(_bstr_t ErrorDescrption)
{
MessageBox(NULL,ErrorDescrption, "錯誤提示",MB_ICONEXCLAMATION|MB_OK);
}
//**************************************************************
//將輸入的短整數類型的數字轉換為_bstr_t的字符串
//輸入:s 短整型
//輸出:_bstr_t 數字對應的字符串
//**************************************************************
_bstr_t FixString(short s)
{
char szBuffer[20];
memset(szBuffer,0,sizeof(szBuffer));
sprintf(szBuffer,"%d",s);
return szBuffer;
}
//**************************************************************
//將輸入的BSTR類型的字符串轉換為_bstr_t的字符串,同時將該字符串
// 包含的'字符轉換成''('為SQL Server 中SQL語句的轉義符)
//輸入:strSQL BSTR類型的字符串
//輸出:_bstr_t類型 字符串(已格式化好)
//**************************************************************
/*
_bstr_t FixString(BSTR bStr)
{
//轉換成char
//USES_CONVERSION;
string str(OLE2T(bStr));
string repStr("''"); //轉換后的字符
string findStr("'"); //被轉換的字符
int nPos = -1;
//開始查找替換
do
{
nPos = str.find(findStr,nPos+1);
if (nPos != -1)
{
//開始替換
str.replace(nPos,1,repStr);
nPos++;
}
}while(nPos >= 0);
return str.c_str();
}
*/
//**************************************************************
//將輸入的單精度浮點類型的數字轉換為_bstr_t的字符串
//輸入:s 單精度浮點類型
//輸出:_bstr_t 數字對應的字符串
//**************************************************************
_bstr_t FixString(float s)
{
char szBuffer[20];
memset(szBuffer,0,sizeof(szBuffer));
sprintf(szBuffer,"%f",s);
return szBuffer;
}
//**************************************************************
//將輸入的貨幣型類型的數字轉換為_bstr_t的字符串
//輸入:s 貨幣類型數字
//輸出:_bstr_t 數字對應的字符串
//**************************************************************
_bstr_t FixString(CURRENCY s)
{
char szBuffer[20];
double d;
VarR8FromCy(s,&d);
memset(szBuffer,0,sizeof(szBuffer));
sprintf(szBuffer,"%lf",d);
return szBuffer;
}
//**************************************************************
//將輸入的長整數類型的數字轉換為_bstr_t的字符串
//輸入:s 長整數類型數字
//輸出:_bstr_t 數字對應的字符串
//**************************************************************
_bstr_t FixString(long s)
{
char szBuffer[20];
memset(szBuffer,0,sizeof(szBuffer));
sprintf(szBuffer,"%ld",s);
return szBuffer;
}
//**************************************************************
//將輸入的日期類型的數據轉換為_bstr_t的字符串
//輸入:d 日期類型數據
//輸出:_bstr_t 日期對應的字符串,格式為yyyy-mm-dd hh:mm:ss
//**************************************************************
_bstr_t FixString(DATE d)
{
SYSTEMTIME tm;
char szBuffer[20];
VariantTimeToSystemTime(d,&tm);
memset(szBuffer,0,sizeof(szBuffer));
//YYYY-MM-DD HH:MM:SS
sprintf(szBuffer,"%d-%02d-%02d %02d:%02d:%02d",
tm.wYear,tm.wMonth,tm.wDay,
tm.wHour,tm.wMinute,tm.wSecond);
return szBuffer;
}
//這時需要求中垂線 取線點兩邊一定長度的點 eg.20
BOOL CalcDblPoint(float xy[][2],float *x1,float *x2,float *y1,float *y2)
{
int ilen=40;
float x0,y0,k1,k2,b2;//,tmp_a,tmp_b,tmp_c;//,x1,x2,y1,y2
x0 = (xy[1][0]+xy[0][0])/2; //中點x
y0 = (xy[1][1]+xy[0][1])/2; //中點y
k1 = (xy[1][1]-xy[0][1])/(xy[1][0]-xy[0][0]); //(y2-y1)/(x2-x1)
//b1 = -k1*xy[0][0]+xy[0][1]; //-(y2-y1)/(x2-x1)*x1+y1
k2 = -1/k1;
b2 = y0-k2*x0;
int a2 = (int)(-b2/k2);
float xx1 = x0 + (float)(ilen*(- a2/sqrt(a2*a2 + b2*b2))); //x = x0 + t * cos?
float xx2 = x0 + (float)(ilen*(a2/sqrt(a2*a2 + b2*b2))); //y = y0 + t * sin?
float yy1 = y0 + (float)(ilen*(b2/sqrt(a2*a2 + b2*b2))); //
float yy2 = y0 + (float)(ilen*(- b2/sqrt(a2*a2 + b2*b2))); //
*x1 = xx1;
*x2 = xx2;
*y1 = yy1;
*y2 = yy2;
/*
tmp_a = k2*k2+1;
//tmp_b = -(2*(x0-k2*b2+y0*k2));
//tmp_c = x0*x0+b2*b2-2*y0*b2+y0*y0-ilen*ilen;
tmp_b = 2*(k2*(b2-y0)-x0);
tmp_c = x0*x0+b2*b2-2*y0*b2+y0*y0-ilen*ilen;
*x1 = (float)(-tmp_b +sqrt(tmp_b*tmp_b - 4*tmp_a*tmp_c))/(2*tmp_a); //(-b+sqrt(b*b-4*a*c))/2*a
*x2 = (float)(-tmp_b -sqrt(tmp_b*tmp_b - 4*tmp_a*tmp_c))/(2*tmp_a); //(-b-sqrt(b*b-4*a*c))/2*a
*y1 = k2 * *x1 + b2;
*y2 = k2 * *x2 + b2;
*/
return TRUE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -