高拍仪之20:生成一维码
二维码已经能够识别,是基于开源的zxing实现的。从使用的角度来说,能够生成一下一二维码,也是很爽的事。
以前做公安行业项目时,接触过条码打印机,是不是就是这里所说的一维码呢?
当然,没有必要老提当年的事。做技术的,做得越久,就会更加发现以前做的都有点垃圾,灰飞烟灭后,发现只是手留余香,现在做什么技术方面的事情能够比较快地实现而已。
花了一天时间,在cptang发来的控件的基础上,完整地实现了生成一维码功能。正准备再接再厉实现二维码,结果用户与我联系,说今天下午有个重量级用户来,要给他演示原理示教系统,准备在河北廊坊推广。倒是好事。那就先把二维码放下,实现起来应该还需要半天时间。
生成一二维码,首先是界面,在插入栏中加入图标即可,剩下的是设置一下Tag、OnClick事件。
再加入一维码类:
class TBarCode1D : public TCbwImage {
typedef TCbwImage inherited;
virtual void __fastcall DoAddToXmlNode(CbwXmlNode * node);
virtual void __fastcall DoGetFromXmlNode(CbwXmlNode * node, int& index);
virtual void __fastcall Clone(TCbwObject * dest);
void __fastcall CreateBmpFile();
public:
__fastcall TBarCode1D();
__fastcall ~TBarCode1D();
__fastcall TBarCode1D(TBuildType buildFlag);
static TCbwObject * Build();
void __fastcall Initial();
};
下来就是逐个研究其数据成员。
运行一下控件的示例程序:
一个个属性研究(这一天时间主要就花在这上面了),在之前编程的基础上,很快可以分门别类地实现各个成员:
enum TBarCode1DType {
_Codabar = 0, _Code11 = 1, _Code25Industrial = 2, _Code25Invert = 3, _IATA = 4, _Code25Interleaved = 5,
_Code25Matrix = 6, _Code25Datalogic = 7, _Coop25 = 8, _Leitcode = 9, _Identcode = 10, _ITF_6 = 11,
_ITF_14 = 12, _ITF_16 = 13, _Code39 = 14, _UPU = 15, _Code39Extension = 16, _Code32 = 17, _PZN = 18, _Code93 = 19,
_Code93Extension = 20, _Plessey = 21, _MSI = 22, _Telepen = 23, _PharmacodeOneTrack = 24, _PharmacodeTwoTrack = 25,
_UPC_A = 26, _UPC_E = 27, _UPC_E0 = 28, _UPC_E1 = 29, _EAN_2 = 30, _EAN_5 = 31, _EAN_8 = 32, _EAN_13 = 33,
_Code_128 = 34, _EAN_128 = 35, _Flattermarken = 36, _Channel_Code = 37, _BC309 = 38, _BC412 = 39, _Clocked_35 = 40,
_FIM = 41, _Patch_Code = 42, _PLANET = 43, _PostNet = 44, _KIX4S = 45, _JapanPost = 46, _RM4SCC = 47, _AP4SC = 48,
_CPC_Binary = 49, _PostBar = 50, _OneCode = 51
};
enum TBarOrientation {
boLeftRight, boRightLeft, boTopBottom, boBottomTop
};
enum TBarDisplayText {
dtNone, dtBarcode, dtFullEncoded
};
enum TBarTextAlignment {
taLeft, taCenter, taRight, taJustify, taLeftQuietZone, taCenterQuietZone, taRightQuietZone, taJustifyQuietZone,
taCustom
};
enum TBarTextPosition {
tpTopIn, tpTopOut, tpBottomIn, tpBottomOut
};
enum TBarEndCode {
A, B, C, D
};
enum TBarPadding {
cipLeft, cipRight
};
enum TBarBearer {
bbFourSides, bbTopBottom
};
class TBarCode1D : public TCbwImage {
CBW_PUBLISH_BARCODE(UnicodeString, BarCode, FBarCode, SetBarCode);
CBW_PUBLISH_BARCODE(TBarCode1DType, Type, FType, SetType);
CBW_PUBLISH_BARCODE(int, Module, FModule, SetModule);
CBW_PUBLISH_BARCODE(double, BarRatio, FBarRatio, SetBarRatio);
CBW_PUBLISH_BARCODE(int, BarHeight, FBarHeight, SetBarHeight);
CBW_PUBLISH_BARCODE(TBarOrientation, BarOrientation, FBarOrientation, SetBarOrientation);
CBW_PUBLISH_BARCODE(TColor, BarColor, FBarColor, SetBarColor);
CBW_PUBLISH_BARCODE(TColor, SpaceColor, FSpaceColor, SetSpaceColor);
CBW_PUBLISH_BARCODE(int, LeftMargin, FLeftMargin, SetLeftMargin);
CBW_PUBLISH_BARCODE(int, TopMargin, FTopMargin, SetTopMargin);
CBW_PUBLISH_BARCODE(TBarDisplayText, DisplayText, FDisplayText, SetDisplayText);
CBW_PUBLISH_BARCODE(TBarTextAlignment, TextAlignment, FTextAlignment, SetTextAlignment);
CBW_PUBLISH_BARCODE(TBarTextPosition, TextPosition, FTextPosition, SetTextPosition);
CBW_PUBLISH_BARCODE(int, TextCSpacing, FTextCSpacing, SetTextCSpacing);
CBW_PUBLISH_BARCODE(int, TextVSpacing, FTextVSpacing, SetTextVSpacing);
CBW_PUBLISH_BARCODE(int, TextHSpacing, FTextHSpacing, SetTextHSpacing);
CBW_PUBLISH_BARCODE(TBarEndCode, StartCode, FStartCode, SetStartCode);
CBW_PUBLISH_BARCODE(TBarEndCode, StopCode, FStopCode, SetStopCode);
CBW_PUBLISH_BARCODE(TBarPadding, Padding, FPadding, SetPadding);
CBW_PUBLISH_BARCODE(bool, SplitText, FSplitText, SetSplitText);
CBW_PUBLISH_BARCODE(TBarBearer, BearerBars, FBearerBars, SetBearerBars);
CBW_PUBLISH_BARCODE(int, BearerWidth, FBearerWidth, SetBearerWidth);
CBW_PUBLISH_BARCODE(int, LeftSpacing, FLeftSpacing, SetLeftSpacing);
CBW_PUBLISH_BARCODE(int, RightSpacing, FRightSpacing, SetRightSpacing);
CBW_PUBLISH_BARCODE(bool, ShowGuards, FShowGuards, SetShowGuards);
CBW_PUBLISH_BARCODE(bool, InterGap, FInterGap, SetInterGap);
CBW_PUBLISH_BARCODE(bool, Bidirectional, FBidirectional, SetBidirectional);
};
具体的事宜交给DrGraph软件去完成。
最终实现效果:
剩下的事,就是把不该出现的属性从属性浏览器中去掉,并把属性名称在资源文件中配置为中文,让自己的用户用得舒服一点。