From: Norm on
Hi,

I am having a problem that I do not understand at all. :D

I am trying to send a message to a running app called FileClean. This
is a new version and the message hook is not able to obtain a hwnd for
the running app. It does work with the older version, but I have not
been able to find any difference's in the properties of either version
and the app name is listed the same when running, in the task manager.
Where else should I be looking for something different.

Here is the code, this is from Karl's example, the
FindWindow(FormClass, App.Title) returns 0 with the new app running and
returns a value with the old app running, but I cannot find what is
different. Both apps when running show FileClean in the task manager:

Public Sub SendStringTo(ByVal Caption As String, ByVal Send As String)

Dim hWnd As Long
Dim cds As COPYDATASTRUCT
'
' Classname constants will vary depending on whether
' using VB5 or VB6. Make sure this constant is correct!
'
Const FormClass As String = "ThunderRT6FormDC"
Const MdiFormClass As String = "ThunderRT6MDIForm"
' Check for MDI form first, if no MDI form is found
' look for regular form. Use the classname just to
' narrow down the potential number of matching windows.
'
hWnd = FindWindow(MdiFormClass, App.Title)
If hWnd = 0 Then
hWnd = FindWindow(FormClass, App.Title)
End If
'MsgBox "hWnd = " & hWnd

' Activate window to which we're passing data.
'
'If IsIDE Then hWnd = Me.hWnd
If hWnd Then
If IsIconic(hWnd) Then
Call ShowWindow(hWnd, SW_RESTORE)
End If

Call SetForegroundWindow(hWnd)
Else
Exit Sub 'no need to continue.
End If

If Len(Send) = 0 Then
Send = "Send Test String"
End If

cds.cbData = LenB(Send)
cds.lpData = StrPtr(Send)
'MsgBox "hwnd = " & hWnd & " cds.cbData = " & cds.cbData &
"cds.lpData = " & cds.lpData
Call SendMessage(hWnd, WM_COPYDATA, Me.hWnd, cds)

Thanks,
Norm


From: Karl E. Peterson on
Norm presented the following explanation :
> I am having a problem that I do not understand at all. :D
>
> I am trying to send a message to a running app called FileClean. This is a
> new version and the message hook is not able to obtain a hwnd for the running
> app. It does work with the older version, but I have not been able to find
> any difference's in the properties of either version and the app name is
> listed the same when running, in the task manager. Where else should I be
> looking for something different.
>
> Here is the code, this is from Karl's example, the FindWindow(FormClass,
> App.Title) returns 0 with the new app running and returns a value with the
> old app running, but I cannot find what is different. Both apps when running
> show FileClean in the task manager:
>
> Public Sub SendStringTo(ByVal Caption As String, ByVal Send As String)
>
> Dim hWnd As Long
> Dim cds As COPYDATASTRUCT
> '
> ' Classname constants will vary depending on whether
> ' using VB5 or VB6. Make sure this constant is correct!
> '
> Const FormClass As String = "ThunderRT6FormDC"
> Const MdiFormClass As String = "ThunderRT6MDIForm"
> ' Check for MDI form first, if no MDI form is found
> ' look for regular form. Use the classname just to
> ' narrow down the potential number of matching windows.
> '
> hWnd = FindWindow(MdiFormClass, App.Title)
> If hWnd = 0 Then
> hWnd = FindWindow(FormClass, App.Title)
> End If

I think you need to stick a breakpoint there, and check what strings
you're looking for. Then, open Spy++ and find the window you hope to
find with your code, and compare the strings. That's about the only
thing that can go wrong if/when FindWindow fails.

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Norm on
Karl E. Peterson laid this down on his screen :
> Norm presented the following explanation :
>> I am having a problem that I do not understand at all. :D
>>
>> I am trying to send a message to a running app called FileClean. This is a
>> new version and the message hook is not able to obtain a hwnd for the
>> running app. It does work with the older version, but I have not been able
>> to find any difference's in the properties of either version and the app
>> name is listed the same when running, in the task manager. Where else
>> should I be looking for something different.
>>
>> Here is the code, this is from Karl's example, the FindWindow(FormClass,
>> App.Title) returns 0 with the new app running and returns a value with the
>> old app running, but I cannot find what is different. Both apps when
>> running show FileClean in the task manager:
>>
>> Public Sub SendStringTo(ByVal Caption As String, ByVal Send As String)
>>
>> Dim hWnd As Long
>> Dim cds As COPYDATASTRUCT
>> '
>> ' Classname constants will vary depending on whether
>> ' using VB5 or VB6. Make sure this constant is correct!
>> '
>> Const FormClass As String = "ThunderRT6FormDC"
>> Const MdiFormClass As String = "ThunderRT6MDIForm"
>> ' Check for MDI form first, if no MDI form is found
>> ' look for regular form. Use the classname just to
>> ' narrow down the potential number of matching windows.
>> '
>> hWnd = FindWindow(MdiFormClass, App.Title)
>> If hWnd = 0 Then
>> hWnd = FindWindow(FormClass, App.Title)
>> End If
>
> I think you need to stick a breakpoint there, and check what strings you're
> looking for. Then, open Spy++ and find the window you hope to find with your
> code, and compare the strings. That's about the only thing that can go wrong
> if/when FindWindow fails.

Karl,

Thanks for the response I did find the problem, duh. I forgot to load
the form receiving the message. I am having another problem now, but am
sure it is something I am doing wrong and will continue to check. I
enter the following keys in the HKCU registry to get a right click
context menu,

'Write registry entries for right click shredding
With New RegOp
.Key = "Software\Classes\*\shell\Erase With FileClean"
.Value("icon") = App.Path & "\FileClean.exe"
.Key = "Software\Classes\*\shell\Erase With FileClean\command"
.Value("Default") = App.Path & "\FileClean.exe %L"
.Key = "Software\Classes\Directory\shell\Erase With FileClean"
.Value("icon") = App.Path & "\FileClean.exe"
.Key = "Software\Classes\Directory\shell\Erase With
FileClean\command"
.Value("Default") = App.Path & "\FileClean.exe %L"
End With

but with the new app when I click on the entry I get a message

"This file does not have a programassociated with it for performing
this action. Please install a program or if one is already installed,
create an association in the Default Programs control panel."

Thanks again,
Norm