Message delivery for Windows-message box

Source: Internet
Author: User
Tags word wrap line editor

The use of Delphi message mechanism can be convenient to operate the background, which is important is the SendMessage () function. Let's take a look at this function

[Delphi]View PlainCopy
    1. function SendMessage (Hwnd:hwnd; Msg:uint; Wparam:wparam; Lparam:lparam): LRESULT; stdcall;

The meanings and descriptions of four of these parameters are as follows:
1.hWnd:
The handle to the object. If you want to send the message to which object, the handle of the object is passed as an argument, and in VB it is easy to
Use "object. HWnd" To get a handle to an object, such as Text1.hwnd and Form1.hwnd, respectively, to get Text1 and Form1 sentences.
Handle. It is a long integer number. Windows gives each control a number, which is called a window handle. With this handle, we
You can tell Windows which control we want to control, so this handle is critical in the API call. Most of the controls in VB are wrapped
The form also has this property, including the HWND attribute, such as the drop-down box, TreeView, and so on. But there are also some controls that do not have this property, such as a label control.
You cannot take advantage of Windows API functions without this property, but you can save system resources.
2.WMSG:
The message that was sent. Depending on the specific needs and different objects, different messages are routed as arguments to produce the expected action. Make
SendMessage delivers messages, mostly to do the following:
① sets some options for the control, as is the case with the cb_setdroppedwidth we want to use. Although each control of VB
Many properties are provided, but there are still a number of options that are not included in the controls. Most of these options can take advantage of the
function to set?
② gets some settings for the control. In the opposite case, sometimes we need to get some settings for the control, which is equivalent to reading the property.
For example, if you want to know how wide the drop-down of a drop-down box is, you can send a cb_getdroppedwidth message to the control.
For this case, the return value of the SendMessage function is the result.
③ to perform certain operations. For example, we'll look in the drop-down box to find out if there is a string "ABC", and of course we can write
A loop that compares each other to see if such a string exists. If we use the API, we only need to send the cb_findstring in the drop-down box
message, the message automatically finds the job and returns the result.
④ simulates user actions. We sometimes want to impersonate a user's actions, such as closing a window on another application. In fact, as long as we can know
The handle of the window, we can send the WM_CLOSE message to that window, and the window will be closed when the message is received, as if the user
Close the window like?
3.wParam, 4.lParam:
The additional message information. These two are optional parameters to provide more information about wmsg messages, and different wmsg may use this
Two parameters of 0, 1, or 2, if no additional parameters are required, the argument is assigned null (in VB is assigned to 0).
LPARAM is defined as any type. Specifying any type prevents VB from type checking, allowing any data type to be passed to the
Ride. Because each message requires different types of parameters and methods of delivery: Some may require long, and some may require a custom
The majority of the requirements are passed by value, but there are also some requirements for the address-by-pass approach. To meet a variety of requirements, we
The number is defined as the any type. For example, we are going to pass a long variable ldata. If the message requires an address pass, you can use:
SendMessage ..., LData.
And if the pass-through method is required, use the
SendMessage ..., ByVal lData
If you pass a constant, we need to use the type suffix to specify the type of the constant, such as "0&", which represents a long type of constant 0, such as
SendMessage ..., ByVal 0&
We can also use the type conversion function CLng to specify a constant as a long type, such as CLng (0).

The program, sometimes defining lParam as any, sometimes defines ByVal LParam as String. What is this for? For
SendMessage function, the use of lparam is very flexible, in general, LPARAM is a pointer, it points to the data type
There are three kinds: long shape, custom data structure type, String type. For the first two types, you need to define LParam as LParam
As any to pass a pointer to the LParam data to the SendMessage function. For string types, you need to define the Byval
LParam As String, because the string type data is different, only the definition of ByVal, the result is a pointer to the string, if there is no
ByVal, you get a pointer to a pointer to a string. In addition, for a few messages, the SendMessage function needs only
LParam The value itself, you need to define LParam as Byval LParam as Long, or in LParam when the program is called
Before you add ByVal?
When a user makes various actions on an edit control, its parent window receives a WM_COMMAND notification message, LPARAM with a control handle
(HWnd), with a low 16-bit ID for the WParam, and a high 16-bit message code with the following table.

Common Edit Control messages:

