# No window,build hangs - embedding glfw window within winforms

**URL:** <https://discourse.glfw.org/t/no-window-build-hangs-embedding-glfw-window-within-winforms/1003>\
**Category:** support\
**Created:** [October 1, 2017, 4:47am UTC](https://discourse.glfw.org/t/no-window-build-hangs-embedding-glfw-window-within-winforms/1003 "2017-10-01T04:47:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LittleQuest](https://avatars.discourse-cdn.com/v4/letter/l/cc9497/32.png) [@LittleQuest](https://discourse.glfw.org/u/LittleQuest)\
**Post date:** [October 1, 2017, 4:47am UTC](https://discourse.glfw.org/t/no-window-build-hangs-embedding-glfw-window-within-winforms/1003/1 "2017-10-01T04:47:18Z")

</div>

I am trying to embed glfw window generated using glfwCreateWindow() as child window within a winform.  
No window appear.Can you help me in embedding glfw window as child window in winforms?

Please find the code below

```
if( !glfwInit() )
	{
		fprintf( stderr, "Failed to initialize GLFW\n" );
		getchar();
		return -1;
	}

	glfwWindowHint(GLFW_SAMPLES, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
	glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
	glfwWindowHint(GLFW_FOCUSED, GL_FALSE);
	glfwWindowHint(GLFW_DECORATED, GL_FALSE);

	// Open a window and create its OpenGL context
	window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
	if( window == NULL ){
		fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
		getchar();
		glfwTerminate();
		return -1;
	}    	

	HWND hWnd = glfwGetWin32Window(window);
	SetParent(hWnd, pFrame); // HWND pFrame is the parent window handle
	LONG nNewStyle = GetWindowLong(hWnd, GWL_STYLE) & ~WS_POPUP | WS_CHILDWINDOW;
	SetWindowLong(hWnd, GWL_STYLE, nNewStyle);
	ULONG_PTR cNewStyle = GetClassLongPtr(hWnd, GCL_STYLE) | CS_DBLCLKS;
	SetClassLongPtr(hWnd, GCL_STYLE, cNewStyle);

	glfwShowWindow(window);

	glfwMakeContextCurrent(window);

	// Initialize GLEW
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		getchar();
		glfwTerminate();
		return -1;
	}

	// Ensure we can capture the escape key being pressed below
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
```

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [October 1, 2017, 12:11pm UTC](https://discourse.glfw.org/t/no-window-build-hangs-embedding-glfw-window-within-winforms/1003/2 "2017-10-01T12:11:15Z")

</div>

I am not sure that what you are trying to do is possible without altering the code of GLFW itself. There is an [issue about creating a GLFW with another window’s hwnd on GLFW Github](https://github.com/glfw/glfw/issues/25), and one comment shows [how to alter GLFW to create the window as a child window](https://github.com/glfw/glfw/issues/25#issuecomment-238135439).

Perhaps an alternative approach might work - for example if you just want to have a GUI with the GLFW window then you can use a graphics API based GUI - I use [dear imgui](https://github.com/ocornut/imgui) but there are many others. Alternatively you could use a GUI system which has native support for OpenGL such as [Qt](https://www.qt.io/).

Finally if you already have a window with WinForms you can use it’s hWnd to create an OpenGL context without using GLFW.

---

<div class="post-metadata">

**Author:** ![LittleQuest](https://avatars.discourse-cdn.com/v4/letter/l/cc9497/32.png) [@LittleQuest](https://discourse.glfw.org/u/LittleQuest)\
**Post date:** [October 5, 2017, 5:04pm UTC](https://discourse.glfw.org/t/no-window-build-hangs-embedding-glfw-window-within-winforms/1003/3 "2017-10-05T17:04:55Z")

</div>

Dear Dough,

Once again for helping me to save a lot of time. 🙂🙂🙂

> without altering the code of GLFW itself

I think this is great and you have already provided me links to have good understanding.I want to use glfw for my application.

> you can use a graphics API based GUI

I will also go thorough the imgui library.Thanks for these coordinates.
