|
CString array[2400];
CListBox listbox;
for (int i = 0; i < 2400; i++) {
listbox.AddString(array[i]);
}
Software Zen: delete this;
|
|
|
|
|
Ya thank you very much for ur reply, whatever you have written is correct and i was owrking int he same way, but i was encountering an error while using with two dimensional arrays.How could i use for two dimensional arrays?
CString average[100][100];
CListBox m_stravevalues;
for(i=0;i<60;i++)
for(j=0;j<40;j++)
{
m_stravevalues.AddString(average[i][j]);
}
Is this correct???
|
|
|
|
|
Not Correct, A Listbox is One Dimensional, and cannot display 2 Dimensions. Maybe you're looking for a Multi Colum listbox??
LateNightsInNewry
|
|
|
|
|
So, anybody could help me, to output this two dimensional array in a List box or Edit box.
|
|
|
|
|
Hi again
i'm in trouble again with strings.
What i want to do is read from a file, line by line (each line has only one word)
and compare it with onother string. the problem is that the way i do it is the following
void Html_Parser::dictionary(string tokencheck)
{
FILE *dFile;
bool found=false;
char string_token[50];
dFile = fopen("dictionary.txt","r");
if (dFile == NULL)
perror ("Error opening file");
else
{
do
{
fgets (string_token , 50 , dFile);
puts (string_token);
if (strcmp (string_token,tokencheck) == 0)//incompatible
{
found=true;
cout<<"found"<
|
|
|
|
|
Don't use all this old fashioned fopen and fgets - This is C++ not C!
Here's how I'd do it. I haven't tested this, it's off the cuff; so you may need to add a semicolon or some such:
void TokenCheck(const string &token)
{
ifstream fs("dictionary.txt");
if ( fs )
{
istream_iterator<string> i(fs);
istream_iterator<string> e;
if ( find(i, e, token)!=e )
{
}
}
}</code>
Uses the following includes:
<string>
<fstream>
<iterator>
<algorithm>
Assumes:
using namespace std;
Steve
|
|
|
|
|
Hey Steve thanks a lot appresiate the help.
can u tell me a good c++ library reference site so i can stop using those old fashion functions thanks again
|
|
|
|
|
I'm not sure about a site - I've got a book on C++ and one on The Standard Library.
Steve
|
|
|
|
|
|
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.
|
|
|
|
|