思享者

知其然亦知其所以然,以至不惑也

  博客园 :: 首页 :: 联系 :: 订阅 订阅 :: 管理
  4 Posts :: 0 Stories :: 3 Comments :: 0 Trackbacks

公告

置顶随笔 #

摘要: Borland C++ Builder 5.0和Borland C++ Builder 6.0软件在网上一大堆都是一些没有用的下载链接!现在我提供给大家可用的下载地址。省去你在茫茫网络中找不到下载链接的烦恼。今天我刚上传到网盘的,下面的链接可以使用,如果不能使用了,请给我留言。我会很快解决。http://115.com/file/e6e5usnr#DownloadCBuilder6_disc1.rarhttp://115.com/file/aqvk7huh#DownloadCBuilder6_disc2.rar阅读全文
posted @ 2011-11-23 13:06 LuckyLuke 阅读(1123) 评论(2) 编辑

2011年11月23日 #

 Borland C++ Builder 5.0和Borland C++ Builder 6.0软件在网上一大堆都是一些没有用的下载链接!现在我提供给大家可用的下载地址。省去你在茫茫网络中找不到下载链接的烦恼。今天我刚上传到网盘的,下面的链接可以使用,如果不能使用了,请给我留言。我会很快解决。

 

http://115.com/file/e6e5usnr#Download
CBuilder6_disc1.rar

http://115.com/file/aqvk7huh#Download
CBuilder6_disc2.rar

posted @ 2011-11-23 13:06 LuckyLuke 阅读(1123) 评论(2) 编辑

2011年11月10日 #

最近在项目中需要判断点和四边形关系,我的算法中涉及到了求解线段夹角的问题,于是编写了如下代码。

问题描述
平面坐标系中,已知三点坐标,求出任意两点组成的线段之间的夹角。
 

使用向量夹角公式
cos<夹角> = 两向量之积 / 两向量模的乘积
<夹角> = arccos( 两向量之积 / 两向量模的乘积 )
 
 1 #include <cmath>
2 using std::acos; // 反余弦函数
3 using std::sqrt; // 平方根函数
4 //---------------------------------------------------------------------------
5
6 // 点结构体的定义
7 struct TPoint : public POINT
8 {
9 TPoint() {}
10 TPoint(int _x, int _y) { x = _x; y = _y; }
11 TPoint(POINT & pt)
12 {
13 x = pt.x;
14 y = pt.y;
15 }
16 };
17 //---------------------------------------------------------------------------
18
19 double getAngle(TPoint pSrc, TPoint p1, TPoint p2)
20 {
21 double angle = 0.0f; // 夹角
22
23 // 向量Vector a的(x, y)坐标
24 double va_x = p1.x - pSrc.x;
25 double va_y = p1.y - pSrc.y;
26
27 // 向量b的(x, y)坐标
28 double vb_x = p2.x - pSrc.x;
29 double vb_y = p2.y - pSrc.y;
30
31 double productValue = (va_x * vb_x) + (va_y * vb_y); // 向量的乘积
32 double va_val = sqrt(va_x * va_x + va_y * va_y); // 向量a的模
33 double vb_val = sqrt(vb_x * vb_x + vb_y * vb_y); // 向量b的模
34 double cosValue = productValue / (va_val * vb_val); // 余弦公式
35
36 // acos的输入参数范围必须在[-1, 1]之间,否则会"domain error"
37 // 对输入参数作校验和处理
38 if(cosValue < -1 && cosValue > -2)
39 cosValue = -1;
40 else if(cosValue > 1 && cosValue < 2)
41 cosValue = 1;
42
43 // acos返回的是弧度值,转换为角度值
44 angle = acos(cosValue) * 180 / M_PI;
45
46 return angle;
47 }
48 //---------------------------------------------------------------------------
附录

acos函数的介绍

Header File
 
math.h 
 
Category
 
Math Routines
 
Prototype
 
double acos(double x);
 
long double acosl(long double x);
 
Description
 
Calculates the arc cosine.
 
acos returns the arc cosine of the input value. 
 
acosl is the long double version; it takes a long double argument and returns a long double result.
 
Arguments to acos and acosl must be in the range -1 to 1, or else acos and acosl return NAN and set the global variable errno to:
 
EDOM  Domain error
 
Return Value
 
