Re: API Class Question
- From: "crferguson@xxxxxxxxx" <crferguson@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 19:26:58 -0000
That is valuable info, and it's one of the things I came across while
looking for a solution. It's also the article that has convinced me
this can't be done in one, easy to reuse, VBA class. It's amazing the
things that Microsoft has exposed via WMI and API, and it's even more
amazing to find that something as common as the title text in a window
can't be accessed the way I'm wanting: in a single VBA class.
Thank you all very much for your input and effort! I learned a ton
about what's available through API with this little exercise.
Cory
On Oct 30, 1:39 pm, "RB Smissaert" <bartsmissa...@xxxxxxxxxxxxxxxx>
wrote:
Not sure it can work in VBA, but this link addresses the problem:http://shorterlink.com/?DM71M6
RBS
<crfergu...@xxxxxxxxx> wrote in message
news:1193763087.977981.326250@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks! I'm doing the same thing. I haven't found anything useful
yet. This would be so much easier if I wasn't limited to VBA. But,
it is how it is....
On Oct 30, 11:36 am, "RB Smissaert" <bartsmissa...@xxxxxxxxxxxxxxxx>
wrote:
I think my solution was for a different problem.
Will have to Google it up.
RBS
<crfergu...@xxxxxxxxx> wrote in message
news:1193761801.232785.245930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thank you very much for your reply. I think I understand where you're
going with this, but I can't seem to get it working. When I add in
the FARPROC function and use it per your example, I'm still getting
the same error that I originally described:
Call EnumWindows(FARPROC(AddressOf GetOpenWindows), VarPtr(tParms))
On Oct 30, 9:45 am, "RB Smissaert" <bartsmissa...@xxxxxxxxxxxxxxxx>
wrote:
I forgot to give an example:
With CC
'base flag
.flags = CC_ANYCOLOR
.flags = .flags Or CC_FULLOPEN
.flags = .flags Or CC_RGBINIT
.rgbResult = lStartColour
.flags = .flags Or CC_ENABLEHOOK
.lpfnHook = FARPROC(AddressOf ChooseColorProc)
'size of structure
.lStructSize = Len(CC)
'assign the custom colour selections
.lpCustColors = VarPtr(dwCustClrs(0))
End With
RBS
"RB Smissaert" <bartsmissa...@xxxxxxxxxxxxxxxx> wrote in message
news:%23vsAMKwGIHA.5544@xxxxxxxxxxxxxxxxxxxxxxx
Try this:
Instead of calling AddressOf directly call it via a function like
this:
Function FARPROC(ByVal pfn As Long) As Long
FARPROC = pfn
End Function
RBS
<crfergu...@xxxxxxxxx> wrote in message
news:1193753665.771584.224290@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OK, so I'm pretty new to API's so forgive me if this is an idiot
question :-)
I'm putting together a class that uses API calls to user32 to
enumerate and list all running applications by their Title text.
One
of the functions uses "AddressOf AnotherFunctionName" to accomplish
this. The code works fantastic in a module. However, when trying
to
migrate this to a reusable class, the code crashes on that line
with
an error of:
"Invalid use of AddressOf operator"
Looking in Help it says:
"You tried to use AddressOf with the name of a class method.
Only the names of Visual Basic procedures in a .bas module can be
modified with AddressOf. You can't specify a class method."
Well, shucks, that just popped my bubble of wanting to make this
code
really efficient by keeping it in a class amongst some other
utility
functions I've written. Seems I can only use it in a module
instead.
My question is this: Is there a way to work around this in a class?
Here's my working module code that simply returns a Long greater
than
zero if an app with all or part of the passed title is found to be
running:
==================================
Option Explicit
Private Declare Function EnumWindows Lib "user32" (ByVal lEnumFunc
As
Long, ByVal wParam As Long) 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 Type AppWindow
sTitle As String
lHandle As Long
End Type
Public Function FindWindowByTitle(ByVal TheWindowTitle As String)
As
Long
'We'll pass a custom structure in as the parameter to store our
result...
Dim tParms As AppWindow
tParms.sTitle = TheWindowTitle
Call EnumWindows(AddressOf GetWindowTitles, VarPtr(tParms))
FindWindowByTitle = tParms.lHandle
End Function
Private Function GetWindowTitles(ByVal TheHandle As Long, TheParms
As
AppWindow) As Long
Dim sTitleText As String
'set a generic 260 length empty string to catch the window text
sTitleText = Space(260)
'get the text
Call GetWindowText(TheHandle, sTitleText, 260)
'remove nulls from the text
sTitleText = TrimNull(sTitleText)
'check to see if all or part of the search string is found
'in the window text
If sTitleText Like TheParms.sTitle Then
'if a match is found, then set the handle number
TheParms.lHandle = TheHandle
'and then exit the function
GetWindowTitles = 0
End If
'reset to 1 to keep the recursive loop going if not match found
GetWindowTitles = 1
End Function
Private Function TrimNull(ByVal TheText As String)
'check to see if string has null characters on the end
If Not InStr(TheText, Chr$(0)) = 0 Then
'if so, then remove the null characters from the end
TheText = Left$(TheText, InStr(TheText, Chr$(0)) - 1)
End If
TrimNull = TheText
End Function
=======================================
Of course the usage of this would be to pass a string to the only
public function FindWindowByTitle.
Thanks for any light that can be shed on this.
Cory- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
.
- Follow-Ups:
- Re: API Class Question
- From: RB Smissaert
- Re: API Class Question
- References:
- API Class Question
- From: crferguson@xxxxxxxxx
- Re: API Class Question
- From: RB Smissaert
- Re: API Class Question
- From: RB Smissaert
- Re: API Class Question
- From: crferguson@xxxxxxxxx
- Re: API Class Question
- From: RB Smissaert
- Re: API Class Question
- From: crferguson@xxxxxxxxx
- Re: API Class Question
- From: RB Smissaert
- API Class Question
- Prev by Date: Macro to check data from excel list against access query and return value back to excel
- Next by Date: Change size of font if cell value is greater than 0
- Previous by thread: Re: API Class Question
- Next by thread: Re: API Class Question
- Index(es):
Relevant Pages
|
Loading