|
You probably still use the font (draw text with it) after you deleted the HFONT handle.
Maybe you selected it?
The solution is to DeleteObject the HFONT handle only after you unselected it in any window using it, e.g when the window is destroyed.
--------------------------------------------------
If my messages appear curt, I apologize.
I try to be brief to save your time as well as mine.
--------------------------------------------------
|
|
|
|
|
I assume the font is being draw correctly if you don't delete it? If so, it sounds like you are calling DeleteObject before you have finished drawing the text. This usually happens becasue you have done something like PostMessage to draw the text then immediately afterwards called DeleteObject. I tend to do this, in "pseudo" code, when changing fonts
hFont = CreateFont
hFoldOld = SelectObject(hFont
drawtext
SelectObject(hFoldOld
DeleteObject(hFont
|
|
|
|
|
I pass the hNewFont as a parameter in a function SetMyFont, this function sets a member variable called m_hFont to hNewFont as follows:
void CMyClass::SetMyFont(HFONT hNewFont)
{
m_hFont = hNewFont;
}
then later I use the member variable m_hFont to draw the text. My exact code is:
HFONT hNewFont = ::CreateFont(iHeight, 0, 0, 0, (IsBold? FW_BOLD: FW_NORMAL),
IsItalic, IsUnderline, IsStrikeOut, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, FontName);
if (hNewFont)
{
SetMyFont(hNewFont);
}
I thought that there is no harm in deleting the handle here because I will use the copy of it, and I delete the m_hFont in the destructor.
Can you help me in this?
Daed
|
|
|
|
|
This statement m_hFont = hNewFont does not "make a copy" of the font, all you have done is assigned the variable m_hFont to hNewFont. m_hFont is a HANDLE it just points to some memory location, i.e. the same memory location as hNewFont. So basically don't delete hNewFont.
I suggest in the construtor
m_hFont = NULL;
then
if(m_hFont)
DeleteObject(hFont)
m_hFont = NULL;
hNewFont = ::CreateFont
if (hNewFont)
{
SetMyFont(hNewFont);
}
|
|
|
|
|
Sorry must learn to type
if(m_hFont)
DeleteObject(m_hFont)
|
|
|
|
|
I tried it, but i will still have one font handle in the memory!
|
|
|
|
|
If is difficult to answer your question, without seeing the code. I assume you are failing to delete a font you have created? You could have called CreateFont twice, thereby overwritting the previous font value?
Assuming, again, it is all in one class.
Constructor
m_hFont = NULL
CreatingFont
if(m_hFont)
DeleteObject(m_hFont)
m_hFont = NULL;
m_hFont = CreateFont(
Destructor
if(m_hFont)
DeleteObject(m_hFont)
This way you are only using m_hFont, so it is easier to check what you are doing. Also check the error returns from the functions.
|
|
|
|
|
Can anybody suggest a good profiling tool that will monitor the execution of a program and breakdown the amount of time spent calling the various Win32 API functions. In particular I need to know how long a program is spending reading, writing and flushing files.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
Personally I prefer Quantify[^] from Rational. But you can do it also with the VC profiler.
TrueTime from Numega works too, but I dont like its interface. Too clumsy. Quantify is intuitive and really easy to use. Also gives better results.
I don't think this is a serious possesion, and the evil most likely comes from your hand. Colin J Davies, The Lounge
|
|
|
|
|
Hi,
I am doing a very basic thing of sending data to a server and getting the reply back.
For which first I have to send in a Login request and get authenticated, once authenticated, I have to send the actual data.
The problem I am facing is when I send the data, it embeds some funny characters before the actual text, which is causing the problem.
Upon further investigation, it was found that if I send the data without the login, it gets to the server correctly.
Is there some kind of REFRESH!!! for the second time when the data is sent so that it has correct values?
[CODE]
=========================================
for login authentication:
e = sendto(sd,"<req><loginid>8888\n",89,0,(struct sockaddr *)&saServer,sizeof(saServer));
For sending Data:
e = sendto(sd,"<req><loginid>8888<reqtype>08<broadcast><messagetype>M<no>5359846<message>Test+Value\n");
==========================================
[CODE]
The second sendto, does not send the data correctly.
Is there some refresh after we do the first sendto?
Kindly Help!!!
Best Regards,
John
|
|
|
|
|
From MSDN-doc I get that the 3rd parameter of ::sendto() is int len .
Are you setting this one correctly to the length of the data you want to transmit?
And: do you get an error-return in your variable e ?
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Hi,
yes the return variable is '0' which is correct.
Thanks,
John
|
|
|
|
|
So, having 0 bytes transfered is correct?
I don't think so! Something is rotten here, and I am of no help, 'cause I never used sockets. Sorry!
But it seems you HAVE TO read the MSDN about this.
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
Oops!! sorry I gave you the return code '0' which means success.
yes, there is a return confirmation which I am getting.
But I am not selecting the entire return confirmation, just taking in first 40 bytes.
Thanks,
John
|
|
|
|
|
John Bosko wrote:
yes the return variable is '0' which is correct.
which is _not_ correct. Try and give the length of the data you want to send as third parameter of the sendto . I think that this is really a buffer problem. When you send your data without preceding it by the login request, the buffer is empty (and not full with the loggin request stuff), so IMO that's why there is no problem in that case.
~RaGE();
|
|
|
|
|
Maybe you should empty the socket buffer before restarting to use sendto again. How are you authenticating it (from the sender point of vue) ? Does the sender got something from the reciever (confirmation message ?) so that he is allowed to send data ? If yes, this could have been sent back if the buffer was not emptied. I experienced that a couple of months ago.
~RaGE();
|
|
|
|
|
Hi,
How do I empty the socket buffer?
If you can help me out with it, I guess it would solve my problem!!!
Kindly Help,
John
|
|
|
|
|
John Bosko wrote:
How do I empty the socket buffer?
I was just looking for it, but i did not find anything, and i cannot remember myself Sorry .. I stiil think this should not happen if you receive the same amount of byte that you send, so be careful to the length parameter in sendto . Sorry i cannot help more.
~RaGE();
|
|
|
|
|
hello @all,
i want to use
<br />
BOOL EnableMenuItem(<br />
HMENU hMenu,
UINT uIDEnableItem,
UINT uEnable
);<br />
i have two menu's:
IDR_MAINFRAME
IDR_MENU1
i want to use it, in the IDR_MENU1.
but when i write:
EnableMenuItem(IDR_MENU1, ID_EXTRAS_SERVICE, MF_GRAYED);
it do not work.
thanks
sunny
|
|
|
|
|
HMENU hMenu is not the resource ID of your menu resource, but the menu handle you get from the CMenu::hmenu member or from the ::LoadMenu() call which created your menu.
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
thanks for reply.
i work with mfc, where can i find this functions? i don´t find them.
thanks
sunny
|
|
|
|
|
OK. I try to explain:
Any function in global space can (should) be preceeded with the scope operator :: This means it is not from the loacal namespace (e.g. class) but global. Most of the time, the compiler can figure it out itself, but it helps human readers to explicitly say that you are calling the global scope function, and not some member.
::LoadMenu() is a WIN32 function in global scope. MSDN will be of help with the details.
CMenu::m_hmenu is the member variable m_hmenu from the namespace CMenu. CMenu is the MFC class dealing with menus. Also MSDN helps here.
Hope this helps
--
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
i don´t think i understand it, but i tried this:
EnableMenuItem(::LoadMenu(IDR_MENU1), ID_EXTRAS_SERVICE, MF_GRAYED);
but it do not work? do you mean something different? can you give me an example?
thanks
sunny
|
|
|
|
|
You probably did the loading of the menu from resources somewhere before.
You said you are using MFC, so you will have a variable of type CMenu somewhere, which represents your IDR_MENU1, right?
Like this:
...
CMenu menuOne;
menuOne.LoadMenu(IDR_MENU1);
... Then you would write:
BOOL e = ::EnableMenuItem( menuOne.m_hmenu, ID_EXTRAS_SERVICE, MF_GRAYED);
And then you can see in the MSDN-entry for EnableMenuItem, that the 3rd parameter in your code is not correct:
MSDN: "This parameter must be a combination of either MF_BYCOMMAND or MF_BYPOSITION and MF_ENABLED, MF_DISABLED, or MF_GRAYED"
So, you have to add either MF_BYCOMMAND or MF_BYPOSITION to it.
"My opinions may have changed, but not the fact that I am right."
Found in the sig of Herbert Kaminski
|
|
|
|
|
oooohhhhhhhhhhhhh.....i know what you mean.
but my problem is, i have NO CMENU objekt.
i make this:
HMENU menu;<br />
menu = LoadMenu(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MENU1));<br />
::SetMenu(*(AfxGetApp()->m_pMainWnd), menu);
what can i do now?
thanks a lot
sunny
|
|
|
|