Solved

Hello msiman! I need your help!

Posted on 1997-08-15
6
261 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now