Problem in Dynamic Windows with Auto-size

Moderator: Rathinagiri

Post Reply
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Problem in Dynamic Windows with Auto-size

Post by dhaine_adp »

Hello,

Here's a modified demo.prg from \hmg\SAMPLES\Controls\Button\BUTTON_3 with termination error as:
ToolBar's Parent Window Can't Be a 'Virtual Dimensioned' Window (Use 'Virtual Dimensioned' SplitChild Instead). Program terminated
The program went bananas when windows1, windows2 and windows3 are maximized.

Here's the modified code:

Code: Select all

/*
 * HMG - Harbour Win32 GUI library
 * Copyright 2002-2008 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
*/

#include "hmg.ch"


***************
Function Main()

   PRIVATE hWndName := ""
   PRIVATE hCtrlTbar := ""

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 200 ;
      HEIGHT 200 ;
      MAIN;
      TITLE 'Button Test'

      DEFINE MAIN MENU
              POPUP 'Test'
                ITEM 'Disable button' ACTION Form_1.Button_1.Enabled := .f.
                ITEM 'Enable button'  ACTION Form_1.Button_1.Enabled := .t.
                SEPARATOR
                ITEM "Window 1" ACTION WIND( "window1" )
                ITEM "Window 2" ACTION WIND( "window2" )
                ITEM "Window 3" ACTION WIND( "window3" )
              END POPUP
      END MENU

      @ 70,70 CHECKBUTTON Button_1 PICTURE "button.bmp" WIDTH 50 HEIGHT 50 

   END WINDOW

   Form_1.Maximize
   ACTIVATE WINDOW Form_1
   Return


******************************
static function wind( cParam )

   IF PCOUNT() = 1
      hWndName := cParam
      hTbarCtrl := "tBar" + cParam
   ENDIF

   DEFINE WINDOW &(hWndName) ;
      AT 0,0 ;
      WIDTH 200 ;
      HEIGHT 200 ;
      TITLE "&hWndName";
      ON INIT WinAutoAdjust( ThisWindow.Name );
      ON SIZE WinAutoAdjust( ThisWindow.Name );
      ON MAXIMIZE WinAutoAdjust( ThisWindow.Name );
      ON PAINT ( hWndName := ThisWindow.Name );
      ON GOTFOCUS ( hWndName := ThisWindow.Name )

      DEFINE TOOLBAR &(hTbarCtrl) OF &(hWndName) BUTTONSIZE 20, 24 FONT "Arial" SIZE 8 BORDER
         BUTTON tbtnNExit CAPTION "E&xit";
            ACTION ( MSGINFO( hWndName, "x" ), DOMETHOD( hWndName,"Release") )
         BUTTON tbtnNew  CAPTION "&New Record" ;
            ACTION NIL
            
         BUTTON tbtnEdit CAPTION "E&dit Record" ;
            ACTION nil
            
         BUTTON tbtnPrint CAPTION "&Print" ;
            ACTION NIL TOOLTIP "Print list"
      END TOOLBAR


      DEFINE MAIN MENU
              POPUP 'Test'
                ITEM 'Disable button'  ACTION tstAct( .F. )// ACTION &(hWndName).Button_1.Enabled := .f.
                ITEM 'Enable button'   ACTION tstAct( .T. )// ACTION &(hWndName).Button_1.Enabled := .t.
              END POPUP
      END MENU

      @ 70,70 CHECKBUTTON Button_1 OF &(hWndName) PICTURE "button.bmp" WIDTH 50 HEIGHT 50 

   END WINDOW
   &(hWndName).CENTER
   &(hWndName).ACTIVATE
   RETURN NIL





******************************
static function tstAct(lvalue)

   SetProperty(hWndName,"Button_1","Enabled",lvalue)
   




************************
Function ISAPPXPTHEMED()
   RETURN ( OS_ISWINXP_OR_LATER() .AND. IsAppThemed() )


