Solved

Modal to Normal ( for experts )

Posted on 2003-11-18
10
589 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

17 Experts available now in Live!

Get 1:1 Help Now