|
I want to send Key to another form of another application using API function.
Can you give me source code to do it ?
Hung
|
|
|
|
|
Here is a code snippet to send commands to the Calculator. Hope it helps:
<br />
Dim ProcID As Integer<br />
' Start the Calculator application, and store the process id.<br />
ProcID = Shell("CALC.EXE", AppWinStyle.NormalFocus)<br />
' Activate the Calculator application.<br />
AppActivate(ProcID)<br />
SendKeys.SendWait("22")<br />
SendKeys.SendWait("*")<br />
SendKeys.SendWait("44")<br />
SendKeys.SendWait("=")<br />
|
|
|
|
|
When I apply this code to Command Prompt( Windows XP ) nothing happens.
I don't know why, I have used Win32 API with VB and all things work smoothly. But I don't know how to apply that code to VB.NET
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Integer) As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_CHAR As Long = &H102
Private Const CH_A As Byte = 65
Private Sub Command1_Click()
Dim handleactive As Long
Dim recString As String
Dim handle As Long
handleactive = GetFocus()
'Call Shell("c:\windows\system32\cmd.exe", vbMaximizedFocus)
'handleactive = GetActiveWindow()
handle = FindWindowEx(0, 0, "ConsoleWindowClass", "C:\WINDOWS\system32\cmd.exe")
DoEvents
SendMessage handle, WM_CHAR, vbKeyC, 0
SendMessage handle, WM_CHAR, vbKeyD, 0
SendMessage handle, WM_CHAR, vbKeyReturn, 0
recString = String(100, Chr$(0))
GetWindowText handleactive, recString, 50
Text1 = recString
End Sub
Hung
|
|
|
|
|
I modified the code for the command prompt as shown below and seems to work fine:
<br />
Dim ProcID As Integer<br />
' Start the application, and store the process id.<br />
ProcID = Shell("CMD.EXE", AppWinStyle.NormalFocus, True, 1000)<br />
' Activate the application.<br />
AppActivate(ProcID)<br />
SendKeys.SendWait(" CD \TEMP" + vbCr)<br />
|
|
|
|
|
When I use this code:
handle = FindWindowEx(0, 0, "ConsoleWindowClass", "cmd.exe")
The returned handle is different between VB & VB.NET. So I can't use SendMessage (Win32 API function). I don't understand . Please help me !
|
|
|
|
|
Ok so I have TabControl and dynamically created TabPage with dynamically created RichTextBox. I am trying to use a OpenFileDialog to open a .rtf in a new TabPage in a new RichTextBox and read the selected rtf file into it. Here is the code that I am using. Somewhat new so feel free to show me better ways of doing what I am trying to do.
<br />
Dim sr As StreamReader<br />
<br />
Try<br />
With OpenFileDialog1<br />
If .ShowDialog = Windows.Forms.DialogResult.OK Then<br />
If .FileName.EndsWith(".rtf") Then<br />
<br />
'Declare new object variables<br />
Dim rtbTextArea As New RichTextBox<br />
Dim newTab As New TabPage<br />
<br />
TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control<br />
<br />
With newTab<br />
.Text = OpenFileDialog1.FileName <br />
.Controls.Add(rtbTextArea) 'Add the rich text Box to the new tab control<br />
rtbTextArea.Dock = DockStyle.Fill 'Set Rich Text box area to fill tab page<br />
.Focus()<br />
End With<br />
<br />
For Each ctl As Control In TabControl1.SelectedTab.Controls 'Find RichTextBox control<br />
If TypeOf ctl Is RichTextBox Then<br />
sr = New StreamReader("" & .FileName & "")<br />
ctl.Text = sr.ReadToEnd<br />
End If<br />
Next<br />
Else<br />
MessageBox.Show("Please choose a Rich Text File (.rtf)")<br />
End If<br />
End If<br />
End With<br />
Catch ex As Exception<br />
MessageBox.Show(MessageBoxIcon.Exclamation, "An error has occured. Please make your selections again")<br />
Finally<br />
If Not (sr Is Nothing) Then<br />
sr.Close()<br />
End If<br />
End Try<br />
<br />
Thanks,
Taen Karth
-- modified at 21:47 Friday 2nd September, 2005
|
|
|
|
|
|
Ha, I forgot to add the question didn't I. Here goes...When I use the code above the text that was read is displayed in the wrong tab.
Not sure why...
Thanks,
Taen Karth
-- modified at 4:38 Saturday 3rd September, 2005
|
|
|
|
|
Nevermind I figured it out. I added
TabControl1.SelectedTab = newTab
Right after
TabControl1.TabPages.Add(newTab) 'Add new Tab Page to tab control
Thanks,
Taen Karth
|
|
|
|
|
I need to grab data from labels on my form so I can perform calculations and other things. Problem is I get a item not declared in the module. I would operfer to put the majority of the code into modules and call as necessary. How do I reference the texytboxes, labels and such in the module. E.g grab the values of the objects input them into the module and return what I need.
I have no problem creating functions, it;s just that I perfer to place my functions into a module and call accordingly.
|
|
|
|
|
If I have understood you correctly: You should use the name of your form or in better words the instance of the form which is beind displayed as follows:
frm.Label1.Text, frm.Text1.Text etc.
|
|
|
|
|
I am trying to capture a windows display, but even if it's off the screen.
The BitBlt api works only for a window that is on the screen, as soon as you move it off the screen or mininmize it you can't capture that windows information.
The OleDraw api is almost what I need but it requires you to pass in the object's IUnknown Interface as one of the arguments and I don't know how to find an objects IUnknown Interface.
My question is either, how do you get an objects IUnknown Interface only knowing the windows handle or is there another api like OleDraw that I should be using when I only have the windows handle, to capture the windows display when it's not on the screen.?
|
|
|
|
|
bountycode wrote:
I am trying to capture a windows display, but even if it's off the screen.
You're wasting your time. You can't capture what is never drawn in the first place. This has been discussed in the boards over and over again.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave,
That is not correct, you can capture what the control is displaying even if it's off the screen using the OleDraw api. I've tested this using an embedded browser control on a form and even setting the text property of a command button while it's off-screen then using the OleDraw api I was able to get the correct information that was on the browser and command button. This works because I can pass in the object for the OleDraw api just by referencing the control by name. What I don't know how to do is pass an object to the api from just the handle to the control.
|
|
|
|
|
It works because you're giving the target object a different device context to draw on. You're forcing the control, and it's child controls, to redraw itself on the new device context. It works great for controls that implement the IViewObject interface. Unfortunately, not every control/form/window does this, but Internet Explorer's components do implement it.
The technique can be used to capture the image of HTML as rendered in a browser window. This is how Windows Explorer can generate a small preview of an HTML file in the left pane of an Explorer window.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have an application I wrote using vb.net 2003 and my screen size is 1024x768 and everything looks great. I then transfer that application to another computer who's screen size is 1024x768 and my screeen does not fit? Any way to fix this?
|
|
|
|
|
I don't understand...Both screens are the same size and one looks different??
Thanks,
Taen Karth
|
|
|
|
|
Yes, the LapTop form exceeds the screen size.
|
|
|
|
|
hellow to all ..
i have datagrid in my form .
how can i get information from the field in the datagrid when i pick it or mark it .
thxx a lottt ..
|
|
|
|
|
Use CurrentCellChanged event.
Then to access the tex use:
<br />
Dim cellText as String<br />
dim row as integer = myGrid.CurrentCell.RowNumber<br />
dim col as integer = myGrid.CurrentCell.ColumnNumber<br />
cellText = myGrid(row,col)<br />
|
|
|
|
|
I'm using DataRowCollection.Find method to locate a row in a DataTable as shown here:
Dim newrow As DataRow
newrow = MyDataSet.MyTable.Rows.Find(5)
After finding the row how do I update all the bound controls on the form to that row. I've used the BindingContext(MyDataSet,"MyDatatable").position in the past and if I use it here how do I know what the position number is?
Thanks again for any help.
|
|
|
|
|
Try using DataView.RowFilter. Reason is that you will get direct access to the DataRow record; however, with find I think you just get a copy of the DataRow record.
|
|
|
|
|
When I load a datagrid from a database, there is a date column that is brought across. But instead of just displaying the date, it displays the Date and an empty time display.
So I get something like this.
Date
---------
30/07/2005 00:00:00
30/07/2005 00:00:00
06/08/2005 00:00:00
When I should be getting :
Date
----------
06/08/2005
|
|
|
|
|
I use:
<br />
Dim newTime As Date = Now.Date<br />
Dim strNewTime As String = newTime<br />
Hope that helps.
Thanks,
Taen Karth
|
|
|
|
|
I am a vb.net learner. Is there any easy utility in vb.net to declare/define procedure like Tools-->add procedure like VB6.plz give me reply.
|
|
|
|