?
Solved

Modal to Normal ( for experts )

Posted on 2003-11-18
10
Medium Priority
?
607 Views
Last Modified: 2010-04-03
Hi guys, I would like to my program set an external application window in Modal mode to normal mode. Because, when the window is showed is normal mode, if I know the HWND of the window, I can hide it and use another window. But if it is showed in modal mode, I can hide the window but I cant use other window, all buttons and edits is disabled. If is possible, I would like to set to normal mode the modal window and hide it to use another window. I would like an example of code that do this. It's for security purposes.

emu10k1
0
Comment
Question by:emu10k1
[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
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9770797
what about

from winapi-helpfile:

--- paste begin

The EndDialog function destroys a modal dialog box, causing the system to end any processing for the dialog box.

BOOL EndDialog(

    HWND hDlg,      // handle to dialog box
    int nResult       // value to return
   );      
 

Parameters

hDlg

Identifies the dialog box to be destroyed.

nResult

Specifies the value to be returned to the application from the function that created the dialog box.

 

Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.

Remarks

Dialog boxes created by the DialogBox, DialogBoxParam, DialogBoxIndirect, and DialogBoxIndirectParam functions must be destroyed using the EndDialog function. An application calls EndDialog from within the dialog box procedure; the function must not be used for any other purpose.
A dialog box procedure can call EndDialog at any time, even during the processing of the WM_INITDIALOG message. If your application calls the function while WM_INITDIALOG is being processed, the dialog box is destroyed before it is shown and before the input focus is set.

EndDialog does not destroy the dialog box immediately. Instead, it sets a flag and allows the dialog box procedure to return control to the system. The system checks the flag before attempting to retrieve the next message from the application queue. If the flag is set, the system ends the message loop, destroys the dialog box, and uses the value in nResult as the return value from the function that created the dialog box.

See Also

DialogBox, DialogBoxIndirect, DialogBoxIndirectParam, DialogBoxParam, WM_INITDIALOG

--- paste end

meikl ;-)
0
 

Author Comment

by:emu10k1
ID: 9771070
I think that it will destroy the application and not only the form, because if I use terminateprocess at the HWND of the window, it closes the application, so these is why I would like to set the window to normal mode and hide it to test if the application is secure or not.

But If you have sure that it can close the window without close the application , please, give me a delphi example of that. Thanks, emu10k1
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 9771163
Have you tried sending a WM_ACTIVATE message to the application with the WA_INACTIVE flag?

SendMessage( ApplicationsHandle, WM_ACTIVATE, WA_INACTIVE, 0 );
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 27

Expert Comment

by:kretzschmar
ID: 9771188
it will close the external modal window,
with the modal-result you give in

sample later

meikl ;-)
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9771190
Depending on the program, changing its state to normal may cause unexpected results. For example, I would call a modal dialog like this:
...do pre-dialog processing..,
result := MyDialog.ShowModal;
...depending on result, do one of several things...

Execution effectively stops at ShowModal until the dialog comes back. If the dialog comes back without pressing any of the buttons (which is what a "normal" dialog would do) then Result could well be undefined or simply wrong.

Is it a standard windows dialog you are trying to circumvent? Or a custom one?

Geoff M.
0
 

Author Comment

by:emu10k1
ID: 9771335
Geoff, it's a custom one, I'm current testing a application developed by a friend. I know that it may cause unexpected result, but it's what I want, if possible, of course.

emu10k1
0
 

Author Comment

by:emu10k1
ID: 9771640
EddieShipman: I've already tried it, and it doesn't work.
0
 
LVL 17

Accepted Solution

by:
geobul earned 2000 total points
ID: 9778296
Hi,

You have to enable the parent form not to change something in the modal form. There is no difference in GWL_STYLE or GWL_EXSTYLE in a form opened using Show and ShowModal you may change using APIs. Everything is done on Delphi level in TCustomForm.ShowModal method. So, enable the form you want to use this way (I suppose that Form1 has called another form in modal state):

procedure TMyControlForm.Button1Click(Sender: TObject);
var h: hwnd;
begin
  h := FindWindow(nil, 'Form1');
  if IsWindow(h) then EnableWindow(h, True);
end;

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 9778375
More code if Form1 has opened Form2 in modal state (these two forms are in an external app):

procedure TMyControlForm.Button1Click(Sender: TObject);
var h: hwnd;
begin
  // enable the parent form named Form1
  h := FindWindow(nil, 'Form1');
  if IsWindow(h) then EnableWindow(h, True);

  // hide the modal form named Form2
  h := FindWindow(nil, 'Form2');
  if IsWindow(h) then ShowWindow(h, SW_HIDE);

  // now you can use the parent Form1 - all controls are enabled
  ...
end;

Regards, Geo
0
 

Author Comment

by:emu10k1
ID: 9778820
Thanks geobul, It's what I need.

emu10k1
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 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