*******************************
function WinAutoAdjust( cForm )

   LOCAL hWnd := GetFormHandle( cForm )

   LOCAL i  // Form Number
   LOCAL k  // Control Number
   LOCAL ParentForm
   LOCAL ControlCount
   LOCAL ControlName
   LOCAL ControlType
   LOCAL nWidth
   LOCAL nHeight
   LOCAL lvisible:= .T.
   LOCAL nDivw
   LOCAL nDivh


   IF GetDesktopWidth() < GetWindowWidth ( hWnd )
      nWidth := GetDesktopWidth()
   ELSE
      nWidth := GetWindowWidth ( hWnd )
   ENDIF
   
   IF GetDesktopHeight() < GetWindowHeight ( hWnd )
      nHeight := GetDesktopHeight()
   ELSE
      nHeight := GetWindowHeight ( hWnd )
   ENDIF
   
   IF IsWindowVisible ( hWnd ) .And. ! IsAppXPThemed()
      HideWindow ( hWnd )
   ELSE
      lvisible := .F.
   ENDIF
   
   i := ASCAN ( _HMG_SYSDATA[ 67 ] , hWnd )
   ParentForm := _HMG_SYSDATA[ 66, i ]
   
   IF _HMG_SYSDATA[ 92, i ] > 0 .and. _HMG_SYSDATA[ 91, i ] > 0
      nDivw := nWidth  / _HMG_SYSDATA[ 92, i ]
      nDivh := nHeight / _HMG_SYSDATA[ 91, i ]
   ELSE
      nDivw := 1
      nDivh := 1
   ENDIF
   
   ControlCount := LEN ( _HMG_SYSDATA[ 3 ] )

   FOR k := 1 To ControlCount
      ControlName := _HMG_SYSDATA[ 2, k ]
      
      IF _IsControlDefined ( ControlName, ParentForm )
         ControlType := _HMG_SYSDATA[ 1, k ]

         IF !EMPTY( ControlName ) .AND. ;
            !( ControlType $ "MENU,HOTKEY,TOOLBAR,MESSAGEBAR,ITEMMESSAGE,TIMER" )

            DO CASE
               //CASE ControlType == "RADIOGROUP"
                  // _HMG_aControlSpacing     := _HMG_SYSDATA[ 22 ]
                  // _HMG_aControlMiscData1   := _HMG_SYSDATA[  8 ]
                  // _HMG_aControlSpacing [k] := _HMG_aControlSpacing [k] * IIF(_HMG_aControlMiscData1 [k], nDivw, nDivh)
                  
               CASE ControlType == "SLIDER"     // do nothing
               CASE ControlType == "STATUSBAR"  // do nothing
               
               CASE ControlType == "LABEL"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height

               CASE ControlType $ "TEXT,RADIOGROUP"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height

               CASE ControlType == "BUTTON"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;
                  _GetControlHeight ( ControlName, ParentForm ) )        // _GetControlHeight ( ControlName, ParentForm ) * nDivh )

               CASE !ControlType $ "TOOLBUTTON"
                  _SetControlSizePos ( ControlName, ParentForm,;
                  _GetControlRow ( ControlName, ParentForm ) * nDivh, _GetControlCol ( ControlName, ParentForm ) * nDivw,;
                  _GetControlWidth ( ControlName, ParentForm ) * nDivw, _GetControlHeight ( ControlName, ParentForm ) * nDivh )
            OTHERWISE
               IF EMPTY( _HMG_SYSDATA[ 28, k ] )
                  _SetFontSize ( ControlName, ParentForm , 8 * nDivh )
               ELSE
                  //_SetFontSize ( ControlName, ParentForm , _HMG_SYSDATA[28] [k] * nDivh )
               ENDIF
            ENDCASE
         ENDIF

      ENDIF
   NEXT k

   _HMG_SYSDATA[ 92, i ] := nWidth
   _HMG_SYSDATA[ 91, i ] := nHeight

   IF lvisible
      ShowWindow ( hWnd )
   ENDIF
   RETURN NIL
The program error call trace:

Code: Select all

