Minimum/Maximum size(WindowPlacement property) of window bug

Reports of bugs and issues with Phoenix.
TechSupport
Site Admin
Posts: 809
Joined: Tue Sep 14, 2004 7:55 pm
Location: Mississauga ON, Canada

Minimum/Maximum size(WindowPlacement property) of window bug

Postby TechSupport » Wed Apr 18, 2007 7:55 am

Minimum/Maximum size of window bug
This is a bug that is introduced in the last update.
The code generated for the setting of the font for a form during the WM_CREATE message
uses the variable ghWndMain when multiple forms are in a project. Because the CreateWindowEx
function has not yet returned, the value of the ghWndMain variable is null at this point.
This means the font for the form is not set.
A temporary fix is to create and set the font in the WM_CREATE handler.

For example, use the following code if the default font is Tahoma.

Code: Select all

'-------------------------------------------------------------------------------

FUNCTION Form1_OnCreate _
  ( _
  BYVAL hWnd        AS DWORD, _ ' window handle
  BYVAL lptcs       AS DWORD, _ ' address of CREATESTRUCT structure
        lMsgResult  AS LONG _   ' value returned to message
  ) AS LONG

  ' Note: this code is a workaround for a bug in the code that is generated
  '       for the setting of the font for a form during the WM_CREATE message.
  ' Create and save the font used by the form
  hFont = phnxCreateFont("Tahoma", 8, %FW_NORMAL, 0, 0, 0, %ANSI_CHARSET)
  SendMessage hWnd, %WM_SETFONT, hFont, %FALSE

END FUNCTION


Or, a simpler solution which does not require a call to CreateFont.

Code: Select all

'-------------------------------------------------------------------------------

FUNCTION Form1_OnCreate _
  ( _
  BYVAL hWnd        AS DWORD, _ ' window handle
  BYVAL lptcs       AS DWORD, _ ' address of CREATESTRUCT structure
        lMsgResult  AS LONG _   ' value returned to message
  ) AS LONG
 
  ' Create and save the font used by the form
  hFont = GetStockObject(%DEFAULT_GUI_FONT)
  SendMessage hWnd, %WM_SETFONT, hFont, %FALSE                             

END FUNCTION


Why is this workaround needed in the OnCreate handler of a form?
The goal here is to make sure the form has a non null value for the font handle
because this code located in the design file

Code: Select all

    CASE WM_CREATE                                           
      ...
      ' Create and save the font used by the form
      hFont = GetStockObject(%DEFAULT_GUI_FONT)
      SendMessage ghWndMain, %WM_SETFONT, hFont, %FALSE

is sending the WM_SETFONT message to window with a null handle because at this point
the value of ghWndMain is zero. This means that the following code, also located in
the design file, will fail.

Code: Select all

    CASE %WM_GETMINMAXINFO
      ' Set the pointer to the address of the MINMAXINFO structure
      ptmmi = lParam
      ' Get the font used by the form
      hFont = SendMessage(hWnd, %WM_GETFONT, 0, 0)
      ' A bug in the operating system causes the WM_GETMINMAXINFO message to be sent
      ' before the WM_NCCREATE and WM_CREATE messages.  A nonzero font handle indicates
      ' that the window has processed these messages and is fully initialized.
      IF ISTRUE hFont THEN
        ' Set the minimum and maximum sizes that can be
        ' produced by dragging the borders of the window
        @ptmmi.ptMinTrackSize.x = 360
        @ptmmi.ptMinTrackSize.y = 394
      END IF

As a result, without the fix, the user will be able to resize the form to a size
that is smaller than the design-time size.

Return to “Phoenix Bug Reports”

Who is online

Users browsing this forum: No registered users and 1 guest