[Delphi]View PlainCopy
  1. Ec_leftmargin (&H1) Ec_usefontinf //Set left margin for use
  2. Ec_rightmargin Ec_usefontinf //Use when setting the right margin
  3. Ec_usefontinf,o//margin sets the left and right margin of the edit control, when wparam contains Ec_leftmargin, the lower 16 bits in lparam Specify the left margin points when wparam contains ec_ RIGHTMARGIN Specifies the right margin point in the high 16 bits of the lparam.  When WPARAM is specified as Ec_usefontinfo, the width of the character "A" of the current font is specified with the right margin and the character "C" to specify the left margin lparam is ignored.
  4. Em_charfrompos (&hd7=215),0, //Gets the offset of the word typeface for the text header at the specified position in the edit control. Use this operation should first specify the line number in the high 16 bits of the 4th parameter, the lower 16 bits specify the column number (or a POINTAPI structure), and the rows and columns are calculated as the origin (0,0) in the upper-left corner of the client area of the edit control. Returns 1 if the specified location exceeds the control client area
  5. Em_canundo (&hc6=198),0,0 //Determines whether the previous edit operation can be undone: detects whether the control undo buffer is empty, usually the control saves the last edit operation on the control in an undo buffer,  Returns true if the buffer is non-empty, indicating that the last operation can be undone, or false if the application can use the return value to suppress or allow the Undo item for the menu or toolbar.
  6. Em_emptyundobuffer (&hcd=205),0,0 //Clears the undo buffer of the control so that it cannot undo the previous edit Operation
  7. Em_fmtlines (&hc8=) //Decide whether to include soft return characters in the retrieved text string
  8. Em_getfirstvisibleine (&hce=206),0,0 //Gets the line number of the topmost text in the text control where it is visible
  9. Em_getline (&hc4=196)//Line number, ByVal variable gets the contents of a row in the edit control, and the variable must be pre-assigned a space
  10. Em_getlinecount (&hba=186,0,0//Gets the total number of rows in the edit control
  11. Em_getmodify (&hb8=184),0,0 ///Determines whether the content of the edit control has changed, returns True if the control text has been modified, and false is not changed.
  12. Em_getpasswordchar (),0,0 //Get the password character of the edit control, return null to indicate no character
  13. Em_getrect (&hb2=178),0, Structure //Get the formatting rectangle of the edit control
  14. Em_getthumb (&hbe=),0,0 //Gets the current position of the scroll box for multiple lines of text edit control (note: is a pixel value)
  15. Em_getsel (&hb0=176),0,//variable gets the cursor position (expressed in bytes), or: (buffer start, buffer end point) takes the range of the selection in the edit control, the lower 16 bits in the return value are the starting point, and the high 16 bits are the end points
  16. Em_gethandle (&hbd=189),0,0//Get text buffer
  17. Em_getwordbreakproc (&hd1=209),0,0 //Get the whole word wrap callback function Editwordbreakproc pointer
  18. Em_getlimittext (wm_user+37=1061),0,0 //Get the maximum length of text in an edit control
  19. Em_getmargins (),0,0 //Gets the left and right margin of the edit control, the return value is lower 16 bits is the left margin, and the height 16 bits is the right margin (must not be used for NT3. Wuyi)
  20. Em_limittext (&hc5=197),//MAX, 0 sets the length of text in the edit control
  21. Em_scrollcaret (&hb7=183),0,0 //move visible range to Cursor
  22. Em_linefromchar (&hc9=201),//offset value, 0 gets the line number where the specified position (or: -1,0 indicates the cursor position) is located
  23. Em_lineindex (&hbb=187),//line number, 0 gets the position (in bytes) of the first character in the text for the specified row (or: -1,0 for the line where the cursor is located )
  24. Em_linelength (&hc1=193)//offset value, 0 gets the length of the text (in bytes) of the row (or -1,0 that represents the cursor) at the specified position
  25. EM_POSFROMCHARPOINT, structure address, offset value gets the row and column number of the specified character position, and the offset value is the offset of the word typeface for the text header.
  26. Em_linescroll (&hb6=182)//columns, number of rows specifies the number of lines of text to scroll horizontally, each scrolling n columns
  27. Em_exgetsel (&h434 = 1076)
  28. Em_exsetsel (&h437=1079),0//structure RichEdit control set text selection, see Em_setsel message, structure refers to Charrange structure
  29. Em_pastespecial (&h440=1088),2 (1),1//RichEdit control pastes the bitmap (or text) in the Clipboard
  30. Em_findtext (&h738=) //richedit Control Body search Operation
  31. Em_findtextex (&h44f=1103) //Ibid .
  32. Em_settextex (&h461=1121) //richedit control Body Replace/insert operation
  33. Em_settargetdevice, GetDC (RichText. hWnd), RichText. Width //15) Set RichTextBox line wrap, follow code: Richtext.rightmargin = IIF (Richtext.rightmargin = 0,1,0)
  34. Em_settargetdevice, 0, 1 //Set RichTextBox do not wrap
  35. Em_posfromchar (&HD6 or &h426)//determines the position of the specified character in the edit control (for NT3. Wuyi)
  36. Em_scroll (&hb5=181), *,0 //Text vertical scrolling.  The third parameter * controls the scroll direction: Sb_linedown (1) Scrolls down one line, Sb_lineup (0) scrolls up a line, Sb_pagedown (3) Scrolls down a page, Sb_pageup (2) Scrolls up one page.
  37. Em_replacesel (&hc2=194),1 (0)//, the string replaces the current selection in the edit control with the specified string, and if the third parameter is wparam 1, this action allows undo, and 0 prohibits undo. String can be used in the method of transmission, also can be used to address the way (example: SendMessage text1.hwnd, Em_replacesel, 0, Text2.text ' This is the value of the way)
  38. Em_setsel (&hb1=177)//, start point, end point Set the text selection range (or set cursor position) in the edit control, which is reversed to specify the range for editing functions such as copy, replace, paste, cut, delete, The cursor is moved back to the specified end point. You can also use the same start and end point to move the cursor instead of the selected range. When the specified starting point equals 0 and the end point equals-1, the text is all selected, and this method is commonly used to empty the edit control. When the specified starting point equals-2 and the end point equals-1, the full text is not selected, and the cursor moves to the text end, which is commonly used to append content at the end of the text.  Note: This operation will fail when the control has no input focus, and the SetFocus should be called first to get the input focus before performing this operation.
  39. Em_undo (&hc7=199),0,0 //Undo the previous edit operation, when the message is repeatedly sent, the control will switch back and forth in undo and redo
  40. Em_setcharformat (&h444)//Change the color of selected text
  41. Em_sethandle (&hbc=188),//buffer pointer, 0 specifies a new text buffer for the edit control.  This action only applies to dialog boxes to create a control with Ds_localedit style.
  42. Em_setlimittext, Length (bytes),0 //sets the maximum length of text in the edit control (must not be used for NT3. Wuyi)
  43. Em_setmargins (&hd3=211) //sets the left and right margin of the edit control (must not be used for NT3. Wuyi)
  44. Em_setmodify (&hb9=185),1 (0),0 //Set or clear the Modify flag for an edit control
  45. Em_setpasswordchar (&hcc=204),//character, 0 specifies the character that the control uses to display the password, and the default is "*".  When the third argument wparam to 0 o'clock, this action clears the Es_password style of the control and displays it as actual characters.
  46. Em_setreadonly (&hcf=207),1 (0),0 //Determines whether the edit control is set to read-only, and also determines the es_readonly style of the control
  47. Em_setrect (&hb3=179),0 (or rect),//structure address set the formatting rectangle for an edit control
  48. EM_SETRECTNP (&hb4=),0 (or rect)//, structure address sets the formatting rectangle for an edit control, except that the control does not redraw at this time
  49. En_change (&h300=768)//Edit the contents of the control have changed.  Unlike En_update, the message is emitted when the body of the edit box appears refreshed.
  50. En_errspace (&h500=) //At any time as long as there is not enough memory to complete an edit operation
  51. En_hscroll (&h601=1537)//user clicked the horizontal scroll bar of the edit control.  Note: This message is sent before the control updates are displayed.
  52. En_vscroll (&h602=1538) //user clicked the vertical scroll bar of the edit control.  Note: This message is sent before the control updates are displayed.
  53. En_killfocus (&h200=) //Edit control loses input focus
  54. En_setfocus (&h100=) //Edit controls get input focus
  55. En_update (&h400=) //control is ready to display the changed body when the message is sent.  It is similar to the EN_CHANGE notification message, except that it occurs before the updated text is displayed.
  56. En_maxtext (&h501=1281)//The user loses the number of characters beyond the bounds specified by the Em_limittext message, or beyond the bounds set by the VB MaxLength attribute, this message will be sent. Also, this message is triggered if automatic horizontal scrolling is not allowed and the insertion point exceeds the width of the control, or automatic vertical scrolling is not allowed, and the insertion point exceeds the height of the control.  In an edit box without es_autohscroll or es_autovscroll, the message is emitted when the body is outside the border of the edit box.
  57. Edit Style message:
  58. Es_multiline ///Specifies whether the edit control can make multiple lines of this edit, if the multiline editor does not specify Es_autohscroll style, the line wraps, and the user presses ENTER at the current cursor to enter a carriage return newline character (0dh,0ah). The text is incremented by one line.  If you do not specify Es_autovscroll, the multiline editor emits a warning sound when the body of the window is filled.
  59. Es_left //text display left?
  60. Es_center//text display centered?
  61. Es_right //text display right?
  62. Es_lowercase //Convert the letters entered by the user into lowercase letters?
  63. Es_uppercase//Convert all the letters entered by the user into capital letters?
  64. Es_oemconvert //Converts the input text from the ANSI code to the OEM code, and then into the ANSI code, in order to ensure the correct invocation of the function AnsiToOem.  This is useful when you include a file name in the edit box.
  65. Es_autohscroll (automatically add horizontal scroll bar?)  When a user types a character at the end of a line, the body automatically scrolls to the right by 10 characters, and the body always rolls to the left when the user presses the ENTER key.
  66. Es_autovscroll //When the user presses the ENTER key on the last visible row, the body scrolls up one page.
  67. Es_number //Receive digital input only, all other character input is invalid.
  68. Es_nohidesel (&h100=) //When the edit box loses input focus, the selected text is hidden, and the selection in the body remains the same.  The selection in the body is invalidated by default and is displayed only when the input focus is obtained.
  69. Es_readonly set the edit box to read-only?
  70. Es_password (&h20=) //causes all typed characters to be displayed with "*".
  71. Es_wantreturn //enables multi-line editor to receive the ENTER key and wrap.  If you do not specify this style, pressing ENTER will select the default command button, which often causes the dialog box to close.
  72. List box actions:
  73. Lb_findstring (&h18f=399),-1,byval //string looks up the strings of the list items, the return value = The index of the list item where the string is located.  1 indicates that the lookup starts at line No. 0, and if a valid list item index value is changed, the lookup starts from that row.
  74. Lb_itemfrompoint (&h1a9=425) //Gets the index of the list item where the cursor is located
  75. Lb_sethorizontalextent (&h194=404),//length, 0 sets the horizontal scroll bar of the list box and the scrolling length, the length is the pixel value
  76. Combo box Action:
  77. Cb_showdropdown (&h14f),1 (0),0//open (Close) the list of combo boxes
  78. Tvm_setbkcolor (&h1100+29=4381)//Set the background color of the Extended tree list control (constant at the beginning of the TVM)
  79. Common window messages:
  80. Wm_getfont (&h31=)//Get the font (handle) of the current control drawing text
  81. Wm_gettext (&hd=),//variable length, variable gets the title of the form, variable must be pre-assigned to empty string (Chr (0)), variable length =len (variable)
  82. Wm_settext (&hc=),0,byval //"string" setting the title of the form
  83. Wm_nclbuttondown (&ha1=161),2,0 //In the non-client area, that is, the border and the title bar (if the definition is a component, then the non-client area including form, etc.) press the left mouse button;
  84. Wm_lbuttondown (&h201=513),2,0 //In the client area, that is, except for the border and the title bar, press the left mouse button
  85. Wm_vscroll (&h115=277), &h10000*p+sb_thumbposition (&H4),0 //synchronized scrolling text, p is the position change amount
  86. Wm_paint
  87. Wm_user (&h400 = 1024x768)
  88. Wm_cut (&h300=768),0,0//Cut
  89. Wm_copy (&h301=769)),0,0//copy
  90. Wm_paste (&h302=770)),0,0 ///paste
  91. Wm_clear (&h303=771)),0,0 //delete
  92. Wm_undo (&h304=772)),0,0/undo
  93. Press the button message:
  94. Bm_setstyle (&HF4)//Set button style
  95. Bs_radiobutton (&H4) //Radio knob-type button, is the parameter used by the Bm_setstyle


For example, a message to Windows lets the text be selected.

[Delphi]View PlainCopy
    1. SendMessage (Text1. Hwnd,em_getsel,0,-1);

Full text selection.

http://blog.csdn.net/sushengmiyan/article/details/7836500

Message delivery for Windows-message box

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.