Date:10/31/14 Time: 15:15:40
Error: HMG 3.3.1 Stable Patch 1 (32 bits)
ToolBar's Parent Window Can't Be a 'Virtual Dimensioned' Window (Use 'Virtual Dimensioned' SplitChild Instead). Program terminated
Called from EVENTS(1074) 
Called from _HMG_PRINTER_SETVSCROLLVALUE(0) 
Called from VIRTUALCHILDCONTROLFOCUSPROCESS(6268) 
Called from EVENTS(1965) 
Called from SETFOCUS(0) 
Called from EVENTS(942) 
Called from C_MSGSTOP(0) 
Called from SHOWERROR(168) 
Called from MSGHMGERROR(81) 
Called from EVENTS(1074) 
Called from _HMG_PRINTER_SETVSCROLLVALUE(0) 
Called from VIRTUALCHILDCONTROLFOCUSPROCESS(6268) 
Called from EVENTS(1965) 
Called from SETFOCUS(0) 
Called from EVENTS(942) 
Called from C_MSGINFO(0) 
Called from MSGINFO(118) 
Called from (b)WIND(63) 
Called from _DOCONTROLEVENTPROCEDURE(5745) 
Called from EVENTS(1649) 
Called from DOMESSAGELOOP(0) 
Called from _ACTIVATEWINDOW(5413) 
Called from DOMETHOD(8032) 
Called from WIND(87) 
Called from (b)MAIN(29) 
Called from _DOCONTROLEVENTPROCEDURE(5745) 
Called from EVENTS(1642) 
Called from DOMESSAGELOOP(0) 
Called from _ACTIVATEWINDOW(5413) 
Called from DOMETHOD(8032) 
Called from WIND(87) 
Called from (b)MAIN(28) 
Called from _DOCONTROLEVENTPROCEDURE(5745) 
Called from EVENTS(1642) 
Called from DOMESSAGELOOP(0) 
Called from _ACTIVATEWINDOW(5413) 
Called from MAIN(39) 
Basically it seems the error came from TOOLBAR control. When all those windows(n) are opened and maximized it thinks that it is a virtually dimensioned window. The dynamic windows creation is defined without "CHILD" clause so they can all sit as one group in the taskbar. Unfortunately this is same error I've got on my app.

To compile, use the build.bat from \hmg\SAMPLES\Controls\Button\BUTTON_3 folder or block comment the original code on your demo.prg in the same folder and paste the code above, save and compile.

To replicate the error, click Test then select Window 1 then again select Window 2 and Window 3. Maximized all windows and if they are not visible, click on the taskbar select the window to bring it into focus then maximized. Once you're done trigger the error from the toolbar control of windows1,2 or 3 and click the button "Exit". Also when you restore those windows, the program loose tracked of which window is which. (Hmm... perhaps I should also add ON MOUSE click windows event).

The error should not happen because its just a recursive call however is there anything more missing?
To terminate the program after the call trace use Windows Taskmanager.

TIA.
Regards,

Danny
Manila, Philippines
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Problem in Dynamic Windows with Authosize

Post by dhaine_adp »

Basically it seems the error came from TOOLBAR control. When all those windows(n) are opened and maximized it thinks that it is a virtually dimensioned window.
I'm quoting my self in here, technically it becomes a virtual windows when it is maximized however when winauthoadjust() applied to a window or Windows1 only it works fine but when there are more than one dynamic windows opened and maximized then the error will occur. I suspect that there's something in _HMG_SYSDATA has to be tweaked to avoid the detection of virtual windows.

Theoretically, splitting the codes into separate prgs' probably fixed the problem but is it the only way or there's another hack?
Regards,

Danny
Manila, Philippines
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Problem in Dynamic Windows with Authosize

Post by Javier Tovar »

Gracias Danny por informar,

Saludos
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Problem in Dynamic Windows with Authosize

Post by dhaine_adp »

Hello,

I have resolved the problem, there's nothing wrong with HMG Library. The problem is the calling convention from the MAIN Window. The problems are: (1) the private variable hWndName is not in sync with the current window in focus so (2) Call SetProperty() with ThisWindow.Name as parameter (3) Quoted below: WinAutoAdjust() has to be changed like:
IF _HMG_SYSDATA[ 92, i ] > 0 .and. _HMG_SYSDATA[ 91, i ] > 0
_HMG_SYSDATA[ 92, i ] := nWidth
_HMG_SYSDATA[ 91, i ] := nHeight
ENDIF
Here's the complete working sample for Dynamic Window along with the revision WinAutoAdjust(). This sample is derived from
\<hmgInstallDir>\SAMPLES\Controls\Button\BUTTON_3\demo.prg

