|
As you probably know, MFC windows can be bandied about quite easily using the Attach() and Detach() functions. Let's say you have a window in view #1, and you want it to move into view 2. Just attach your window, set the parent, redraw and voila.
pView2->m_Window.Attach( pView1->m_Window.Detach() );
pView2->m_Window.SetParent( pView2 );
My problem occurs when I use the CWnd:CreateControl() function to create an OCX activeX control. I try to move it as described above, but something gets goofed up and the control doesn't see view 2 as it's new parent.
I've looked into the Microsoft code a bit and the control feature seems to be controlled by a couple of undocumented, CCmdTarget drived, classes: COleControlSite and COleControlContainer. I have no clue how to poke these classes so that they start drawing the control into the new parent window.
HELP!
Thanks,
Aaron
|
|
|
|
|
hmmmm
i wonder ... do you have to get the handle to the underlying control object as well or instead of before you can attach it to another view?
and does the view you want to attch it to have to be derived from the same base class as the view your detaching it from?
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Well I'm a little unsure what object in the COLEControlSite controls where the activeX draws. The class contains a CWnd* member, but attaching it to the new window didn't seem to make a difference.
As for the views having the same base class, they do. I am running a very simple wizard generated MDI app, and I'm simply swapping the window from one view to another. Remember, when I switch to using a dialog instead of the activeX window everything works fine.
I hope I don't have to go through all the hassle of sending a question to MSDN. Last time I spent a day writing up the problem and making a test app only to get the response "Yup, that's a bug. Sorry."
I have a date with destiny and it looks like she's ordered the lobster
|
|
|
|
|
hmmmmm
the cwnd derived control windows are special windows as far as i know that allow the embedded object to access their dc's basically and reflect messages both ways ... if you need to attach and detach them it seems you must also initialise the control site to wire up the plumbing for the control to talk via the view
thats as far as i can tell from skwizzing thru the msdn ... sorry i cant be of more help
i guess we'll just have to wait for the activex guru to step up and explain all ... 'cos i'll be interested to hear this one too
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
COleControlSite and COleControlContainer provide an implementation of the OLE interfaces for ActiveX control containers (IOleClientSite, IOleInPlaceSite, IOleControlSite...)
I haven't used MFC for awhile. You might want to try using CWnd::AttachControlSite on the new view. It's protected so you'll have to derive and hack (you'll probably be seeing the ASSERT dialog in your sleep). This is the kind of stuff that sent me to WTL.
|
|
|
|
|
If i've got a cstring variable that holds for example:
"cat\r\nmouse\r\ndog"
how can i split them into 3 separate cstring variables that contain just cat, mouse and dog respectively. Do i need GetBuffer to do this? If so, how do you specify the right size?
Thanks.
|
|
|
|
|
Pretty easily, actually.
CString1 s1 = "cat\r\nmouse\r\ndog";
CString sCat, sMouse, sDog;
sCat = s1.Left(3);
sMouse = s1.Mid(5,5);
sDog = s1.Right(3); Of course this relies on the fact that you know where the texts are within the string. if you want to just seperate them into three strings based on cr/nl:
CString1 s1 = "cat\r\nmouse\r\ndog";
CString s2, s3, s4;
s2 = s1.SpanExcluding("\r\n");
s1 = s1.Right(s1.GetLength() - (s2.GetLength() + 2));
s3 = s1.SpanExcluding("\r\n");
s4 = s1.Right(s1.GetLength() - (s3.GetLength() + 2)); Again, this assumes many things, but I think you get the idea that there are lots of ways to attack this problem.
|
|
|
|
|
It's useful sometimes to use internal function AfxExtractSubString (which is defined in afxwin.h and implemented in winstr.cpp).
It's prototype is:
BOOL AFXAPI AfxExtractSubString(CString& rString, LPCTSTR lpszFullString, int iSubString, TCHAR chSep = '\n');
so it works only with one-character separators.
With the best regards, Vitaly.
|
|
|
|
|
or copy the cstring into a char array (standard string) and use strtok()
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
Hi there All,
Changing Text in Statics and controls at run time ?
Well i'm trying to do something which i'm sure its possible and i dont know how.
Actually i want to make a loop (which loop ??)through all the Controls and Windows
under an SDI project and change all the labels of the controls\windows
(including the static ones).
How can this be done,
I'll apritiate any help,
Ariel.
|
|
|
|
|
When you say all the controls, what controls ? An SDI app has toolbar(s), a menu, but do you have controls embedded into your view, or in your toolbars ? Do you want to change YOUR items, or those provided by MFC ? The way to change the text is SetWindowText, the way to get ahold of an item you don't own ( for example if you subclass a common dialog ), is GetDlgItem, but I'm not sure how you would iterate through a dialog in a loop, unless you called GetDlgItem for ALL possible ID's and check for a valid return before calling SetWindowText.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
How can I execute a SQL command using the OLE DB Consumer Templates? I don't want anything complicated like returning data, I just want to do a bunch of INSERT and UPDATE statments at once.
|
|
|
|
|
This was based on one of the MSDN samples. You have to have an open CDataSource.
HRESULT CAbstractDatabase::ExecuteSQL( LPCTSTR pszSQL, BOOL bShowErrors /* = TRUE */ )
{
// DataSource object must be initialized.
HRESULT hr;
if( m_DataSource.m_spInit.IsEqualObject( NULL ))
return E_INVALIDARG;
CSession conn;
CCommand<cnoaccessor,cnorowset,cnomultipleresults> cmd;
// Open session using datasource.
hr = conn.Open( m_DataSource );
if( FAILED(hr) )
{
if(bShowErrors)
DisplayOLEDBErrorRecords( hr );
return hr;
}
// Open command using session.
hr = cmd.Open( conn, pszSQL );
if( FAILED(hr) )
{
if(bShowErrors)
DisplayOLEDBErrorRecords( hr );
}
// Close command and session and return result.
cmd.Close();
conn.Close();
return hr;
} // ExecuteSQL
tangle@micron.net
|
|
|
|
|
Dear all,
How can I declare a variable so that all cpps in my MFC project can access the
variable?
Thanks.
Vickie
|
|
|
|
|
in whatever.h:
extern int myGlobalVariable;
in whatever.cpp
int myGlobalVariable = 0;
in any file you want to use myGlobalVariable:
#include "whatever.h"
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I can't get it work even I have followed what you'd said, since there are many others header files included in my cpps. Will this be the reason leading to my errors?
Thanks a lot!
|
|
|
|
|
Be sure to include the header with the 'extern' wherever you are going to use it. Or stick the header include in your stdafx.h
|
|
|
|
|
Like this (applies to C++ not just MFC):
yourcode.h:
extern globalVariableType YourGlobalVariable;
yourcode.cpp:
globalVariableType YourGlobalVariable;
This is freqently use for making the MFC CWinApp class global like this:
extern CMyApp theApp;
(this is because theApp is already defined in your MyApp.cpp file by MFC). This nicely replaces:
((CMyApp*)AfxGetApp())->Bogus();
with:
theApp.Bogus();
Hope this helps
--------------------------------
Todd C. Wilson (tcw@nopcode.com)
www.nopcode.com
ICQ: 5638028
"I picked up a Magic 8-Ball the other day and it said 'Outlook not so good.' I said, 'Sure, but Microsoft still ships it.'"
|
|
|
|
|
IE programming is one area that I am lacking, so I have to ask: What is the easiest way (if any way) to obtain the text in an running separate instance of IE's window? In this case, it would be the text from controls that are of the "Internet Explorer_Server" window class.
The end result would be a call that I could make that would populate a buffer with all of the text (or up to a specified amount of text) in that control instance.
This would be similar to a cut and paste operation, but without involving the standard clipboard (ie, would not trash any existing text in CF_TEXT format that is already there).
Can this be done?
-=- James.
|
|
|
|
|
i might be tempted to grab the stuff off the clipboard into a buffer then send a few messages to the ie window to select all and copy ... then grab that text into another buffer and restore the first buffer
prolly a better way but ie stuff isnt my strong point either
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
> i might be tempted to grab the stuff off the clipboard into a buffer
> then send a few messages to the ie window to select all and copy
I would be too, but:
o The "Internet Explorer_Server" window does not respond to WM_COPY or EM_SETSEL messages
o That would cause a visual "blip" on the target window, which is undesired.
But thanx for the response, anyway.
-=- James.
|
|
|
|
|
I'd like to program a ftp-server.
Can anyone tell me, what i have to do
in order to set up one?
A little bit c++ code or a link
would be nice...
thanks...
FoxHunter
|
|
|
|
|
well foxy its not quite so simple unfortunately.
"a bit of code ... would be nice..." would amount to a few thousand lines of code at the least.
maybe you should research the basic stuff of network programming, multi-threading and the ftp protocol as a good start.
its not rocket science in theory but getting a good ftp server that actually works and is scalable, robust and efficient is a bit of an art.
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
"I'd like to build my own B2 bomber, could you please point me to somewhere I can get all the parts for free and tell me how to put them together? Just a short explanation would be nice... thanks..."?
|
|
|
|
|
Ok... it wasn't quite that drastic
Adam
cabadam@houston.rr.com
|
|
|
|