|
Hi All,
I am writing a non MFC Application using Opengl (Win32 Project) but i am using
some MFC Headers below
#include // MFC core and standard components
#include // MFC extensions
#include // MFC Automation classes
#include // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include
#include
////////////////////////////////////////////////////////////////////////
I want to use Web Browser Control On my project (Activex) but i am not
using any form i want create web browser using createWindow function
////////////////////////////////////////////////////////////////////////
It will be really help full if anyone please send me sample code
Thanks,
Soumyadipta De
|
|
|
|
|
In MFC application I've open a file on a click event as follows.
<br />
void CSRFToolDlg::OnBnClickedOpen()<br />
{<br />
char* ReadFileName = "G:\\Work On\\CPP\\SRFTool\\text_file.txt" ;
<br />
if(openFile.Open(ReadFileName, CFile::modeCreate | CFile::modeReadWrite))<br />
{<br />
AfxMessageBox("File creates successfully", MB_OK) ;<br />
}<br />
else<br />
{<br />
AfxMessageBox("Error in file opening", MB_OK) ;<br />
}<br />
}<br />
Then I wrote few text to it as follows, again on a click event.
<br />
void CSRFToolDlg::OnBnClickedWrite()<br />
{ <br />
GetDlgItemText(IDC_S_WRITE, readString) ;<br />
AfxMessageBox("Data write to the file successfully", MB_OK) ;<br />
openFile.Write(readString, readString.GetLength()) ;<br />
}<br />
Here readString is a CString.
Then try to read that file and print it on a text box(edit control). How can I do that. Try to use a buffer, but failed to do it. Like this,
<br />
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
char tempBuffer[256] ;<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;<br />
<br />
SetDlgItemText(IDC_S_READ, readText) ;<br />
}<br />
Where I'm going wrong.
I appreciate your help all the time...
Eranga
|
|
|
|
|
you didnt specify, what is the output/error you are getting.
and what does openFile.Read() return?
any way,
Eranga Thennakoon wrote: readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;
instead of strlen(tempBuffer) try giving 256 and see;
---------------------------------------------------------------------
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
chandu004 wrote: you didnt specify, what is the output/error you are getting.
and what does openFile.Read() return?
Sorry about that and I got this error.
'CWnd::SetDlgItemTextA' : cannot convert parameter 2 from 'UINT' to 'LPCTSTR'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
chandu004 wrote: instead of strlen(tempBuffer) try giving 256 and see;
I'll already do it, but the issue is there. I used strlen(tempBuffer) to set the length of string same to the buffer.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I'll already do it, but the issue is there. I used strlen(tempBuffer) to set the length of string same to the buffer.
i didnt get this can u explain more?
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
Ok,
As you said I've replace the strlen(tempBuffer) part with 256. It avoid a warning conversion from 'size_t' to 'UINT', possible loss of data
Initially I've create a buffer of size 256. I want to put my string there and use it. I think it is clear.....
To read the file I used openFile.Read() with two arguments, the buffer and length what I want to read. If I use 256 it read all the buffer, more than my string. If the buffer is not empty it can read something else. Is it clear.
But it not work.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: To read the file I used openFile.Read() with two arguments, the buffer and length what I want to read. If I use 256 it read all the buffer, more than my string.
atleast you have got your string here right?
but you are getting extra characters here am i right?
so while writing itself, append the string with \0 at the end and see.
now you will get the packed string without extra characters.
gud luck.
--------------------------------------------------
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
That is one of major thing I want to avoid, print/getting extra characters.
I appreciate your help all the time...
Eranga
|
|
|
|
|
may be use like this and see.
void CSRFToolDlg::OnBnClickedWrite()
{
GetDlgItemText(IDC_S_WRITE, readString) ;
//terminate the string with \0 here.
AfxMessageBox("Data write to the file successfully", MB_OK) ;
openFile.Write(readString, readString.GetLength()) ;
}
|
|
|
|
|
chandu004 wrote: readstring[readstring.GetLength()]='\0';
On this gives an error, says
left operand must be l-value
I appreciate your help all the time...
Eranga
|
|
|
|
|
try using readstring.SetAt();
take care of the syntax.
|
|
|
|
|
Eranga Thennakoon wrote: openFile.Write(readString, readString.GetLength())
Try casting the CString to (LPCTSTR) first.
openFile.Write((LPCTSTR)readString, readString.GetLength())
- NS -
|
|
|
|
|
Actually this part is ok, it is write the text to the file correctly. I can't read the file, which is open and write something on it before.
By the way, since I've define the readString as a CString, it is required to cast?
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: I can't read the file, which is open and write something on it before.
Can you show the exact code that is used for open and read?
Eranga Thennakoon wrote: By the way, since I've define the readString as a CString, it is required to cast?
Since I am unaware of the parameter type, I said to make it sure that casting is proper. If you can see the data written, obviously it is not needed.
- NS -
|
|
|
|
|
For open
<br />
void CSRFToolDlg::OnBnClickedOpen()<br />
{<br />
char* ReadFileName = "G:\\Work On\\CPP\\SRFTool\\text_file.txt" ;
<br />
if(openFile.Open(ReadFileName, CFile::modeCreate | CFile::modeReadWrite))<br />
{<br />
AfxMessageBox("File creates successfully", MB_OK) ;<br />
}<br />
else<br />
{<br />
AfxMessageBox("Error in file opening", MB_OK) ;<br />
}<br />
}<br />
For write,
<br />
void CSRFToolDlg::OnBnClickedWrite()<br />
{<br />
GetDlgItemText(IDC_S_WRITE, readString) ;<br />
openFile.Write((LPCTSTR)readString, readString.GetLength()) ;<br />
AfxMessageBox("Data write to the file successfully", MB_OK) ;<br />
}<br />
For read, actually this way is not correct, because it not read the file at all. Just use the string and print.
<br />
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
SetDlgItemText(IDC_S_READ, readString) ;<br />
}<br />
I've tried this, but not work.
<br />
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
char tempBuffer[256] ;<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;<br />
<br />
SetDlgItemText(IDC_S_READ, readText) ;<br />
}<br />
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;
Taking the length of tempBuffer is wrong.
And my doubt is that, before you read, are you sure that the file is opened for read?
- NS -
|
|
|
|
|
No, I'm try to find the length of the string in buffer. strlen() gives it, right? I found it on MSDN. It gives the length of CString.
Actually file is open on previous click event.
I appreciate your help all the time...
Eranga
|
|
|
|
|
but here, unless you are reading your text from file, how are you able to get its length?
any way, you can see your inbox and see my mail, to which, you can forward it.
|
|
|
|
|
Eranga Thennakoon wrote: Actually file is open on previous click event.
After that you write the value? If so the file pointer is at the end of content, right? Then you have to reset it to initial position. In the case of CFile, you can use SeekToBegin API
- NS -
|
|
|
|
|
Yes it is true. But those comes later, isn't it? I mean need worried about those things when I use multiple lines of text. At the time I can read at least a single line pal.
That why I need your help.
I appreciate your help all the time...
Eranga
|
|
|
|
|
I am not much clear about what you said. I think you have a file having multiple lines. So when you write a string then you think that the file pointer is not at the end of the file. Am I right?
- NS -
|
|
|
|
|
Actually you no need think in that much.
Right now just write a line of text and want to read it to a edit control and display. That's it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
sorry! for the delay Eranga
right now i'm called for a meeting.
i will get back by 5:30 pm
and guide u.
till then good luck!
i have some clue for u
in write button,
1.open the file in write mode,
2.write the data
3.close the file.
in read button,
1.open the file in read mode,
2.read the data
3.close the file.
|
|
|
|
|
Thanks for the tip. I'll work it on.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: write a line of text and want to read it
For this, I have said to use SeekToBegin. Hope it will work.
- NS -
|
|
|
|