Cancel
Showing results for 
Search instead for 
Did you mean: 

femap api-global integer property-hMainWnd

Creator
Creator

hello everty body,as caption,why hMainWnd is a 8 bytes integer ? In general the handle of window is a 4 bytes integer, how can I get the handle of femap by API?

10 REPLIES

Re: femap api-global integer property-hMainWnd

Siemens Phenom Siemens Phenom
Siemens Phenom

hMainWnd is an 8-byte integer because it is a 64-bit handle to the Window since FEMAP is a 64-bit program.  How you access it depends on what language you are using to program the API.

 

In the embedded API window, you can use the data type Huge_ for 8 byte integers

Re: femap api-global integer property-hMainWnd

Creator
Creator
@grudy,Thank you very much for your good repy.
Does it mean in vb.net I need to delcare window system API as 64-bit format(not 32-bit old format in vb6) when I use the femap hMainWnd in my applicaton?like the following:
Declare Auto Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer, among it hWndChild must be "As IntPtr" not "As integer".

Re: femap api-global integer property-hMainWnd

Siemens Genius Siemens Genius
Siemens Genius

In VB.NET if you want to declare a variable to hold hMainWnd, you could declare it as a long or IntPtr data type. IntPtr is platform specific anyway, so either should work.

 

As you mentioned, the function signature you're using is for vb6. If you want the proper one for VB.NET, check pinvoke.net.

 

Patrick

Re: femap api-global integer property-hMainWnd

Creator
Creator

femap.PNG

As above fig,I embeded femap in my program using below code:

Public Function InitFemap(h As IntPtr) As Boolean
     FemapApp = CreateObject("femap.model")
     rc = FemapApp.feAppEmbed(h, 0, 0, 600, 400)

...

End function

However, I found the embeded femap window can be moved or resized.

How can I prevent embeded femap window to be moved or resized? 

Re: femap api-global integer property-hMainWnd

Siemens Genius Siemens Genius
Siemens Genius

You could possibly use the Windows GetWindowLong/SetWindowLong API calls to get/set the window styles, but some of those can't be changed after the window is created. Easier way is to set the coordinates of the window to some negative number and set the window size to larger than your container to hide the window chrome.

Re: femap api-global integer property-hMainWnd

Creator
Creator

Thank you for your reply!

If I want to use API like SetWindowLong,that mean I need the handle of the dynamic created femap window,How can I get the handle? I know the hMainWnd property is the handle, but the help says the handle is "ready-only"? Could I modify the window style by the handle hMainWnd?

Re: femap api-global integer property-hMainWnd

Siemens Genius Siemens Genius
Siemens Genius

The window handle is a read only property and shouldn't be changed. The handle is basically an ID for every window/control/etc in Windows. That's what gets passed into Get/SetWindowLong. I still think just playing with the origin and the embedded window size is the easier way to go though.

 

Re: femap api-global integer property-hMainWnd

Creator
Creator

Hi,I tried the method which  play with the origin and the embedded window size,but the femap window still be moved or sized,Could you give some example? I also try to use Setwindowlong API, the code is below:

Public Function InitFemap(h As IntPtr) As Boolean
  FemapApp = CreateObject("femap.model")
  rc = FemapApp.feAppEmbed(h, -10, -10, 600, 400)
  dlgWndProc = AddressOf myWindowProc
  myWndProc = Marshal.GetFunctionPointerForDelegate(dlgWndProc)
  oldsWindowProc = SetWindowLongPtr64(FemapApp.hMainWnd, GWL_WNDPROC, myWndProc)
...
End Function

 

but the return value is 0, and I use getLastError and the error code is 5(No permissions), I use spy++ to check the embeded femap window ,it shows the window proc is not available, why we can not change the embeded femap window proc?

Re: femap api-global integer property-hMainWnd

Siemens Genius Siemens Genius
Siemens Genius

Well, first off, you don't want to change the wndproc. I don't even think you can across different threads anyway, but assuming you could, that would probably break a lot of things within FEMAP, so I really don't recommend that approach.

 

If you use Get/SetWindowLong, you want to get/set the window style (GWL_STYLE). Then XOR to toggle WS_CAPTION and WS_THICKFRAME (https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx).

 

If you want to try offsetting, you'll need to make sure the negative coordintes are enough to hide the window chrome and it's also wide / tall enough to do the same, based on the container. Ex:

 

app.feAppEmbed(grpFemap.Handle, -8, -30, grpFemap.Width + 16, grpFemap.Height + 55)

 

 

image.png

 

The exact pixel widths could be dependent on your specific device though and how Windows decides to render them.

 

May I ask what you're trying to do? Perhaps I could give some better advice or if there's isn't a good way to accomplish what you want we can look into an enhancement to the API for a future version.