Difference between revisions of "Forms & Dialogs"

From Team Developer SqlWindows Wiki
Jump to: navigation, search
(Added tip on modal forms)
Line 88: Line 88:
 
|TEXT=WIKI_ShowWindowOnTaskbarWithAccessories.zip
 
|TEXT=WIKI_ShowWindowOnTaskbarWithAccessories.zip
 
}}
 
}}
 +
 +
 +
<!------------------------------------------------------------------------------------------------------------------------------>
 +
{{TipHeader|Simulating a 'modal' form window}}
 +
For dialogs we have flavors 'Modal' and 'Modeless'.<br>
 +
A modal dialog is created using SalModalDialog. The execution will continue after the dialog has been closed.<br>
 +
The modeless dialog is created using SalCreateWindow which will continue execution after the dialog is created.<br>
 +
 +
 +
We do not have a 'modal' form window type, they are for default always modeless. So your application will not wait until the form is closed.<br>
 +
 +
 +
But why not use a modal dialog when we need a window to "halt" your execution until it is closed?<br>
 +
Well, there are some differences between dialogs and form windows. One of them is that a dialog does not have a menu strip and does not have<br>
 +
a system menu (minimize, maximize).<br>
 +
So when using a modal dialog, you will have to take those "limitations".<br>
 +
 +
 +
Using this simple trick, we can "simulate" a modal form window:<br>
 +
 +
 +
First create a modal dialog and hide it. On the SAM_CreateComplete of that modal dialog, you create the needed form window.<br>
 +
Because the modal dialog is still open, the execution will wait until the hidden modal dialog is closed.<br>
 +
Now, when closing the form window, notify the hidden dialog that the form has been closed. Then the dialog will end itself.<br>
 +
After the hidden dialog has closed, the execution will continue.<br>
 +
 +
 +
This may come in handy when you have a form window which is used in different workflows. For instance, a form window is used to display images.<br>
 +
In one workflow you need to create a floating window in your application, while the user is executing other tasks. In this case you need a "normal" form window.<br>
 +
In the other workflow, you want to display the image using the same form, but now the application should wait until the form is closed.<br>
 +
By using this trick you can achieve this, so reusing the same form as "modeless" and "modal" flavors.<br>
 +
 +
 +
Here you can download a sample:
 +
 +
{{Download
 +
|URL=http://samples.tdcommunity.net/index.php?dir=&file=WIKI_ModalForm.zip
 +
|TEXT=WIKI_ModalForm.zip
 +
}}
 +
  
  
 
[[Category:Top Level Windows]]
 
[[Category:Top Level Windows]]

Revision as of 22:53, 22 November 2013

Form Window & DialogBox


Contents


Pointer2.png How to drag a window without a caption Pointer.png

See:

MediaWikiLink.png How to drag a window without a caption


Pointer2.png How to force a window on the taskbar Pointer.png

When a top-level window is created without a specific parent (hWndNULL) the window will be visible on the Windows taskbar.
Windows created using a parent, will not be shown.

To be able to use a parent while creating a window AND having it placed on the taskbar, use the following:
On creation of the window, set the GWL_EXSTYLE to WS_EX_APPWINDOW.

Beware, a top level window with accessories enabled has a different internal window hierarchy compared to
a window without accessories.
For top level windows having accessories, hWndForm should be changed to the parent of hWndForm.
You can not use SalParentWindow, that function will return the owner of the window.
You need to call GetParent from WinApi as declared above.

So, declare these external functions and system constants:

Library name: USER32.DLL
   Function: GetWindowLongA
      Export Ordinal: 0
      Returns
         Number: LONG
      Parameters
         Window Handle: HWND
         Number: INT

   Function: SetWindowLongA
      Export Ordinal: 0
      Returns
         Number: LONG
      Parameters
         Window Handle: HWND
         Number: INT
         Number: LONG

   Function: GetParent
      Export Ordinal: 0
      Returns
         Window Handle: HWND
      Parameters
         Window Handle: HWND


Constants
   System
      Number: GWL_EXSTYLE	= -20
      Number: WS_EX_APPWINDOW	= 0x00040000

For top level windows without accessories enabled, do this:
set the WS_EX_APPWINDOW style to the window (hWndForm) at creation:

On SAM_Create
   Call SetWindowLongA( hWndForm, GWL_EXSTYLE, GetWindowLongA( hWndForm, GWL_EXSTYLE ) | WS_EX_APPWINDOW )

For top level windows WITH accessories enabled, do this:
set the WS_EX_APPWINDOW style to the parent window of hWndForm at creation:

On SAM_Create
   Call SetWindowLongA( GetParent( hWndForm ), GWL_EXSTYLE, GetWindowLongA( GetParent( hWndForm ), GWL_EXSTYLE ) | WS_EX_APPWINDOW )

The window will then be shown on the taskbar.


Here you can download a sample:

Down.png WIKI_ShowWindowOnTaskbarWithAccessories.zip


Pointer2.png Simulating a 'modal' form window Pointer.png

For dialogs we have flavors 'Modal' and 'Modeless'.
A modal dialog is created using SalModalDialog. The execution will continue after the dialog has been closed.
The modeless dialog is created using SalCreateWindow which will continue execution after the dialog is created.


We do not have a 'modal' form window type, they are for default always modeless. So your application will not wait until the form is closed.


But why not use a modal dialog when we need a window to "halt" your execution until it is closed?
Well, there are some differences between dialogs and form windows. One of them is that a dialog does not have a menu strip and does not have
a system menu (minimize, maximize).
So when using a modal dialog, you will have to take those "limitations".


Using this simple trick, we can "simulate" a modal form window:


First create a modal dialog and hide it. On the SAM_CreateComplete of that modal dialog, you create the needed form window.
Because the modal dialog is still open, the execution will wait until the hidden modal dialog is closed.
Now, when closing the form window, notify the hidden dialog that the form has been closed. Then the dialog will end itself.
After the hidden dialog has closed, the execution will continue.


This may come in handy when you have a form window which is used in different workflows. For instance, a form window is used to display images.
In one workflow you need to create a floating window in your application, while the user is executing other tasks. In this case you need a "normal" form window.
In the other workflow, you want to display the image using the same form, but now the application should wait until the form is closed.
By using this trick you can achieve this, so reusing the same form as "modeless" and "modal" flavors.


Here you can download a sample:

Down.png WIKI_ModalForm.zip