Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am using DirectX for previewing Video From Different USB cameras connected to the PC.So I am able to preview them on my main window continuously up to 4 cameras at a time,for this i used IVideoWindow to avoid problem like Active Movie Window am able to preview cameras on my main window.

Now, I am facing a problem like when i click on any of my IVideoWindow it is giving the Coordinates coresponding to IVideoWindow window not to my main Window,For Eg: If i AM displaying First IVideoWindow at [10,100]i.e.,left=10and top=100.if i click on corner of the VideoWindow its Coordinates like [0,0] instead of [10,100].
So I am able to handle the click events but not getting the correct coordinates what I required.

Can anyone help me out from this problem.
Thanks to all in advance.
Posted
Updated 4-May-11 19:32pm
v3

I think you are mixing between client and screen coordinates.

Client coordinates are coordinates relative to the upper-left corner of the window being clicked.
Screen coordinates are coordinates relative to the upper-left corner of the screen.

You can convert the coordinates using PointToClient, PointToScreen methods in .NET, ClientToScreen or ScreenToClient in MFC.
Have also a look to ClientRectangle property in .NET, or GetWindowRect and GetClientRect.

In MSDN, they always say if a point is given in screen or client coordinates.
 
Share this answer
 
v2
Comments
RamyaRaj from NewDelhi 5-May-11 1:30am    
hi Olivier Levrey,
Thanks for your reply but my problem is when i click on the window means not not on the main window it is on IVideoWindow what i used for streaming video . If i convert the coordinates using Clienttoscreen method for all IvideoWindow's its giving same coordinates is there any method to convert that coordinates to screen coordinates.Thanks in Advance.

Regards,
RamyaRaj
barneyman 5-May-11 2:35am    
have a look at MapWindowPoints then - that should be capable of mapping your IVideoWindow points to the parent window space
RamyaRaj from NewDelhi 5-May-11 7:17am    
hi barneyman,
thanks for your solution,but here in MapWindowPoints we need to pass first two arguments as from which Window to which window we need to change the coordinates but here when i click the IvideoWindow i am getting only the information about point where i clicked but not from which IvideoWindow i got this Click
so how can i pass HWnd information to that function can you help me out from this problem.Thanks in Advance

Regards,
RamyaRaj
barneyman 5-May-11 7:21am    
IVideoWindow::get_Owner will give you the HWND that the window is currently using
RamyaRaj from NewDelhi 5-May-11 7:26am    
yes even i used put_MessageDrain evevt to pass handle of my click events to main window but when i click on IVideoWindow the coordinates what i am getting are corresponding to that window but not to main Hwnd.
At the moment, I think, inferring from your posts, that you have a single CWnd window, and then you are telling each IVideoWindow where to position itself on that window i.e.

pseudocode
vidWindow[0..3]->put_Owner(*this);

// assume this hwnd is 0,0,100,100
vidWindow[0]->SetWindowPosition(0,0,50,50);
vidWindow[1]->SetWindowPosition(50,0,50,50);
vidWindow[2]->SetWindowPosition(0,50,50,50);
vidWindow[3]->SetWindowPosition(50,50,50,50);

vidWindow[0..3]->put_MessageDrain(*this);

this means you can't determine which video window is telling you about a click

If you create a child CWnd window for each IVidWnd you have more chance to work out what's happening

again, pseudocode

class ChildVideoWindow : public CWnd
{
public
 Create(IVideoWindow *vw, RECT &where, UINT id, Cwnd *parent):m_id(id) 
 {
   Create(WC_STATIC, "", ws_child | ws_visible, where, parent, id);
   vw->put_Owner(*this);
   vw->put_MessageDrain(*this);
 }

 void OnLButton(UINT flags, Point where)
 {
   GetParent()->SendMessage( WM_LBUTTONDOWN, MAKDWORD(flags,m_id), MAKEDWORD(where.x,where.y);
 }

protected:

UINT m_id;

};

// in your Parent CWnd


 ChildVideoWindow childVideos[4];
 childVideos[0..3].Create(vidWindow[0..3],rect0..3,0..3, this);


ParentCWnd::OnLButton(UINT flags, Point where)
{
 int videoWindowThisMessageCameFrom=HIWORD(flags);
 ....

}
 
Share this answer
 
Comments
barneyman 7-May-11 20:56pm    
hi barneyman,
I tried your solution but preview from all cameras are opening in activewindow when i tried to use WS_CLIPSIBLINGS its generating error

when i used
Create(WC_STATIC, "", ws_child | ws_visible, where, parent, id);
what you suggested me its providing error like create doesnot take 6 parameters so i did in the following way
CWnd* pWnd = new CWnd;
pWnd->Create(_T("STATIC"), "", WS_CHILD | WS_VISIBLE, where, parent, id);
wheather this may be a cause for opening in Active window mode

And also
when to call this
void OnLButton(UINT flags, Point where)

in our child window class
or it will automatically enters into it when we click on IVideoWindow because of message drain.Can you please help me out from this problem.Whether I am going wrong anywhere.Thanks in advance.

Regards,
RamyaRaj.
barneyman 7-May-11 21:01pm    
it's important for you to make each child window the parent of each videowindow

The videowindow feeds the message pump of the child window, which is how you get the Childs OnLBButton
RamyaRaj from NewDelhi 9-May-11 1:11am    
hi barneyman,

Why these are opening in Active movie window how can I solve this problem.

Regards,
RamyaRaj.
barneyman 9-May-11 1:20am    
i don't understand what 'active movie window' means

Are you giving each of the ivideowindows their own window, using put_Owner?
RamyaRaj from NewDelhi 9-May-11 2:27am    
IT IS LIKE OPENING THE CAMERA PREVIEW IN A SEPERATE WINDOW NOT STICKING ON TO MY MAIN CWnd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900