|
The painting code is right. It sounds more like that the code you're using to test it is somehow not passing the right font. Or perhaps you're creating a font that's local (allocated on the stack) and it's going out of scope. SetFont takes a pointer. If that pointer becomes invalid, I'd suspect that the dc.SelectObject( GetFont() ); would fail.
If you're unsure, post the code that calls SetFont and I'll take a look.
Joel Lucsy
|
|
|
|
|
Thank you for your information. However it is not that case.
Below is the answer from MS newsgroup:
"
There is no default implementation of WM_SETFONT and WM_GETFONT. You
need to implement these message handlers to store and return the current
HFONT (or NULL as the case may be), and Invalidate if LPARAM is TRUE.
IIRC, ClassWizard won't help with these, so you'll need to add them
manually using ON_MESSAGE macros in your message-map, and remember that
the prototype is 'LRESULT memberFxn(WPARAM, LPARAM)'. In your WM_PAINT
handler, you will need to SelectObject the currently stored HFONT (if
there is one) into your CPaintDC, and SelectObject it back out again
when you're done.
--
Jeff Partch [VC++ MVP]
"
I follow his instruction. It works well.
Anyway, thanks again.
|
|
|
|
|
When you call SetFont() , are you doing something like this?
CFont font;
font.CreateFont(...);
SetFont(&font); If you do this, the font will be destroyed as soon as the CFont object goes out of scope, so the default system font will be returned by GetFont(). Make sure you either detach the font (CFont::Detach() ) or use a font object that is a class member.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am trying to set a bitmap as background for the CRebar control. But it seems it can only display the image as original size. How can I scale the picture according to the size of the rebar. I want the whole bitmap as background.
|
|
|
|
|
hi all
thakns for your help so far
at the moment im using the following to convert a string to long
CString stud_id = "00123"
long l;
l = atol (stud_id);
which works ok, but it removes the leading zeros off
so im left with l = "123"
when i want l to = "00123"
does ne1 have ne ideas how to solve this
thanks
si
|
|
|
|
|
The long data type doesn't work like that - 00123 and 123 are identical, because they are stored internally as a binary number, instead of the characters that make up the digits. If you go the other way, look at this:
<br />
long l=123;<br />
CString str, str2;<br />
str.Format(_T("%.5d"), l);
str2.Format(_T("%d"), l);
Note that if you write:
<br />
long l=0123;
Then a C/C++ compiler will treat the literal value as base-8 (octal) instead of base-10 (denary).
--
Ian Darling
|
|
|
|
|
si_69 wrote:
which works ok, but it removes the leading zeros off
so im left with l = "123"
Leading zeros on a number has no significance to the value itself.
123, represented as a number implies an infinite number of leading zeros!.
123 == 0123 == 00123 == 000000123
If you, however, need to display your number with leading zeros, then you can either stick with your string representation, or use something like:
<br />
CString strValue;<br />
long nValue = 1234;<br />
<br />
strValue.Format(_T("%.6ld"), nValue);<br />
<br />
std::cout<<(LPCTSTR)strValue<<std::endl;<br />
"..Even my comments have bugs!"
Inspired by Toni78
|
|
|
|
|
RChin wrote:
Leading zeros on a number has no significance to the value itself.
Really? Tried e.g. sscanf lately? As any good C or C++ programmer should know, any number (including literals within the program itself) having a leading zero is an octal number.
Now, let's try to rephrase that statement.
|
|
|
|
|
Sorry. Didn't realise I had to take into account all the number bases on the face of the planet as well! I was commenting on the representation of any number by the system.
See Ian Darling's comment above. He probably has made it more clearer.
So let me rephrase that:
With respect to our natural counting system, .....
"..Even my comments have bugs!"
Inspired by Toni78
|
|
|
|
|
I see this is a student id#. Even though this is a number in most cases it is better to leave it as a string. But if you want to save space and you know it is a fixed # length you can add the leading zeros back when you display the number. Try something like printf("%05d",l); will make it back to 5 digits by adding leading zeros.
John
|
|
|
|
|
Anyone know how to force a socket to close in user mode that may be running in another process. Not wanting to to have to write my own firewall here, but from what I can tell so far, its either writing my own Winsock layered service or writing a kernal mode driver to hook into the network stack, which I don't really trust myself to do. I'm not wanting to look at things at the packet level, just stop inbound connections on particular ports from a range a IP addresses that I want my app to decide on the fly.
I'm wanting simply to block connections from IP addresses I choose on ports I choose easily. I know there are things out there, but I'm wanting to have a go myself.
From what I can tell, this seems much easier on Unix that Windows.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Giles wrote:
Anyone know how to force a socket to close in user mode that may be running in another process.
Kill that process or shut down the NIC.
I'm wanting simply to block connections from IP addresses I choose on ports I choose easily.
Did you try to google first? Yep, pcap seems to be what you want.
|
|
|
|
|
Mike Nordell wrote:
Kill that process or shut down the NIC.
Sadly, no can do. At worst all I want is a socket error returned back to the process or a disconnect, and hope it handles it properly.
Even better, would be to stop a listening server even seeing the incoming request, but likewise I need to stop the outbound request to one of those IP addresses. Its kind of a firewall, but the thing is the rules are being made up on the fly, so I can't just conifgure and ordinary firewall and leave it.
Mike Nordell wrote:
Did you try to google first? Yep, pcap seems to be what you want.
I've been googling all day, though not for the right thing. Thanks.
This seems to be much more on the right track, though I can't seem to download the file right now.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Did you try to google first? Yep, pcap seems to be what you want.
Giles wrote:
I've been googling all day, though not for the right thing. Thanks.
Glad to be of help. Information overload, eh? It's hell when you know something like this just have to be out there, but no matter how one tries to restrict the searches one gets like 100k hits back.
If you need source code, it's often quite useful to add "source code" (with the quotes). Another place to look at (and you would have found libpcap there also) is freshmeat. Even that it's mainly GNU/Linux stuff, there are quite a few Win32 (compatible) projects there also. Oh, I might add that's another keyword for Google - Win32.
++luck;
|
|
|
|
|
help me how to use key press function in C programming at DOS 16-bit environment. i mean just like:
if (press Delete on keyboard)
{
....process....
}
thousands thanks
>>teaching is also learning<<
|
|
|
|
|
I found something, but I don't know if it's usefull.
MSDN:
_getch
Requirements
_getch <conio.h> Win 98, Win Me, Win NT, Win 2000, Win XP
Return Value
Returns the character read. There is no error return.
Remarks
The _getch and _getwch functions read a single character from the console without echoing. _getche and _getwche read a single character from the console and echo the character read. None of these functions can be used to read CTRL+C. When reading a function key or an arrow key, each function must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.
That would make:
<br />
char ch;<br />
<br />
ch = _getch(); <br />
ch = _getch();
Don't forget:
#include <conio.h>
|
|
|
|
|
You are programming for DOS. What is that?? Just kidding. I have not worked with a complier that would produce DOS code in the last 7 years... The stuff about _getch() that Xander80 said should work in dos.
John
|
|
|
|
|
I am maintaining a service that uses ReadDirectoryChangesW() calls to monitor a set of directories. When a file is dropped (or pasted or copied) into the monitored directory the service detects the new file and processes the new file.
I want to make sure the file is "all there" before taking any action on the file. Currently the service does a "_stat" call to get the file size and then tries an "_sopen" to make sure it is accessible. If either call fails it performs a set of retries.
Occasionally this setup fails. For example, a set of three files are being pasted into the monitored folder and the service fails reading the first file. When I check the folder...none of the files are there!!! Not sure, but somehow the Explorer copy/paste operation is being halted by the file tests. Any ideas? Is there a better way to see if the pasted file exists and is available?
PS: The copy/paste is being done between a local drive and a mounted network drive.
Jack
|
|
|
|
|
1. I use GetFileAttributes() to determine if a file 'exists'.
2. There are 'known' issues with _sopen and network drivers. Especially caching problems. I think you should use a Win32 API instead for checking for the ability to open the file. Look at CreateFile and the flag OPEN_EXISTING.
C++/MFC/InstallShield since 1993
|
|
|
|
|
Blake,
Thanks for the reply! Do you think that the symptoms I am seeing could have to do with the 'known' issues? Any idea where to get more info on those issues? (any docs out there? what criteria might I search the web with?)
I will give the CreateFile a try. Any suggestions on what flags to use? Should I loop with a set of retries in case the file is still being transferred?
Thanks again!
|
|
|
|
|
Hello, how can I allow a CRichEditCtrl to copy/paste "normal text" e.g. from a CEdit-Control?
|
|
|
|
|
If you just want to add such a popup menu showing cut, copy, paste etc., see this article: http://www.codeproject.com/richedit/popupdemo.asp[^]. This way you can make your own context menu.
To programatically copy/paste something into the rich edit control, see functions CRichEditCtrl::Copy and CRichEditCtrl::Paste .
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Hello ,
Iam developing a Secure browser .The secure browser needs to capture the events in an HTML Page and execute a DLL function.One way is to capture it in HTML page thru on-click handlers and call the DLL function from the HTML event handler( thru Java script).But this is not required .
What i need is to capture HTML page button clicks by the vc++ app which launches the HTML page .Iam using internet explorer's functions to display the HTML page .
|
|
|
|
|
Hello,
I'm sorry if I've already posted this message. I'm having some issues with posting. I'm developing an app on Windows 2000 using Visual .Net. It works fine on Win 2000, but I bring the app over to a PC running XP and it tells me I'm missing DLL's!!! Just as a test, I wrote a simple hello world program, and I still get the same error. I've tried the app on severl different PC's running XP and get the same error. What's going on? Is it an operating issue? Or is there something wrong with my .Net settings??? Thanks. Please reply to ttran7700@yahoo.com
|
|
|
|
|
ttran7700 wrote:
it tells me I'm missing DLL's!!!
Which ones?
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|