Need help for my plugin to unity And multi-touch on PC!!

Do you know if I can access to windows HWND of Unity? Like when I call :


BOOL TOUCH_API InitInstance(HINSTANCE hInstance, int nCmdShow)
{

   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd) {

      return FALSE;
   }


and change RegisterTouchWindow to :


   // register the window for touch instead of gestures

RegisterTouchWindow(hWnd, 0);  

   // the following code initializes the points

   for (int i=0; i< MAXPOINTS; i++){

     points*[0] = -1;*
 _points*[1] = -1;*_
 <em>_idLookup *= -1;*_</em>
 <em>_*}*_</em> 
 <em>_*ShowWindow(hWnd, nCmdShow);*_</em>
 <em>_*UpdateWindow(hWnd);*_</em>
 <em>_*return TRUE;*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
<em>_*<hr>*_</em>
<em>_*<p>because the Dll works perfectly if I disable this part of script : </p>*_</em>
<em>_*<hr>*_</em>
<em>_*```*_</em>
<em><em>*hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,*</em></em>
 <em><em>*CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);*</em></em>
<em>_*```*_</em>

2 Answers

2

That sounds like a pure Windows API problem.... If you use a native code plugin in Unity it have no relation to Unity except that it's loaded into the same process. To find the window handle (only for standalone builds of course, won't work in the editor or web), you have to use the common windows API. Use one of these functions: Enumwindows, GetWindow, Findwindow or maybe EnumThreadWindows with either the window classname of unity (i'm too lazy to look it up for you) or the currentThreadID/currentProcessID. Inside the enum callback you can use GetWindowThreadProcessId or sotr out the riht window.

Thank you, it's very helpful!! I finally use the : HWND WINAPI GetForegroundWindow(void);

GetForegroundWindow

Have a good day!! :D