|
Thanx ,
Where should i handle that ?
|
|
|
|
|
Handle it in your main window , WindowProc function, this is the window that it gets sent to.
|
|
|
|
|
|
Does anyone know if it is possible to login to a winNT box from over a network. I.E the other computer is at its login screen therefore standard screen sharing programs cannot be used as I think they require a server to be running on the unlogged in machine.
Thanks
Coremn
---------
I sig there for I am
(not an animal!!!)
|
|
|
|
|
Windows NT terminal server will do this, as will "VNC", provided you "install vnc as a service"
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I am trying to create an example using for_each to delete objects where they are stored in a container as pointers. I have this:
class pType
{
public:
pType::pType()
{
cout << "Constructor\n";
}
pType::~pType()
{
cout << "Destructor\n";
}
};
template <class T> void ptrErase(T * type)
{
delete type;
};
in main()
vector <pType *> vecpType;
for (i = 0;i < 20; ++i)
{
pType * pInt = new pType;
vecpType.push_back(pInt);
}
for_each(vecpType.begin(), vecpType.end(), ptrErase<pType>);
I get a linker error,
STL.obj : error LNK2001: unresolved external symbol "void __cdecl ptrErase(class pType *)" (?ptrErase@@YAXPAVpType@@@Z)
Debug/STL.exe : fatal error LNK1120: 1 unresolved externals
I am not as familiar with templated functions as I would like, could someone tell me what I am doing wrong pls ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Change this:
template<class T>
void ptrErase(T * type)
{
delete type;
};
to this:
template<class T>
struct ptrErase : public unary_function<T, void>
{
void operator() (T type)
{
delete type;
}
};
because the for_each function requires a function object rather than a simple function.
The operator() allows you to call the name of your object, just like it were a function call.
|
|
|
|
|
Thanks - I had contemplated that this might be the problem after posting, but I was hoping not for ease of readability ( it's a beginners tutorial after all ).
This works great - thanks again.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Some of the features in STL, and C++ for that matter, are convoluted, and I think that is what shys alot of people away from these features in the first place. This is a shame because learning some of these techniques can lead to very elegant solutions.
|
|
|
|
|
In case you wonder, your original code should have worked, but it doesn't due to a limitation of VC++ --it lacks support for so called explicit instantiation of template functions, or better stated, its support is broken. Don't know the status of this bug in VC++ 7.0.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Have a little question for you all. In regards to STL -- what distribution of it do you use? (assuming that you use it of course).
Visual C++ 6 has STL support (to a point), it seems incomplete though. I downloaded and started using the SGI STL which is complete (except I found that it only supports the depricated <iostream.h> not the new <iostream> .. what the heck is going on?
I'm a little confused .. maybe I'm just not seeing some obvious small detail here ..
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
I prefer the SGI STL implementation.
A while back I created a test program to compare STL versus MFC's container classes, and MFC's classes kicked butt over STL, that is the STL that is included with DevStudio. Then I recompiled the program with SGI's version and the competition was feirce depending on the way that the container was used. Sometimes STL was more efficient, others it was MFC container classes, which is to be expected.
The SGI implementation supports other classes that I don't think are in the standard yet. One of my favorite classes in the SGI implementation is the hashmap and hashset, this is used in the exact same way that the map and set are used, but the underlying representation is a hash table rather than a table.
I could not find what you were talking about between depricated and new, could you give more details on that?
|
|
|
|
|
What I meant was that (this is only one instance), the SGI STL has been designed to support the old header file naming style. That is, you would include iostream.h <-- rather than iostream -- if you do include iostream so you can access the new features you will get a lot of errors because it doesn't handle it yet for some reason.
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
sgi STL is not being built upon, hence the deprecation problem. Use STLPort instead - www.stlport.com, it has the hash table, the additional modifiers, etc., in fact everything the SGI STL has and more.
I believe VC.NET has a better STL - previously they have been stuck with an old Dinkumware implimentation for purely legal reasons.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
I just downloaded STLport and am reading about it's use.. thanks for the suggestion.
Travis D. Mathison ---
--- After three days without programming, life becomes meaningless ...
|
|
|
|
|
Hi,
I have an SDI application that has a CFormView derived class as well as a docking window with a CDialog derived class. When the user clicks on the Print command, the message goes to the CFormView derived class where I modified the CFileDialog with two radio buttons to either print the main CFormView or the CDialog window.
Well, when I do this and I call the CDialog derived printing code for some reason, the document gets printed three times and then throws an exception. In actuallity, it should only print one page, I also tried setting the max page to 1 to no evale. I can't figure out why this happens, I guess it could be because the CFormView class is processing the print call but I'm not sure.
Does anyone have any suggestions on how I can fix this peculiure problem?
Thanks in advance,
Craig
|
|
|
|
|
I would recommend emulating the Doc?view printing procedure for your dialog derived class. I did something similar when printing to PDF files. The whole code for that procedure here is shown, so some of the code will not be relevant to what you are doing, but it will give you some idea of how to progress:
DOCINFO di ;
CPrintInfo printInfo ;
CRefinementProDoc *pDoc = GetDocument() ;
CString filename ;
CDC dc ;
CRect draw_area ;
ASSERT_VALID(pDoc) ;
filename = pDoc->GetPathName() ;
filename.MakeLower() ;
if (filename == "")
{
filename = pDoc->GetTitle() ;
if (filename.Find(" (modified)") >= 0)
filename = filename.Left(filename.GetLength() - 11) ;
}
if (filename.Find(".sds") >= 0)
filename = filename.Left(filename.GetLength() - 4) ;
if (filename.Find(".mds") >= 0)
filename = filename.Left(filename.GetLength() - 4) ;
filename += ".pdf" ;
CFileDialog dlg(FALSE, "PDF", filename, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, "Adobe acrobat PDF files (*.pdf)|*.pdf||") ;
dlg.m_ofn.lpstrInitialDir = theApp.g_szLastDirectory ;
pView = this ;
dlg.SetTemplate("MYFILEOPEN", "MYFILEOPENEXPLORER") ;
dlg.m_ofn.Flags |= OFN_ENABLEHOOK ;
dlg.m_ofn.lpfnHook = (LPOFNHOOKPROC)OFNHookProcOldStyle ;
if (dlg.DoModal() == IDCANCEL)
return ;
for (int i = 0 ; i < MAX_DLLS ; i++)
global_page_status[i] = g_bAllowPrint[i] ;
filename = dlg.GetPathName() ;
HDC hDC = theApp.g_PDF.GetPrinterDC() ;
if (hDC == NULL)
return ;
OnAboutToPrint() ;
di.cbSize = sizeof(DOCINFO) ;
di.lpszDocName = pDoc->GetPathName() ;
di.lpszOutput = filename ;
dc.Attach(hDC) ;
printInfo.m_bDirect = TRUE ;
printInfo.m_rectDraw.left = 0 ;
printInfo.m_rectDraw.right = dc.GetDeviceCaps(HORZRES) ;
printInfo.m_rectDraw.top = 0 ;
printInfo.m_rectDraw.bottom = dc.GetDeviceCaps(VERTRES) ;
draw_area = printInfo.m_rectDraw ;
dc.StartDoc(&di) ;
OnPreparePrinting(&printInfo) ;
for (printInfo.m_nCurPage = 1 ; printInfo.m_nCurPage <= printInfo.GetMaxPage() ; printInfo.m_nCurPage++)
{
dc.StartPage() ;
OnPrint(&dc, &printInfo) ;
dc.EndPage() ;
printInfo.m_rectDraw = draw_area ;
}
OnEndPrinting(&dc, &printInfo) ;
dc.EndDoc() ;
VERIFY(dc.DeleteDC()) ;
if (theApp.g_bStartPDF)
ShellExecute(NULL, NULL, filename, NULL, NULL, SW_SHOWMAXIMIZED) ;
theApp.SetLastDirectory(filename.Left(filename.ReverseFind('\\'))) ;
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
|
|
|
|
|
Roger,
Thanks so much for your example, I will try it and see if it will solve the problem I am having.
Thanks again,
Craig
|
|
|
|
|
I just created an MDI application using visual studio. I'm trying to draw graphics using openGL in the child window. How exactly do I do this. Am I supposed to attach a function for the child window class where I can draw, or do I declare an instance of the child window class in my drawing function or what?
|
|
|
|
|
Hi,
You need to draw the graphics in the OnDraw handler of your CView derived class. However, OpenGL is never that simple, so I would suggest you have a look here for an article that might help you.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
When subclassing controls is it posible to use a classes member function as the message handler procedure...?
class MyClass : public CWnd
{
MyHandler() { }
OnCreate()
{
WNDCLASS wc;
wc.lpfnWndProc = MyHandler;
HWND hwnd = CreateWindow(blah);
}
}
The above method didn't work for me, I haven't yet tried actually subclassing using SetWindowLong() but I can't see this working either.
Anybody have any idea's...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Only if you make the member function static. A non-static member will expect to get the hidden this pointer passed, and windows won't do that!
There's a lot of info on methods for using members as callbacks which also applies to this problem. Basically, you can use a static member or a global C-style function.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I'm currently using a global C style function, but would prefer to use a more C++ approach.
I'll try static functions and see whats happens...
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Steen Krogsgaard wrote:
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
LOL
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
|
|
|
|
|
Create a static member function in your class.
Then Call SetWindowLong, and set the GWL_USERDATA field as the this pointer in your
class. Then in your handler, you will get teh window long data and use that as your class pointer.
class MyClass : public CWnd
{
HWND m_hWnd;
public:
static LRESULT MyHandler(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lResult;
MyClass *ThisPtr = dynamic_cast<MyClass*>(::GetWindowLong(hWnd, GWL_USERDATA));
if (!ThisPtr)
{
}
switch (nMsg)
{
case WM_CREATE:
{
lResult = ThisPtr->OnCreate(nMsg, wParam, lParam);
...
}
case ...:
...
}
return lResult;
}
HWND CreateWindow()
{
WNDCLASS wc;
wc.lpfnWndProc = MyHandler;
m_hWnd = CreateWindow(blah);
::SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);
return m_hWnd;
}
LRESULT OnCreate (WPARAM wParam, LPARAM lParam)
{
}
};
There are other ways that are possible, I think that this a fairly straight forward technique if you are going to Write your own class framework to manage your windows.
|
|
|
|