539 views
in GUI Development by

Hello,

I currently have <1920,1080> in the profile settings for ScreenSize. Now I want the window to expand as I drag it larger and automatically fill the empty area with color. I get the pixels of width and height of the window with "GetActiveWindow" & "GetWindowRect" functions.

How can I now set that my window expands automatically when I drag it larger?

Some pictures:

 

Best regards
Justin

 

1 Answer

+1 vote
by
 
Best answer

Hello Justin,

I assume you refer to the Win32 Platform Package. In this case the size of the window is predetermined by the value set in ScreenSize attribute. It is fixed and not intended to be changed at the runtime since usually the design of the application imposes the size of the window. Anyway, to support the UI with dynamic size would require multiple modifications of the Platform Package code. For the recent version 12, these would be:

1. In the WindowProc() function look for the WM_SIZE Windows message handler. Delete the original code found there. The function is found in the module gfx_system_windows.c.

2. In the WM_SIZE message handler, recreate the DIB (Windows bitmap acting as frame buffer memory) with the new window size. (use the functions CreateDIB() and DestroyDIB()).

3. In the WM_SIZE message handler, recreate the Viewport. (use the functions EwInitViewport() and EwDoneViewport()).

4. In the WM_SIZE message handler, adjust the root object dimension. For this purpose invoke the method OnSetBounds() of the root object providing to it the new dimension.

5. In the WM_SIZE message handler, update the global variable ViewerSize.

Following could be the code (without having verified that it works):

case WM_SIZE :
{
  XObject rootObject = EwGetAppRootObject();
  int     width      = LOWORD( aLParam );
  int     height     = HIWORD( aLParam );
  XPoint  size       = { width, height };
  XRect   rect       = { 0, 0, width, height };

  /* Each time the window is resized -> free the old framebuffer */
  if ( Viewport    ) EwDoneViewport( Viewport );
  if ( Framebuffer ) DestroyDib( Framebuffer );

  /* Create new framebuffer */
  if (( Framebuffer = CreateDib( width, height )) == 0 )
  {
    ... failed -> end application ...
  }

  /* Also create the viewport as bridge between the Windows DIB and the
     Graphics Engine bitmap */
  if (( Viewport = EwInitViewport( size, rect, 0, 255, Framebuffer,
        0, 0, ViewportProc )) == 0 )
  {
    ... failed -> end application ...
  }

  /* Remember the new size in the global variable */
  ViewportSize = size;

  /* update the size of the root object */
  CoreRectView__OnSetBounds( rootObject, rect );
  CoreGroup__InvalidateArea( rootObject, rect );
  EwProcessSignals();
  EwUpdateViewer();
}
break;

Now the UI application should be resizable. For example, when the size changes, the position and the size of components existing in your application can be updated. When you have a Filled Rectangle view in the background of the Application component, just configures its Layout property to be as shown below. This will have the effect of the rectangle automatically adapting the new size and so filling the entire screen:

Well, I hope it helps you further.

Best regards

Paul Banach

by

Hello Paul,

 

I changed the code, but the black stripes are already there.

 

 

I'll create a new project right away and see if it's the same there.

Best regards
Justin

by

Okay, it was my fault, I had set something wrong in Embedded Wizard, so the black line was there.

Now it's gone and the resizing works without any problems.

Thanks Paul for your help/support!

Best regards

Justin

by

Now I found another problem.

If you minimize the program, the program crashes and the error "Failed to create framebuffer."

 

by

That's true. The problem here is that when the window is minimized, Windows sends a WM_SIZE message with size 0,0. Modifying the if-condition in case WM_USER +1: seems to help. The modification takes care to perform the operation only when the window size is valid ( width > 0 ) && ( height > 0 ):

/* Any size changes? */
if (( width > 0 ) && ( height > 0 ) &&
   (( width != ViewerSize.X ) || ( height != ViewerSize.Y )))
  {
    /* Each time the window is resized -> free the old framebuffer */
    if ( FrameBuffer ) DestroyDib( FrameBuffer );
    FrameBuffer = 0;
    ....

I keep my fingers crossed, that it is the solution ...

by
Thank you, it works!

 

Many thanks and best regards

Justin

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...