SendMessage API Functions Apply SendMessage API Functions in PowerBuilder Applications in PowerBuilder
I. Introduction
In PowerBulider, the API function SendMessage can be completed, and some of the PBs are very difficult to use.
Now, the use of the API function in the use of PowerBuilder, exemplifies several aspects of use, in order to play the effect of the brick 引 玉 (The following code can use the Send function in PowerBuilder to replace the SendMessage this API function, Hurry, code is not tested)
Second, function description
SendMessage function description:
Description
Call a window function to send a message to that window. This function will not return unless the message is handled. SendMessageBynum, SendMessageBystring is the "Type Security" declaration form of this function
return value
Long, determined by the specific message
Parameters Table
Parameter type and instructions
HWND Long, the handle of the window to receive the message
WMSG long, message identifier
WPARAM Long, depending on the message
LPARAM ANY, depending on the message
The function send function has been used in PowerBuilder.
Function State: Send (Handle, Message #, LOWORD, Long)
Send function description:
Description
Call a window function to send a message to that window. This function will not return unless the message is handled.
return value
Long, determined by the specific message
Parameters Table
Parameter type and instructions
Handle Long, the handle of the window to receive the message
Message # long, message identifier
LowWord Long, depending on the message
Long Long, depending on the message
3, application example
Define external functions reference declaration:
Funcation Long SendMessage (Long HWND As Long, Long WMSG, Long WPARAM, Long LPARAM) Library "User32.dll" Alias for "SendMessagea"
Funcation Long ReleaseCapture () library "user32.dll"
Define instance variables:
Constant Long LB_ItemFromPoint = 425
Constant Long htcaption = 2
Constant Long WM_NCLBUTTONDOWN = 161
Constant Long em_getline = 404
Constant Long em_getlinecount = 399
Constant long em_getlinecount = 186
Constant long em_getline = 196
Constant Long TVM_SetItemHeight = 4379
Constant long em_linescroll = 182
Constant long em_limittext = 197
1. Detect position items when mouse movement in the list box
PowerScript:
Write the following code in the custom event UE_MOUSEMOVE (PBM_MOUSEMOVE) of the list box:
pos = unitstopixels (parent.pointerx (), XUnitsToPixels!) unitstopixels (parent.pointery (), yUnitsToPixels!) * 65536idx = SendMessage (handle (this), LB_ITEMFROMPOINT, 0, pos) If idx <65536 Then sle_1.Text = lb_1.text (idx)
2, find the matching item in the list box
PowerScript:
Open event of the window:
lb_1.additem ("software")
LB_1.Additem ("Computer Games")
lb_1.additem ("TV")
LB_1.Additem ("TV station")
LB_1.Additem ("Computer")
LB_1.Additem ("Computer Game Software")
Modified event for the SINGLINEEDIT control:
Long li_index
LI_INDEX = SendMessage (Handle (this), em_getlinecount, -1, sle_1.text)
lb_1.selectItem (li_index)
3, add horizontal scroll strips for Listbox
PowerScript:
Open event of the window:
lb_1.additem ("software")
LB_1.Additem ("Computer Games")
lb_1.additem ("TV")
LB_1.Additem ("TV station")
LB_1.Additem ("Computer")
LB_1.Additem ("Computer Game Software")
SendMessage (Handle (this), EM_GETLINE, 250, 0)
4. Implement the drag no title bar
PowerScript:
Custom event UE_LBUTTONDOWN (PBM_LBUTTONDOWN) in the window
Long ReturnVal
x = releasecapture ()
Returnval = sendMessage (hwnd, wm_nclbuttondown, htcaption, 0)
5, get multiple lines of text box
PowerScript:
CommandButton's Clicked event
Messagebox ("", sendMessage (Handle (MLE_1), EM_GETLINECUNT, 0, 0))
6, set the tree list control header line height
PowerScript:
Tv_1 constructor event:
SendMessage (Handle (TV_1), TVM_SETITETETETETETETEMHT, 60, 0)
7. Break through the limitations of multi-line text box 32k in PowerBuilder
PowerScript:
SendMessage (Handle (MLE_1), EM_LIMITTEXT, 65534, 0)
8, use the program code to control the text box and rolling
PowerScript:
SendMessage (Handle (SLE_1), EM_LINESCROLL, 0, 1) //
SendMessage (Handle (SLE_1), EM_LINESCROLL, 0, -1) //
SendMessage (Handle (SLE_1), EM_LINESCROLL, 1, 0) // Right Roll
SendMessage (Handle (SLE_1), EM_LINESCROLL, -1, 0) // Left volume
Third, conclude
When writing a PowerBuilder app, you should fully invoke the associated API function to expand some of the PB's shortcomings.