|
Hi,
Frankly, I'm not sure that there is any problems with sending the strings between threads in the same process, but I vaguely remember something about CString and threads, you'll have to look it up un MSDN.
Inter-thread communication is always faced with the challenge that the two (or more) threads can access the data simultaneously, so you'll need to protect the integrity of the data by using one of the synchronization tokens. Or, if the data you send are going to be read only in the receiving thread it's best to pass a copy instead of a reference (when you pass the address of the CString objects in WPARAM and LPARAM they are of course passed by reference).
Of course, if the receiving thread is in another process the problems gets worse, as the two threads now don't even share a memory space.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Hi Steen
Thankyou very much for guiding me in such an ellaborative manner, i really don't have words to convey my gratitudes. i have included your method in my code and its working excellent now
could you plz teach me one more thing. What will happen if cs1 or cs2 ( or data object) goes out of scope before the window pointed by hwnd receives (or pumps out) the message from message queue.
also what will happen if i change values in cs1 or cs2 before the window pointed by hwnd receives the message from message queue.
any ways once again thank you very much and plz give some time to these question of mine as well i will be very thankful to you
regards
Azam
|
|
|
|
|
Hi Muhammad,
this is why I made the distinction between SendMessage and PostMessage. SendMessage is synchronous meaning that it will call the receiving windows' WindowProc directly, bypassing the message queue. So the call to SendMessage will behave exactly as any other function call. It is not possible for cs1 or cs2 to go out of scope or to be changed by the caller during the call. What the callee does with the data is another matter, and these changes will be relayed back to the caller as you have passed cs1 and cs2 as references (pointers).
The points you have here are absolutely valid if you use PostMessage. It's a "fire-and-forget" call - you have no control or knowledge about when the callee will execute. In this case it's best to pass a copy of the data in the call:
<br />
LPTSTR lpsz1 = new TCHAR[cs1.GetLength()+1];<br />
_tcscpy(lpsz1, cs1);<br />
::PostMessage(hwnd, WM_MYMESSAGE, (WPARAM)lpsz1, 0),<br />
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Hi Steen
once again thank you very must for explaining me all these, your way of defining things is superb and ful explainatory. Now its crystal clear to me the difference b/w SendMessage and PostMessage, i have always been confused b/w them, any ways you have been a source of knowledge for me.
thanks a lot
regards
Muhammad Azam
|
|
|
|
|
Hi,
I have got Problem With ActiveX.I created ActiveX Using OWC. i tested this activex in dialog based apllication. when i closed(on application termination) the dialog got an error , memmory location feefee() could not read. problem is my program is try to free the memory that isn't allocated.how can override this problem.
by
baijumax
|
|
|
|
|
i have an application using visual c++ 5.0 where a right-click on an application toolbar icon gives a submenu. The submenus initially come up correctly, but then quickly go into the background behind the application toolbar or existing context menus. Seems to be intermittent too, sometimes they'll stay in foreground.
Also getting this problem with the windows that pop up from a click on a 'What's This' help.
The winhelp calls are all:
WinHelp(..,..,HELP_CONTEXTMENU,..)
Any ideas how I keep the new screens in the foreground?
Thanks,
tkd
|
|
|
|
|
Alright...this is a small part of a problem I'm doing for C++ class..We have to store a floating integer T. T=1.5 . Now, we have to convert this stored value to hex...Kinda like this:
float t;
t = 1.5;
std::hex << t << "\n";
Or whatever..You get the idea tho..store the value, and convert it to it's hex format.
Have any suggestions?
|
|
|
|
|
hello,
i think you ar elooking for sprintf() function
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
depends how do you want to convert it to hex ... you know usually only ints are converted to hexes ... floating part is not carried over.
You could do printf( "%X", (int) t ); to print it in hex, but it will print only integer part.
If you want to print its binary representation you could do printf( "%08X", *((long*) &t) );
|
|
|
|
|
I have an unusual piece of code that i am writing where i need to output 3 rectangles of 3 different sizes to a window and alternate them every second. Basically it shows a new rectangle every second. Anyhow i can do it where the rectangles are alternated its just if a smaller rectangle appears on a larger one that on doesn't go away. Is there an MFC function that i am missing?
|
|
|
|
|
YEah look for invalidateRect() api that may help in above cause
basically this api repaint any given rectangular position in the given window.
now follow simple logic,first copy the image data or triangle coordinate in another variabel ,which you want to display and send message to window to repint that position
like this(remember this is logic)
triangle a,b,c & tmp;
you hav displayed them at any given time,
now oN WM_TIMER message of Seconds
copy one triangle in another like this
tmp=a;
a =b;
b=c;
c =tmp;
and call invalidate() to repaint or display the triangle
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi,
How can I extract an Icon from an Image List as HBITMAP, with a specific backgrund color?
TIA
Peter
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist Fold With Us! || Agile Programming | doxygen
|
|
|
|
|
I do it by creating a new bitmap the same size as an icon in the image list, do a FillRect() with the background colour, then Draw() the icon on it.
CBitmap *CMyImageList::GetBitmap(int index, CSize size, COLORREF clrBkGrnd)
{
int count = GetImageCount();
if (!(index < count && index >= 0))
return NULL;
IMAGEINFO info = {0};
GetImgeInfo(index, &info);
CSize ImageSize(info.rcImage.right - info.rcImage.left,
info.rcimage.bottom - info.rcImage.top);
int x = 0;
int y = 0;
if (size.cx != ImageSize.cx)
x = (size.cx - ImageSize.cx) / 2;
if (size.cy != ImageSize.cy)
y = (size.cy - ImageSize.cy) / 2;
CBitmap *pbmp = NULL;
CDC DC;
if (DC.CreateCompatibleDC(NULL))
{
int saved = DC.saveDC();
pbmp = new CBitmap;
if (pbmp)
{
if (pbmp->CreateCompatibleBitmap(NULL, size.cx, size.cy))
{
if (DC.SelectObject(pbmp))
{
DC.FillSilidRect(0, 0, size.cx, size.cy, clrBkGrnd);
Draw(&DC, index, CPoint(x, y), ILD_NORMAL);
}
}
}
DC.RestoreDC(saved);
}
return pbmp;
}
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi, I have a simple dialog box app and would like to add a progress bar to it. The progress bar simply needs to move toward completion when a button is pressed. It needs to move toward completion based simply on a time, ie needs to be finished after the button is pressed in 5 seconds. Thanks for the help sorry i am such a noob. The progress bar ID i am using is OnOutofmemoryProgress2. Thanks.
|
|
|
|
|
add WM_TIMER functionality in your program suing winodow handller menu.
according to your calculation set the timer and using the Progressbar variable finsih it within 5 sec.
and by the way ->
The progress bar ID i am using is OnOutofmemoryProgress2. Thanks.
--> is not id,its a event on Progressbar and id is like this IDR_PROGRESSBAR1 or some thing like that.
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
|
I'm interested in finding a method to verify the digital signature of a file so that I'll know if it's been altered since I signed it.
I looked at WinVerifyTrust(), but it only exists in NT/XP - not Win9x (which I still need to support).
Microsoft does however have a tool called ChkTrust.exe
Does anyone know "how" chktrust.exe works under win9x?
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
Well, after a few hours of digging and testing my theories - I've answered my own question. There's this thing called CAPICOM.DLL that provides a number of com interfaces for checking the authenticode signature on a file. And it even (as the rumor goes) have a redistributable for win98!
With a little work, I'm sure somebody with more time on their hands than I, could write up a full featured article that also Signs and timestamps a file.
#ifndef __SIGNED_CODE_H__
#define __SIGNED_CODE_H__
#import "capicom.dll" named_guids no_implementation
#pragma once
class CSignedCode
{
protected:
CComQIPtr<CAPICOM::ISignedCode> m_spSignedCode;
public:
CSignedCode(LPCTSTR pszFileName)
{
HRESULT hr = m_spSignedCode.CoCreateInstance(CAPICOM::CLSID_SignedCode);
if( SUCCEEDED(hr) && pszFileName && *pszFileName )
SetFileName( pszFileName );
}
HRESULT SetFileName( LPCTSTR pszFileName )
{
if( !m_spSignedCode )
return E_POINTER;
return m_spSignedCode->put_FileName( CComBSTR(pszFileName) );
}
HRESULT Verify(BOOL bAllowWindowsPromptUI)
{
if( !m_spSignedCode )
return E_POINTER;
return m_spSignedCode->raw_Verify(bAllowWindowsPromptUI?VARIANT_TRUE:VARIANT_FALSE);
}
HRESULT GetDescription(CString& rstrDescription)
{
if( !m_spSignedCode )
return E_POINTER;
CComBSTR bs;
HRESULT hr = m_spSignedCode->get_Description(&bs);
if( SUCCEEDED(hr) )
rstrDescription = bs;
return hr;
}
HRESULT GetURL(CString& rstrDescriptionURL)
{
if( !m_spSignedCode )
return E_POINTER;
CComBSTR bs;
HRESULT hr = m_spSignedCode->get_DescriptionURL(&bs);
if( SUCCEEDED(hr) )
rstrDescriptionURL = bs;
return hr;
}
HRESULT GetFileName(CString& rstrFileName)
{
if( !m_spSignedCode )
return E_POINTER;
CComBSTR bs;
HRESULT hr = m_spSignedCode->get_FileName(&bs);
if( SUCCEEDED(hr) )
rstrFileName = bs;
return hr;
}
};
#endif //__SIGNED_CODE_H__
[ Jason De Arte | Toy Maker | 1001010.com ]
|
|
|
|
|
Query:
I am building an MFC app. I try to open the resource file and I get a red circle icon with a white asterisk inside that says the "resource is open in another editor".
I then close all files (presumably) and restart. I get the same message from the resource. What's up w/ that? Nothing is "open"....
thanks
|
|
|
|
|
hi,
"resource is open in another editor" is coming when you already open the resource file.You can open the resource file twise.
thanks..
|
|
|
|
|
Hello. How can I do the following: when choosing some item from a popup menu (with a right button click) another popup is shown offering some things to do with that item. I don't need it to do classic way that is to use InsertMenu method with MF_POPUP flag but so that this additional menu is shown only on mouse click.
|
|
|
|
|
Handle WM_MENURBUTTONUP to know when the user r-clicks a menu. In response to that message, call TrackPopupMenu() again with the TPM_RECURSE flag.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but how will we fit the hamster inside the accordion?
|
|
|
|
|
|
Hi Dudes,
How to compile HTML files like we do in HTMLHelp Creation. Is there any SDK to do that.
Thanks & Regards,
Promise (hmmm... I am afraid of it).... Some times.
If you have in the cause and
the means and in God, the hot
Sun will be cool for you.
|
|
|
|
|
DELIVER THE PROMISE wrote:
Is there any SDK to do that.
Yes. Click here[^].
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|