Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997

Streamline Your API Declares, Part 2

While we are speaking of SendMessage, there is another trick you may find interesting enough to include in your programming habits. When used with some particular messages, the lParam argument is really considered as two words combined. The EM_LINESCROLL can scroll a multilined text box, the low word of lParam contains the number of lines to scroll vertically (positive values scroll up), and the high word contains the number of lines to scroll horizontally (positive values scroll left); other, similar messages are EM_SETSEL for text boxes, CB_SETEDITSEL for combo boxes, and LB_SELITEMRANGE for list boxes. In such cases you need to prepare the long value to be passed to the routine, which slows down your code and makes it less readable. It seems that a simple multiplication should do the work:

 
' scroll a multilined textbox "HO" 
' lines horizontally
' and "VE" lines vertically
' beware: this approach does NOT 
' work properly
longValue& = HO * 65536& + VE




The above code does not work correctly when HO is positive and VE is negative, and for a more general scrolling routine you have to resort to a more convoluted and slower method:

 
tmp$ = Right$("000" & Hex$(HO), 4) & _
        Right$("000" & Hex$(VE), 4)
longValue = Val("&H" & tmp$)




The solution is declaring an aliased function that splits the lParam into two distinct parameters of Integer type, as in:

 
Declare Sub SendMessageSub2 Lib _
        "User" Alias "SendMessage" _
        (ByVal hWnd%, ByVal msg%, ByVal _
        wParam, ByVal lParam1%, _
        ByVal lParam2%)




Now the call is much simpler:

 
SendMessageSub2 Text1.hWnd, _
        EM_LINESCROLL, 0, HO, VE




The trick works because a push of a Long value onto the stack has the same effect as the push of its high word followed by the push of its low word.

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date