diff --git a/example/bin/taskdialog.exe.manifest b/example/bin/taskdialog.exe.manifest index e702396e18..e5a62c5ece 100644 --- a/example/bin/taskdialog.exe.manifest +++ b/example/bin/taskdialog.exe.manifest @@ -3,7 +3,7 @@ taskdialog @@ -18,7 +18,7 @@ - + @@ -45,8 +45,8 @@ + /> - \ No newline at end of file + diff --git a/example/taskdialog.dart b/example/taskdialog.dart index 92c4ffc838..afc9c59802 100644 --- a/example/taskdialog.dart +++ b/example/taskdialog.dart @@ -13,6 +13,11 @@ // taskdialog.exe.manifest. Place the compiled taskdialog.exe in the same folder // as the manifest and then when you run this it should display two task dialog // samples. +// +// If that doesn't work, make sure that external manifests are enabled in the +// registry. This can be done by running the following command in an elevated +// command prompt: +// REG ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide" /v PreferExternalManifest /t REG_DWORD /d 1 /f import 'dart:ffi'; @@ -20,18 +25,22 @@ import 'package:ffi/ffi.dart'; import 'package:win32/win32.dart'; void showSimpleTaskDialog() { - final windowTitle = 'Dart TaskDialog Sample'.toNativeUtf16(); - final mainInstruction = 'Please read this important message'.toNativeUtf16(); - final content = 'Task dialogs are great for sharing a longer string of ' - 'explanatory content, where you need a user to read an instruction ' - 'before making a decision. Of course, you cannot guarantee that the ' - "user will actually read the text, so it's important that you also " - 'provide an undo function for when the wrong choice is selected.' - .toNativeUtf16(); - final buttonSelected = calloc(); + using((arena) { + final windowTitle = + 'Dart TaskDialog Sample'.toNativeUtf16(allocator: arena); + final mainInstruction = + 'Please read this important message'.toNativeUtf16(allocator: arena); + final content = 'Task dialogs are great for sharing a longer string of ' + 'explanatory content, where you need a user to read an instruction ' + 'before making a decision. Of course, you cannot guarantee that ' + 'the user will actually read the text, so it\'s important that you ' + 'also provide an undo function for when the wrong choice is ' + 'selected.' + .toNativeUtf16(allocator: arena); + final buttonSelected = arena(); - try { - final hr = TaskDialog( + try { + final hr = TaskDialog( NULL, NULL, windowTitle, @@ -40,83 +49,83 @@ void showSimpleTaskDialog() { TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_OK_BUTTON | TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CANCEL_BUTTON, TD_INFORMATION_ICON, - buttonSelected); - if (SUCCEEDED(hr)) { - switch (buttonSelected.value) { - case MESSAGEBOX_RESULT.IDOK: - print('User clicked on the OK button.'); - default: - print('User canceled the task dialog.'); + buttonSelected, + ); + if (SUCCEEDED(hr)) { + switch (buttonSelected.value) { + case MESSAGEBOX_RESULT.IDOK: + print('User clicked on the OK button.'); + default: + print('User canceled the task dialog.'); + } } + } on ArgumentError { + print( + 'If you see an error "Failed to lookup symbol", it\'s likely because ' + 'the app manifest declaring a dependency on comctl32.dll v6 is ' + 'missing.\n\nSee the comment at the top of the sample source code.\n', + ); + rethrow; } - // ignore: avoid_catching_errors - } on ArgumentError { - print('If you see an error "Failed to lookup symbol", it\'s likely because ' - 'the app manifest\ndeclaring a dependency on comctl32.dll v6 is ' - 'missing.\n\nSee the comment at the top of the sample source code.\n'); - rethrow; - } finally { - free(windowTitle); - free(mainInstruction); - free(content); - } + }); } void showCustomTaskDialog() { - // Note that this example does not explicitly free allocated memory, since it - // returns quickly to the command prompt. As part of a real app, you'd - // certainly want to free each string here. - final buttonSelected = calloc(); - - final buttons = calloc(2); - buttons[0] - ..nButtonID = 100 - ..pszButtonText = - 'Take the blue pill\nThe story ends, you wake up in your bed and ' - 'believe whatever you want to believe.' - .toNativeUtf16(); - buttons[1] - ..nButtonID = 101 - ..pszButtonText = - 'Take the red pill\nYou stay in Wonderland, and I show you how deep ' - 'the rabbit hole goes.' - .toNativeUtf16(); + using((arena) { + final buttonSelected = arena(); - const matrixDescription = - 'In The Matrix, the main character Neo is offered the choice between ' - 'a red pill and a blue pill by rebel leader Morpheus. The red pill ' - 'represents an uncertain future: it would free him from the enslaving ' - 'control of the machine-generated dream world and allow him to escape ' - 'into the real world, but living the "truth of reality" is harsher and ' - 'more difficult. On the other hand, the blue pill represents a ' - 'beautiful prison: it would lead him back to ignorance, living in ' - 'confined comfort without want or fear within ' - 'the simulated reality of the Matrix.'; + const numberOfButtons = 2; + final buttons = arena(numberOfButtons); + buttons[0] + ..nButtonID = 100 + ..pszButtonText = + 'Take the blue pill\nThe story ends, you wake up in your bed and ' + 'believe whatever you want to believe.' + .toNativeUtf16(allocator: arena); + buttons[1] + ..nButtonID = 101 + ..pszButtonText = + 'Take the red pill\nYou stay in Wonderland, and I show you how deep ' + 'the rabbit hole goes.' + .toNativeUtf16(allocator: arena); - final config = calloc() - ..ref.cbSize = sizeOf() - ..ref.pszWindowTitle = 'TaskDialogIndirect Sample'.toNativeUtf16() - ..ref.pszMainInstruction = 'Which pill will you take?'.toNativeUtf16() - ..ref.pszContent = - 'This is your last chance. There is no turning back.'.toNativeUtf16() - ..ref.hMainIcon = TD_WARNING_ICON.address - ..ref.pszCollapsedControlText = 'See more details.'.toNativeUtf16() - ..ref.pszExpandedControlText = matrixDescription.toNativeUtf16() - ..ref.dwFlags = TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS - ..ref.cButtons = 2 - ..ref.pButtons = buttons; + const matrixDescription = + 'In The Matrix, the main character Neo is offered the choice between a ' + 'red pill and a blue pill by rebel leader Morpheus. The red pill ' + 'represents an uncertain future: it would free him from the enslaving ' + 'control of the machine-generated dream world and allow him to escape ' + 'into the real world, but living the "truth of reality" is harsher and ' + 'more difficult. On the other hand, the blue pill represents a ' + 'beautiful prison: it would lead him back to ignorance, living in ' + 'confined comfort without want or fear within the simulated reality of ' + 'the Matrix.'; - final hr = TaskDialogIndirect(config, buttonSelected, nullptr, nullptr); + final config = arena(); + config.ref + ..cbSize = sizeOf() + ..pszWindowTitle = + 'TaskDialogIndirect Sample'.toNativeUtf16(allocator: arena) + ..pszMainInstruction = + 'Which pill will you take?'.toNativeUtf16(allocator: arena) + ..pszContent = 'This is your last chance. There is no turning back.' + .toNativeUtf16(allocator: arena) + ..hMainIcon = TD_WARNING_ICON.address + ..pszExpandedInformation = + matrixDescription.toNativeUtf16(allocator: arena) + ..dwFlags = TASKDIALOG_FLAGS.TDF_USE_COMMAND_LINKS | + TASKDIALOG_FLAGS.TDF_EXPAND_FOOTER_AREA + ..cButtons = numberOfButtons + ..pButtons = buttons; - if (SUCCEEDED(hr)) { - if (buttonSelected.value == 100) { - print('Ignorance is bliss.'); - } else { - print("I've been expecting you, Mr Anderson."); + final hr = TaskDialogIndirect(config, buttonSelected, nullptr, nullptr); + if (SUCCEEDED(hr)) { + if (buttonSelected.value == 100) { + print('Ignorance is bliss.'); + } else { + print("I've been expecting you, Mr. Anderson."); + } } - } else { - print('that failed.'); - } + }); } void main() {