|
Hi Steve,
I have searched this algorithm -- it is dealing with clipping. Does it have anything deal with my question?
regards,
George
|
|
|
|
|
hi all,
please help me how can i sort (based on a object member variable )
a vector that holds object.
Regards,
Prashanth.v
|
|
|
|
|
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
// My object.
class MyObject
{
public:
MyObject(int Index) : m_Index(Index) {}
int m_Index;
};
// Output to stream.
ostream& operator<<(ostream &s, const MyObject &o)
{
s << o.m_Index;
return s;
}
// A functor to compare two 'MyObject's based on the member 'm_Index'.
struct MyObjectLess
{
bool operator()(const MyObject &l, const MyObject &r) const
{
return l.m_Index < r.m_Index;
}
};
int main(int argc, char* argv[])
{
// Our collection.
vector<MyObject> objects;
// Fill the collection.
objects.push_back(MyObject(3));
objects.push_back(MyObject(1));
objects.push_back(MyObject(4));
objects.push_back(MyObject(1));
objects.push_back(MyObject(5));
objects.push_back(MyObject(9));
// Print the collection.
cout << "Before sorting:" << endl;
copy(objects.begin(), objects.end(), ostream_iterator<MyObject>(cout, "\n"));
cout << endl;
// Sort them based on the 'm_Index' member variable.
sort(objects.begin(), objects.end(), MyObjectLess());
// Print the collection.
cout << "After sorting:" << endl;
copy(objects.begin(), objects.end(), ostream_iterator<MyObject>(cout, "\n"));
cout << endl;
return 0;
}
Steve
|
|
|
|
|
If you talk about STL library, then the sorting can be done with sort function defined in algorithm . You have to devine a "binary predicate", wich compares objects according to your needs. Solution depends on how you store objects in vector -- as values or as pointers. The bellow sample shows both cases:
struct MyObject
{
MyObject(int x, int y)
{
mX = x; mY = y;
}
static bool ComparatorByX_values(const MyObject & obj1, const MyObject & obj2)
{
return obj1.mX < obj2.mY;
}
static bool ComparatorByX_pointers(const MyObject * obj1, const MyObject * obj2)
{
return obj1->mX < obj2->mY;
}
int mX, mY;
};
int main()
{
{
std::vector< MyObject > vector;
vector.push_back(MyObject(3, 20));
vector.push_back(MyObject(2, 10));
vector.push_back(MyObject(1, 30));
std::sort(vector.begin(), vector.end(), MyObject::ComparatorByX_values);
for(size_t i = 0; i < vector.size(); ++i)
{
printf("%i\n", vector[i].mX);
}
}
{
std::vector< MyObject * > vector;
vector.push_back(new MyObject(3, 20));
vector.push_back(new MyObject(2, 10));
vector.push_back(new MyObject(1, 30));
std::sort(vector.begin(), vector.end(), MyObject::ComparatorByX_pointers);
for(size_t i = 0; i < vector.size(); ++i)
{
printf("%i\n", vector[i]->mX);
}
}
}
Hope this will ispire you.
-- modified at 10:46 Friday 2nd June, 2006
|
|
|
|
|
the object class must overload the comparison operators ( < , > , <= , >= ) and then, simply call std::sort(vec.beging(), vec.end());
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
Hi,
I want to draw line graph without using MsExcel. I found many application on codeguru to plot the graph using Excel feature. But want to plot the line graph without using Excel. Can anybody help me out?
Thanks:-
Mike
|
|
|
|
|
I wrote an article about a chart control here[^]. Maybe it is helpfull for you ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
I have dowloaded a code from codeproject that adds a icon in systemtray and also a popup menu appears when a right click is made on the icon, but the if I do not select any option fron popup menu and click on some where else this popup menu do not disappear, why it is happening.
How it can disappear if i do not select any option and click some else where it should disappear.
Code snipts are here :
in header file
afx_msg void OnTrayNotify(WPARAM wParam, LPARAM lParam);
in message map
ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify)
Notify function defenition
afx_msg void CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam)
{
UINT uID;
UINT uMsg;
uID = (UINT) wParam;
uMsg = (UINT) lParam;
if (uID != 1)
return;
CPoint pt;
switch (uMsg )
{
case WM_LBUTTONDOWN:
GetCursorPos(&pt);
ClientToScreen(&pt);
OnTrayLButtonDown(pt);
break;
case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
GetCursorPos(&pt);
OnTrayRButtonDown(pt);
break;
}
return;
}
void CTrayMinDlg::OnTrayLButtonDown(CPoint pt)
{
MessageBox("You have clicked Left mouse Button ");
}
void CTrayMinDlg::OnTrayRButtonDown(CPoint pt)
{
//m_menu is the member of CTrayMinDlg as CMenu m_menu;
m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN|
TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this);
}
Regards.
|
|
|
|
|
|
Yes I used the same one. the popup menu apeared on clicking the tray icon do not disappear if i click on some other window. It remains there, and to make it disappear I have to select something from menu.
I want to hide the popup menu when I click on some other menu or in some other area
Regards.
|
|
|
|
|
MSDN library mentions this problem in the description of ::TrackPopupMenu function. In order to solve it, there is a recomendation to make the window foreground before TrackPopupMenu , and then to post a benign message immediately after TrackPopupMenu :
::SetForegroundWindow(hwnd);
::TrackPopupMenu(...);
::PostMessage(hwnd, WM_NULL, 0, 0);
Or, in case of MFC, inside a member:
SetForegroundWindow();
TrackPopupMenu(...);
PostMessage(WM_NULL);
Hope this will help.
-- modified at 10:11 Friday 2nd June, 2006
|
|
|
|
|
hai all's
whenever i execute the program in VC++(MFC(exe)) project the i have find
the error (could not execut the program:Invalid directory(win 32 error(267)
and this error is always for all my programs .
plz tell me where i am wrong.
mailing me
Yogi
|
|
|
|
|
Giving it just a try....
Its not clear from your posts what context are you working in.
Try and check the settings for the project . May be the path of the exe is not mapping currently. Go to project>settings>Debug>(set the path of the exe manually).
Does this help you?
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
|
I am able to load(AfxLoadLibrary) the libavcodec dll in a VC7 Dialog based application. However I dont know how to call the functions within this DLL to encode/decode video. Has anybody done anything of this sort?
|
|
|
|
|
GetProcAddress for get the address of a function
whitesky
|
|
|
|
|
Ok, the def file says "avcodec_register_all @ 97 ; " so how would I use this with GetProcAddress?
"GetProcAddress(hModule, avcodec_register_all);" ??
Some kinda code snippets would be really helpful
Thanks anyway for replying
|
|
|
|
|
|
I have already had a look at that. But am unsure about the typedef thingy. Plus i am using the AfxLoadLibrary option.
This is what I am trying and it builds and executes fine
HMODULE hmodule;<br />
hmodule = AfxLoadLibrary("libavcodec.dll");<br />
if (!AfxLoadLibrary(_T("libavcodec.dll")))<br />
AfxMessageBox("failed to load");<br />
typedef void * (__stdcall *avcodec_register_all)();<br />
GetProcAddress(hmodule,"avcodec_register_all");<br />
void * objptr= avcodec_register_all();
I know this will sound dumb but if I wanted to encode video, I will have to typedef every function that I call fm the DLL?
-- modified at 4:45 Friday 2nd June, 2006
|
|
|
|
|
i write a sample i hope that helpful to you
<br />
<br />
<br />
typedef BSTR FAR (WINAPI *TESTFUNCTION)(HWND hWnd,TCHAR lpt[50]);<br />
TESTFUNCTION m_TestFunction;<br />
<br />
LibraryDll=LoadLibrary("Testdll.dll");<br />
<br />
m_TestFunction=(TESTFUNCTION)GetProcAddress(LibraryDll,"TestFunction");
<br />
m_TestFunction(pWnd->m_hWnd,NULL);
whitesky
|
|
|
|
|
Thank you for the code
But i am looking for code specific to FFMPEG and the libavcodec dll.
Any takers??
|
|
|
|
|
I write one example for you but i dont know whats your dll(exactly)
whitesky
|
|
|
|
|
You can learn more about FFMPEG from http://ffmpeg.mplayerhq.hu/[^]
Basically its an Audio/Video encoding/decoding thingy (OpenSource).You get dlls when you build ffmpeg and I am trying to use these DLLs in my VC++ application.Unfortunately, since its OpenSource, there isnt much documentation available online. Thanks for all your help though 
|
|
|
|
|
Thanks for link but where your dll that has problem(exactly address)
and if you need to decode and encode you can see codeproject examples
whitesky
|
|
|
|
|
My dll has no problem. its in trying to use the functions of the dll that I get stuck . I dont know how to do it
Sorry for not having made that clear sooner.
|
|
|
|