|
If it's the only way to do this, then I will rather look for some webcamera with it's own API. Anyway thank you for help.
|
|
|
|
|
Hi,
I would like to know how this can be done in MFC. I have a Single Doc/View MFC application in which I display images and Zoom in/out of them etc and eveyrthing works fine except for the image position. I use scroll bars position to zoom in the image and redraw them. But, now I would like to do this so that whenever I zoom in an image, I would like to keep the image center fixed, in other words, I would like to perform zoom in/out functions with respect to the center of the image being displayed in the client area and reset the scroll bar position accordingly.
At present-
I update the scroll bar sizes as soon as I change the zoom factor.
m_cs.cx = ImgWidth()*zoom_const;<br />
m_cs.cy = ImgHeight()*zoom_const;<br />
SetScrollSizes(MM_TEXT, m_cs);<br />
InvalidateRect(NULL, true);
and then in Draw() function-
if (zoom_const > 1)<br />
{<br />
dib->Draw(&dc, true, 0,0,myRect.Width(), myRect.Height(),<br />
sp.x/zoom_const,sp.y/zoom_const,<br />
myRect.Width()/zoom_const,myRect.Height()/zoom_const);<br />
}<br />
else<br />
dib->Draw(&dc, false, 0,0,myRect.Width(), myRect.Height(),sp.x,sp.y,myRect.Width(), myRect.Height());
Could someone guide me on this??
thanks in advance.
PKNT
|
|
|
|
|
Obviously when you zoom you need to recalculate the center position.
CPoint GetNewPos(CPoint const& oldPos, CSize const& oldSize, CSize const& newSize)
{
CPoint newPos;
newPos.x = (LONG)(((__int64)oldPos.x * newSize.cx) / oldSize.cx);
newPos.y = (LONG)(((__int64)oldPos.y * newSize.cy) / oldSize.cy);
return newPos;
}
You will also need to tell the scroll bar that its position has changed (as its sizes have changed).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thanks for the reply. Whats oldPos here? For example if you have an image displayed where its left top position is (0,0) when you zoom in and if you want to do it with respect to the center of the image displayed in client area, then the new position wont be (0,0), right? from your function it still return (0,0) which is not correct. Is that true or am I interpreting it in wrong way?
Here is what I tried to implement-
int x = sp.x/zoom_prev; //sp = scrollposition
int y = sp.y/zoom_prev;
int x1 = x+myRect.Width()/zoom_prev;
int y1 = y+myRect.Height()/zoom_prev;
newpos.x = x1-myRect.Width()/zoom_const;
newpos.y = y1-myRect.Height()/zoom_const;
but this is not producing correct results
PKNT
|
|
|
|
|
oldPos would be the point you want to remain invariant - so, the center of the image.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I wasn't able to resolve this issue.... can some one help me on this?? I tried several different ways and everytime it doesnt seem right. I would really appreciate any help...
thanks
PKNT
|
|
|
|
|
Hello,
In MFC - I would like to capture mouse clicks On Main Frame in my CView. This is how I send a Mouse Left Click:
if(pActiveView->IsKindOf( RUNTIME_CLASS(CRView)) ){
CRView *pView = (CRView*)pActiveView;
if (pMsg->message == WM_LBUTTONDOWN){
pView->SendMessage(WM_LBUTTONDOWN,MAKELPARAM(pView->m_MousePos.x,pView->m_MousePos.y), (LPARAM)0);
}
}
How can I receive it in my CView? Also, not sure if I got the Wparam and LParam correctly?
Thanks
sft
|
|
|
|
|
Add an OnLButtonDown[^] handler to your view.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
If you're sending a left mouse button message to the view, that handler should catch it.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Wow, you were right. Thanks a lot man.... The only problem the Point coordinates are coming back (0,0). I thought I am sending the Point correctly as WPARAM. pView->SendMessage(WM_LBUTTONDOWN,MAKELPARAM(pView->m_MousePos.x,pView->m_MousePos.y), (LPARAM)0);
Any Ideas?
Thanks
sft
modified on Friday, February 27, 2009 4:25 PM
|
|
|
|
|
The same one...WM_LBUTTONDOWN messages sent by the OS are treated exactly the same as the ones you send yourself!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello Everybody,
I am facing a strange problem.
Requirement: Get the length of contents of a file and modify the header present in the file to represent the length in Hexadecimal format.
Existing Code:
if( cFilePointer.Open(strFileName ,CFile::modeRead) )
{
strContents.Empty();
dwRead = 0;
do
{
dwRead = cFilePointer.Read(cBuffer,100);
if ( dwRead > 0)
strContents.operator +=(cBuffer);
}while(dwRead > 0 );
int iTotalLength = strContents.GetLength();
sprintf(cLengthOfString,"%4x",iTotalLength);
for ( int iIndex = 0;iIndex<4;iIndex++)
{
if ( cLengthOfString[iIndex] == 32 )
cLengthOfString[iIndex] = 48;
strContents.SetAt(iIndex+6,cLengthOfString[iIndex]);
}
cFilePointer.Close();
int iTemp = 0;
int iIndexOfChar = 0;
int iFileNameLength = strFileName.GetLength();
CString strSlash("\\");
while ( iTemp < iFileNameLength)
{
iIndexOfChar = strFileName.Find(strSlash,iTemp);
if ( iIndexOfChar == -1 )
break;
strFileName.Insert(iIndexOfChar,strSlash);
iTemp = iIndexOfChar + 2;
}
hFile = CreateFile(strFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if ( hFile )
cFilePointer.m_hFile = hFile;
if(cFilePointer)
{
cFilePointer.Write(strContents,iTotalLength);
cFilePointer.Close();
}
}
Problem:
When I executing the above code, the file is having every alternative character as NULL.
Please help in the above.
Thanks in advance,
Neelesh K J Jain.
|
|
|
|
|
Your project is a Unicode project, isn't it. That means you are writing Unicode (well, UTF-16) characters out to your file. Then, when you read with an ASCII file reader, you are reading the file as 8-bit characters, so you see the most significant byte of the UTF-16 characters as NULLs.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you Stuart,
Can you please help in converting from ASCII to Unicode and vice versa, so that I don't face this problem in either of the conversion.
Neelesh K J Jain.
|
|
|
|
|
|
If you're using VC++2003, 2005 or 2008, it's very easy. If you #include <atlconv.h>, you have various string conversion macros[^] available.
If you're using Visual C++ 6, you have similar macros[^] available.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have a print method here. I'm trying to print lets say 3 numbers per line ( print(2);). If I had 7 elements, my output would be.
10 12 13
11 15
17 12
How do I get that first line to only print two? Is it going to be something with i % num?
public void print( int num )
{
if( num < 1 )
num = 1;
for(int i = 0; i < size; i++)
{
System.out.print(list[i] + " ");
if( i != 0 && i % num == 0)
System.out.println();
}
}
|
|
|
|
|
Hmmmm - that's not C++, is it - that's C#. Wrong forum, me bucko!
But anyway - the reason is because your test is wrong. Should be if(i % num == (num-1)) .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I tried that, but it will print something like
10 12
14 13 15
and that still isn't right.
I figured it out, it's actually my System.out.println(list[i]) has to come after the if statement.
Java too btw. Thanks for the idea though.
|
|
|
|
|
This worked OK when I translated it to C++:
public void print( int num )
{
if( num < 1 )
num = 1;
for(int i = 0; i < size; i++)
{
System.out.print(list[i] + " ");
if( i % num == (num-1) || i==size-1)
System.out.println();
}
}
in roughly comparable idiomatic C++, this is:
void print(std::vector<int> const& list, int num )
{
if( num < 1 )
num = 1;
for(int i = 0; i < list.size(); i++)
{
std::cout << list[i] << " ";
if( i % num == (num-1) || i==list.size()-1)
std::cout << std::endl;
}
}
jonig19 wrote: Java too btw
Java, C# - I wasn't a million miles away Maybe I ought to add C# to my sig!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello!
When opening the Property Pages of a project in Visual Studio 2005/2008, the configuration and platform are set by default to the Active ones. For example: Active(Release) and Active(Win32).
Is there any possibility to set the All Configurations and All Platforms options by default in those two combo-boxes? What I mean is that I would like not the set them manually to All Configurations and All Platforms everytime I open the Property Pages of a project, but have them instead set by default.
Thanks in advance!
|
|
|
|
|
I don't think there is.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I have created a MFC dialog based application.
I tried to use shared pointer, but it not geting compiled.
std::tr1::shared_ptr<CSharedpointerDlg> sharedpointer;
How to rectify this error
: error C2039: 'tr1' : is not a member of 'std'
: error C2065: 'shared_ptr' : undeclared identifier
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
VC++6 doesn't include TR1 - how could it? It shipped before the original C++ standard came out, never mind TR1!!!!
To get TR1 features, use VC++2008 or Boost's[^] implementation[^].
Oh and by the way - VC++6 is no longer supported in much of Boost, so you may have problems there.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|