Tips for using BCB (1)

Source: Internet
Author: User
1. How to obtain memo rows and columns

Create an application and add two tlabel components named label1 and label2 to form form1;
Add two tbutton components named button1 and button2. Add a tmemo component named memo1.
Then add the following code in the code editor.
Void _ fastcall tform1: button1click (tobject * sender)
{
Label1-> caption = sendmessage (memo1-> handle, em_linefromchar,-1, 0) + 1;
}
//---------------------------------------------------------------------------
Void _ fastcall tform1: button2click (tobject * sender)
{
Label2-> caption = memo1-> selstart-sendmessage (memo1-> handle, em_lineindex,-1, 0) + 1;
}
This method also applies to RichEdit.

2. How to make the last row always display after adding a row to memo
Or how to control the scrollbar and pull it to the bottom

Sendmessage (memo1-> handle, em_scroll, sb_linedown, 0)

3. Add colors to text in tstringgrid

Tstringgrid is a grid Controller provided by C ++ builder for users. In the United States, it is not enough, it has not provided for the division of repair and change the font color, small square. Actually, tstringgrid needs to implement this function. You just need to add some processing in the Process Order. The square method is to customize a two-dimensional number group cellbuf. Its downlink label corresponds to the row of the single-element column of the grid, it is used to store the face color, text, and other information of each grid unit.

Struct cellstru
{
Ansistring MSG; // text message
Tcolor color; // text color
};

Cellstru cellbuf [maxcol] [maxrow];

After cellbuf is first modified, add the following code to the ondrawcell response of stringgrid1, a grid controller.
Void _ fastcall tform1: stringgrid1drawcell (tobject * sender, int Col,
Int row, trect & rect, tgriddrawstate state)
{
Stringgrid1-> canvas-> font-> color = cellbuf [col] [row]. color;
Stringgrid1-> canvas-> textout (rect. Left + 3, rect. Top + 3, cellbuf [col] [row]. msg );

}

4.BCB undisclosed code editing hotkeys

 

Shift left or right
 
Select a piece of code,
(1) press Ctrl + k, loosen, and then press I to move the whole part to the right;
(2) press Ctrl + k, loosen, and then press u to move the entire text to the left.
Or, after anti-white,
(1) press Ctrl + Shift + I to shift the whole part to the right,
(2) press Ctrl + Shift + u to move the entire text to the left.

5. Application of the task bar status area

There is a status area on the taskbar of windows95, which displays the current input method (Chinese version), current time, and other information. When the print manager is started, the print manager icon is displayed, indicates that the printer is working. We can use this technology to set an icon for a program that is working in the background to display its working status. You can click the mouse to query details or modify work parameters. The following describes the implementation methods.

6. add and delete icons

Both operations are implemented by calling the shell_policyicon function and passing two parameters: one is the operation instruction, the addition is nim_add, And the deletion is nim_delete; the other is the notifycondata structure, and the initialization is required. You can add multiple icons by specifying different icon identification numbers. The following two functions add and remove icons respectively.

// Addtaskbaricon: adds the specified icon to the status area of the taskbar. If yes, true is returned. Otherwise, false is returned. // hwnd: Specifies the window for receiving messages. // uid: icon ID // hicon: the icon handle to be added // ipsztip: the prompt message bool addtaskbaricon (hwnd, uint uid, hicon, lpstr lpsztip) {bool res; policyicondata tnid; tnid. cbsize = sizeof (policyicondata); tnid. hwnd = hwnd; tnid. uid = uid; tnid. uflags = nif_message | nif_icon | nif_tip; // the message sent to the callback function of the specified window when you click the icon. The tnid is customized by the programmer. ucallbackmessage = mywm_policyicon; tnid. hicon = hicon; If (lpsztip) lstrcpyn (tnid. sztip, lpsztip, sizeof (tnid. sztip); else tnid. sztip [0] = '/0' // nim_add: add the icon res = shell_policyicon (nim_add, & tnid); If (hicon) destroyicon (hicon); Return res ;} // deletetaskbaricon: remove the specified icon in the addtaskbar state area. If the operation succeeds, true is returned. Otherwise, false is returned. // hwnd: The Window specified when the icon is added. // uid: the icon ID bool deletetaskbaricon (hwdn hwnd, uitn UID) {bool res; policyicondata tnid; tnid. cbsize = sizeof (policyicondata); tnid. hwnd = hwnd; tnid. uid = uid; // nim_delete: Move the icon res = shell_policyicon (nim_delete, & tnid); Return res ;}

