Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Hello msiman! I need your help!

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
MacSverre
Asked:
MacSverre
  • 3
  • 2
1 Solution
 
msimanCommented:
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
 
MacSverreAuthor Commented:
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
 
msimanCommented:
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's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ESICommented:
or FindWindow(vbNullString,vbNullString)
or vbNull ?
but FindWindow(0&, 0&) should work...strange
0
 
MacSverreAuthor Commented:
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
 
msimanCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now