get OpenFileDialog button pressed - visual-c++

I'm using an OpenFileDialog to let the user chose a file to open.
it works, but if I chose a file and insted of pressing OK I press CANCEL it still opens the file because I picked up one.
I found this code in the MSDN, but I can't see ::DialogResult::OK in my apllication
if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )
{
if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
{
// Insert code to read the stream here.
myStream->Close();
}
}
my code is:
fileD1->ShowDialog();
while(!fileD->FileName->Lenght!=0)
{
}
and here I open the file
any other idea of how to know which button I pressed?
I'm using c++ and visual studio 2008

save the return of this ->> openFileDialog1->ShowDialog()
into a value and then check the value
DialogResult::OK
or
DialogResult::CANCEL

Related

Which HID key code to use for KEYCODE_BACK button mapping?

Platform:
STB Xiaomi Mi Box S 4
OS Version:
Android Version 9
Issue description:
I want to use the USB keyboard gadget to control the box. I mapped the remote controller buttons (arrow buttons/select/home) into corresponding HID key codes following the page. However, none of the specified/corresponding key codes (0x00f1, 0x009e) for the KEYCODE_BACK button is working as expected.
Question:
Do you maybe know which HID key code should be used for the BACK button?
Appreciated any help!
I found detailed document about HID usages. I hope you can find your answer from the pdf.
PDF: https://usb.org/sites/default/files/hut1_21.pdf
You may use the following code to determine if the Key is Back / Menu on the Android device / key code
if ((event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_MENU || event.getKeyCode() == KeyEvent.KEYCODE_BUTTON_MODE) && event.getRepeatCount() == 0) {
if( onBackPressed() ) { // function to determine if we should block the action in your code and do something else return true if you want to proc
return true;
} else {
// let the Android system handle the back button
return false;
}
}

In Linux, Which component decides to open a new window in gedit?

