Ctrl_Create

 

The "Ctrl_Create()" function is called when sliceOmatic create its interface windows.

 

We use this function to create a "box" tool ("box_box").  This tool is the same size as the interface's window, and its name is the title of the module.

 

If your module has sub-windows, they must be created here.  For more information on this, please see the "Sub-window" section further down.

 

 

Syntax

 

extern "C" __declspec(dllexport) int  Ctrl_Create(

          HWND wnd,

          int width,

          int height

)

 

 

Parameters

 

wnd

A handle to the interface's window

 

width

The horizontal size of the window (in pixels).

 

height

The vertical  size of the window (in pixels).

 

 

Return value

 

The function returns "0" if an error occurred, "1" otherwise.

 

 

Remarks

 

This function is only optional if you do not have a control window.

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

Library:

          sliceO_Structures.lib

 

 

Example

 

...

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Create

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                    width (int)          horiz. size of the window

//                    height (int)          vert. size of the window

//          Returns:          (int)          0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Create( HWND wnd, int width, int height )

{

char  *          Title_Font_Name =          (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char  *          Title_Font_Weight =          (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =          (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

short          Border_Dim =          (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          box_box.Name = "------- Edit -------" ;

          box_box.Font_Name   = Title_Font_Name ;

          box_box.Font_Scale  = Title_Font_Scale ;

          box_box.Font_Weight = Title_Font_Weight ;

          box_box.Flag      = OUTIL_DISABLE | OUTIL_NO_3D ;

          box_box.Pos_X     = 1 ;

          box_box.Pos_Y     = 1 ;

          box_box.Dim_X     = width - 2 ;

          box_box.Dim_Y     = height - 2 ;

          box_box.border    = Border_Dim;

          box_box.color.set( WINDOW_COLOR_TAG_MODE_R,

                                         WINDOW_COLOR_TAG_MODE_G,

                                         WINDOW_COLOR_TAG_MODE_B ) ;

          box_box.Init( wnd ) ;

 

          return( 1 ) ;

}

 

...

 

 

Sub-windows

 

There are 2 kind of sub-windows that you may want to create: you may want a sub-window inside your interface window, or you may want a completely independent pop-up window.

 

A sub-window inside the interface window may be used to display some OpenGL graphics (the Blow-up tool and the 3D Light tool use such a window).  These windows are created as child windows inside the "Ctrl_Create()" function.  they use the same "Registered class" function as the parent ("TOOL") and, if you specified the same Window ID as the parent, then any mouse or key event inside the sub-window will be treated by the same parsing function as the parent window (In other words, the Ctrl_Click(), Ctrl_Motion(), etc.. will be called for all mouse events inside the interface window and its sub-windows.)

 

 

A completely independent sub-window may be used to display additional information (the "Surface/Volume" Tool use 3 such windows.  One to specify the parameters, one to display numerical results, and one to display a graph).  These windows will need their own registered class, these are created inside the "Ctrl_Create()" function.  the windows themselves can then be created by your application (typically as a response to a user click on button inside the "Ctrl_Click()" function.)

 

 

 

Example with included sub-windows: Sample sub-window from the 3D Light tool module.

// --- I need one OpenGL sub-window ---

HWND          Light_Wind ;

 

// --- Interface tools ---

static          Boxs          box_box ;

static          Boxs          box_image ;

...

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Create

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Create( HWND wnd, int width, int height )

{

          // ====================================================================

          // ====================================================================

          // ===================          !!!! IMPORTANT !!!!          =======================

          // ====================================================================

          // ====================================================================

          // --- Since we have child windows, we only want the creation of the main window ---

          static char flag ;

          if ( flag )

              return( 1 ) ;

          flag++ ;

          // ====================================================================

          // ====================================================================

 

          char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

          char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

          short  Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

          short  Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          box_box.Name = "------- 3D Light Control -------" ;

          box_box.Flag      = OUTIL_DISABLE | OUTIL_NO_3D ;

          box_box.Pos_X     = 1 ;

          box_box.Pos_Y     = 1 ;

          box_box.Dim_X     = width - 2 ;

          box_box.border    = Border_Dim;

          box_box.color.set( WINDOW_COLOR_TOOL_R,

                                 WINDOW_COLOR_TOOL_G,

                                 WINDOW_COLOR_TOOL_B ) ;

          box_box.Font_Name   = Title_Font_Name ;

          box_box.Font_Scale  = Title_Font_Scale ;

          box_box.Font_Weight = Title_Font_Weight ;

          box_box.Init( wnd ) ; 

 

 

          // ====================================================================

          // ====================================================================

          // ===================          !!!! IMPORTANT !!!!          =======================

          // ====================================================================

          // ====================================================================

          // ===          All child windows of this window must be created here!              ===

          // ==          If you give the same ID at the child window, it will be              ===

          // ===          processed by the same functions as the parent.                        ===

          // ===          If you use ID+1, it will not cause any call-backs.              ===

          // ====================================================================

          // ====================================================================

 

          // --- Create the associated OpenGL window ---

          HINSTANCE hInstance = (HINSTANCE) GetWindowLong( GetActiveWindow(), GWLP_HINSTANCE ) ;

 

          // --- Get the ID of the parent window ---

          LONG window_ID = GetWindowLong( wnd, GWL_ID ) ;

 

          // --- The dimensions are not important, they will be changed in the "resize" section ---

          Light_Wind = CreateWindow( "TOOL", NULL,

                                        WS_CHILD | WS_DISABLED | WS_VISIBLE,

                                        0, 0, 10, 10,

                                        wnd, (HMENU) (window_ID), hInstance, NULL ) ;

          assert( Light_Wind ) ;

          // ====================================================================

          // ====================================================================

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Resize

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Resize( HWND wnd, int width, int height )

{

          // ====================================================================

          // ====================================================================

          // ===================          !!!! IMPORTANT !!!!          =======================

          // ====================================================================

          // ====================================================================

          // --- Since we have child windows, we only want the creation of the main window ---

          // On the first call of the child's resize, its window is not yet defined.

          if ( ! Light_Wind )

              return( 1 ) ;

          if ( wnd && (wnd == Light_Wind) )

              return( 1 ) ;

          // ====================================================================

          // ====================================================================

 

          // --- we need a few variables ---

          char  *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

          char  *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

          short  Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

          short  Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          if ( wnd ) {

              box_box.Pos_X     = 1 ;

              box_box.Pos_Y     = 1 ;

              box_box.Dim_X     = width - 2 ;

              box_box.Dim_Y     = height - 2 ;

              box_box.border    = Border_Dim;

              box_box.Font_Name   = Title_Font_Name ;

              box_box.Font_Scale  = Title_Font_Scale ;

              box_box.Font_Weight = Title_Font_Weight ;

              box_box.Init( wnd ) ; 

          } else {

              wnd = box_box.wnd ;

          }

 

          ...

 

          // Note: Creating a "box" with the same dim as the sub-window is useful for the

          //       for the other interface functions (Ctrl_Click()...).

          box_image.Flag  = OUTIL_DISABLE | OUTIL_EMPTY ;

          box_image.Pos_X = ... ;

          box_image.Pos_Y = ... ;

          box_image.Dim_X = ... ;

          box_image.Dim_Y = ... ;

          box_image.color = box_box.color ;

          box_image.Init( wnd ) ;

 

          // ====================================================================

          // ====================================================================

          // --- resize the sub-window ---

          // Note: window coord are top to bottom instead of bottom to top

          MoveWindow( Light_Wind,

                    box_image.Pos_X,

                    height - (box_image.Pos_Y + box_image.Dim_Y),

                    box_image.Dim_X,

                    box_image.Dim_Y,

                    NULL ) ;

          EnableWindow( Light_Wind, TRUE ) ;

          // ====================================================================

          // ====================================================================

 

          return( 1 ) ;

}

 

Example with independent sub-windows

// --- child windows ---

HWND          Hwnd_Surface_A ;

LRESULT CALLBACK WndProcCalc_A( HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) ;

 

// --- Interface tools ---

static          Boxs          box_box ;

 

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Create

//

//          Parameters:          wnd (HWND)          Pointer to Window's created window

//                              width (int)          horiz. size of the window

//                              height (int)          vert. size of the window

//          Returns:          (int)                    0 if error

//

//          This is called once when your control window is created

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Create( HWND wnd, int width, int height )

{

          // --- Since we have child windows, we only want the creation of the main window ---

          static char flag ;

          if ( flag )

              return( 1 ) ;

          flag++ ;

 

char   *Title_Font_Name =   (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_NAME" ) ;

char   *Title_Font_Weight = (char *) Fct_Variable_Value( "$INTERFACE_TITLE_FONT_WEIGHT" ) ;

short          Title_Font_Scale =  (short)  Fct_Variable_Value( "$INTERFACE_TITLE_FONT_SCALE" ) ;

short          Border_Dim =              (short)  Fct_Variable_Value( "$INTERFACE_BORDER_DIM" ) ;

 

          box_box.Name = "---- TAG Surface/Volume ----" ;

          box_box.Flag      = OUTIL_DISABLE | OUTIL_NO_3D ;

          box_box.Pos_X     = 1 ;

          box_box.Pos_Y     = 1 ;

          box_box.Dim_X     = width - 2 ;

          box_box.Dim_Y     = height - 2 ;

          box_box.border    = Border_Dim;

          box_box.color.set( WINDOW_COLOR_TOOL_R,

                                 WINDOW_COLOR_TOOL_G,

                                 WINDOW_COLOR_TOOL_B ) ;

          box_box.Font_Name   = Title_Font_Name ;

          box_box.Font_Scale  = Title_Font_Scale ;

          box_box.Font_Weight = Title_Font_Weight ;

          box_box.Init( wnd ) ; 

 

 

          // ====================================================================

          // ====================================================================

          // ===================          !!!! IMPORTANT !!!!          =======================

          // ====================================================================

          // ====================================================================

 

          WNDCLASSEX  Wnd_Calc_A ;

 

          // --- Create the associated OpenGL window ---

          HINSTANCE hInstance = (HINSTANCE) GetWindowLong( GetActiveWindow(), GWLP_HINSTANCE ) ;

 

          // --- create the Calc_A window class ---

          Gray_Brush  = (HBRUSH) CreateSolidBrush( COLOR_GREY ) ;

 

          Wnd_Calc_A.cbSize        = sizeof (Wnd_Calc_A) ;

          Wnd_Calc_A.style         = CS_HREDRAW | CS_VREDRAW ;

          Wnd_Calc_A.lpfnWndProc   = WndProcCalc_A ;

          Wnd_Calc_A.cbClsExtra    = 0 ;

          Wnd_Calc_A.cbWndExtra    = 0 ;    // pointer to local data structure

          Wnd_Calc_A.hInstance     = hInstance ;

          Wnd_Calc_A.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;

          Wnd_Calc_A.hCursor       = LoadCursor (NULL, IDC_ARROW) ;

          Wnd_Calc_A.hbrBackground = Gray_Brush ;

          Wnd_Calc_A.lpszMenuName  = NULL ;

          Wnd_Calc_A.lpszClassName = "Calc_A" ;

          Wnd_Calc_A.hIcon         = LoadIcon ( hInstance, "ICON1" ) ;

          Wnd_Calc_A.hIconSm       = LoadIcon ( hInstance, "ICON1" ) ;

 

          RegisterClassEx (&Wnd_Calc_A) ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Destroy

//

//          Parameters:          (void)

//          Returns:          (int)                    0 if error

//

//          This is called when sliceO is closing.  This is a good occasion to

//          release any allocated resources and close all interface tools.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Destroy( void )

{

          Error_Fct( hwnd, FCT_IN_TRACE, "Tool Surface: Ctrl_Destroy()" ) ;

 

          // --- close any open sub-windows ---

          if ( Hwnd_Surface_A )

              DestroyWindow( Hwnd_Surface_A ) ;

 

          DeleteObject( Gray_Brush ) ;

 

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Ctrl_Click

//

//          Parameters:          wnd (HWND)          Pointer to Window's generating the signal

//                              up_down (int)          state of the mouse buttons

//                              x, y (int)          current cursor position

//          Returns:          (int)                    0 if error

//

//          This is called each time the cursor is inside your menu and the state

//          of the mouse buttons has changed.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) int          Ctrl_Click( HWND wnd, int up_down, short x, short y )

{

          if ( ! up_down )

              return( 0 ) ;

 

          // ====================================================================

          // === Open separated detailed results window

          // ====================================================================

          if ( but_blow_a.Select( up_down ) ) {

              if ( ! but_blow_a.Cur_Value ) {

                    but_blow_a.Cur_Value = 1 ;

                    but_blow_a.Adjust() ;

 

                    // --- only 1 window at a time ---

                    if ( ! Hwnd_Surface_A ) {

                        // --- Create the associated OpenGL window ---

                        HINSTANCE hInstance = (HINSTANCE) GetWindowLong( GetActiveWindow(), GWLP_HINSTANCE ) ;

 

                        Hwnd_Surface_A = CreateWindowEx( WS_EX_ACCEPTFILES | WS_EX_TOPMOST,

                                                   "Calc_A", "Surface Values",

                                               WS_OVERLAPPEDWINDOW | WS_VISIBLE,

                                               CW_USEDEFAULT, CW_USEDEFAULT,

                                               600, 203,

                                               NULL, NULL, hInstance, NULL) ;

                        assert( Hwnd_Surface_A ) ;

                    }

                    EnableWindow( Hwnd_Surface_A, TRUE ) ;

              } else {

                    EnableWindow( Hwnd_Surface_A, TRUE ) ;

                    ShowWindow( Hwnd_Surface_A, SW_SHOW ) ;

                    BringWindowToTop( Hwnd_Surface_A ) ;

              }

              return( 1 ) ;

          }

 

          ...

 

 

See also