get_os_window_handleT_get_os_window_handleGetOsWindowHandleGetOsWindowHandle (Operator)


get_os_window_handleT_get_os_window_handleGetOsWindowHandleGetOsWindowHandle — Get the operating system window handle.


This operator does not work in an HDevelop graphics window opened with dev_open_window.


get_os_window_handle( : : WindowHandle : OSWindowHandle, OSDisplayHandle)

Herror T_get_os_window_handle(const Htuple WindowHandle, Htuple* OSWindowHandle, Htuple* OSDisplayHandle)

void GetOsWindowHandle(const HTuple& WindowHandle, HTuple* OSWindowHandle, HTuple* OSDisplayHandle)

void* HWindow::GetOsWindowHandle(void** OSDisplayHandle) const

static void HOperatorSet.GetOsWindowHandle(HTuple windowHandle, out HTuple OSWindowHandle, out HTuple OSDisplayHandle)

IntPtr HWindow.GetOsWindowHandle(out IntPtr OSDisplayHandle)


get_os_window_handleget_os_window_handleGetOsWindowHandleGetOsWindowHandleGetOsWindowHandle returns the operating system window handle of the HALCON window WindowHandleWindowHandleWindowHandleWindowHandlewindowHandle in OSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandle. Under Unix-like systems, additionally the operating system display handle is returned in OSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandle. The operating system window handle can be used to access the window using functions from the operating system, e.g., to draw in a user-defined manner into the window. Under Windows, OSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandle can be cast to a variable of type HWND. Under Unix-like systems, OSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandle can be cast into a variable of type Window, while OSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandle can be cast into a variable of type Display.

Execution Information


WindowHandleWindowHandleWindowHandleWindowHandlewindowHandle (input_control)  window HWindow, HTupleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)

Window handle.

OSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandleOSWindowHandle (output_control)  pointer HTupleHTupleHtuple (integer) (IntPtr) (Hlong) (Hlong)

Operating system window handle.

OSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandleOSDisplayHandle (output_control)  pointer HTupleHTupleHtuple (integer) (IntPtr) (Hlong) (Hlong)

Operating system display handle (under Unix-like systems only).

Example (C)

/* Draw a line into a HALCON window under Unix-like systems using X11 calls. */
#include "HalconC.h"
#include <X11/X.h>
#include <X11/Xlib.h>

int main(int argc, char **argv)
  Hlong hwin, win, disp;
  Display *display;
  Window window;
  GC gc;
  XGCValues values;
  static char dashes[] = { 20, 20 };

  open_window(0, 0, 500, 500, 0, "visible", "", &hwin);
  get_os_window_handle(hwin, &win, &disp);
  display = (Display *)disp;
  window = (Window)win;
  gc = XCreateGC(display, window, 0, &values);
  XSetFunction(display, gc, GXset);
  XSetLineAttributes(display, gc, 10, LineOnOffDash, CapRound, JoinRound);
  XSetDashes(display, gc, 0, dashes, 2);
  XSetForeground(display, gc, WhitePixel(display, DefaultScreen(display)));
  XSetBackground(display, gc, BlackPixel(display, DefaultScreen(display)));
  XDrawLine(display, win, gc, 20, 20, 480, 480);
  XFreeGC(display, gc);
  return 0;

/* Draw a line into a HALCON window under Windows using GDI calls. */
#include "HalconC.h"
#include "windows.h"

int main(int argc, char **argv)
  Hlong hwin, win, disp;
  HDC hdc;
  HPEN hpen;
  HPEN *hpen_old;
  LOGBRUSH logbrush;
  POINT point;
  static DWORD dashes[] = { 20, 20 };

  open_window(0, 0, 500, 500, 0, "visible", "", &hwin);
  get_os_window_handle(hwin, &win, &disp);
  logbrush.lbColor = RGB(255,255,255);
  logbrush.lbStyle = BS_SOLID;
  hpen =  ExtCreatePen(PS_USERSTYLE|PS_GEOMETRIC, 10, &logbrush, 2, dashes);
  hdc = GetDC((HWND)win);
  hpen_old = (HPEN *)SelectObject(hdc, hpen);
  MoveToEx(hdc, 20, 20, &point);
  LineTo(hdc, 480, 480);
  DeleteObject(SelectObject(hdc, hpen_old));
  ReleaseDC((HWND)win, hdc);
  return 0;


If the window is valid get_os_window_handleget_os_window_handleGetOsWindowHandleGetOsWindowHandleGetOsWindowHandle returns 2 (H_MSG_TRUE). Otherwise, an exception is raised.

Possible Predecessors