|
thankyou... i tried using CAnimateCtrl but doesnt seems like it helps..
MCI control is a lot better, especially with memory requirement. But seems like it's a little jerky. QuickTime is the best thus far - which makes me wonder why we need avi in the first place.
norm
|
|
|
|
|
Hi, I launched a thread that's responsible for loading a sequence of bitmap into memory, so, I need a lot of memory for this thread. Here's the code fragment:
unsigned long nThreadID;
HANDLE hThread;
hThread = CreateThread( NULL, 5000000, (LPTHREAD_START_ROUTINE) LoadFrames, this, 0, &nThreadID);
So, as you see, I've allocated 5MB of memory to this thread. However, I keep getting memory allocation error from my thread function:
long WINAPI LoadFrames(LPARAM lparam)
{ //*
...
...
hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), sPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
if( hBitmap != NULL)
{
pDoc->GetBitmapSeq(i).Attach(hBitmap);
}
else
{
//Out of memory!! dwError==8 implies "ERROR_NOT_ENOUGH_MEMORY"!!?! I really dont understand, I was monitoring the system monitor and the thread has less than 3MB allocated to it.
DWORD dwError = GetLastError();
... more exception handling code...
}
return 1;
} //*
Thanks!
norm
|
|
|
|
|
You are allocating a 5M Stack for the worker thread. Is that what you really want? Where does LoadImage() get its memory from. I doubt that its the stack.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Thanks for the feedback first of all. LoadImage return a BITMAP hBitmap which is stored in a variable (of type BITMAP of course) in the "thread function". The images sequence is stored in a CBitmap array in the document class, which is separate from the thread... so, all I need is just enuf memory for ONE bitmap (700kB), and yes 10MB is an overkill, but I really dont understand why LoadImage results in memory error:
long WINAPI LoadFrames(LPARAM lparam)
{ //*
CString sPath;
HBITMAP hBitmap = NULL;
CAutoPlayMFCDoc * pDoc = NULL;
pDoc = (CAutoPlayMFCDoc*) lparam;
//Load the rest of the frames!
for(int i=NUM_PRELOAD; i<num_bitmap; i++)
="" {="" **
="" spath="pDoc-">GetPath();
if( sPath.GetLength() > 0 )
{ //***
hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), sPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
if( hBitmap != NULL)
{
pDoc->GetBitmapSeq(i).Attach(hBitmap);
}
else
{
//That's the problem: dwError==8 implies "ERROR_NOT_ENOUGH_MEMORY"
DWORD dwError = GetLastError();
pDoc->SetLoadState(1);
i = i -1; //reload the frame
break;
}
//Increment m_nTargetDocFrame:
pDoc->SetTargetDocFrame(i);
} //***
} //**
return 1;
} //*
norm
|
|
|
|
|
The "dwError==8 implies "ERROR_NOT_ENOUGH_MEMORY"" may be a red herring. If you move this code into the main app thread does it work?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Yes, after I adjust the number of frames to be preloaded in the document class' constructor, i got the same error (from LoadImage() in document class constructor)...
How can I adjust the memory for the mainthread? or the application thread?
norm
|
|
|
|
|
I don't think it is a memory problem. Maybe there is a problem with the bitmap you are loading. Why don't you try some others, including some smaller ones.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
what do u mean problem with bitmaps? anyway, your suggestion "try smaller bitmap" is probably pointing to the right direction, it seems that the application consistently returns error (dwError = 8) around the time when it finishes loading the 32nd frame.
But u're right, it's got nothing to do with memory allocated to the thread.
norm
|
|
|
|
|
Hello -
I'm building a product that requires an html wysiwyg editor - I upgraded to Visual C++ .NET (7) to get MFC 7 - with the CHtmlEditView / CHtmlEditDoc classes, only to find that there is no IDM_TABLE command.
I also tried inserting using IHTMLDocument2:
BSTR str = SysAllocString(L"<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#CCCCCC\" bgcolor=\"#E6E6E6\"><tr><td width=\"11%\"> </td></tr></table>");<br />
<br />
IHTMLDocument2 *pDoc;<br />
long col=0;<br />
IDispatch * pDocDisp = NULL; <br />
<br />
pDocDisp = GetHtmlDocument();<br />
HRESULT h = pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc );<br />
if( h == S_OK )<br />
{<br />
IMarkupServices *pMS = NULL;<br />
IMarkupPointer *pMkStart = NULL;<br />
IMarkupPointer *pMkFinish = NULL;<br />
<br />
<br />
CComPtr<IHTMLElement> pElement; <br />
HRESULT hr = pDoc->createElement(L"TABLE", &pElement);<br />
pElement->put_outerHTML(str);<br />
<br />
pDoc->QueryInterface(IID_IMarkupServices, (LPVOID *) &pMS);<br />
pMS->InsertElement(pElement, pMkStart, pMkFinish);
and also tried IHTMLTable / QueryInterface. None worked.
If anyone has a solution to my problem I'd be greateful.
Thanks.
Art Cote
Art Cote
|
|
|
|
|
IHTMLElement has a function called InsertAdjacentHTML.
BTW: I would recommend you to use smart pointers which make life a lot easier, and they also help avoiding memory leaks.
Just us it as follows:
IDispatchPtr pDisp = ...
IHTMLDocument2Ptr pDoc(pDisp);
IHTMLElementCollectionPtr pCollection;
pDoc->get_all(&pCollection);
IHTMLElementCollection pAllTables(pCollection->tags(CComVariant("table")));
...
|
|
|
|
|
As someone said, insertAdjacentHTML is a fine stuff :
CComQIPtr<IHTMLDocument2> pHtmlDoc( GetHtmlDocument() );
CComBSTR bstrWhere = "BeforeEnd";
CComBSTR bstrText = ...;
CComPtr<IHTMLElement> pBody;
pHtmlDoc->get_body( &pBody );
pBody->insertAdjacentHTML( (BSTR)bstrWhere, (BSTR)bstrText);
How low can you go ? (MS rant)
|
|
|
|
|
Thanks for the responses. One question - is insertAdjacentHTML feasible for drag drop operation, i.e.,
a la IDM_TEXTBOX message - simply drops edit box on
CHtmlEditView.
What I'd ultimately want to do is to be able to insert
a table based on parameters entered in dialog, then
drop table onto CHtmlEditView. Similar to the DHTMLedit component using IDM_TRIED_INSERTTABLE.
Thanks a bunch for responding so quickly.
|
|
|
|
|
Art Cote wrote:
One question - is insertAdjacentHTML feasible for drag drop operation, i.e.,
These are separate things. Handling drag&drop events is a different matter, which should not interfere with adding html code to an existing page.
How low can you go ? (MS rant)
|
|
|
|
|
The solution:
BSTR bstrText = SysAllocString(L"<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#CCCCCC\" bgcolor=\"#E6E6E6\"><tr><td width=\"11%\"> </td><td width=\"11%\"> </td><td width=\"11%\"> </td></tr><tr><td width=\"11%\"> </td><td width=\"11%\"> </td><td width=\"11%\"> </td></tr></table>");<br />
<br />
IHTMLDocument2 *pDoc; <br />
IDispatch * pDocDisp = NULL; <br />
pDocDisp = GetHtmlDocument();<br />
HRESULT h = pDocDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDoc );<br />
BSTR bstrWhere = SysAllocString(L"BeforeEnd"); <br />
IHTMLElement *pBody;<br />
IHTMLLocation *pLocation;<br />
pDoc->get_body( &pBody );<br />
<br />
pBody->insertAdjacentHTML( (BSTR)bstrWhere, (BSTR)bstrText);<br />
<br />
SysFreeString(bstrText);<br />
SysFreeString(bstrWhere);<br />
pDoc->Release();<br />
pDocDisp->Release();
works fine - putting a table into CHtmlEditView. However how does one access
the IHTMLTable interface - when I to get_activeElement I get the body,
not the selected table.
Thanks.
Art
|
|
|
|
|
Art Cote wrote:
I to get_activeElement I get the body,
not the selected table.
What selected table ? You haven't selected anything here.
I guess you mean you are willing to get a IHTMLTable pointer from the table you have just inserted. That's easy, change your html tags so that you add a <table ...> with a name="mytable" attribute.
Then from the document.all collection, you can ask the DOM to retrieve the IHTMLElement whose name is "mytable" :
IHTMLElementCollection::item Method
HRESULT item( VARIANT name /*VT_BSTR*/, <-- "mytable"
VARIANT index,
IDispatch** pdisp
);
Finally, cast it to IHTMLTable
How low can you go ? (MS rant)
|
|
|
|
|
Oops - I meant to get the only table element on the page-
eventually i will setup element selection.
The code works - does one need to update the document somehow ?? so the changes to the table are shown?
(fragment)
<br />
pDoc->get_all(&pCollect); <br />
pCollect->item(varID,varIdx, &pDocDisp );<br />
pDocDisp->QueryInterface(IID_IHTMLTable, (void**) &pElem);<br />
<br />
pElem->put_cols(cols);<br />
<br />
.
.
.
Thanks again...
art
|
|
|
|
|
|
I know this may sound like a dumb question, however I'm stumped. Can someone tell me what a Dword is used for?
Thanks,
John
|
|
|
|
|
a DWORD is the same as an unsigned int .
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
it's used wherever you need 32 bits of unsigned storage. there's no rule that says what you should do with it.
-c
"[it was..] one of those evenings when you feel that not only will there definitely be a revolution, but that the Association of Manufacturers will foot the bill."
-- Umberto Eco, Foucault's Pendulum
|
|
|
|
|
One more piece of information as to why the DWORD is defined. The windows header files as well as many other development frameworks #define all of their types with a name like DWORD, INT, UINT and so on. This is so that the underlying datatype, can be changed to a compatible when the program is ported to a new system. Such as moving your C++ code to the new 64-bit windows implemenation or even to linux or mac (depending on what you are programming).
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
In the Intel environment, DWORD is a D ouble WORD , where a WORD is a 16 bit value. A DWORD is therefore a 32 bit value. It is used as a generic container for any 32 bit value (signed and unsigned integers, and some pointer values). DWORD originates from Intel x86 assembly language. It worked its way into Windows programming back in the MS-DOS and Windows 1.x/2.x/3.x days, when you had to deal with the segmented memory model.
Software Zen: delete this;
|
|
|
|
|
I most certainly can make sense of a DWORD now. Thanks you all for the help.
John
|
|
|
|
|
When working with console applications from within Visual C++.NET, How would I get the console window to stay open after the program has executed so that I may view the results of the code? Do you change these properties within Visual C++ or Windows?
|
|
|
|
|
You can start the program with either Run or Debug. One of them leaves the program open with a "press any key to continue" message. I don't remember which one though.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|