|
Hi everyone,
I am trying to scroll a window by more than one unit at a time. currently I am doing this
[CODE]
for(int i=0; i<100; i++)
pParent->m_SkinList.PostMessage(WM_VSCROLL, MAKELONG(SB_LINEDOWN,0),NULL);
[/CODE]
I have my current code inside a for loop to make it scroll down multiple times and it works, but it freezes up my app until the for loop is done.
How can I scroll by multiple lines using a single PostMessage call? Can I scroll variably in a single call without using a for loop?
Thanks,
Greg
|
|
|
|
|
The HIWORD of the wParam parameter is the position to scroll to
pParent->m_SkinList.PostMessage(WM_VSCROLL, MAKELONG(SB_LINEDOWN,nPos),NULL);
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Do exactly as you`ve been told, and mind that the SB_PAGEDOWN could be used too.
Sincerely yours, Ilya Kalujny.
|
|
|
|
|
Hi all,
I have a question about SetFont.
Now I create a class that is derived from CWnd, and use SetFont to set a
font to it. Then I override the Paint function to display the content I
want. The problem happens there, no matter what font I set, when I draw the
text in Paint, it display with the same font, I think it is the system font.
How can I make the SetFont work?
Thanks in advance
|
|
|
|
|
if you are using DrawText or TextOut, you have to use CreateFont/SelectObject . SetFont doesn't do what you think it does.
something like this:
CFont fnt;
fnt.CreateFont(...);
CFont *pOldFont = dc.SelectObject(&fnt);
dc.TextOut(...);
or
dc.DrawText(...);
dc.SelectObject(pOldFont);
-c
CheeseWeasle
|
|
|
|
|
Thank you for your reply.
After reading your comment, I have another question. I have used SetFont to set a font to it. How can I know which font I have set when I want to use it in Paint function. Because my class is used by other people, I have to use a generic way to know which font they set. Actually I have tried another way, I override the SetFont function in my class, and remember the font they said. It worked. But because the SetFont is not a virtual one, when they use a CWnd pointer to call the SetFont function, my SetFont will not be called.
Thanks again.
|
|
|
|
|
vincentye wrote:
How can I know which font I have set when I want to use it in Paint function
have you tried GetFont() ?
-c
CheeseWeasle
|
|
|
|
|
Sure I did.
Some of my code is below:
void CColItem::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(rect);
CFont *OldFont = NULL;
OldFont = dc.SelectObject(GetFont());
..............
dc.TextOut(xText, yText, strWindowText);
..............
dc.SelectObject(OldFont);
}
Thanks again
|
|
|
|
|
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
|
|
|
|