How can I get the HWND (Native Window Handle) of the client region of UIPANEL on MATLAB Figure?

조회 수: 28 (최근 30일)
Hi!
I need to have access from the outside to a given region of MATLAB Figure. I want to ask this region, using UIPANEL. Can I get the native window handle for UIPANEL, using undocumented MATLAB-Java interface?
I tried using this approach:
hFig = figure();
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
jh = get(hFig, 'JavaFrame');
hwnd = get(jh, 'nativeWindowHandle');
But the way I access the client area , which contains all the UI Components. But this is not what I need.
I would be very grateful for any information on this issue. Thanks!

채택된 답변

Yair Altman
Yair Altman 2011년 4월 11일
uipanels don't have their own HWND. If you use a utility such as Spy++ (which is bundled with Microsoft Visual Studio) or Winspector, you will see that there are very few actual window handles. Of these, you can get access to two:
1. Top-level window frame (SunAwtFrame) HWND -
jFrame = get(handle(hFig), 'JavaFrame');
HWND = jFrame.fFigureClient.getWindow.getHWND;
2. Axis canvas (SunAwtCanvas) HWND - this is the NativeWindowHandle property value that you have noted above. (there are several alternatives of accessing this handle). If you use this handle, be sure to check the corresponding NativeWindowHandleValid property. For example, if the window is not visible (e.g., closed), this property will have a false value.
3. OpenGL (MatlabOpenGLWindow) HWND - this is a child of the NativeWindowHandle HWND, and can be gotten from:
jFrame = get(handle(hFig), 'JavaFrame');
HWND = int32(jFrame.getNativeChildWindowHandle/2^32);
HWND = bitshift(jFrame.getNativeChildWindowHandle,-32); %alternative
Yair Altman

추가 답변 (2개)

Evgeny Pr
Evgeny Pr 2011년 3월 12일
It seems that I'm moving in the right direction... :)
For example:
h = figure;
jc = javacomponent(java.awt.Canvas, [100 100 200 200], h);
drawnow;
hwnd = jc.getPeer.getHWnd;
There is only one question: How to get java.awt.Canvas from UIPANEL? If UIPANEL based on Canvas... :)

Oleg Komarov
Oleg Komarov 2011년 3월 12일
You may want to give a look at FindJObj - find java handles of Matlab graphic objects on the FEX.
May save you a lot of time.
Oleg
  댓글 수: 1
Evgeny Pr
Evgeny Pr 2011년 3월 12일
Yes, I use this function and other functions writen by Yair Altman, for example UIINSPECT.
UIPANEL components is not found using FINDJOBJ. :(
For example:
h = figure;
hp = uipanel('Parent', h, 'Units', 'pixels', 'Position', [10 10 200 200])
findjobj(hp, 'nomenu')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by