Welcome to Foxite.COM Community Weblog Sign in | Join | Help

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
Published Tuesday, May 23, 2006 2:29 PM by stuartd
Filed Under:
Attachment(s): taskdialog.jpg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Calling Vista's TaskDialog API

Stuart,

Copied and pasted your code and got the following error:

"Cannot find entry point TaskDialog in the DLL."

On the line beginning with

"Return = TaskDialog(_vfp.hwnd, ..."

I'm running VFP 9 SP 1 under XP Pro SP 2 with themes enabled.

Thoughts?

Malcolm
Tuesday, May 23, 2006 8:38 PM by Malcolm Greene

# re: Calling Vista's TaskDialog API

Malcolm, note that calling Vista features in XP might not produce the desired results. :-)
Tuesday, May 23, 2006 8:57 PM by Garrett Fitzgerald

# re: Calling Vista's TaskDialog API

Garrett,

DOH! I hate when I say things like that! :)

Thanks for the clarification!

Malcolm
Tuesday, May 23, 2006 11:21 PM by Malcolm Greene

# So long MessageBox and thanks for all the memories

For any developer building on Windows, you know there are two ways to build a dialog – roll your
Tuesday, September 19, 2006 10:25 PM by Shell Blog

# So long MessageBox and thanks for all the memories

For any developer building on Windows, you know there are two ways to build a dialog – roll your
Wednesday, September 20, 2006 5:15 AM by Microsoft Daily News

What do you think?

(required) 
required 
(required)