Solved

Application lose focused

Posted on 2001-08-10
11
173 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
  • 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

707 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

18 Experts available now in Live!

Get 1:1 Help Now