473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Find Window Question

Hello Group

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

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
Nov 30 '06 #1
2 2191
On 2006-11-30, Newbie Coder <ne**********@pleasespamme.comwrote:
Hello Group

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
Private Declare Auto Function FindWindow Lib "user32" _
(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
Dec 1 '06 #2
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?
Dec 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fabrice Labrousse | last post by:
Hello, Here is a hard problem i cannot solve about window.opener method I think you'll need to be a specialist to find the solution... i can't find the solution by myself ! Please help me. Here...
4
by: Yves-Alain NICOLLET | last post by:
I have a script that opens a small window containing a button which when clicked performs a find to the next occurence of a string. It works well when the string is made of only one word or of...
44
by: Carlos Andr?s | last post by:
Hi everybody. I've got a problem. I'd like to avoid opening a new window when you have pressed the shift key and you click in the left button of the mouse. I've tried the next solution, in the...
0
by: amit | last post by:
hi I have created a tool which does a find and replace thru DTE, now after it is done, it opens up a window, "FIND REACHED THE STARTING POINT OF SEARCH" I want to disbale this window...
17
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I find the size of a browser window?...
0
by: kloplop321 | last post by:
I found this code(vb only) and it does about the same thing(in vb, not vb .NET 2005) Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute...
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
10
by: Gary | last post by:
I'm trying to find a way to determin which window Within-Another-Program currently has the focus. THE SITUATION: (Skip down to "My Question" if you don't want the background...) * This is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.