|
First off, why are you using malloc as apposed to new? Is this C? (as apposed to C++).
Second - is the text file you are reading ASCII? Or Unicode? _TCHAR = char for ASCII builds or w_char for Unicode ones - it doesn't really help you here as the text file is always going to be one type or the other regardless of your build.
The thing to keep in mind is _tcscat will stop if it finds a \0 somewhere in the string - try executing a _tcslen on the 'fileLine' that is stoping at 150 chars or so, what does that return? If that returns the shorter length, it's possiable the string being read in has embedded \0's that _tcscat is stoping when it finds it.
|
|
|
|
|
It's C++, but I'm a novice. Bare with me.
The file is ASCII.
I've been messing around with this and the concat works fine for normal char functions and produces the expected output. I tried to convert this output to _TCHAR (this string is later going to be passed into a DB package (PL/SQL)) and again, it cut off the conversion where the original code stopped concatonating?
Any thoughts?
Cheers,
Tom.
|
|
|
|
|
No worries,
If the file is ASCII then _TCHAR is of no use to you.
TCHAR is a special define that maps to plain old char when _UNICODE is not defined, and to wide char (IE a unicode char, w_char) when _UNICODE is defined. Are you defining _UNICODE for your project? Could you put up the code you are using to read the file line please.
Try replacing _TCHAR with char and _tcscat with strcat and let me know if it still complies. If not, you have some unicode issues going on - if you want to convert the char string to unicode you need to use something like MultiByteToWideChar etc.
Also, why are you derefrencing completeString ? _tcscat takes arguments of TCHAR*, if completeString is of type TCHAR* you end up with TCHAR when you derefrence it, im supprised that even compiles..
Try something like this:
char aSmallLine[400] = {0};
char* apCompleteString = new char[4000];
memset(apCompleteString, 0, 4000);
while(<read a line from the file and put it in aSmallLine>)
{
strcat(apCompleteString, aSmallLine);
}
// do something with apCompleteString
delete [] apCompleteString;
|
|
|
|
|
does anyone know how i could display the prompt of my menu items into my MFC dialog status bar ?
the string table is already created, but i can't find the way of catching such a text when the miouse is over an item...
thx all
TOXCCT alias Nicolas C.
|
|
|
|
|
Hi all,
I'd created a DLL with Automation option checked. After building the project, from Tools->Register control i registered the dll and it showed the message, dll successfully registered. But when i check thr registry, i can't find the dll.Where am i going wrong?
rgrds
kevcs2
|
|
|
|
|
I would like to save what I draw in my CDC into the bitmap.
But I cannot find the way how to do it.
It would be enough to store it into CBitmap
(the way how to save CBitmap into .bmp file I already know
Something like how to implement function:
bool SaveDC(CDC device, LPCTSTR lpszFile)
Thank you
viliam
|
|
|
|
|
The fastest and most quickest option is pixel-wise copying:
1. Create a fresh, unselected bitmap object (CBitmap).
2. Get the dimensions of the DC.
3. Create the underlying Windows bitmap by using CreateBitmap member function. Remember to use DC's dimensions.
3. Achieve a pointer to the bitmap's data (See MSDN -> CBitmap)
4. Run through a for-loop, copying the color of each pixel from the DC into the bitmap's data matrix.
This is the easiest way, although if your color settings are strange, it may result WEIRD bitmaps. An alternative might be that you create a compatible DC, then select a blank bitmap into it, copy from source to destination, and then save the bitmap. This allows some control over color changes.
Alternatively, use some ready-made classes, such as CxImage, available from CodeProject.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
- Create a new device context compatible with the original DC using
CreateCompatibleDC . We'll call this the memory device context.
- Use
CreateCompatibleBitmap to create a bitmap of the appropriate size. It needs to be compatible with the original DC, not the memory device context created in step 1.
- Select the bitmap into the memory device context using
SelectObject .
- Use
BitBlt to copy the appropriate area of the original DC into the memory DC. You can now save your bitmap.
|
|
|
|
|
ok i know this is the wrong forum
but is there anyone who have used licensed winforms controls in a managed c++ app???
apparently vc++ does not embed .net licenses into the host app by default
so is there anyone that knows how to get a .net license to be compiled into the host app?
ive tried to make generate a binary license with the lc.exe tool but how do i get the resulting binarylicense into the compiled app??
(and i havent bought a licensed control , im just trying to get my own to be compiled into managed c++ apps)
//Roger
|
|
|
|
|
Hi All,
I want to know the width of a font,Before I Create a font. My aim is to provide
a character ratio for the font.
Iam creating the font using the "CreateFont" method.In this Function,the 2nd parameter
is width.So to Create a Font with a particular character ratio,I need to give in this 2nd
parameter a value which is equal to (widthoffont * characterratio).
sO THATS why I want to know the width of the font before creating a font before.Is it
possible?.
I tried as follows:
CFont font:
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
font.CreateFont(-height,0,rotVal.x ,rotVal.y,style,FALSE,FALSE,0,ANSI_CHARSET,
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,
reinterpret_cast<const unsigned="" short*="">(facename.c_str()));
// In "CreateFont" method Iam giving width as 0 in the 2nd parameter as I dont know the width in advance & I tried to get the width windows allocated using the logFont Structure. But Iam not getting the width windows allocated instead Iam getting '0' which I gave in the "CreateFont" method.How is it possible to get the width windows allocated.
Would be nice if someone tells me how to achieve this....
font.GetLogFont(&lf);
long width = lf.lfWidth;
font.CreateFontIndirect(&lf);
Thanks in advance.........
|
|
|
|
|
First create a dummy font with the facename, and height you want. Use CreatePointFont for this purpose. Then use the GetFontLog to get the LOGFONT structure from the point font.
Now you can delete the dummy font object using DeleteObject . Adjust the width by multiplying the LOGFONT::lfWidth parameter, then use CreateFontIndirect with the LOGFONT structure to create a font with equal height, typeface and other properties, but a modified width.
If this isn't what you meant, then please give more details on what you want. Just by saying 'Character Ratio', you don't make any sense. What do you mean by that ? Explain, draw, create a sketch, describe. Anything to help us understand what is it that you actually want. Firstly, answer the question "What is character ratio ?"
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
The thing I would like to do is
For Eg:-If I have a Text with a particular font Drawn into the DeviceContext.What I would like to do now is pull this text from both sides,so that it looks stretched.I give a value to the extent I want it to be stretched.this value I call the "Character Ratio".ie:If I give the characterratio value 1,the text will the stretched a bit.The stretching increases with higher values of Characterratio.
I can achieve this by increasing the windowsfontwith by a givenratio.
Hope u understand what I mean.Could u show me want u have told with a sample code...
Thanks..
|
|
|
|
|
This is what MSDN says about the lfWidth parameter:
If lfWidth is zero, the aspect ratio of the device is matched against the digitization aspect ratio of the available fonts to find the closest match, determined by the absolute value of the difference.
Otherwise, the lfWidth determines the average width of the font, in logical units. Apparently your only way now is to test it yourself: use the routine I gave you, but instead of multiplying with the 'Character Ratio', multiply the ratio itself with a certain parameter and then insert it into the lfWidth parameter directly. As you request the LOGFONT made by CreatePointFont , it should return zero in lfWidth (see above, in italics).
Instead, just give some arbitary values to lfWidth , see how your text behaves, draw a conclusion and implement a routine for your stretching.
I don't have any sample code available currently, so you'll just have to experiment yourself.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I proceeded as u said,but
Iam getting the LOGFONT::lfWidth as zero
|
|
|
|
|
Do you have any ideea how to paste gif, jpg images in a rtf editor project based on dialog box?
Thank you.
Adriana
|
|
|
|
|
You can't do this without using COM.
If you don't know COM it is a very ugly thing...
As I can remeber you have to implement the IRichEditOleCallback COM interface and then you have to set this interface as OLE callback in your rich edit control.
// Class REOLECallback implemenets IRichEditOleCallback
IRichEditOleCallback* mREOLECallback = new REOLECallback();
::SendMessage((HWND)m_yourRTFCtrl.GetSafeHwnd(), EM_SETOLECALLBACK, 0, (LPARAM) mREOLECallback);
If have found an implementation in the internet which seems to work, the method which does the main thing is GetNewStorage:
<br />
class REOLECallback : public IRichEditOleCallback<br />
{<br />
public:<br />
REOLECallback() { mRefCounter = 0; }<br />
~REOLECallback(){}<br />
<br />
STDMETHOD_(ULONG, AddRef) (void);<br />
STDMETHOD_(ULONG, Release) (void);<br />
STDMETHOD(QueryInterface) (REFIID iid, void** ppvObject);<br />
<br />
STDMETHOD(ContextSensitiveHelp) (BOOL fEnterMode) { return E_NOTIMPL; }<br />
STDMETHOD(DeleteObject) (LPOLEOBJECT lpoleobj) { return E_NOTIMPL; }<br />
STDMETHOD(GetClipboardData) (CHARRANGE FAR *lpchrg, DWORD reco, LPDATAOBJECT FAR *lplpdataobj) { return E_NOTIMPL; }<br />
STDMETHOD(GetContextMenu) (WORD seltype, LPOLEOBJECT lpoleobj, CHARRANGE FAR *lpchrg, HMENU FAR *lphmenu) { return E_NOTIMPL; }<br />
STDMETHOD(GetDragDropEffect) (BOOL fDrag, DWORD grfKeyState, LPDWORD pdwEffect) { return E_NOTIMPL; }<br />
STDMETHOD(GetInPlaceContext) (LPOLEINPLACEFRAME FAR *lplpFrame, LPOLEINPLACEUIWINDOW FAR *lplpDoc, LPOLEINPLACEFRAMEINFO lpFrameInfo) { return E_NOTIMPL; }<br />
STDMETHOD(GetNewStorage) (LPSTORAGE FAR *lplpstg);<br />
STDMETHOD(QueryAcceptData) (LPDATAOBJECT lpdataobj, CLIPFORMAT FAR *lpcfFormat, DWORD reco, BOOL fReally, HGLOBAL hMetaPict) { return E_NOTIMPL; }<br />
STDMETHOD(QueryInsertObject) (LPCLSID lpclsid, LPSTORAGE lpstg, LONG cp) { return S_OK; }<br />
STDMETHOD(ShowContainerUI) (BOOL fShow) { return E_NOTIMPL; }<br />
<br />
private:<br />
DWORD mRefCounter;<br />
};<br />
<br />
STDMETHODIMP REOLECallback::GetNewStorage(LPSTORAGE FAR *lplpstg)<br />
{<br />
LPLOCKBYTES lpLockBytes = NULL;<br />
SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);<br />
if (sc != S_OK) return sc;<br />
sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, lplpstg);<br />
if (sc != S_OK) lpLockBytes->Release();<br />
return sc;<br />
}<br />
<br />
STDMETHODIMP REOLECallback::QueryInterface(REFIID iid, void** ppvObject)<br />
{<br />
if (iid == IID_IUnknown || iid == IID_IRichEditOleCallback)<br />
{<br />
*ppvObject = this; AddRef();<br />
return S_OK;<br />
}<br />
else<br />
{<br />
return E_NOINTERFACE;<br />
}<br />
}<br />
<br />
STDMETHODIMP_(ULONG) REOLECallback::AddRef()<br />
{<br />
mRefCounter++;<br />
return mRefCounter; <br />
}<br />
<br />
STDMETHODIMP_(ULONG) REOLECallback::Release()<br />
{<br />
if ( --mRefCounter == 0 )<br />
{<br />
delete this;<br />
return 0;<br />
}<br />
else<br />
{<br />
return mRefCounter; <br />
}<br />
}<br />
As I remember this is what you have to do, but I am not sure if there was soemthing else what you have to consider.
BUT this seems only to work if you paste images which are embbeded into RTF text. So if you paste an image from Wordpad it will work, but if you want to paste an image from Paint in may not work!
|
|
|
|
|
Can you give me an example?
|
|
|
|
|
As I mentioned the most important part is to implement the IRichEditOleCallback interface. You can use the class REOLECallback which I have found in the internet.
I assume that you use a CRichEditCtrl in a dialog. You must create an object of the REOLECallback class in your OnInitDialog method. Then you have to set yourw callback class as OLE callback for your rich edit ctrl using SendMessage with parameter EM_SETOLECALLBACK! If you have done this it should work.
<br />
IRichEditOleCallback* mREOLECallback = new REOLECallback();<br />
::SendMessage((HWND)m_yourRTFCtrl.GetSafeHwnd(), EM_SETOLECALLBACK, 0, (LPARAM) mREOLECallback);<br />
Unfortunatly I can't give you more details because I don't understand every detail myself. I was happy when it worked with the code I have found in many sources.
You may want to take a look at the description of EM_SETOLECALLBACK and IRichEditOleCallback in the MSDN library. You will find some additional information there.
|
|
|
|
|
Thanks a lot. But do you have any ideea why I cannot paste img from Paint?Or do you know how to solve this problem?
|
|
|
|
|
No sorry, I am not a COM expert. The solution I have found seems only to work with RTF text and embedded objects like graphics. I don't know what you have to do if you want to paste OLE objects like graphics etc. and I have found no additional information.
I think you must do much more OLE stuff if you want to paste OLE objects, but I have absolutely no idea how you can do this. Maybe you should post in the COM/OLE fourm, too.
It would be very nice if you post your efforts in this thread, since I am also interested in this subject.
|
|
|
|
|
Here are some additional issues which may help you:
* The GetIRichEditOle method of the CRichEditCtrl class returns an IRichEditOle pointer. This may be useful, but the documentation is very thin.
* Take a look in the source code of the CRichEditView class. You can find the source code in the installing directory of your Visual Studio installation. CRichEditView is a wrapper for CRichEditCtrl so it may contain the solution for your problem, because I think it can paste graphics!
|
|
|
|
|
I must do this in a Rich edit control. I am almost desperately. Can you help me? I don't know if I can post this because I'm doing this for a company.I know about RichEditView.
|
|
|
|
|
I know that this subject is very ugly. I have spent 1 week until I have found this minimal solution. Since pasting RTF text with embedded objects was good enough for me I have stopped looking for other solutions. So this is all I can offer you...
I have not found any further informaion about this topic.
The 2 tipps are only subjects where I would take a look at.
And I don't want your complete code, I only wanted to say that you may post here, if you find a solution for the problem somewhere in the internet
|
|
|
|
|
OK, but do you have any idea why my app does not copy images from Word?
|
|
|
|
|
What about pasting metafiles, the format is CF_METAFILE.
|
|
|
|
|