Solved

Application lose focused

Posted on 2001-08-10
11
179 Views
Last Modified: 2007-12-19
I have 2 applications (app1 and app2) run the same time. From app1, I call a DLL to display a report on the screen. After print out report, close it, it doesnt focus back to the app1, but app2

I'm using VB6, Crystal Report 7

Thanks in advance
nguyenn
0
Comment
Question by:nguyenn
[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
  • 7
  • 4
11 Comments
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372474
In VB you are working with a Form object just call:
call Form1.Show()

to invoke the Form1 of your Vb exe project.

;O)
WoK
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372515
The api function to focus an specific window (app) is in VB:

Public Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

hWnd
[in] Handle to the window
nCmdShow
[in] Specifies how the window is to be shown
SW_SHOW  = 5
Activates the window and displays it in its current size and position

WoK

0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372538
To get a window handle (hWnd) for your application call:

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

For instance:

Dim hWnd As Long
hWnd = FindWindow ("","App_Window_Titel")
call ShowWindow (hWnd,5)

Thats was it
WoK
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 1

Author Comment

by:nguyenn
ID: 6372556
Hi Wok,

The first comment cannot apply to my app, since when calling report, i'm using vbModal

i.e. frmReport.Show vbModal

Could you give me a sample code of your sencond comment

Thanks
0
 
LVL 4

Accepted Solution

by:
WolfgangKoenig earned 50 total points
ID: 6372599
Sorry the right code(tested) is like following:

Dim hWnd As Long
hWnd = FindWindow(vbNullString, "MSDN Library - October 1999")
Call ShowWindow(hWnd, 9)

WoK

0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372622
I have tested the 'nCmdShow' and only 9 works but
the MSDN says following about the 'nCmdShow' parameters:

SW_FORCEMINIMIZE Windows 2000: Minimizes a window, even if the thread that owns the window is hung. This flag should only be used when minimizing windows from a different thread.
SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.  
SW_SHOWDEFAULT Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.  
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window.
This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
 
SW_SHOWNA Displays the window in its current size and position.
This value is similar to SW_SHOW, except the window is not activated.
 
SW_SHOWNOACTIVATE Displays a window in its most recent size and position.
This value is similar to SW_SHOWNORMAL, except the window is not actived.
 
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.



Here are the defines for the vars:
define SW_HIDE             0
#define SW_SHOWNORMAL       1
#define SW_NORMAL           1
#define SW_SHOWMINIMIZED    2
#define SW_SHOWMAXIMIZED    3
#define SW_MAXIMIZE         3
#define SW_SHOWNOACTIVATE   4
#define SW_SHOW             5
#define SW_MINIMIZE         6
#define SW_SHOWMINNOACTIVE  7
#define SW_SHOWNA           8
#define SW_RESTORE          9
#define SW_SHOWDEFAULT      10
#define SW_FORCEMINIMIZE    11
#define SW_MAX              11


Normally SW_SHOWNORMAL should do the right but it don't work normally ... That the reason i have choose SW_SHOWNA for the above example.

WoK

0
 
LVL 1

Author Comment

by:nguyenn
ID: 6372751
Hi Wok,

I tried both ways, but it still doesnt work. After closing report form, it focus to the app2.

I'm very appreciated for your help
nguyenn
0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372816
You must take the windows title of app2:

Dim hWnd As Long
hWnd = FindWindow ("","App2_Windows_Titel")
'hWnd must be <> 0 ! after this (debug it)

call ShowWindow (hWnd,1) 'try on of these out
call ShowWindow (hWnd,5) 'try on of these out
call ShowWindow (hWnd,9) 'try on of these out

(The windows titel you can found at the windows tray bar when you move the nouse over it ...)

0
 
LVL 4

Expert Comment

by:WolfgangKoenig
ID: 6372821
Ops i means App2 -> App1
0
 
LVL 1

Author Comment

by:nguyenn
ID: 6373072
Hi Wok,

I passed my app1's title to function called (app.Title), and tried all of possible ways above but it doesnt help me out. One thing I could guess, my app2 collect data and save to the database all the time, that why eventhough we set focus to app1, but app2 is running and it setfocus to app2. I'm curious it doesnt happen to other reports (report file, not from report dll)

0
 
LVL 1

Author Comment

by:nguyenn
ID: 6373533
Although my problem hasnt solved, but I would like to give all my points to you for your gracious helped. Thanks again Wok,

Have a nice day :)
nguyenn
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

691 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