|
Or just this:
if (string_token==tokencheck)
This is potentially more efficient because c_str() may allocate a buffer to store the string on some implementations - It is not mandatory for a basic_string to store the string in one chunk of contiguous memory: some use a collection chunks, for example. On such implementations calling c_str() may not be as "cheap" as one may expect.
The following operators are defined in <string> which allow the above usage:
template<class CharType, class Traits, class Allocator>
bool operator==(
const basic_string<CharType, Traits, Allocator>& _Left,
const CharType *_Right
);
template<class CharType, class Traits, class Allocator>
bool operator==(
const CharType *_Left,
const basic_string<CharType, Traits, Allocator>& _Right
);
Steve
|
|
|
|
|
Hi,
I want to put a semi-transparent bitmap into my dialog, and I've the following code:
BLENDFUNCTION bf;
bf.AlphaFormat = 0;
bf.BlendFlags = 0;
bf.BlendOp = AC_SRC_OVER;
bf.SourceConstantAlpha = 0x7f;
CRect rect;
GetDlgItem(IDC_PRUEBA_TRANS)->GetWindowRect(&rect);
CClientDC dc(this);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
AlphaBlend(GetDlgItem(IDC_PRUEBA_TRANS)->GetDC()->GetSafeHdc(), 0, 0, rect.Width(), rect.Height(), dc, 0, 0, rect.Width(), rect.Height(), bf);
This code purpose was to test if AlphaBlend is working all-right with my dialog, and it seem that it does.
Now my problem is: I've bitmaps as "BITMAPS" in my resource file. IDC_PRUEBA_TRANS is a CStatic Ctrl with Bitmap enabled and a Bitmap loaded through designer (not code). If I do such:
AlphaBlend(dc, 0, 0, rect.Width(), rect.Height(), dcMem, 0, 0, rect.Width(), rect.Height(), bf);
The transparent bitmap will be drawn on the opaque one, so the transparency will not be visible (for that reason, I tried to put a form shot into IDC_PRUEBA_TRANS, to test it).
So I'd like to know how can I get a CDC from a CBitmap or whatever way of do this thing...
Thank you,
Rafael Fernández López.
|
|
|
|
|
Just off the top of my head, but do not set the static control to load the bitmap. If you can draw the bitmap your self, then you already know that it will fit (or can be made to fit) within the static controls rectangular client area. Set the static control to just provide the rectangular area where the drawing will occur, basicaly a place holder.
INTP
Every thing is relative...
|
|
|
|
|
Hi, i have a property sheet which is tabbed and the tabs are stacked
there are 6 tabs which strech across two lines,
however when the property sheet is first called, the lower line of tabs seem to be
hidden, they only appear when i have clicked onto another tab
i have posted an image of what i mean, as its hard to explain [^]
Pages are added like
BOOL CTabSettings::OnInitDialog()
{
CDialog::OnInitDialog();
m_sheet.AddPage(&m_page0);
m_sheet.AddPage(&m_page1);
m_sheet.AddPage(&m_page2);
m_sheet.AddPage(&m_page3);
m_sheet.AddPage(&m_page4);
m_sheet.AddPage(&m_page5);
m_sheet.AddPage(&m_page6);
m_sheet.Create(this, WS_CHILD | WS_VISIBLE , 0);
m_sheet.ModifyStyleEx (0, WS_EX_TRANSPARENT);
m_sheet.ModifyStyle( 0, WS_TABSTOP );
m_sheet.SetActivePage(4);
m_sheet.SetActiveWindow();
// move to left upper corner
m_sheet.SetWindowPos( NULL, 0, 0, 0, 0,
SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE );
...
Can any one help
thanks
si
|
|
|
|
|
for sheet, it is better to active all pages if u can.
try to add code at last.
int i,iNum=m_sheet.GetPageCount();
for(i=0;i<iNum;i++) m_sheet.SetActivePage(i);
m_sheet.SetActivePage(4);
A special image tool for C++ programmers, don't miss it!
The world unique Software Label Maker is here for you and me ...
A nice hyper tool for optimizing your MS html-help contents.
|
|
|
|
|
thanks but thats hasnt solved it , any other ideas ??
|
|
|
|
|
please tell me how can i get .exe file path which is runnable file of my project and is running now.
thank you.
|
|
|
|
|
u can use GetModuleFileName() to get the path of the executable including the file name..
u can then remove the filename from that pah to get the working directory..
This filename can be removed either manually or use PathRemoveFileSpec()
nave
|
|
|
|
|
|
So far I have had everything working without a hitch, right up until I introduced threads to my projects. Let me explain what I am doing. I create a class which opens a CompoundFile using ole2's IStorage and Istream. The class then creates another class object passing along the Istream pointer.
This new class then creates a clone of the stream and launches a thread from where the stream should be read. The cloned copy is stored as a class member, before the thread is launched the seek pointer is set and there are no problems. The thread function is a static class member and I have enabled the access to the rest of the class by passing the this pointer.
The problem is here from inside the thread
long hr = 0;
hr = stream->Read(&_id,2,&s);
if (FAILED(hr)) {
printf("Read stream failed");
}
stream->Read(&_ssz,2,&s); The program throws an 'Access Error' when trying to read. The address of the stream is correct, but the IUnknown members of the stream are not.
This is the code I used to initialy open the document and stream, I have a feeling the problem is here somewhere.
hr = ::StgOpenStorage(wcFilename, NULL,STGM_READ|STGM_SHARE_DENY_WRITE , NULL, 0, &pStorage);
if(FAILED(hr)) {
if(hr == STG_E_FILENOTFOUND)
printf("File not found.");
else if(hr == STG_E_FILEALREADYEXISTS)
printf("Not a compound file.");
else
printf("StgOpenStorage() failed w/error %08lx", hr);
return;
}
hr = pStorage->OpenStream(L"Workbook",NULL,NULL,STGM_READ|STGM_SHARE_EXCLUSIVE|STGM_DIRECT,NULL,&pStream);
if(FAILED(hr)) {
printf("Open stream failed");
pStorage->Release();
return;
}
|
|
|
|
|
I would need to see the code for the thread you spawn and the code which spawns it. Do you realize that you can't just use an interface pointer created in one thread in another thread without marshaling it to the new thread? Are you performing marshalling?
Steve
|
|
|
|
|
I have just realised that that is probably what I have done wrong. At the moment I am trying to find out how to implement Marshaling. My first attempt is this
long hr = CoMarshalInterThreadInterfaceInStream(IID_IStream,NULL,&_stream);<pre>which is returning -2147024809.
|
|
|
|
|
Here's one way to do it:
------------------------
IStream *pMarshalData;
HRESULT hr = CoMarshalInterThreadInterfaceInStream(IID_IStream, pStream, &pMarshalData);
if ( SUCCEEDED(hr) )
{
// Spawn your new thread here. Pass it the pMarshalData pointer.
}
// In the spawned thread somewhere.
IStream *pStream;
HRESULT hr = CoGetInterfaceAndReleaseStream(pMarshalData, IID_IStream, reinterpret_cast<void**>(&pStream));
if ( SUCCEDED(hr) )
{
// Use pStream.
pStream->Release();
}
------------------------
The astute reader may notice that we're using "pMarshalData" in another thread without marshalling. This is OK as the object returned by this API is free threaded.
Steve
|
|
|
|
|
Using your suggestion
IStream *pMarshalData;
HRESULT hr = CoMarshalInterThreadInterfaceInStream(IID_IStream, NULL, &pMarshalData);
if ( SUCCEEDED(hr) )
{
} This is returning -2147221008.
|
|
|
|
|
That is not my suggestion. This was:
HRESULT hr = CoMarshalInterThreadInterfaceInStream(IID_IStream, pStream, &pMarshalData);
pStream is your stream. As my sample code shows you have to unmarshall at the other end before you can use your stream.
Steve
|
|
|
|
|
_stream is my stream, the only difference is that it is a class member.
-- modified at 8:17 Saturday 22nd April, 2006
Eek, sorry, I just noticed what you mean. I incorrectly pasted the wrong code snippet, the second paramater should not be NULL it should be _stream . After trying the first time I changed the paramaters a little, my appologies.
|
|
|
|
|
Problem solved, I was neglecting to call CoInitialize(). Thanks for your help.
|
|
|
|
|
Well I thought I had this working, but it seems that the CoGetInterfaceAndReleaseStream function is entering into an endless loop and not returning. This is of course causing any following code not to be executed, and later my WaitForMultipleObjects does just that and waits.
_stream = NULL;
HRESULT hr = CoGetInterfaceAndReleaseStream(_marshal,
IID_IStream, (void **)&_stream);
if ( FAILED(hr) )
{
return;
} Is it possibly related to the initial flags when opening the stream? I have tried changing them but it only leads to the stream failing to open.
|
|
|
|
|
waldermort wrote: Is it possibly related to the initial flags when opening the stream?
I'd say no.
He's something for you to try. Place the following debugging code after you spawn your thread and marshal the stream:
MSG m;
while ( GetMessage(&m, NULL, 0, 0) )
{
DispatchMessage(&m);
}
If this code stops CoGetInterfaceAndReleaseStream from hanging it is probably because your STA apartment isn't playing by the rules and running a message pump.
Steve
|
|
|
|
|
Wow, you really know your stuff. You were right adding the code after spawning the thread stopped it from hanging. So I guess my question is, why is it not playing by the rules? I thought that when COM creates an STA it also creates a message loop.
|
|
|
|
|
waldermort wrote: I thought that when COM creates an STA it also creates a message loop
You created this STA - it's up to you to run message loops - It can be no other way as COM has no way of knowing when it's safe to do so.
When you marshal the stream pointer to the other thread what you're really doing is setting up a communication channel from the worker thread to the main thread. When you call a stream function in the worker thread COM has to get the main thread to call into the stream object and the worker thread waits till the main thread makes the call. Once the main thread is done it sends the data to the worker thread and both continue on their merry ways. But how can COM know when it's safe to hijack the main thread and make a call into the stream on behalf of the worker thread? It's different for all the threading models but for a STA this happens when you run a message pump. To make all this happen COM needs to setup a proxy in the worker thread and a stub in the main thread. This is what COM was trying to do when your code hung. More specifically it was trying to get the main thread to do its part and setup the stub but it needs it to run a message pump.
Also, as you may see based on this description, even though you have multiple threads any call into the stream from the worker thread actually gets the main thread to do the work. You may actually lose performance. Do you really need multiple threads?
Steve
|
|
|
|
|
Stephen Hewitt wrote: Do you really need multiple threads?
The stream I am reading can be broken into 8 sections (it's a 1mb file). To read the whole stream without threading takes appx. 18 seconds. I'm hoping to increase this speed by reading each section in a thread. I have coded it in such a way that whether to use threads can be defined before the file is opened.
|
|
|
|
|
Well, I must say enabling the use of threads was a waste of 2 days. Performance went from 18 seconds to just over 30 seconds. The only alternative I can see is to copy the main stream into a buffer and split it into the individual sections. Which would a total waste of time and memory.
|
|
|
|
|
waldermort wrote: long hr =
Some advice. Use HRESULT not long .
Steve
|
|
|
|
|
In my program ,I create other top frame (it's a topest frame):
pFrame = theApp.m_pDrawDocTemplate->CreateNewFrame(this, NULL);
theApp.m_pDrawDocTemplate->SetDefaultTitle(this);
pFrame->SetParent (NULL);
theApp.m_pDrawDocTemplate->InitialUpdateFrame(pFrame, this, TRUE);
but I can't run step debug in the view of the new frame .
this is all
-- modified at 5:18 Saturday 22nd April, 2006
|
|
|
|
|