Code: Select all

/*
 * HMG - Harbour Win32 GUI library
 * Copyright 2002-2008 Roberto Lopez <mail.box.hmg@gmail.com>
 * http://www.hmgforum.com//
 *
 * Revision: October 31, 2014
 * Revised by: Danny Del Pilar
 * HMG Sample: Managing Dynamic Windows Sample
 *
 *
*/

#include "hmg.ch"


***************
Function Main()

   PRIVATE hWndName := ""

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 200 ;
      HEIGHT 200 ;
      MAIN;
      TITLE 'Button Test'

      DEFINE MAIN MENU
              POPUP 'Test'
                ITEM 'Disable button' ACTION Form_1.Button_1.Enabled := .f.
                ITEM 'Enable button'  ACTION Form_1.Button_1.Enabled := .t.
                SEPARATOR
                ITEM "Window 1" ACTION WIND( "window1" )
                ITEM "Window 2" ACTION WIND( "window2" )
                ITEM "Window 3" ACTION WIND( "window3" )
              END POPUP
      END MENU

      @ 70,70 CHECKBUTTON Button_1 PICTURE "button.bmp" WIDTH 50 HEIGHT 50 

   END WINDOW

   Form_1.Maximize
   ACTIVATE WINDOW Form_1
   Return


**********************
static function wind()

   PARAMETER hWndName

   DEFINE WINDOW &(hWndName) ;
      AT 0,0 ;
      WIDTH 200 ;
      HEIGHT 200 ;
      TITLE "&hWndName";
      ON INIT WinAutoAdjust( ThisWindow.Name );
      ON SIZE WinAutoAdjust( ThisWindow.Name );
      ON MAXIMIZE WinAutoAdjust( ThisWindow.Name )

      DEFINE TOOLBAR tbar1 OF &( ThisWindow.Name )  BUTTONSIZE 20, 24 FONT "Arial" SIZE 8 BORDER
         BUTTON tbtnNExit CAPTION "E&xit";
            ACTION ( MSGINFO( ThisWindow.Name, "x" ), DOMETHOD( ThisWindow.Name,"Release") )
         BUTTON tbtnNew  CAPTION "&New Record" ;
            ACTION NIL
            
         BUTTON tbtnEdit CAPTION "E&dit Record" ;
            ACTION nil
            
         BUTTON tbtnPrint CAPTION "&Print" ;
            ACTION NIL TOOLTIP "Print list"
      END TOOLBAR


      DEFINE MAIN MENU
              POPUP 'Test'
                ITEM 'Disable button'  ACTION tstAct( ThisWindow.Name, .F. )// ACTION &(hWndName).Button_1.Enabled := .f.
                ITEM 'Enable button'   ACTION tstAct( ThisWindow.Name, .T. )// ACTION &(hWndName).Button_1.Enabled := .t.
              END POPUP
      END MENU

      @ 70,70 CHECKBUTTON Button_1 OF &( ThisWindow.Name ) PICTURE "button.bmp" WIDTH 50 HEIGHT 50 

   END WINDOW
   &(hWndName).CENTER
   &(hWndName).ACTIVATE
   RETURN NIL





******************************
static function tstAct(cName ,lvalue)

   SetProperty(cName,"Button_1","Enabled",lvalue)
   




************************
Function ISAPPXPTHEMED()
   RETURN ( OS_ISWINXP_OR_LATER() .AND. IsAppThemed() )


