Calling Vista's TaskDialog API
Calling the TaskDialog API from FoxPro (in Vista build 5308) turned out to be a bit harder than
Craig Boyd makes it sound but once it emerged that the string parameters have to be manually null-terminated and converted to Unicode it became much easier (if you don't convert the strings the output looks like
this)
declare integer TaskDialog in "comctl32.dll" ;
integer nHWND, ;
integer hInstance, ;
string cTitle, ;
string cDescription, ;
string cContent, ;
integer nButtons, ;
integer nIcon, ;
integer @ nResult
* Icons
#define TD_ICON_BLANK 100
#define TD_ICON_WARNING 101
#define TD_ICON_QUESTION 102
#define TD_ICON_ERROR 103
#define TD_ICON_INFORMATION 104
#define TD_ICON_BLANK_AGAIN 105
#define TD_ICON_SHIELD 106
* Button values: ABORT and IGNORE appear to have been deprecated.
#define TD_OK 1
#define TD_YES 2
#define TD_NO 4
#define TD_CANCEL 8
#define TD_RETRY 16
#define TD_CLOSE 32
cTitle = "Taskdialog title bar text"
cDescription = "Description text"
cContent = "Main content of task dialog text: what to do and " + ;
"where to do it"
cTitle = strconv(cTitle + chr(0), 5)
cDescription = strconv(cDescription + chr(0), 5)
cContent = strconv(cContent + chr(0), 5)
nButton = 0
nReturn = TaskDialog(_vfp.hwnd, 0, cTitle, cDescription, cContent, ;
TD_OK + TD_CLOSE, TD_ICON_SHIELD, @nButton)
if nReturn = -2147024809
? "Invalid arguments were passed"
else
do case
case nButton = 1
? "You pressed OK"
case nButton = 2
? "You pressed Cancel"
case nButton = 4
? "You pressed Retry"
case nButton = 6
? "You pressed Yes"
case nButton = 7
? "You pressed No"
case nButton = 8
? "You pressed Close"
otherwise
? "Return value was " + transform(nButton)
endcase
endif