|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Find Window QuestionI am trying to find a window using the known classname, which I got through Spy++ The classname is'AfxWnd80s' & when I use FindWindow API to return the INT32 with the window handle it returns 0 (zero) Example: Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32 Dim i As Int32 = FindWindow("AfxWnd80s", VbNullString) MessageBox.Show(i.ToString) This window displays maybe once a week so, I will have a long wait in which to test it Any Ideas? TIA Newbie Coder On 2006-11-30, Newbie Coder <newbie_coder@pleasespamme.com> wrote:
> Hello Group Private Declare Auto Function FindWindow Lib "user32" _> > I am trying to find a window using the known classname, which I got through > Spy++ > > The classname is'AfxWnd80s' & when I use FindWindow API to return the INT32 > with the window handle it returns 0 (zero) > > Example: > > Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" > (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32 > (Byval lpClassName As String, ByVal lpWindowName As String) As IntPtr Don't alias API calls anymore. That is a relic of the bad old days of VB6 when VB could not call unicode api calls directly. Just declare the function Auto. The .NET marshaller is smart enough to figure out the proper function to call on the current platform. If you alias to the "A" function on a NT based platform (NT, 2000, XP, etc) - you are causing the runtime way more work then is necessary, because it will first convert your string from it's unicode format to ansi, and then pass that buffer to the api call. The api call will promptly convert the ansi string it was passed to unicode and delegate the call to the "W" function. The situation is even worse if the api call actually modifies the string (which this one doesn't)... Because then that whole process has to be reversed on top of the fact that because you used a system.string to recieve the buffer rather then a system.text.stringbuilder, the vb.net marshaler get's involved to cover your butt from the fact that strings are immutable. In fact, using system.string as a api buffer will not work correctly in C# because it doesn't cover for you :) > Dim i As Int32 = FindWindow("AfxWnd80s", VbNullString) Dim i As IntPtr = FindWindow ("AfxWnd80s", Nothing)> -- Tom Shelton Thanks for your reply, but your code returns zero because I tried it before
I posted the question All you have done is changed my Int32 to IntPtr However, I know the Marshall... but I was knocking togething a 2 min program I thought, but was wrong. Plus I have a VB background stending from VB 3 It seems that the class I have to get is nested within another class So, I used FindWindow to get parent & then FindWindowEx passing the handle from the FindWindow as the first parameter. Example: Dim i as Int32 = FindWindow("[class name here]", VbNullString) Dim ii as Int32 = FindWindowEx(i, 0, "AfxWnd80s", VbNullString) MessageBox.Show(ii.ToString) returns the wrong handle because there are more than one control with the 'AfxWnd80s' class Any ideas?
Email Socket Question
Best way to get a Junior Programmer up to speed deployment of project migrating MSDE to SQLExpress End Processing in Multithreaded App Exposing Com Interfaces of a .Net Class Library (Trouble Regsvr32) Cross-thread operation not valid. catching close button Combo box to start at first character after user selects NNTP Question Calculate inside a form and use the same form as Insert record form |
|||||||||||||||||||||||