*******************************
function WinAutoAdjust( cForm )

   LOCAL hWnd := GetFormHandle( cForm )

   LOCAL i  // Form Number
   LOCAL k  // Control Number
   LOCAL ParentForm
   LOCAL ControlCount
   LOCAL ControlName
   LOCAL ControlType
   LOCAL nWidth
   LOCAL nHeight
   LOCAL lvisible:= .T.
   LOCAL nDivw
   LOCAL nDivh


   IF GetDesktopWidth() < GetWindowWidth ( hWnd )
      nWidth := GetDesktopWidth()
   ELSE
      nWidth := GetWindowWidth ( hWnd )
   ENDIF
   
   IF GetDesktopHeight() < GetWindowHeight ( hWnd )
      nHeight := GetDesktopHeight()
   ELSE
      nHeight := GetWindowHeight ( hWnd )
   ENDIF
   
   IF IsWindowVisible ( hWnd ) .And. ! IsAppXPThemed()
      HideWindow ( hWnd )
   ELSE
      lvisible := .F.
   ENDIF
   
   i := ASCAN ( _HMG_SYSDATA[ 67 ] , hWnd )
   ParentForm := _HMG_SYSDATA[ 66, i ]
   
   IF _HMG_SYSDATA[ 92, i ] > 0 .and. _HMG_SYSDATA[ 91, i ] > 0
      nDivw := nWidth  / _HMG_SYSDATA[ 92, i ]
      nDivh := nHeight / _HMG_SYSDATA[ 91, i ]
   ELSE
      nDivw := 1
      nDivh := 1
   ENDIF
   
   ControlCount := LEN ( _HMG_SYSDATA[ 3 ] )

   FOR k := 1 To ControlCount
      ControlName := _HMG_SYSDATA[ 2, k ]
      
      IF _IsControlDefined ( ControlName, ParentForm )
         ControlType := _HMG_SYSDATA[ 1, k ]

         IF !EMPTY( ControlName ) .AND. ;
            !( ControlType $ "MENU,HOTKEY,TOOLBAR,MESSAGEBAR,ITEMMESSAGE,TIMER" )

            DO CASE
               //CASE ControlType == "RADIOGROUP"
                  // _HMG_aControlSpacing     := _HMG_SYSDATA[ 22 ]
                  // _HMG_aControlMiscData1   := _HMG_SYSDATA[  8 ]
                  // _HMG_aControlSpacing [k] := _HMG_aControlSpacing [k] * IIF(_HMG_aControlMiscData1 [k], nDivw, nDivh)
                  
               CASE ControlType == "SLIDER"     // do nothing
               CASE ControlType == "STATUSBAR"  // do nothing
               
               CASE ControlType == "LABEL"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height

               CASE ControlType $ "TEXT,RADIOGROUP"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height

               CASE ControlType == "BUTTON"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;
                  _GetControlHeight ( ControlName, ParentForm ) )        // _GetControlHeight ( ControlName, ParentForm ) * nDivh )

               CASE !ControlType $ "TOOLBUTTON"
                  _SetControlSizePos ( ControlName, ParentForm,;
                  _GetControlRow ( ControlName, ParentForm ) * nDivh, _GetControlCol ( ControlName, ParentForm ) * nDivw,;
                  _GetControlWidth ( ControlName, ParentForm ) * nDivw, _GetControlHeight ( ControlName, ParentForm ) * nDivh )
            OTHERWISE
               IF EMPTY( _HMG_SYSDATA[ 28, k ] )
                  _SetFontSize ( ControlName, ParentForm , 8 * nDivh )
               ELSE
                  //_SetFontSize ( ControlName, ParentForm , _HMG_SYSDATA[28] [k] * nDivh )
               ENDIF
            ENDCASE
         ENDIF

      ENDIF
   NEXT k

   IF _HMG_SYSDATA[ 92, i ] > 0 .and. _HMG_SYSDATA[ 91, i ] > 0
      _HMG_SYSDATA[ 92, i ] := nWidth
      _HMG_SYSDATA[ 91, i ] := nHeight
   ENDIF

   IF lvisible
      ShowWindow ( hWnd )
   ENDIF
   RETURN NIL
Regards,

Danny
Manila, Philippines
Javier Tovar
Posts: 1275
Joined: Tue Sep 03, 2013 4:22 am
Location: Tecámac, México

Re: Problem in Dynamic Windows with Authosize

Post by Javier Tovar »

Bien Danny, lo voy a probar!

Saludos
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Problem in Dynamic Windows with Authosize

