Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Hello msiman! I need your help!

Posted on 1997-08-15
6
Medium Priority
?
306 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 450 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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

715 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