|
Hi!
I want to change the caption of my property page (CPropertyPage ) with setting the pszTitle member of the PROPSHEETPAGE struct.
It works fine when I am init the pszTitle member with something like _T("Hi!") , but when I am init the member with a CString object, in the tab control of my property sheet (CPropertySheet ) some stupid characters are displayed.
This code works fine:
m_psp.dwFlags |= PSP_USETITLE;
m_psp.pszTitle = _T("Hi!");
But this code will display some stupid characters:
CString strTitle(_T("Hi!"));
m_psp.dwFlags |= PSP_USETITLE;
m_psp.pszTitle = strTitle;
I think the problem is that the system is working with UNICODE and this member (pszTitle ) exspects a LPCSTR and no LPCTSTR .
But why does the first code sequenz woking and the second not?
And how can I fix that?
(Working with embedded Visual C++ 3.0 + MFC)
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
It's nothing to do with Unicode. Your CString object will get deleted at the end of the current method, but the title is not displayed until later on, at which point it has a bad pointer. If you want to use a CString, make it a member variable of the property page.
Dave
|
|
|
|
|
It's not the problem of UNICODE, but your confusion on character string and character pointer. Look at your code:
CString strTitle(_T("Hi!"));<br />
m_psp.pszTitle = strTitle;
Above code is wrong, wrong and, WRONG!
I cannot remember how many times it's been emphasized that you do NOT copy string like that, instead, you should do it the correct way:
free((void*)m_psp.pszTitle);<br />
m_psp.pszTitle = _tcsdup(_T("Hi!"));
Then your problem should be gone.
|
|
|
|
|
Hi Bin! Thanks for your answer!
But I have a second question.
When I do it you told me, I have to free the pszTitle at the end, or???
...
free((void*)m_psp.pszTitle);
m_psp.pszTitle = _tcsdup(_T("Hi!"));
...
...
...
free((void*)m_psp.pszTitle);
Or does the CPropertyPage class that automatic in the destructor???
Thanks!
Daniel
|
|
|
|
|
CPropertyPage will handle that in its destructor.
|
|
|
|
|
The MSDN says:
"Calling CreateDIBitmap with fdwInit as CBM_INIT is equivalent to calling the CreateCompatibleBitmap function to create a DDB in the format of the device and then calling the SetDIBits function to translate the DIB bits to the DDB."
So, should I interpret this to mean that CreateDIBitmap actually calls SetDIBits, or just that the results are the same? I ask, because I'm trying to find out if a DC can support CreateDIBitmap or not. Because of the quoted sentence, I assumed that I should check GetDeviceCaps for RC_DI_BITMAP. But, there's a situation where GetDevCaps says RC_DI_BITMAP isn't supported, but CreateDIBitmap still works.
Anyone know anything about this? I hate programming.
-c
Green's Law of Debate:
Anything is possible if you don't know what you're talking about.
|
|
|
|
|
Hi all, it's me again. After some searching I found a function that does what I need, converts a ddb to a dib. Problem is it doesn't work and I don't know why. I'll post my trouble code and hopefully someone can send me in the right direction. Thanks in advance.
Mike.
<br />
<br />
HPALETTE hPal;<br />
CDC* pDC;<br />
<br />
ASSERT( bitmap.GetSafeHandle() );<br />
<br />
if( dwCompression == BI_BITFIELDS )<br />
return NULL;<br />
<br />
hPal = (HPALETTE) pPal->GetSafeHandle();<br />
if (hPal==NULL)<br />
hPal = (HPALETTE) GetStockObject(DEFAULT_PALETTE);<br />
<br />
<br />
int f = ::GetLastError();<br />
<br />
<br />
bitmap.GetObject(sizeof(bm),(LPSTR)&bm);<br />
<br />
bi.biSize = sizeof(BITMAPINFOHEADER);<br />
bi.biWidth = bm.bmWidth;<br />
bi.biHeight = bm.bmHeight;<br />
bi.biPlanes = 1;<br />
bi.biBitCount = bm.bmPlanes * bm.bmBitsPixel;<br />
bi.biCompression = dwCompression;<br />
bi.biSizeImage = 0;<br />
bi.biXPelsPerMeter = 0;<br />
bi.biYPelsPerMeter = 0;<br />
bi.biClrUsed = 0;<br />
bi.biClrImportant = 0;<br />
<br />
int nColors = (1 << bi.biBitCount);<br />
if( nColors > 256 ) <br />
nColors = 0;<br />
dwLen = bi.biSize + nColors * sizeof(RGBQUAD);<br />
<br />
<br />
hDC = (HDC)GetDC();<br />
<br />
<br />
DWORD wx = ::GetDeviceCaps(hDC, RASTERCAPS);<br />
<br />
<br />
TRACE("Raster capabilities : %08X\n",wx);<br />
<br />
<br />
hPal = SelectPalette(hDC,hPal,FALSE);<br />
<br />
<br />
f = ::GetLastError();<br />
<br />
<br />
RealizePalette(hDC);<br />
|
|
|
|
|
Mike Savoie wrote:
// We need a device context to get the DIB from
hDC = (HDC)GetDC();
so, you're calling this from a window of some kind?
have you tried ::GetDC(NULL) instead?
-c
Green's Law of Debate:
Anything is possible if you don't know what you're talking about.
|
|
|
|
|
Hi, thanks for the quick response. No, it's not called from a window. That's why I'm having such a hard time. All the examples I've found display to windows. The way this program works is that once you click the OK button. A pre-generated Large bmp file is created. Then this app is called to crop part of the original file, and save to a new file. All the bitmap manipulation happens unseen in the background, and the file is then passed to a different function for printing. That's why I'm so confused. Like I said every example uses windows, or resource files. Neither of which I have. I hope this makes sense, hehe I've been hacking at this for a couple weeks now and it's turning me into a babbling buffoon! Again thanks for the quick help.
PS- CWnd::GetDC(); //error C2660: 'GetDC' : function does not take 1 parameters
|
|
|
|
|
Mike Savoie wrote:
PS- CWnd::GetDC(); //error C2660: 'GetDC' : function does not take 1 parameters
are you trying ::GetDC(NULL) ? (ie. don't try CWnd::GetDC(NULL) )
-c
Alcohol is the anesthesia by which we endure the operation of life.
-- George Bernard Shaw
|
|
|
|
|
Dude, if I knew where you were I'd kiss ya!! (umm, well maybe buy ya a beer) haha yeah ::GetDC(NULL); worked. A few more bugs and it'll be finished. Thanks again.
|
|
|
|
|
Hi!
I want to read some information stored in a file.
I mean such as Comment, Title, Author or Keywords.
Are there some APIs that do that ... or must I access the file directly?
Maybe somebody have some code example for me?
Furthermore I want to write (change) this information...
Thanks
Martin
|
|
|
|
|
|
Hi all.
I want to have a CComboBox control that accepts a user's new entry (like a CEdit control) and then adds this entry to the CComboBox.
Here is an example:
Current entries: Cat, Dog, Canary
User types: d-o-l-p-h-i-n (the word dolphin)
Since not in the list, I want my code to add it.
I saw the examples for the IAutoComplete, but I'm not really concerned with that - I just want something simple and that/those examples seem too complex (maybe not? )
Can anyone help me with adding entries to a CComboBox WHILE IN THE CComboBox control?
Thanks so much.
Johnny
|
|
|
|
|
No big magic here - just use CComboBox::FindStringExact to check if user has typed new or existing string, and CComboBox::AddString or CComboBox::InsertString to actually add new entry to dropdown part of the combo.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
hi!
i've encountered serious problem, which couldnt solve for hours.
i've got a couple of views splitted by CSplitterWnd
in one of this views (ParentView) i dynamically create CWnd-derived object (SpinEdit) that holds CEdit and CSpinButtonCtrl (analogously to CInPlaceEdit by Chris Maunder).
the problem is:
i cant handle WM_KILLFOCUS message in SpinEdit window. Spy++ shows that this message isnt sent to SpinEdit window than user clicks mouse button on ParentView.
maybe problem is in ParentView? it is completely owner drawn and has no more child-controls except this dynamically created SpinEdit.
any help will be greatly appreciated
nobody is perfect
|
|
|
|
|
This may be of help http://www.codeproject.com/dialog/killfocus.asp[^]
Roger Allen
Sonork 100.10016
I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.
|
|
|
|
|
Hello,
I have learned a ton in the past few days.. Having never programmed UI Threads (with the help of articles on Code Project and all of you) I have implemented a UI thread that contains a CSocket for file transfer.. The server works perfect except when I close the server I have a memory leak.. This is how I start the UI Thread and how I close the UI thread.. what am I doing wrong??
Here is the creation inside CMainFrame
CFtThread* pThread = (CFtThread*)AfxBeginThread(RUNTIME_CLASS(CFtThread),
THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
pThread->m_nPort = 21;
pThread->ResumeThread();
pThread->OnStartListening();
Here is how I am trying to close the thread.. it's in CMainFrame::OnClose()
void CMainFrame::OnClose()
{
..... code
CFtThread* pThread = (CFtThread*)AfxGetThread();
pThread->ExitInstance();
..... code
CFrameWnd::OnClose();
}
In my int CFtThread::ExitInstance() I try to close the socket and remove any connected sockets...
int CFtThread::ExitInstance()
{
m_sSocket.ShutDown(2);
m_sSocket.Close();
POSITION pos, temp;
pos = m_pEpList.GetHeadPosition();
while(!m_pEpList.IsEmpty())
{
temp = pos;
CFtSocket* pSocket = (CFtSocket*)m_pEpList.GetNext(pos);
pSocket->Close();
m_pEpList.RemoveAt(temp);
}
return CWinThread::ExitInstance();
}
Any ideas on why I still have a memory leak?
Thanks,
Rob Jones
|
|
|
|
|
u are emtying the list, but are u deleting the pointers if any??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Yes I delete all Socket pointers.. It's in a different function.. 99% of the time the pointers are gone and the pointer list is empty.. I just empty it on close "just incase"..
|
|
|
|
|
AfxGetThread() returns a CWinThread pointer to the thread that makes the call. From your chunks of code it looks like you are trying to close your main thread from the OnClose() event handler for it, and thus not actually closing your CFtThread object.
I don't know what would happen if you cast a CWinThread pointer to CFtThread; I would have thought something more significant than a memory leak would happen when you try to call members of CFtThread.m_sSocket.
You get given a pointer to your CFtThread as a return from AfxBeginThread(). Try using that to close the thread.
Signature space for rent. Apply by email to....
|
|
|
|
|
I set a member pointer to CFtThread (in CMainFrame) and tried to use that pointer (from AfxBeginThread()) to close the thread.. seems that maybe the app closes before the thread does.. is there a way to wait for the thread to close before closing the app?
|
|
|
|
|
Thats cool. Just these two lines in your sample code made me suspicious:-
CFtThread* pThread = (CFtThread*)AfxGetThread();
pThread->ExitInstance();
Anyway. Only your CFtThread thread can terminate itself safely. You need to devise a mechanism for signaling to it that it needs to terminate. For a suitable signalling mechanism, see CWinThread::PostThreadMessage. You could use a custom message for it.
When your thread receives the message, it should call AfxEndThread().
for detailed info, see msdn "multithread programming | with mfc"
Signature space for rent. Apply by email to....
|
|
|
|
|
Dumping objects ->
strcore.cpp(118) : {93} normal block at 0x01222E40, 52 bytes long.
Data: < ' ' C:\C> 01 00 00 00 27 00 00 00 27 00 00 00 43 3A 5C 43
C:\Code\FtServer\FtThread.cpp(17) : {91} client block at 0x01222F40, subtype 0, 168 bytes long.
a CFtThread object at $01222F40, 168 bytes long
Object dump complete.
I'm unsure what strcore.ccp is... not sure if this helps.
Any ideas?
|
|
|
|
|
strcore.cpp needn't concern you:- MFC internals. The useful part of that dump is the line:-
a CFtThread object at $01222F40, 168 bytes long
tells you what it was.
Signature space for rent. Apply by email to....
|
|
|
|