Post by serge_girard »

Danny,

When I open the popup menu the programs get hungup... I had to kill it.

Serge
There's nothing you can do that can't be done...
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Problem in Dynamic Windows with Authosize

Post by dhaine_adp »

Danny,

When I open the popup menu the programs get hungup... I had to kill it.
Hi Serge,

I tested again the latest sample code I've posted and it works fine for me as I described. My OS is Win XP Pro. Tomorrow I'll test it with Win 7. You can try another test if you will.

1. Go to \<hmgInstallDir>\SAMPLES\Controls\Button\BUTTON_3\
2. ren demo.prg demo1.prg
3. Copy & paste the last code I've posted and Save As demo.prg
4. Double click on the file build.bat to compile the code.

If this is the way you tested the sample code then I'm sorry, I have no idea what have just happened. BTW I'm using the HMG Unicode Build 32 bit.
Regards,

Danny
Manila, Philippines
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Problem in Dynamic Windows with Authosize

Post by esgici »

Thanks Danny :)

I hope this we be applied as a standard feature to HMG.

Regards
Viva INTERNATIONAL HMG :D
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Problem in Dynamic Windows with Auto-size

Post by dhaine_adp »

Hello everyone,

For those who have this run-time with Windows Autosize or WinAutoAdjust() as follows:

Code: Select all

Date:06/29/2015 Time: 22:56:17
Error BASE/1083 Argument error: *

Called from WINAUTOADJUST(460)
Called from (b)MAIN(137)
Called from _DOWINDOWEVENTPROCEDURE(5989)
Called from EVENTS(1605)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5625)
Called from DOMETHOD(8687)
Called from GENERICBRWOBJ:BEGINBROWSEDISPLAY(426)
Called from STARTFILEMAIN(86)
Called from PATHOLOGYCASE(61)
Called from (b)MAIN(153)
Called from _DOCONTROLEVENTPROCEDURE(5957)
Called from EVENTS(1662)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5625)
Called from MAIN(204) 
The RT error above happened when there are more than one windows opened (Main + Child + Child, etc.) and the WinAutoAdjust() is fired by windows events. In my case, I don't have a BUTTON control object on my Main Window but the Child Windows has. In effect all windows is affected by auto-size event and the BUTTON object _GetControlRow() and GetControlCol() methods, both returns NIL value. Multiplication (*) operation is required to approximate the new objects dimension but with a NIL value, RT Error BASE/1083 Argument error: * is triggered. I've posted my hacked perhaps it may help somebody.

Code: Select all

************************
Function ISAPPXPTHEMED()
   RETURN ( OS_ISWINXP_OR_LATER() .AND. IsAppThemed() )


