Solved

Hello msiman! I need your help!

Posted on 1997-08-15
6
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month5 days, 14 hours left to enroll

626 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