|
Hi,
I'm changing the text of an application writtewn in vb.net using the user32.dll method "SetWindowText".
The text of the application changes but the textchanged event for the form doesn't fire off.
Is there anything I need to do after sending the "SetWindowText" to the recieving app to fire off the even or something within the app itself?
Thanks,
Chris
modified on Thursday, October 28, 2010 6:14 AM
|
|
|
|
|
Of course it doesn't fire. You completely bypassed the .NET code that would have fired the event had the text been changed through the Forms Text proprty settor when you sent the message directly to the windows message pump.
There is nothing you can do to force the target app to fire off it's TextChanged event when you used this method.
Short of extrodinary difficult effort (read: not worth the cost to develop), I don't see how you're going to pull this off.
|
|
|
|
|
You should use SendMessage function to send a WM_SETTEXT message instead. SetWindowText will not cause this message if the target window is not owned by the same process you are making the call, and if WM_SETTEXT is not sent, TextChanged event will not be fired.
Anyway, I think this question should be in Windows API forum.
|
|
|
|
|
Thanks for the hint.
I solved the problem like this:
Using the following declarations:
Public Declare Function apiFindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Public Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String) As Boolean
Public Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
Private Const WM_SETTEXT As Integer = &HC
I then search for another instance of the application and send the message with the relevant details if it finds one.
Dim window As IntPtr = apiFindWindowEx(Nothing, Me.Handle, "WindowsForms10.Window.8.app.0.378734a", "PDF Viewer")
If Not window = 0 Then
SendMessage(window, WM_SETTEXT, 0, Command())
Me.Close()
End If
Then in the application (it's the same app but I only want one open at a time) there is this piece of code that checks the messages when they're recieved:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_SETTEXT Then
If justopened = True Or Me.Text = "PDF Viewer" Or Me.Text = "File Browser" Then
Else
pdfrecieved(Me.Text) 'goes and does stuff
End If
End If
End Sub
Thanks for the help!
|
|
|
|
|
Hi,
How to map drive by checking domain name when user log on,such as when user log on domain 1 map network drive = X
and if user log on domain 2 map netwrork drive =Y
I have write a script it as below details,tt seemed didn't work.Plese help. Thanks in advance
Option Explicit
Dim objSystemInfo
Dim objWSHShell
Dim strLogonServer
Dim objNetwork
Dim strDriveLetter, strRemotePath
Set objWSHShell = Wscript.CreateObject("Wscript.Shell")
strLogonServer = objWSHShell.ExpandEnvironmentStrings("%LOGONSERVER%")
WScript.Echo "Server Name is :" & strLogonServer
Set objSystemInfo = CreateObject("ADSystemInfo")
WScript.Echo "Site Namen is: " & objSystemInfo.SiteName
strDriveLetter = "X:"
strRemotePath = "\\domainname\home\"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath
WScript.Quit
|
|
|
|
|
I don't exactly what you're looking for because your code doesn't check which domain the user logged into. But, here's an example of where the det the domain name:
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Domain = " & WshNetwork.UserDomain
|
|
|
|
|
Thank Dave
How to check domain if i have multiple domain and map network drive. Thanks in advance.
|
|
|
|
|
Why don't you use a script in the 'NETLOGON' share of one of the DC's of the domain you're connecting to ?
|
|
|
|
|
Hi,
Because of user working on multiple domain. I can't specific drive for them. I think it should be check domain before map network drive. Plese suggest me. Thank you
|
|
|
|
|
|
What did I tell you about posting this crap?
|
|
|
|
|
The NETLOGON share exists on any domain controller of any Active Directory domain.
There you can put some scripts that will be executed for users, if activated in their account management window.
Thus, the only things you have to do are :
- create a script (.bat or .cmd) in the netlogon share of one of the domain controllers that will connect a given drive letter to a given share on a particular server
For example :
net use H: \\myserver\users$\%username%
net use I: \\mysecondserver\common
- in the user's account management window, just give the filename of your script in the 'Connection script' field
The script will be executed when the user opens his session.
If you do that on both domains, no need to check for which domain is involved : the entire login process will take care of that for you.
|
|
|
|
|
Considering I already showed you how to get the domain the user is in, writing the IF statement to see if it matches whatever your requirements are for a particular drive mapping is on you.
|
|
|
|
|
Hi
I have write it as below details;
Set WshNetwork = WScript.CreateObject("WScript.Network") WScript.Echo "Domain = " & WshNetwork.UserDomain
strDriveLetter = "J:"
strRemotePath = "\\Domain\home\"
It didn't map network drive. Plese suggest me. Thank you
|
|
|
|
|
I can't tell you the exact code to use.
I have no idea what you're checking for (not that your code does ANY checking of anything what-so-ever!) and no idea what your server name and share names are. If this code is EXACTLY what you are running (no substituting "Domain" for anything,) you also do not know enough about Windows networking to take an intelligent guess at what you're supposed to be doing.
You cannot map a drive to a Domain. You map a drive to a \\<ServerName>\<ShareName>.
|
|
|
|
|
Thank you Dave. I will learn more.Sorry for make you confusing.
|
|
|
|
|
Hello, i have a problem, in my application i have a datagridview with rows, i can insert rows without any problem, i have a condition when its true i will remove this row, to know wich index has the row i have made a function, and i call it and the return value is correct but the next code line doesnt execute, can anybody help me??
Thanks and sorry for my english.
Dim row_to_delete as intenger
...
for i....
if .... then..
row_to_delete=find(i)
datagridview.rows.removeat(row_to_delete)' this line seems to doesnt execute
...
----------------------------------
public function find(byval code as integer) as integer
dim index_row as integer
for x =0...
if code =datagridview.item(0,x).value then
index_row=x
return index_row
end function
|
|
|
|
|
Put your code snippets within <pre> tags to post it in the forum, and try to put the relevant code just as you have it in your application. RemoveAt method in DataGridViewRowCollection might fail in many cases. Have a look at this[^] to see when it can fail.
|
|
|
|
|
If you delete a row, it screws up the enumerator because all the rows index positions change.
The easiest way to delete a bunch of rows in one operation, is to reverse the collection of row indexes and delete them from highest number to lowest number, the collection doesn't get screwed up that way.
If you don't yet know what rows you want to delete and are processing them based on some value within the table, them do exactly the same thing, start the search at the end of the collection and work backwards.
For X as integer = ( datatable.rows.count -1 ) to 0 step -1
If datatable.rows(X).columns(y) = "value" then datable.rows.removeAt(X)
next
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
It works! thank you very much for the reply
|
|
|
|
|
Hi,everyone!I have a XML, its structure was like below:
<Height>
<Standard>4721
<PN>1.6
<A DN="250">300</A>
<A DN="350">400</A>
<A DN="450">500</A>
<A DN="550">600</A>
</PN>
<PN>2.5
<A DN="250">300</A>
<A DN="350">400</A>
<A DN="450">500</A>
<A DN="550">600</A>
</PN>
</Standard>
</Height>
I want to get the selected node's text,for example,when PN = 1.6,DN = 250,the selected node's text was 300;PN=2.5,DN=350,the text should be 400.I tried use "for each node in childnodes",but it returned "1.6 300400500600".How could get the node I wanted?
I think that should be first selected "PN",and then get each childnode in <pn>. But I don't know how to do this
PLZ give me some help,thx!
|
|
|
|
|
System.Xml has a method SelectSingleNode, which requires an xPath expression in order to work. Your method should look somewhat like the following:
Sub GetSelected(string _PN, string_ DN)
' Put some code here to read your XML document into a XMLDocument variable,
' called XDoc for instance.
XmlNode _XN = XDoc.SelectSingleNode("/Height/Standard/" + _PN + "/A")
End Sub
(yes, I'm not a hero in vb, 5 pts if you guess my 'dialect').
Hope this steers you in the right direction!
"My personality is not represented by my hometown."
|
|
|
|
|
Hello,Eaverae! Your suggestion is helpful for me to get more details about the method "SelectedSingleNode".Thank you! I have got my solution like below:
For Each node1 In list1
Dim val As String
val = node1.Attributes("PN").Value
If val = TextBox1.Text Then
Dim list2 As XmlNodeList = node1.SelectNodes("Height")
Dim node2 As XmlNode
For Each node2 In list2
Dim val2 As String
val2 = node2.Attributes("DN").Value
If val2 = TextBox2.Text Then
TextBox3.Text = node2.InnerText
End If
Next
End If
Next
What's more, I have change the XML element
<PN>
to
<PN PN="1.6">
|
|
|
|
|
I am learning to program in VB.NET(2008 Express) and also learning to use version control software (TortiseSVN).
I am creating simple projects with VS while I learn the language(Using the book VB 2008 Step by Step ).
I have not been able to determine if I should put all the files in the project directroy under version control and if not what files and folders to exclude.
I am not sure what the files in the project directory do, any infomation would really be helpful.
eg of contents of project folder.
bin (folder)
My Project (folder)
obj (folder)
*.vb
*.resx
*.vb
*.sln
*.suo
*vbproj
*.vbproj.user
Thanks cages
|
|
|
|
|
There is no need to keep the bin folder and its contents in source control. Same applies to the suo and vbproj.user files.
SUO files contain information about IDE settings for the user while .user contain similar information for the corresponding vbproj.
|
|
|
|