******************************************
function WinAutoAdjust( cForm, lMaxEvent )

   LOCAL hWnd := GetFormHandle( cForm )

   LOCAL i  // Form Number
   LOCAL k  // Control Number
   LOCAL ParentForm
   LOCAL ControlCount
   LOCAL ControlName
   LOCAL ControlType
   LOCAL nWidth
   LOCAL nHeight
   LOCAL lvisible:= .T.
   LOCAL nDivw
   LOCAL nDivh

   DEFAULT lMaxEvent TO .f.

   IF GetDesktopWidth() < GetWindowWidth ( hWnd )
      nWidth := GetDesktopWidth()
   ELSE
      nWidth := GetWindowWidth ( hWnd )
   ENDIF
   
   IF GetDesktopHeight() < GetWindowHeight ( hWnd )
      nHeight := GetDesktopHeight()
   ELSE
      nHeight := GetWindowHeight ( hWnd )
   ENDIF
   
   IF IsWindowVisible ( hWnd ) .And. ! IsAppXPThemed()
      HideWindow ( hWnd )
   ELSE
      lvisible := .F.
   ENDIF
   
   i := ASCAN ( _HMG_SYSDATA[ 67 ] , hWnd )
   ParentForm := _HMG_SYSDATA[ 66, i ]
   
   IF _HMG_SYSDATA[ 92, i ] > 0 .and. _HMG_SYSDATA[ 91, i ] > 0
      nDivw := nWidth  / _HMG_SYSDATA[ 92, i ]
      nDivh := nHeight / _HMG_SYSDATA[ 91, i ]
   ELSE
      nDivw := 1
      nDivh := 1
   ENDIF
   
   ControlCount := LEN ( _HMG_SYSDATA[ 3 ] )

   FOR k := 1 To ControlCount
      ControlName := _HMG_SYSDATA[ 2, k ]
      
      IF _IsControlDefined ( ControlName, ParentForm )
         ControlType := _HMG_SYSDATA[ 1, k ]

         IF !EMPTY( ControlName ) .AND. ;
            !( ControlType $ "MENU,HOTKEY,TOOLBAR,MESSAGEBAR,ITEMMESSAGE,TIMER" )

            DO CASE
               //CASE ControlType == "RADIOGROUP"
                  // _HMG_aControlSpacing     := _HMG_SYSDATA[ 22 ]
                  // _HMG_aControlMiscData1   := _HMG_SYSDATA[  8 ]
                  // _HMG_aControlSpacing [k] := _HMG_aControlSpacing [k] * IIF(_HMG_aControlMiscData1 [k], nDivw, nDivh)
                  
               CASE ControlType == "SLIDER"     // do nothing
               CASE ControlType == "STATUSBAR"  // do nothing
               
               CASE ControlType == "LABEL"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height
            
               CASE ControlType $ "TEXT,RADIOGROUP"
                  _SetControlSizePos( ControlName, ParentForm,;
                  _GetControlRow( ControlName, ParentForm ) * nDivh, ;   // row
                  _GetControlCol ( ControlName, ParentForm ) * nDivw ,;  // column
                  _GetControlWidth( ControlName, ParentForm ) * nDivw,;  // with
                  _GetControlHeight ( ControlName, ParentForm ) )        // height
            
               CASE ControlType == "BUTTON"
                  IF !_GetControlRow( ControlName, ParentForm ) == NIL .AND. ;
                     !_GetControlCol ( ControlName, ParentForm ) == NIL
                     _SetFontSize ( ControlName, ParentForm , 9 )
                     _SetControlSizePos( ControlName, ParentForm,;
                     _GetControlRow( ControlName, ParentForm ) * nDivh, ;
                     _GetControlCol ( ControlName, ParentForm ) * nDivw ,;
                     _GetControlWidth( ControlName, ParentForm ) * nDivw,;
                     _GetControlHeight ( ControlName, ParentForm ) )        // _GetControlHeight ( ControlName, ParentForm ) * nDivh )
                  ENDIF
            
               CASE !ControlType $ "TOOLBUTTON"
                  _SetControlSizePos ( ControlName, ParentForm,;
                  _GetControlRow ( ControlName, ParentForm ) * nDivh, _GetControlCol ( ControlName, ParentForm ) * nDivw,;
                  _GetControlWidth ( ControlName, ParentForm ) * nDivw, _GetControlHeight ( ControlName, ParentForm ) * nDivh )
            OTHERWISE
               IF EMPTY( _HMG_SYSDATA[ 28, k ] )
                  _SetFontSize ( ControlName, ParentForm , 8 * nDivh )
               ELSE
                  //_SetFontSize ( ControlName, ParentForm , _HMG_SYSDATA[28] [k] * nDivh )
               ENDIF
            ENDCASE
         ENDIF

      ENDIF
   NEXT k

   _HMG_SYSDATA[ 92, i ] := nWidth
   _HMG_SYSDATA[ 91, i ] := nHeight

   * MainForm.imgMainBK.Hide()
   * MainForm.imgMainBK.Row := 52
   * MainForm.imgMainBK.Width  := MainForm.ClientAreaWidth
   * MainForm.imgMainBK.Height := MainForm.ClientAreaHeight - 75
   * MainForm.imgMainBK.Show()   
   
   IF lvisible
      ShowWindow ( hWnd )
   ENDIF
   RETURN NIL
Those commented lines as * MainForm.etc.... is the main window's background image and also being sized and resized as needed. It's not a good solution but for the time being it serves what I'm intending to do.
Regards,

Danny
Manila, Philippines
Post Reply