Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

Best way to show a picture in an X# VOForm 12 Feb 2022 08:36 #21532

  • Chris
  • Chris's Avatar


  • Posts: 3974
  • Hi Dick,

    Thanks, but I'm afraid just seeing what you do won't be enough, after all it's just a double click, not much can go wrong about itself :)
    We would need to install debugging tools to find what's the problem in this particular case, but I think that's really overkill for debugging an empty window that you do not need anyway. In case you do get this anytime again, please let us know though!

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 28 Feb 2022 21:42 #21708

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1661
  • Hello Chris,

    I add my remark in a issue I posted today here too, for future readers:

    I reinstalled 2.10c and now the VO Form designer opened normally. Also on Frank's sample. I think the betaversion I still had installed may have been the cause of the FormDesigner not opening.

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    Best way to show a picture in an X# VOForm 02 Mar 2022 19:43 #21735

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1661
  • Hello Chris,

    Chris wrote: About the toolbox, you can choose to add a CustomControl to the window (from the VO toolbox), make it as large as you want and position it accordingly on the window, and then when you use SetParent(), use the handle of that custom control, instead of the handle of the window. That should do the trick.
    .


    In Frank's sample program with the Winforms control on it, the PostInit says:
    SetParent(Self:pictureBox1:Handle, Self:Handle())

    When I add a Customcontrol in the VO style Window editor, change the name to PICT and change the above line to:
    SetParent(self:oDCPict:Handle())

    I get a compiler as error 1 below and with
    SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())

    I get a runtime error 2).

    What parameter(s) am I suppose to add? Or should I do something else?

    1 Severity Code Description Project File Line Suppression State
    Error XS7036 There is no argument given that corresponds to the required formal parameter 'hWndNewParent' of 'VOWin32APILibrary.Functions.SetParent(PTR, PTR)' VOMDIApp2 C:\Temp\VOMDIApp2\Window1.prg 51

    2 System.NullReferenceException: Object reference not set to an instance of an object.

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    Best way to show a picture in an X# VOForm 02 Mar 2022 22:13 #21736

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Dick,

    SetParent() needs 2 arguments, first the handle of the control you need to move and second the handle of the parent, so your (2) version is the correct one.

    It's very strange if you are getting a NullReferenceException with it, are you sure it happens in this line of code and not sometime later in the program? Try checking the SELF:oDCPict object before using SetParent(), is it indeed NULL?

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 02 Mar 2022 23:02 #21737

    • ic2
    • ic2's Avatar
    • Topic Author


  • Posts: 1661
  • Hello Chris,

    It is not so strange, I realize now. I out commented some of the existing lines including the instantiation. So the error makes sense ;)

    When I replace the SetParent line with SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())
    the program uses the CustomControl which I added in the form editor.

    I am still wondering if that is the most efficient way? I can't do something like this:

    Self:oDCPict:= System.Windows.Forms.PictureBox{} (XS0029, implicit conversion of PictureBox to VO.Custom.Control) and all the other assignments are not of that CustomCOntrol class. But the (working) code feels a bit contrived:
    Self:pictureBox1:= System.Windows.Forms.PictureBox{}
    Self:pictureBox1:Location := System.Drawing.Point{1, 1}
    Self:pictureBox1:Name := "e""pictureEdit1"
    Self:pictureBox1:Size := System.Drawing.Size{400, 400}
    Self:pictureBox1:SizeMode:= System.Windows.Forms.PictureBoxSizeMode.Zoom
    Self:pictureBox1:Visible := True
    Self:pictureBox1:TabIndex := 700
    Self:pictureBox1:Load("c:\temp\SomePict.jpg")	
    SetParent(Self:pictureBox1:Handle, Self:oDCPict:Handle())		

    Dick

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 02 Mar 2022 23:43 #21740

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Dick,

    You can't assign a Windows.Forms control to a VO GUI control object, in the same way you cannot assign a WPF control to a WinForms object or vice versa. Or like assigning a VO style ragged array to a fixed size array, they are just different things.They are both controls that you can put on a window, but they have a completely different design and of course also different class hierarchy.

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Best way to show a picture in an X# VOForm 14 Jun 2022 09:46 #22744

    • KeesIC2
    • KeesIC2's Avatar


  • Posts: 49
  • Hi,

    I used code similar to the code below to show a .NET HTML editor control on a VO MDI datawindow with a custom control. I have also tried it in another app on a VO dialogwindow without the custom control. In both cases, everything works (you can type in the control, use the cursor keys and edit text) except for the ENTER key. This should produce a new line but seems to do nothing at all. I have written code to intercept key presses inside the control and the ENTER is not detected at all so I suspect the ENTER key is somehow not "passed on" to the control. The same control on a Winforms form works fine including the ENTER key. Can anyone think of a reason why specifically the ENTER key would not work on a VO window?

    Thanks for any help!

    Kees.

    Frank Müßner wrote: Hello Dick,

    I use this code when I need a .Netcontrol on a VO window.

        self:pictureEdit1:= DevExpress.XtraEditors.PictureEdit{}
        self:pictureEdit1:Location := System.Drawing.Point{self:size:Width-175, 124} //tt:Height-289}
        self:pictureEdit1:Name := "e""pictureEdit1"
        self:pictureEdit1:Properties:SizeMode := DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom
        self:pictureEdit1:Properties:BorderStyle := DevExpress.XtraEditors.Controls.BorderStyles.NoBorder
        self:pictureEdit1:Properties:ShowMenu := false
        self:pictureEdit1:Size := System.Drawing.Size{162, 162}
        self:pictureEdit1:Visible := True
        self:pictureEdit1:TabIndex := 500
        SetParent(SELF:pictureEdit1:Handle, self:Handle())

    runs without problems until now.

    Maybe it will help you

    Frank

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 14 Jun 2022 11:56 #22747

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Kees,

    Try adding this code to your app:

    USING System.Collections.Generic
    GLOBAL gaHandlesForEnter := List<IntPtr>{} AS List<IntPtr>
    
    // put this method inside the App subclass in your code
    METHOD BeforeDispatch(hWnd,uMsg,wParam,lParam)
    	IF uMsg == WM_KEYDOWN .and. wParam == VK_RETURN
    		IF gaHandlesForEnter:Contains((IntPtr)hWnd)
    			SendMessage(hWnd, WM_CHAR , 10 , 0)
    			SendMessage(hWnd, WM_CHAR , 13 , 0)
    			RETURN FALSE
    		END IF
    	ENDIF
    RETURN TRUE

    Now, after you put any .Net control to a VO window (with SetParent()), add this code exactly after SetParent():

    gaHandlesForEnter:Add(oMyNetControl:Handle)

    Does it work ok now?

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 14 Jun 2022 20:10 #22748

    • KeesIC2
    • KeesIC2's Avatar


  • Posts: 49
  • Hi Chris,

    Thank you for the code. I have tried it but unfortunately it makes no difference. I have also put a MessageBox below the line "IF uMsg == WM_KEYDOWN .and. wParam == VK_RETURN" and it does not appear if I press Enter so I guess the ENTER key does not even make it to that point.

    Kees.

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 14 Jun 2022 23:01 #22749

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Kees,

    Can you please send me a complete zipped sample solution showing the not working correctly control on the VOWindow?
    I do have the devexpress controls, so no need to send those dlls also.

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 15 Jun 2022 09:40 #22750

    • KeesIC2
    • KeesIC2's Avatar


  • Posts: 49
  • Hi Chris,

    Thank you for taking the time to look at my issue! I have just sent you the solution.

    Kees.

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 17 Jun 2022 17:28 #22790

    • KeesIC2
    • KeesIC2's Avatar


  • Posts: 49
  • Hi,

    Chris Pyrgas helped me a lot to get a control, intended for Winforms or WPF to work on a VO form. The problem was that the control did not respond to some keys or key combinations. With his permission I would like to share the solution which worked very well. I added two methods to the class that inherits from the App class.

    METHOD BeforeDispatch(hWnd,uMsg,wParam,lParam)
    
    IF uMsg == WM_KEYDOWN
    
        IF IsExplorerServer(hWnd)
            LOCAL netMsg AS System.Windows.Forms.Message
            netMsg := System.Windows.Forms.Message{}
            netMsg:HWnd := hWnd
            netMsg:Msg := uMsg
            netMsg:WParam := (IntPtr)((Int32)wParam)
            netMsg:LParam := (IntPtr)((Int32)lParam)
    				
            LOCAL control AS System.Windows.Forms.Control
            // Find the .NET object corresponding to the handle
            // Could be a control, or could be the owning window
            // If there isn't one look up the ownership chain, 
            // will have to eventually hit an owning control or failing that, the owning window
            DO WHILE control == NULL
                control := System.Windows.Forms.Control.FromHandle(hWnd)
                hWnd := GetParent(hWnd)
            ENDDO
            IF control != NULL
                IF control:PreProcessMessage(REF netMsg)
                    RETURN FALSE
                ENDIF
            ENDIF
        ENDIF
    
    ENDIF
    
    RETURN TRUE
    You could also check for certain keys by using for example

    IF uMsg == WM_KEYDOWN .AND. (wParam == VK_RETURN)

    instead of checking just for WM_KEYDOWN.

    The method IsExplorerServer checks for the correct control, in my case the class name was "Internet Explorer_Server" but this should be changed according to the control used.

    STATIC METHOD IsExplorerServer(hWnd AS PTR) AS LOGIC
    
    STATIC LOCAL buffer := MemAlloc(30) AS PTR
    
    IF GetClassName(hWnd, buffer, 30) == 24 // length of class name
        IF Psz2String(buffer) == "Internet Explorer_Server"
            RETURN TRUE
        ENDIF
    ENDIF
    
    RETURN FALSE
    Thank you very much Chris! Maybe someone else will find it useful also.

    Kees.

    Please Log in or Create an account to join the conversation.

    Last edit: by KeesIC2.

    Best way to show a picture in an X# VOForm 23 Jun 2022 15:29 #22842

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Keese,

    Are you aware of that the allocated "buffer" memory is never released ?

    btw: why do you declare the var "buffer" as a STATIC LOCAL ?

    Try this code with "lHandleStaticMemoryCorrectly" set to true/false and you see the difference.

    FUNCTION Start( ) AS VOID 
    
    // -----------
    MemTrace(TRUE)
    // -----------  
    		
    MemTest()
    
    RETURN
    
    FUNCTION MemTest() AS VOID 
    LOCAL lHandleStaticMemoryCorrectly AS LOGIC
    LOCAL i AS DWORD 
    
     	lHandleStaticMemoryCorrectly := FALSE // TRUE 
    	
    	FOR i := 1 TO 4
    
    		IF lHandleStaticMemoryCorrectly
    			IsExplorerServer_New(NULL_PTR ) 
    		ELSE 	
    			IsExplorerServer(NULL_PTR ) 
    		ENDIF 
    		
    		ListAllStaticMem()			
    
    	NEXT
    	?
          
    	
    FUNCTION IsExplorerServer(hWnd AS PTR ) AS LOGIC
    STATIC LOCAL buffer := MemAlloc(30) AS PTR
    
    IF GetClassName(hWnd, buffer, 30) == 24 // length of class name
        IF Psz2String(buffer) == "Internet Explorer_Server"
            RETURN TRUE
        ENDIF
    ENDIF  
    
    RETURN FALSE
    
    FUNCTION IsExplorerServer_New(hWnd AS PTR ) AS LOGIC
    LOCAL lOk AS LOGIC 
    LOCAL buffer := MemAlloc(30) AS PTR
    
    IF GetClassName(hWnd, buffer, 30) == 24 // length of class name
        IF Psz2String(buffer) == "Internet Explorer_Server"
            lOk := TRUE
        ENDIF
    ENDIF
    
    MemFree ( buffer )  // <----------- 
    
    RETURN lOk 
               
    
    FUNCTION ListAllStaticMem() AS VOID
        
    	?
    	? "Currently allocated static memory:"
    	? "----------------------------------"
    	
    	MemWalk(StaticMemChecker) 
    
    	RETURN 
    	
    FUNCTION StaticMemChecker( pMem AS IntPtr, nSize AS DWORD) AS LOGIC // callback 
    	
    	? pMem , nSize  
    	
    	RETURN TRUE		 
    

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    Best way to show a picture in an X# VOForm 23 Jun 2022 17:04 #22847

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Karl-Heinz,

    This was my code that I had sent to Kees, and did it this way just to keep it simple. I thought that not releasing 30 bytes for the duration of the app is not a big deal ;)

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Best way to show a picture in an X# VOForm 25 Jun 2022 16:49 #22878

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Chris,

    ok, because you´re using at least a STATIC LOCAL instead of a LOCAL the memory leak is acceptable ;-)

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2