Solved

Hello msiman! I need your help!

Posted on 1997-08-15
6
274 Views
Last Modified: 2012-08-13
I successfully adapted the answer you gave infoanytime to his/hers question "passing Param to existing instance of prg" to my own use, which is to just activate the previous instance and kill the new one. That is, I got it working in Win32... But in Win16 I can't get the "FindWindow" line to work, and that ,obviously, breaks the whole thing. Can you help me with this?



I've posted "my" code below, so you know exactly what I'm doing...





Thanks in advance!



   MacSverre



*** begin code ***

si = FindWindowA(&O0, &O0)

'here's the showstopper...



Do

   si = GetWindow(si, GW_HWNDNEXT)

Loop Until (ShowWindowText(si) = Me.Caption And si <> hwnd) Or si = GetWindow(si, GW_HWNDLAST)



If si > 0 And si <> hwnd And si <> Getwindow(si, GW_HWNDLAST) Then

   SetForegroundWindow si

   ShowWindow si, SW_MAXIMIZE

   End

End If
0
Comment
Question by:MacSverre
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:msiman
ID: 1430966
well i suspect the error is the private declare
in the fisrt line....
if you write me the declaration lines, i'll tell you exactly
what to change ok?
i think i know what's the error.
just show me the declaration lines ok?
i'll be happy to help you out...
0
 
LVL 2

Author Comment

by:MacSverre
ID: 1430967
As you can see from the declarations posted below, the FindWindow in Win16 has parameters of type "Any", whereas the Win32 version uses type "Long". Because of this I get a "Type mismatch" error when calling FindWindow with parameters (&O0, &O0).



In addition to posting the declares, I also post the main code (what I posted earlier was the Win32 version) and the "ShowWindowText" function.



*** begin declares ***

   Private Declare Sub SetWindowTextA Lib "User" (ByVal hWnd As Long, ByVal lpString As String)

   Private Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer

   Private Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer

   Const GW_HWNDFIRST = 0

   Const GW_HWNDLAST = 1

   Const GW_HWNDNEXT = 2

   Const GW_HWNDPREV = 3

   Const GW_OWNER = 4

   Const GW_CHILD = 5

   Const GW_MAX = 5



   Private Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer

   Private Declare Function GetWindowTextLength Lib "User" (ByVal hWnd As Integer) As Integer



   Private Declare Function ShowWindow Lib "User" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

   Const SW_ERASE = &H4

   Const SW_HIDE = 0

   Const SW_INVALIDATE = &H2

   Const SW_MAX = 10

   Const SW_MAXIMIZE = 3

   Const SW_MINIMIZE = 6

   Const SW_NORMAL = 1

   Const SW_OTHERUNZOOM = 4

   Const SW_OTHERZOOM = 2

   Const SW_PARENTCLOSING = 1

   Const SW_PARENTOPENING = 3

   Const SW_RESTORE = 9

   Const SW_SCROLLCHILDREN = &H1

   Const SW_SHOW = 5

   Const SW_SHOWDEFAULT = 10

   Const SW_SHOWMAXIMIZED = 3

   Const SW_SHOWMINIMIZED = 2

   Const SW_SHOWNA = 8

   Const SW_SHOWMINNOACTIVE = 7

   Const SW_SHOWNOACTIVATE = 4

   Const SW_SHOWNORMAL = 1



   Private Declare Function SetForegroundWindow Lib "User" (ByVal hWnd As Long) As Long

***  end declares  ***



*** begin function ***

Function ShowWindowText(ByVal hWnd As Long) As String

   l = GetWindowTextLength(hWnd)

   c$ = Space$(l)

   r = GetWindowText(hWnd, c$, l + 1)

   If r > 0 Then ShowWindowText = c$ Else ShowWindowText = ""

End Function

***  end function  ***



*** begin main code ***

   'si = FindWindow(&O0, &O0)

   'si = FindWindow("0", "0")

   si = GetWindow(0, GW_HWNDFIRST)

   

   Do

      si = GetWindow(si, GW_HWNDNEXT)

   Loop Until (ShowWindowText(si) = Me.Caption And si <> hWnd) Or si = GetWindow(si, GW_HWNDLAST)

   'seek through apps in memory to one with the same caption

   

   If si > 0 And si <> hWnd And si <> GetWindow(si, GW_HWNDLAST) Then

      SetForegroundWindow si

      ShowWindow si, SW_MAXIMIZE  'Tilpasses prog...

      End

   End If

***  end main code  ***





Hope you can work it out...



   MacSverre
0
 
LVL 2

Accepted Solution

by:
msiman earned 150 total points
ID: 1430968
i guess this is the answer, howver i am not very sure
i understood your question, so if i m wroing PLEASE
correct me.
the findwindow(0,0) didn't work, so
use findwindow(NULL,NULL), this should work
ok?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:ESI
ID: 1430969
or FindWindow(vbNullString,vbNullString)
or vbNull ?
but FindWindow(0&, 0&) should work...strange
0
 
LVL 2

Author Comment

by:MacSverre
ID: 1430970
Thanks to both of you!



msiman, I give your answer a rating of "Good" (instead of Excellent) because NULL didn't actually work; I had to use vbNullString (which I probably wouldn't have found out without ESI's help)...



FYI; I had to change the declaration for "ShowWindow" to use Integer instead of Long (for all variables), as specified by the Win 3.1 API...





Again, Thank you very much!



   MacSverre
0
 
LVL 2

Expert Comment

by:msiman
ID: 1430971
well, if ESI reads that:
i aow you a favor...
next question is "ON ME..." :)
email me the question and i'll answer it for free... :)
10x


0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 79
VB6 Compile Compatibility Issue 4 102
MS Access 03, TransferText, decimal places 8 72
How to read File Date Created using VB6 8 39
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question