Open New Form on button click, Close exisiting Form, VS2010 - visual-studio-2010

Sorry for asking a really dumb question. I've been a vb6 programmer for years and I am just developing my first application in VS2010.
I'm trying to open a new form on a button click and close the current form.
In VB6 I would have used.
Me.Close
Form.Show vbmodal
I've googled for a solution and it tells me the code is basically the same
form.show()
me.close
However, when I click the button the program closes. If I take away me.close, the form shows.
I'm really confused.
Thanks
John

If the form that you are closing is the one that starts your application ('startup form'), then your application ends.
Try with
Me.Hide()
form.Show()
But you could also change the Property Shutdown mode for the project.
On the Applications Tab set the Shutdown mode to When the last form closes.
Of course, in this case, the order of the commands should be
form.Show()
Me.Close()

Try with Me.Hide() in place of Me.Close().

Dim f As New Form1
f.Show()
Checked!! as you see I declare f as new Form1, here you have to change with your form name under form properties then the next line is to show the copy of f!

Related

Crash when calling getOpenFileName from QItemDelegate's custom editor

Prerequisites:
I have a custom QItemDelegate which creates custom editor for treeview items.
The editor consists of a QLineEdit and QToolButton. The button is used to open the file dialog for selecting the file and placing it's path into line edit.
I use a call to QFileDialog::getOpenFileName to open the file dialog. The dialog is native Windows file dialog (this is important).
When the editor is created the first time, everything works ok no matter how often I press that button. But after the editor is closed and reopened again the first press on the button results in a crash. The reason of the crash is that my custom editor eventually gets deleted.
Here is some code:
void CCustomEditor::on_RunSetupBtn_clicked()
{
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
if (qFilename.isEmpty())
return;
SetCommandLine(QDir::toNativeSeparators(qFilename), m_qParameters);
}
I have made some digging and found out that calling WinAPI function GetOpenFileName results in the very same way: my editor gets deleted (although crash doesn't happen). It seems that Qt calls it also internally.
I have tracked down the reason of why my editor gets deleted and found out that when getOpenFileName is called, active window changes and focus changes with it.
In the first case the focus is moved from TreeView item, but in the second case it is moved from the editor itself!
This results in the deletion of editor because of 'focus out' event.
It is important to say that this situation doesn't happen if 'DontUseNativeDialog' flag is set when file dialog is created. Therefore this should be a bug in Qt's window management between native windows and Qt widgets.
As a workaround of this bug I suggest the following solution: before making a call to getOpenFileName set the focus to the button itself.
m_pUI->RunSetupBtn->setFocus();
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
The other workaround is to use 'DontUseNativeDialog' flag, but the resulting file dialog doesn't look native, in fact it is quite ugly.
If someone has a better solution, feel free to share.
I have a similar problem with getOpenFileName and getSaveFileName. My solution is, after getOpenFileName, getSaveFileName or at the end of the function set the windows as active with activateWindow().

Is it possible to disable "Display hidden-mode notification tooltip" programmatically on UFT?

I'm trying to run some automation tests in my application but the UFT Hidden-mode notification tooltip is coming in front of the objects in the screen, preventing my tests to run.
I know I can un-check the option "Display hidden-mode notification tooltip" in Remote Agent Settings to fix this issue and it works fine on my machine after I do this, but these tests are executed in other machines, by other users in my company, and it would be a real effort to tell each and everyone of them to change this setting on their machine.
Is it a way to disable this checkbox programmaticaly instead?
EDIT:
Here is a little more detail on where this is affecting me:
I'm testing a Web application and in some of my test cases I need to download a file from this application. I do that by clicking on "Save As" in the context menu which is displayed on a notification bar at the bottom of the browser.
Following is the portion of code to perform such operation:
Dim brwBottom
Set brwBottom = Browser("brw_Bottom_Save_As")
If brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Exist Then
brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Click
brwBottom.WinMenu("wm_Selector").Select "Save As"
End If
This works fine on my machine because UFT notification is not being displayed, but in other machines where the UFT Notification is displayed, it overlaps the menu and my script is unable to select the "Save As" option. So, in case it is not possible to programmatically close this notification at runtime, is there any alternative solution to click on the "Save As" button, even with this notification overlapping it?
I managed to identify the UFT Notification tooltip and close it. With this, there is no more objects in front of the button I need to click and my script can be executed successfully.
Following is the code used. I'm not marking this as the acceptable answer yet because I am still waiting for my team to accept the solution, but this works.
Dim brwBottom
Set brwBottom = Browser("brw_Bottom_Save_As")
' To close UFT Notification Tooltip, if exists
If Window("regexpwndtitle:=NotificationWindow").Exist(2) Then
If InStr(Window("regexpwndtitle:=NotificationWindow").GetROProperty("nativeclass"),"UFTRemoteAgent") > 0 Then
Window("regexpwndtitle:=NotificationWindow").Close
End If
End If
If brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Exist Then
brwBottom.WinObject("wo_Notification").WinButton("wb_Selector").Click
brwBottom.WinMenu("wm_Selector").Select "Save As"
End If
Create UFT GUI test and include these three lines:
extern.Declare micLong, "WritePrivateProfileString", "kernel32.dll", "WritePrivateProfileString", micString, micString, micString, micString
extern.WritePrivateProfileString "RemoteAgent", "ShowBallon", "0", Environment("ProductDir") + "\bin\mic.ini"
systemutil.CloseProcessByName "UFTRemoteAgent.exe"
From ALM, run it on all your UFT machines.
Notes:
This will switch the flag that controls such tooltip to be off, so next time Remote Agent launches will read it and won't display the tooltip anymore.
The third line will kill UFT's remote agent for GUI testing which is in charge of the communication between UFT and ALM Client and this will cause an error in ALM's Automatic Runner (The RPC server is unavailable)... just ignore it. We need to kill it so it is re-launched next time we try to run a test from ALM (as mentioned above, new value for tooltip will be read)
EDIT:
I just found something interesting: this flag is actually saved in two locations:
mic.ini
RemoteAgentGUISettings.xml
but the one that actually makes the change effective is RemoteAgentGUISettings.xml (it seems they're switching from .ini files to .xml... which makes sense). In this case, the code will change a little, but the idea is the same:
filePath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%appdata%") + "\Hewlett-Packard\UFT\Persistence\Dialogs\RemoteAgentGUISettings.xml"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load filePath
Set nNode = xmlDoc.selectsinglenode ("//SettingsViewModel/IsShowBalloon")
nNode.text = "false"
strResult = xmldoc.save(filePath)
systemutil.CloseProcessByName "UFTRemoteAgent.exe"
This time I made sure it works ;)
I totally understand your pain because my projects also need to interact with IE download bar. Usually, I use SendKeys to handle download activity in different projects.
When download bar comes out, you can send ALT+N first to set focus on download bar, then send some tab keys to select on Save, and some Down Arrow key to select SaveAs.
In this way, you don't need to bother handle UFT notifications...
Sample SendKeys codes can be easily Googled.
Can you activate the desired browser with the following, and then try to do Save as
hwnd = Browser("title:=.*").GetROProperty("hwnd")
Window("hwnd:=" & hwnd).Activate

Close a newly opened tab or window in Selenium IDE

Using Selenium IDE with Windows7 and Firefox, an automatic click on a link may produce either a new tab or a new window.
close() closes the original window or tab, not the new one. Maybe if I had the ID of the newly created one I could select it and then close it but I don't know how to do this automatically. I've asked on the Selenium forum and read the questions here, but they focus on WebDriver, not the IDE. Any help would be appreciated!
Stig
I had same problem and found a solution:
click on link that opens the new tab
add command waitForPopUp
set focus to new tab via command selectPopUp
make your verifications or other commands regarding to your content in new tab
use command close to close tab
use command selectWindow to set focus to the old window
Screenshot of my Selenium IDE commands:
That works for me.
Use selectWindow(windowID) command to switch to new window in Se IDE. You can select new window by its windowID/name/title.
Hope this helps...
Agreed with surya use selectWindow(windowID), you can get the window title by right click on the page check the option verifyTitle and in front of that you have your Title. Hope it helps out.
selectWindow(windowID) has option to mention title of the webpage/window as a way to identify the target window.
syntax = selectWindow title=My Special Window
note: title = title of webpage that is visisble in webpage's title bar. Or right click on webpage and select menu "Page source". In source doc, select the text between ....
So if the title of webpage = My Special Window, you will see My Special Window.
Hope this will help.
Swasati Paul
You could use the iterator to iterate amongst the windows, close the new window and come back to the originalWindow. And you can put this under the try block because it will only iterate if a new window opens. Or else, it will continue executing normally in the current window.
try{
Set <Strings> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentPage = it.next();
String newPage = it.next();
driver.switchTo().window(newPage);
driver.close(); //it will close the new window and automatically come back to the currentPage
}
finally
{
//continue with your script here
//this script will run regardless of the execution of the execution of the try block
}

VB run code on start of the application

I am a Java programmer and don't know much about VB.
My task:
Create an exe. When I run the exe it will read a text file, and after that it will display the content. After that the application code ends.
What i have done:
I have created a project and created a button on the form. On click of the button I have given the option to read.
Problem
I am not able to find the event which has to be used to run code on start up and code to end the application when my task completes.
Please help me with the process which I have to follow. If the code is provided, it's best, but if somebody knows any web resources it will also be a great help.
You can create a Visual Basic 6 program to run without any form.
You need to create a module. Put a Public Sub Main inside of it.
Then in under Project Properties, General Tab; change the startup object to be Sub Main.
To do something at form's start up, use Form_Load() event.
To close a form, use unload me.
To close your application, use end.
Hope this solves your problem. If not, you are welcome for further queries.

Getting screenshot of Child Window

If I have a handle to a window, how do I take a screenshot of any new child windows when they show up? Right now I have code that takes a screenshot every .1 seconds of a windows form. When I click on a drop down list box the subsequent screenshots do not include it. Using spy++ I can see that a new child window was created but not sure how to make sure it is included in my screenshots. Does anybody have any code that might include child windows?
Thanks in advance,
Bob
Yes, the dropdown of a ComboBox is a special window, a LISTBOX. .NET doesn't provide a built-in way to get the handle for it, you can P/Invoke SendMessage and send the CB_GETCOMBOBOXINFO message. COMBOBOXINFO.hwndList contains the handle.
Note that there are other controls that behave that way, DateTimePicker for example. Also note that the window can extend beyond the bounds of your form.
The code in this thread should be helpful to get the P/Invoke right.

Resources