Let's consider that I open a file with the command gedit toto1.txt, a new window shows up with the content of toto1.txt. This sound familiar and usual, however the two following cases are not that straight to undertand: (1) a new command (let's says gedit toto2.txt) open a new tab in the previous window and (2) a new command (let's says gedit toto3.txt) will open a new tab in a new window.
My question is : which component decide to open the new window in case (2) and what are the condition to do so ? Why It did not opened a new window in case (1) ?
Any idea ?
It's gedit itself that makes that decision. Let's take a look at the source code. The function open_files will open a new window when it cannot find an active window (or when the flag --new-window was explicitly specified).
static void
open_files (GApplication *application,
gboolean new_window,
...)
{
GeditWindow *window = NULL;
if (!new_window)
{
window = get_active_window (GTK_APPLICATION (application));
}
if (window == NULL)
{
gedit_debug_message (DEBUG_APP, "Create main window");
window = gedit_app_create_window (GEDIT_APP (application), NULL);
gedit_debug_message (DEBUG_APP, "Show window");
gtk_widget_show (GTK_WIDGET (window));
}
...
}
So what's an "active window"? Let's look at get_active_window:
static GeditWindow *
get_active_window (GtkApplication *app)
{
GdkScreen *screen;
guint workspace;
gint viewport_x, viewport_y;
GList *windows, *l;
screen = gdk_screen_get_default ();
workspace = gedit_utils_get_current_workspace (screen);
gedit_utils_get_current_viewport (screen, &viewport_x, &viewport_y);
/* Gtk documentation says the window list is always in MRU order */
windows = gtk_application_get_windows (app);
for (l = windows; l != NULL; l = l->next)
{
GtkWindow *window = l->data;
if (GEDIT_IS_WINDOW (window) && is_in_viewport (window, screen, workspace, viewport_x, viewport_y))
{
return GEDIT_WINDOW (window);
}
}
return NULL;
}
So, the answer is: gedit will open a new window if there's not already a gedit window on screen.
(Well, there could of course be bugs here. I haven't looked very closely. That viewport_x/y stuff looks a bit suspect, as a viewport should have four coordinates: top/bottom/left/right. The code might be confused by multi-monitor setups).
Looks like this is done by gedit itself :)
But, if you want to open document in new window you can use --new-window switch. Try to call gedit with --help from command line.
If you need an straight answer on question "How gedit determine is it can use existing window or must open a new one?" i think you must see the gedit source code at https://github.com/GNOME/gedit

How to copy the entered text in dialog with button from code?

I want to copy the text in DialogBox in my clipboard from code after button click.
I need in my dialog a button with function ctrl+c .
I have this code for my Dialog:
Dialog dialog;
DialogField dialogField;
str string;
;
dialog = new Dialog("My personal dialog");
dialogField= dialog.addFieldvalue(extendedTypeStr(String30), string, "insert the text to be copied");
// ctrl + c button
//I need a button with the function to copy the text entered
dialog.run();
if (dialog.closedOk())
{
}
}
Thanks for help,
enjoy!
Check the TextBuffer.fromClipboard method.
Example use:
TextBuffer txtb = new textBuffer();
#define.ExampleFile(#"c:\test.txt")
#define.ExampleOpenMode("w")
// Set code access permission to help protect the use of TextBuffer.tofile
new FileIoPermission(#ExampleFile, #ExampleOpenMode).assert();
if ( txtb.fromClipboard() )
{
// Got text from clipboard - save it to file
txtb.toFile(#ExampleFile);
}
// Close the code access permission scope.
CodeAccessPermission::revertAssert();
It should be easy to adapt to a dialog.

Set visible Tab or section in dynamics crm 2011

I'm a bit confused how to use that function. I'd like to hide/show tab and section by using this logic.
function setVisibleTabSection(tabname, sectionname, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (sectionname == null)
tab.setVisible(show);
else {
var section = tab.sections.get(sectionname);
if (section != null) {
section.setVisible(show);
if (show)
tab.setVisible(show);
}
}
}
}
I didn't get how to invoke the function properly.
I created this function, also, a tab ("tab_8"), the section name is ("tab_8_section_1"), where I put the text field ("new_conf_report").
after that, I call this function (at the same place where a code was written) as setVisibleTabSection("tab_8", "tab_8_section_1", false);
moreover, I call this function "onLoad" event
however I got the next errors:
" var tab = Xrm.Page.ui.tabs.get(tabname); "'Xrm.Page.ui.tabs' - IS null or it isn't object
"tab.setVisible(show); " Object doesn't support this method
thanks in advance
You can debug your code. Just put the word debugger in JS code. When you launch the form press F12 in tab Script press "begin script" and you are able to step by step understand how the code is working.
If you are passing strings you have to call them like this:
setVisibleTabSection("tab", "Sectname", false);

Implementing a blocking modal view/dialog like in Windows Forms - is it possible?

In short:
I want to show a view or action sheet and only continue code execution after the user has dismissed the view / sheet. So: line one shows the view, line two reads some result variable.
In detail why I would need this:
I'm porting a Windows Forms application over to the iPad. The original implementation has a communication class which uses a web service to communicate with the server. It offers a couple of methods to get data. Conveniently it checks prior to each call if the user still has a valid connection or if he has to re-enter his password for security reasons.
If the password is required, the .NET class shows a modal dialog which blocks any further code executio and if the password was entered, retries the last call it has made before showing the dialog.
Now using CocoaTouch I'm facing a problem. I replaced the code that shows the dialog with a UIActionSheet. Works great but code execution continues immediately, whereas in Windows Forms it is blocked (the next line in Windows Forms after showing the dialogs is to read the entered password from the dialog) until the dialog has been closed.
I tried a Thread.Sleep() until the user dismisses the UIActionSheet but the Thread.Sleep() also blocks the main loop and my view won't even be drawn.
The alternative I currently see is to change all methods in the already working class and give them a return value: if password required, handle it, then retry.
But this means that all over my code I will have to add these checks because at any given moment the password might be needed. That's why it is nested in communication class in Windows Forms.
Any other ideas?
René
Yes, it is possible.
To do this, what you can do is to run the mainloop manually. I have not managed to stop the mainloop directly, so I instead run the mainloop for 0.5 seconds and wait until the user responds.
The following function shows how you could implement a modal query with the above approach:
int WaitForClick ()
{
int clicked = -1;
var x = new UIAlertView ("Title", "Message", null, "Cancel", "OK", "Perhaps");
x.Show ();
bool done = false;
x.Clicked += (sender, buttonArgs) => {
Console.WriteLine ("User clicked on {0}", buttonArgs.ButtonIndex);
clicked = buttonArgs.ButtonIndex;
};
while (clicked == -1){
NSRunLoop.Current.RunUntil (NSDate.FromTimeIntervalSinceNow (0.5));
Console.WriteLine ("Waiting for another 0.5 seconds");
}
Console.WriteLine ("The user clicked {0}", clicked);
return clicked;
}
I think this approach using async/await is much better, and doesn't suffer from freezing the app when rotating the device, or when the autoscrolling interferes and leaves you stuck in the RunUntil loop forever without the ability to click a button (at least these problems are easy to reproduce on iOS7).
Modal UIAlertView
Task<int> ShowModalAletViewAsync (string title, string message, params string[] buttons)
{
var alertView = new UIAlertView (title, message, null, null, buttons);
alertView.Show ();
var tsc = new TaskCompletionSource<int> ();
alertView.Clicked += (sender, buttonArgs) => {
Console.WriteLine ("User clicked on {0}", buttonArgs.ButtonIndex);
tsc.TrySetResult(buttonArgs.ButtonIndex);
};
return tsc.Task;
}

Resources