Solved

Modal to Normal ( for experts )

Posted on 2003-11-18
10
586 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

11 Experts available now in Live!

Get 1:1 Help Now