C ++ Builder XE2 casual Learning (1)

Source: Internet
Author: User
Tags textout

Programming N for a long time, Coding has become a habit and an interest. If you don't touch the keyboard in a day, it seems that there is always something missing.

However, in the past few years, it was not only an old face, but also the strength to learn new knowledge. I have always stayed in Windows desktop application programming, and I have tried some management system related knowledge, it's always a bit tepid. It is a loyal fan of Borland. It is an excuse for your unwillingness or inability to learn new things.

The new year of 2012 has passed, and the spring festival of the year of the dragon has passed. The end of the day of the Maya is approaching, and there is no excuse to delay the time. As a result, the old tune new bullet, "New year new weather", prepare for study, and start planning again.

If you plan something, start with what you are interested in. I found that the C ++ Builder version has been released to XE2! Let's take a look at N new features and N new technologies. It's worth learning. Especially FireMonkey. GPU is also supported. I had the urge to learn GPU a long time ago. I will solve it this time.

Therefore, this series of logs is just for myself. I write them in my blog.

Since I learned C ++ Builder XE2 from the beginning, my opinion is only for my personal understanding, and I am very unauthoritative. I am not responsible for anyone who follows in the ditch.

 

The determination is down. It takes some time to write this series of blog posts. I am also a programmer with Chinese characteristics. I try not to spend any money on other people's software, but my own program will spend the best effort to let users pay for money, bind hard disk, CPU, network card, and so on for user registration. Here, I made another mistake. I wrote articles on the Internet and got a lot of reposted articles. It feels nice, but it has nothing to do with myself at last. Er, we must turn this situation around and draw on a watermark. That is to say, in this series of BLOG articles, the images in it will be printed with my own watermark.

 

How can we do this? Either download a software or compile a small program by yourself. Of course, it's a small program. It's only used to write a BLOG. In terms of your own requirements, in the WORD version document, all images are normal, but when sent to the BLOG, these images will be copied and saved as image files.

 

OK. This program is used to directly paste the image information in the clipboard with a watermark and automatically save it to the specified directory.

 

Start coding this program...

Coding...

 

Unexpectedly, it took two hours to compile the program. Another common problem for programmers is that they want to make a tool that is as useful as possible, including skin replacement and configuration. The basic functions are implemented, but they are still ugly.

Well, it seems that in C ++ Builder XE2, skin replacement is very easy and I look forward to learning about it.

 

Core code (you can understand it before you can write comments ):

If (Clipboard ()-> HasFormat (CF_BITMAP ))
 
{
Graphics: TBitmap * pBitmap = new Graphics: TBitmap;
PBitmap-> Assign (Clipboard ());
Image_Canvas-> Width = pBitmap-> Width;
Image_Canvas-> Height = pBitmap-> Height;
Image_Canvas-> Picture-> Assign (pBitmap );
Delete pBitmap;
 
TCanvas * canvas = Image_Canvas-> Canvas;
Canvas-> Brush-> Style = bsClear;
Canvas-> Font-> Assign (Label_Font-> Font );
 
Int angle = 45, horz = 100, vert = 100;
Try
{
Angle = Edit_Angle-> Text. ToInt ();
Horz = Edit_Horz-> Text. ToInt ();
Vert = Edit_Vert-> Text. ToInt ();
} Catch (...){}
 
UpdateFont (canvas, Label_Font-> Font, 1, 1, 1, angle );
For (int x = 0; x <Image_Canvas-> Width * 2; x + = horz)
For (int y = 0; y <Image_Canvas-> Height * 2; y + = vert)
Canvas-> TextOut (x, y, Edit_Text-> Text );
 
AnsiString BMP filename = Edit_Path-> Text;
If (! IsEndWith (BMP filename ,"\\"))
BMP filename + = "\\";
CreateDirectory (BMP filename );
For (int I = 1; ++ I)
{
AnsiString tempFileName = Format ("% scbw % d % s ",
ARRAYOFCONST (BMP filename. c_str (), I, ComboBox_PicType-> Text. c_str ())));
If (! FileExists (tempFileName ))
{
BMP filename = tempFileName;
Break;
}
}
BMP filename = ChangeFileExt (BMP filename, ". BMP ");
Image_Canvas-> Picture-> SaveToFile (BMP filename );
GlobalImageObject-> OnCommand (Format ("<request FileName = '% s' Type = 'set'/> ",
ARRAYOFCONST (BMP filename. c_str ()))));
GlobalImageObject-> OnCommand (Format ("<request Type = 'set' ImageFormat = '% s'/> ",
ARRAYOFCONST (ComboBox_PicType-> Text. c_str ()))));
If (! SameText (ComboBox_PicType-> Text, ". bmp "))
DeleteFile (BMP filename );
}
Else
ShowMessage ("the clipboard does not contain www.2cto.com image information. Please try again! ");
If (Clipboard ()-> HasFormat (CF_BITMAP) {Graphics: TBitmap * pBitmap = new Graphics: TBitmap; pBitmap-> Assign (Clipboard ()); image_Canvas-> Width = pBitmap-> Width; Image_Canvas-> Height = pBitmap-> Height; Image_Canvas-> Picture-> Assign (pBitmap); delete pBitmap; TCanvas * canvas = Image_Canvas-> Canvas; canvas-> Brush-> Style = bsClear; canvas-> Font-> Assign (Label_Font-> Font); int angle = 45, horz = 100, ver T = 100; try {angle = Edit_Angle-> Text. toInt (); horz = Edit_Horz-> Text. toInt (); vert = Edit_Vert-> Text. toInt ();} catch (...) {} UpdateFont (canvas, Label_Font-> Font, 1, 1, 1, angle); for (int x = 0; x <Image_Canvas-> Width * 2; x + = horz) for (int y = 0; y <Image_Canvas-> Height * 2; y + = vert) canvas-> TextOut (x, y, edit_Text-> Text); AnsiString BMP filename = Edit_Path-> Text; if (! IsEndWith (BMP filename, "\") BMP filename + = "\"; CreateDirectory (BMP filename); for (int I = 1; ++ I) {AnsiString tempFileName = Format ("% scbw % d % s", ARRAYOFCONST (BMP filename. c_str (), I, ComboBox_PicType-> Text. c_str (); if (! FileExists (tempFileName) {BMP filename = tempFileName; break ;}} BMP filename = ChangeFileExt (BMP filename ,". BMP "); Image_Canvas-> Picture-> SaveToFile (BMP FileName); GlobalImageObject-> OnCommand (Format (" <request FileName = '% s' Type = 'set'/> ", ARRAYOFCONST (BMP filename. c_str (); GlobalImageObject-> OnCommand (Format ("<request Type = 'set' ImageFormat = '% s'/> ", ARRAYOFCONST (ComboBox_PicType-> Text. c_str (); If (! SameText (ComboBox_PicType-> Text, ". bmp") DeleteFile (bmp filename);} else ShowMessage ("the Clipboard contains no image information. Please try again! ");
 
 
 
 
 
After running, the option setting interface is as follows:
 
 
 

 

 

Copy and paste the image.

 

 

 

 

 

The image file name is automatically saved in the specified directory.

 

 


As expected, www.2cto.com is a very responsible site ). If you are interested in writing this series of articles, join the group 208894875 for in-depth communication.


From ArWen's column

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.