acos and acosl of an argument between -1 and +1 return a value in the range 0 to pi. Error handling for these routines can be modified through the functions _matherr_matherr and _matherrl.
 
下一期准备将点和四边形关系的代码和思路贴出来。欢迎大家提出意见,不胜感激~~~
posted @ 2011-11-10 14:10 LuckyLuke 阅读(1354) 评论(0) 编辑

 1 using Word = Microsoft.Office.Interop.Word;
2
3 // 创建Word文档
4 Word.Application WordApp = null;
5 Word.Document WordDoc = null;
6
7 Object Nothing = System.Reflection.Missing.Value;
8 WordApp = new Word.ApplicationClass();
9 WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
10
11 // Word文件路径
12 string filename = System.Windows.Forms.Application.StartupPath + "\\test.doc";
13 string message = "";
14
15 try
16 {
17 // 创建Word文档
18 // ... ...
19 }
20 catch (Exception ex)
21 {
22 MessageBox.Show(message = "文件导出异常!" + ex.ToString());
23 }
24 finally
25 {
26 //文件保存
27 WordDoc.SaveAs(ref filename, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
28 WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
29
30 // Solution-1
31 object saveOption = Word.WdSaveOptions.wdDoNotSaveChanges;
32 WordApp.Quit(ref saveOption, ref Nothing, ref Nothing);
33 }

解决方案 二

 1             try
2 {
3 if (WordDoc != null)
4 {
5 System.Runtime.InteropServices.Marshal.ReleaseComObject(WordDoc);
6 WordDoc = null;
7 }
8 WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
9 }
10 catch
11 {
12 try
13 {
14 if (WordApp != null)
15 {
16 System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
17 WordApp = null;
18 }
19 }
20 catch (Exception ex1)
21 {
22 MessageBox.Show(ex1.ToString());
23 }
24
25 }



posted @ 2011-11-10 13:45 LuckyLuke 阅读(105) 评论(0) 编辑

2011年10月25日 #

最近都在维护一个老项目,使用的开发平台是BCB6,经常用到StringGrid。这个控件默认显示格式都是左对齐,可是这样很不美观,至少我的项目中需要它居中显示文本~~~所以将居中显示的方法记录在此,以便日后自己和他人复用

该控件没有显示格式相关的属性,因此无法直接设置居中,只能通过间接的方法。

幸好,BCB提供了一个相关的接口来自定义文本输出,就是StringGrid控件的OnDrawCell事件,添加对应的事件处理方法可以达到自定义输出文本格式的目的。

 

假设我们在form中添加了一个StringGrid的实例用来显示XY坐标,它的Name属性为:StrGridXY,添加OnDrawCell事件处理方法如下

 1 // 使文字居中显示
2 void __fastcall TMyForm::StrGridXYDrawCell(TObject *Sender, int ACol,
3 int ARow, TRect &Rect, TGridDrawState State)
4 {
5 StrGridXY->Canvas->FillRect(Rect); // 使用当前的brush填充矩形,覆盖目前cell中的内容显示
6 DrawText(((TStringGrid*)Sender)->Canvas->Handle
7 , ((TStringGrid*)Sender)->Cells[ACol][ARow].c_str()
8 , -1
9 , (RECT*)&Rect
10 , DT_SINGLELINE | DT_VCENTER | DT_CENTER);
11 }

最终效果


注意:

Line 5

StrGridXY->Canvas->FillRect(Rect);

很多人将这一句遗漏掉,导致单个Cell中出现两个同样的内容。

你可以将此句注释掉或者将此句移到该方法的最后一行,看看有什么效果。

前者导致我们上述提及的单个Cell中有两个复本的值比如显示了两个“p1”;

后者将导致cell的内容为空。

避免方法

如果要避免上述的情况,有以下两种途径

1. 可以将StringGrid的DefaultDrawing设为false,这样每次要绘制cell内容的时候,只调用你的DrawCell方法,而不会出现两次绘制的情况。

2. 不改动上述属性,记得将Line 5那句代码添加至事件处理方法中,使用当前brush填充该cell,达到覆盖原先cell的文本显示效果。然后,再进行居中显示文本的操作(DrawText)。不过这样还是绘制了两次文本,只是第一次的效果被覆盖掉了,完全没必要~~所以还是采取第一种方法吧!

posted @ 2011-10-25 17:01 LuckyLuke 阅读(383) 评论(1) 编辑