requested item

Started by James Fuller, May 28, 2016, 11:15:47 AM

Previous topic - Next topic

James Fuller

Jose,
  Excellent work on your FreeBasic include files.
I am a bit out of practice but the one item I would like to see and did not find in the help file is a control layout operation. I've seen some of your PB code where you do it manually in the WM_SIZE event but this is way too tedious for any window with more than a coulple of controls.

Maybe Paul could adapt or add to cMaker to provide this capacity?

James

José Roca

Dominic uses the Jeffrey Richter's layout algorithm, but I have been unable to find Richter's code.

José Roca

I have found UILayout.h in a Chinese site, with comments in Chinese. I will try to adapt it to FreeBASIC.

James Fuller

Jose,
  Attached is an exe that uses the original "c" code compiled with the TDM-GCC-64 compiler. It has the same problem all approaches I have tried except one. I tried Patrice's code and it has the same issue. IUP is the only one I've found where frame text does not flicker
Most mail hosts whine on included exe's so I posted here.

Watch your email from my jcfuller22 gmail account for more info

James

José Roca

Well, I have done the translation from the code found in the Chinese site.

This is the first test, with a button, that works fine. We may need to do more tests.
You will find the class in the attached .rar file.


' ########################################################################################
' Microsoft Windows
' File: CW_LAYOUT_Button.fbtpl
' Contents: CWindow layout button example
' Compiler: FreeBasic 32 & 64 bit
' Copyright (c) 2016 Jose Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################

#INCLUDE ONCE "windows.bi"
#INCLUDE ONCE "Afx/CWindow.inc"
#INCLUDE ONCE "Afx/CUILayout.inc"

USING Afx.CWindowClass
USING Afx.CUILayoutClass

DIM SHARED g_UILayout AS CUILayout PTR

DECLARE FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                          BYVAL hPrevInstance AS HINSTANCE, _
                          BYVAL szCmdLine AS ZSTRING PTR, _
                          BYVAL nCmdShow AS LONG) AS LONG

   END WinMain(GetModuleHandleW(NULL), NULL, COMMAND(), SW_NORMAL)

' ========================================================================================
' Window procedure
' ========================================================================================
FUNCTION WndProc (BYVAL hWnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

   SELECT CASE uMsg

      CASE WM_CREATE
         EXIT FUNCTION

      CASE WM_COMMAND
         SELECT CASE LOWORD(wParam)
            CASE IDCANCEL
               ' // If ESC key pressed, close the application sending an WM_CLOSE message
               IF HIWORD(wParam) = BN_CLICKED THEN
                  SendMessageW hwnd, WM_CLOSE, 0, 0
                  EXIT FUNCTION
               END IF
         END SELECT

      CASE WM_SIZE
         g_UILayout->AdjustControls(LOWORD(lParam), HIWORD(lParam))
         EXIT FUNCTION

    CASE WM_DESTROY
         PostQuitMessage(0)
         EXIT FUNCTION

   END SELECT

   FUNCTION = DefWindowProcW(hWnd, uMsg, wParam, lParam)

END FUNCTION
' ========================================================================================

' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS HINSTANCE, _
                  BYVAL hPrevInstance AS HINSTANCE, _
                  BYVAL szCmdLine AS ZSTRING PTR, _
                  BYVAL nCmdShow AS LONG) AS LONG

   ' // Set process DPI aware
   AfxSetProcessDPIAware

   DIM pWindow AS CWindow
   pWindow.Create(NULL, "CWindow with a button", @WndProc)
   pWindow.SetClientSize(500, 320)
   pWindow.Center

   ' // Add a button
   pWindow.AddControl("Button", pWindow.hWindow, IDCANCEL, "&Close", 350, 250, 75, 23)

   g_UILayout = NEW CUILayout(pWindow.hWindow, 100, 100)
   g_UILayout->AnchorControl(AP_BOTTOMRIGHT, AP_BOTTOMRIGHT, IDCANCEL, FALSE)

   FUNCTION = pWindow.DoEvents(nCmdShow)

   IF g_UILayout THEN Delete g_UILayout

END FUNCTION
' ========================================================================================


James Fuller

Jose,
It's a no-go here compiled as 64bit on Win10
Compiles fine but nothing shows when run.

James

José Roca

I dont have Windows 10 to test.

BTW the HandleMinMax procedure was missing, although I don't know what it is his purpose, because it is not used in the class.

James Fuller

#7
I tried the exe compiled on Win10 on a Win7 box and it failed there also.
I'm not set up to compile on Win7.

If I comment out the call in WM_SIZE the window shows.
James

José Roca

Attached is the compiled test. It works in my computer with Windows 7.

James Fuller

Runs fine on Win7 does not on Win10.

James

José Roca

There is nothing I can't do. As I said, I don't have Windows 10. You have the source code, try to find where it fails.

Paul Squires

Quote from: Jose Roca on May 28, 2016, 05:19:34 PM
There is nothing I can't do. As I said, I don't have Windows 10. You have the source code, try to find where it fails.


I have Windows 10. I will try to debug the problem now. I will report back soon.
Paul Squires
PlanetSquires Software

Paul Squires

Seems like the problem is with WM_SIZE. That message is sent during your window creation but of course the pointer has not been initialized until a short time later. When the second WM_SIZE arrives then the pointer is okay. It seems that the GPF occurs on the first null pointer during the first WM_SIZE. Just need to test for a null pointer I think.


      CASE WM_SIZE
         If g_UILayout Then
            g_UILayout->AdjustControls(Loword(lParam), Hiword(lParam))
         End If
         Exit Function

Paul Squires
PlanetSquires Software

José Roca

For some unknown reason, it doesn't GPF in my computer, when it should. Now the question is if it works in Windows 10 after adding the check or not.

Paul Squires

It works for me on Windows 10 when I add the check. It GPF's when the check is omitted. Let's see if James experiences the same as I do.
Paul Squires
PlanetSquires Software