Hi Chris,
Thank you for taking the time to look at my issue! I have just sent you the solution.
Kees.
Best way to show a picture in an X# VOForm
Best way to show a picture in an X# VOForm
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.
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.
Thank you very much Chris! Maybe someone else will find it useful also.
Kees.
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.
Code: Select all
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
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.
Code: Select all
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
Kees.
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
Best way to show a picture in an X# VOForm
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.
regards
Karl-Heinz
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.
Code: Select all
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
Karl-Heinz
Best way to show a picture in an X# VOForm
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
.
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
.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
Best way to show a picture in an X# VOForm
Hi Chris,
ok, because you´re using at least a STATIC LOCAL instead of a LOCAL the memory leak is acceptable
regards
Karl-Heinz
ok, because you´re using at least a STATIC LOCAL instead of a LOCAL the memory leak is acceptable
regards
Karl-Heinz