Faceți căutări pe acest blog

luni, 9 februarie 2015

API Messagebox

VFP's native Messagebox() has some limitations.
1 The maximum length of the message is 1024 (it appears that characters after the 1024th are truncated)
MessageBox(SPACE(1023)+"123", "Message title", 0)
2 Unicode characters cannot be showed
3 Other limitations

API Messagebox() is easy to be used and has no such restrictions.
There are two type of messageboxes:
- MessageBoxA, useful for ASCII messages
- MessageBoxW, useful for Unicode messages

1 In the first example, is shown a message, with more than 1024 characters:
DECLARE INTEGER MessageBoxA IN user32;
    INTEGER hWindow, STRING lpText,;
    STRING lpCaption, LONG uType

= MessageBoxA(_screen.HWnd, SPACE(5000)+"123", "Message title", 0) 



2 The second example contains another set of buttons (6)
DECLARE INTEGER MessageBoxA IN user32 INTEGER hWindow, STRING lpText,STRING lpCaption, LONG uType
 

= MessageBoxA(_screen.HWnd, "Well ?"+CHR(13)+"Oh, no, no, no!", "Message title", 6)

3 The window shown in front of all windows from your desktop (WS_EX_TOPMOST style => 0x1000)
DECLARE INTEGER MessageBoxA IN user32 INTEGER hWindow, STRING lpText,STRING lpCaption, LONG uType
= MessageBoxA(_screen.HWnd, "Well ?", "Message title", 0x1000)


This style can be applied even to VFP messagebox:
MESSAGEBOX("AAAAA !",0x1000)


4  The ability to display Unicode characters.
To achieve this, instead of MessageBoxA must be used MessageBoxW.
The message and the title are strings ended with a CHR(0).
Regular text must be converted with STRCON(...,5), but can be used Unicode characters as a blob constant. (See http://www.news2news.com/vfp/?function=73)

Example for regular text
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, STRCONV("Well ?"+CHR(13)+"Oh, no, no, no!"+CHR(0),5), STRCONV("Message title"+CHR(0),5), 0)


Examples for blob constant (for Unicode, see http://unicode-table.com/en/)

 Character "0" is Unicode 0x0030. As blob constant will be written 0h3000 (note the reversed order of the two bytes). Because the string must be ended with a CHR(0), displaying a "0" become :
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h300000, STRCONV("Message title"+CHR(0),5), 0)


To display "01", the blob constant will be 0h3000310000, where 3000 is Unicode "0", 3100 is Unicode "1" and 00 is the string terminator.
DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h3000310000, STRCONV("Message title"+CHR(0),5), 0)


Note that some characters might not be displayed.
 Another Unicode message.

DECLARE INTEGER MessageBoxW IN user32 INTEGER hWindow, STRING lpText, STRING lpCaption, LONG uType
= MessageBoxW(_screen.HWnd, 0h26094709350940092E09470935093E0900, STRCONV("Message title"+CHR(0),5), 0)

See http://www.tek-tips.com/viewthread.cfm?qid=1743552

Niciun comentariu:

Trimiteți un comentariu