Receive messages returned by the icon

_________________________________

The icon in the status area can receive user input and send the received mouse message to the callback function in the specified window. The program can respond to user input. The following is an example of the corresponding window callback function and message processing function:

// Mainwndproc: The Window callback function that processes the messages passed to the window // windows determines the corresponding callback function lresult callback mainwndproc (hwnd, uint message, wparam, lparam) {Switch (Message) {// mywm_policyicon: the message case mywm_policyicon specified when the icon is added: // call the custom message processing function on_mywm_policyicon (wparam, lparam); break ;...... Case wm_destroy: postquitmessage (0); break; default: Return (defwindowsproc (hwnd, message, wparam, lparam);} return lparam;} // on_mywm_policyicon: message generated by the status bar icon // wparam: the first parameter of the callback message, and the icon ID // lparam: The second parameter of the callback message, the code of the mouse message void on_mywm_policyicon (wparam, lparam) {uint uid; uint umousemsg; uid = (uint) wparam; umousemsg = (uint) lparam; // This function only processes the left-click message. For example, you can add the Code if (umousemsg = wm_lbuttondown) for processing other // mouse messages) // a message box, MessageBox (null, "Be happy, don't worry. "," taskbaricon ", mb_ OK); return ;}
7. How to Use code to minimize or restore programs

 


You can implement it using one of the following three methods.
Method 1: Send a Windows message to the handle attribute of the main window or application-> handle. This message is wm_syscommand, and wparam is set to SC _minimize or SC _restore. You can call the sendmessageapi function to send messages.

// Set wparam to SC _minimize to minimize the window size.
Sendmessage (Application-> handle, wm_syscommand, SC _minimize, 0 );

// Set wparam to SC _restroe to restore the window
Sendmessage (Application-> handle, wm_syscommand, SC _restore, 0 );
Method 2: Call the showwindowapi function. You must transfer the application object handle to the showwindow function. If the handle you send to the showwindow function is the main window, the main window will be minimized to the desktop rather than the taskbar ).
// Minimize: Send sw_minimize to showwindow
Showwindow (Application-> handle, sw_minimize );

// Restore: Transfer sw_restore to showwindow
Showwindow (Application-> handle, sw_restore );
Method 3: Call the minimize or restore function of the Application object.
// Call minimize to minimize the application
Application-> minimize ();

// Call restore to restore the application
Application-> restore ();
It is easier to call the application method, but it is more powerful to send wm_syscommand messages. In addition, the wm_syscommand message allows you to maximize the program, change the cursor to help the cursor, scroll the program, move a window, change the window size, and even simulate alt-tab switch to another window. Note: it is better to use API functions to implement these functions.
Even if you call showwindow, you probably don't want to use it to minimize or restore programs. When the hidden window is minimized, showwindow will cause the animation to be minimized. This seems a bit silly, because the animation is far from the center from the position of the Main Window of the program.

8. VCL class derived from BCB and dynamic control creation
 

Take generating a tmemo derived class and dynamically creating the VCL control as an example.
Class tmemoex: Public tmemo
{
.
.
}
Extern tmemoex memoex;
 
Class tform1: Class tform
{
Public:
Tmemoex * memoex;
.
.
}
 
Void _ fastcall tform1: formshow (tobject * sender)
{
Memoex = new tmemoex (this );
Memoex-> parent = this;
.
.
}
Follow these steps:
Class definition;
Extern tmemoex memoex;
Tmemoex * memoex;
Memoex = new tmemoex (this );
Memoex-> parent = this;





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.