Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 609
  • Last Modified:

Modal to Normal ( for experts )

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
emu10k1
Asked:
emu10k1
  • 4
  • 2
  • 2
  • +2
1 Solution
 
kretzschmarCommented:
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
 
emu10k1Author Commented:
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
 
EddieShipmanCommented:
Have you tried sending a WM_ACTIVATE message to the application with the WA_INACTIVE flag?

SendMessage( ApplicationsHandle, WM_ACTIVATE, WA_INACTIVE, 0 );
0
Industry Leaders: 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!

 
kretzschmarCommented:
it will close the external modal window,
with the modal-result you give in

sample later

meikl ;-)
0
 
gmayoCommented:
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
 
emu10k1Author Commented:
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
 
emu10k1Author Commented:
EddieShipman: I've already tried it, and it doesn't work.
0
 
geobulCommented:
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
 
geobulCommented:
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
 
emu10k1Author Commented:
Thanks geobul, It's what I need.

emu10k1
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now