Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Widgets - General questions or Mixed problems » why the ctrl does`t have HWND?
why the ctrl does`t have HWND? [message #46390] Wed, 04 May 2016 12:18 Go to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
Ctrl ctrl;
HWND hwnd = ctrl.GetHWND();
// hwnd == 0?? 


I must get the hwnd of the ctrl,then show video on the hwnd;
the show video work is undertaken by a DLL.
In MFC, i pass m_pPreviewDlg.m_hWnd to the DLL, then it shows Video.
I do not know how to do in U++,Please help Razz
Re: why the ctrl does`t have HWND? [message #46393 is a reply to message #46390] Wed, 04 May 2016 22:24 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Dig into GetHWND code, you will see that a Ctrl need to be top and no parent and be created to have non-null HWND.

In you case, if you call a Open() to have it created before calling to GetHWND(), you have a better chance to get what you want.


GUI_APP_MAIN
{
	MyApp a;
	DUMP(a.GetHWND());
	a.Open();
	a.Hide(); // call this if you don't want the window actually opened
	DUMP(a.GetHWND());
	
	
	a.Sizeable().MinimizeBox().MaximizeBox().Run();
}


Output

a.GetHWND() = 0x00000000
a.GetHWND() = 0x000402d8



HTH,

Lance
Re: why the ctrl does`t have HWND? [message #46395 is a reply to message #46393] Thu, 05 May 2016 02:39 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
YES,it works!
Thank you ,Lance Smile
Re: why the ctrl does`t have HWND? [message #46396 is a reply to message #46393] Thu, 05 May 2016 03:11 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
now can get the TopWindow`s hwnd,
but how to get a Ctrl`s hwnd?
Re: why the ctrl does`t have HWND? [message #46397 is a reply to message #46396] Thu, 05 May 2016 03:30 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
They don't have one. They use related top window's device context to draw themselves.

In you case you may want to use a popup window to fake the Ctrl. A popup is a top level window and has its own HWND. Override the ctrl's layout virtual function (maybe some more to have the popup move/resive with the Ctrl)...
Re: why the ctrl does`t have HWND? [message #46398 is a reply to message #46397] Thu, 05 May 2016 04:08 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
This is a small demonstration. If you resize the mainwindow or move it, you will notice the popup will detach from the ctrl it's faking.

To make it work better, you should write a small control to take care of reset the popup's size/position even visibility when that of the ctrl it's faking has changed. Some of the Ctrl virtual functions you should override could by Layout, State()...

Hopefully someone more knowledgeble will give you a complete list or even a more appropriate way to do that.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;
struct MyApp: public TopWindow
{
	MyApp()
	{
		Add(e.LeftPos(30,600).TopPos(40,400));
	}
	LineEdit e;
	Label l;
	
	
	typedef MyApp CLASSNAME;
};

GUI_APP_MAIN
{
	MyApp a;
	a.MinimizeBox().MaximizeBox().Open();
	a.	l.SetRect(a.e.GetRect()+a.GetScreenRect().TopLeft());
	a.	l.PopUp(&a.e, true, false, false,false);
	a.Run();
	
}
Re: why the ctrl does`t have HWND? [message #46399 is a reply to message #46398] Thu, 05 May 2016 04:56 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Still very primitive, but you can get some idea.

Not all State (reason) needs to be taken care of. Seems it's fine if you only do the POSITION case.

Flicks, flicks, flicks. Let's see if somebody can make it smoother.

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class MyPopup : public Ctrl
{
public:
	virtual void Paint(Draw& w)
	{
		w.DrawText(10,20,String().Cat()<<"Daw in the faked Ctrl,"
		 " my HWND is"<<GetHWND(),StdFont(),White());
		 
	}
};

class PopupHolder : public Ctrl
{
public:

	void Reset()
	{
		if(!GetTopCtrl())
			return;
		popup.Close();
		popup.SetRect( GetRect() + this->GetTopCtrl()->GetScreenRect().TopLeft() );
		popup.PopUp(this,true,false);
	}

	virtual void State(int reason)
	{
		switch(reason)
		{
		
		//	FOCUS      = 10,
		case ACTIVATE: //   = 11,
			LOG("ACTIVATE");
			Reset();
			break;
		case DEACTIVATE:// = 12,
			LOG("DEACTIVATE");
			popup.Close();
			break;
		case SHOW://       = 13,
			LOG("SHOW");
			Reset();
			break;
	//	ENABLE     = 14,
	//	EDITABLE   = 15,
		case OPEN://       = 16,
			LOG("OPEN");
			Reset();
			break;
		case CLOSE://      = 17,
			LOG("CLOSE");
			popup.Close();
			break;
		case POSITION://   = 100,
			LOG("Position");
			Reset();
			break;
		case LAYOUTPOS://  = 101,
			LOG("LAYOUTPOS");
			Reset();
			break;
		}
	}
	
	MyPopup popup;
};
struct MyApp: public TopWindow
{
	MyApp()
	{
		//Add(e.LeftPos(30,600).TopPos(40,400));
		Add(h.SizePos());
	}
	PopupHolder h;
	
	
	typedef MyApp CLASSNAME;
};

GUI_APP_MAIN
{
	MyApp().MinimizeBox().MaximizeBox().Sizeable().Run();
	
}

[Updated on: Thu, 05 May 2016 04:59]

Report message to a moderator

Re: why the ctrl does`t have HWND? [message #46400 is a reply to message #46399] Thu, 05 May 2016 08:50 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
yeah, i have run you code,the ctrl now can fllow the TopWindow,

Thank you so much, Lance. You saved the day. Very Happy

[Updated on: Thu, 05 May 2016 09:14]

Report message to a moderator

Re: why the ctrl does`t have HWND? [message #46403 is a reply to message #46400] Thu, 05 May 2016 12:20 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
You're welcome.

I wasn't quite sure if it's good for your purpose as I noticed every time the popup is closed and reopen, a new HWND will be created. I was thinking if it can be remedied by another Ctrl member function PopupHWND or something like that. Gad it satifies your need already.

Re: why the ctrl does`t have HWND? [message #46404 is a reply to message #46390] Thu, 05 May 2016 20:52 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hello akabee!

Sorry for replying so late, but I think there is better way to do this. Have a look at DHCtrl in CtrlCore/Win32GuiA.h (or CtrlCore/X11GuiA.h for Linux version). DHCtrl is a special Ctrl that does nothing, but has its own HWND (or Window in X11 backend). DHCtrl can be added to your layouts and manipulated just like any other widget, so you don't need to keep track of the popup and move it all the time.

I think one of the original intents behind DHCtrl was actually quite similar to your usecase: It is used for direct rendering of OpenGL in GLCtrl. You can have a look at that one too, to get some hints about DHCtrl usage.

Best regards,
Honza
Re: why the ctrl does`t have HWND? [message #46427 is a reply to message #46403] Tue, 10 May 2016 10:26 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
ye, just as you say ,in order to prevent the hwnd change,i only do SetRect in POSITION,
but this still kind of complicated
so i change to DHCtrl dolik.rce mentioned!
Re: why the ctrl does`t have HWND? [message #46428 is a reply to message #46404] Tue, 10 May 2016 10:50 Go to previous messageGo to next message
akebee is currently offline  akebee
Messages: 90
Registered: August 2011
Location: China
Member
i use 2 DHCtrl to display video.

DHCtrl dh1;
DragDHCtrl dh2;

	Add(dh1.LeftPos(0,690).TopPos(32,540));
	dh1.AddChild(&dh2.LeftPos(0,320).TopPos(32,240));

now comes two problem:


  1. dh2 is always flashing
  2. appears blank when i drag dh2

i made two gif to show the problems.
index.php?t=getfile&id=5010&private=0
index.php?t=getfile&id=5011&private=0
  • Attachment: GIF2.gif
    (Size: 731.18KB, Downloaded 479 times)
  • Attachment: GIF.gif
    (Size: 696.97KB, Downloaded 447 times)

[Updated on: Tue, 10 May 2016 10:52]

Report message to a moderator

Re: why the ctrl does`t have HWND? [message #46432 is a reply to message #46428] Tue, 10 May 2016 17:40 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

If I remember correctly, sometimes the flickering problems can be be solved by using Ctrl::Backpaint(). You can try experimenting with the various values it can take (NOBACKPAINT, FULLBACKPAINT, TRANSPARENTBACKPAINT and EXCLUDEPAINT).

Honza
Previous Topic: DropList color is the same when editable or not
Next Topic: ColumnList clipping problem
Goto Forum:
  


Current Time: Fri Mar 29 14:50:59 CET 2024

Total time taken to generate the page: 0.02119 seconds