Click to See Complete Forum and Search --> : CWnd::FromHandle - Really want CView::FromHandle
R Berry
August 20th, 1999, 12:02 PM
I have an SDI application that acts as a console taking in lots of commands from user... one of these causes a bitmap to be read into memory and lots of associated info. - currently this is being done by acquiring a handle for the window and using the SDK CreateWindow() with the handle as one of the parameters - huge sections of code currently rely on the handle etc. - Now this display needs more functionality - I could create a CWnd using CWnd::FromHandle but really I'd like the functionality of CScrollView & Doc - Being inexperienced I've only ever created these classes as part of a new SDI application - can I attach them to this new window? If so what's the best way to use the development enviroment, initialise the Doc. etc. without creating a new SDI?
Many thanks,
Rachel
Brian Budge
August 20th, 1999, 12:12 PM
Yes, you can use these without the AppWizard Framework. What you need to do is use a Document Template. I have some example code for you; it is for a MDI application, but you should be able to figure it out for SDI.
//first I create the Template hint: multiTemplate is, I believe, of type CMultiDocTemplate
multiTemplate = new CMultiDocTemplate(
IDR_SINGENTYPE,
RUNTIME_CLASS(CSingenDoc), //name of the Document class
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CSingenView)); //name of the View class
AddDocTemplate(multiTemplate);
//now to get a new document/view pair up and running we do this
CSingenDoc* doc=(CSingenDoc*)multiTemplate->OpenDocumentFile(NULL,true);
//hint: you don't really need the stuff left of (CSingenDoc... unless you need a pointer to your document (which I did)
and Whoalla - we now have newly functioning doc/view pair. Of course you still need to create yourself a C*Doc and C*View pair of classes, but you should be able to figure this out from looking at an old MFC App.
Hope this helps you out,
Brian Budge
Brad Barber
August 23rd, 1999, 07:00 AM
If you want the functionality of CScrollView and you know that it is a CScrollView, you can do this...
CScrollView* l_pScrollView = (CScrollView*)CWnd::FromHandle(l_hWnd);
Hope this helps,
Brad
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.