|
Hi,
You can use API from Wininet:
FindFirstUrlCacheEntry
FindNextUrlCacheEntry
FindCloseUrlCache
-----------
Mila
|
|
|
|
|
Hi all,
Who can help me for my below question? I will appriciate that.
In my MFC project, I used RichEdit replacing RichEdit2, but the color of the text are shifted one unit.
My code:
CString strings[3] = {_T("Apple"), _T("Orange"), _T("Pear")};
for (int i = 0; i < 3; i ++)
{
CHARFORMAT2 cf;
m_richEditCtrl.GetSelectionCharFormat(cf);
if ( i % 2 == 0 )
{
cf.crTextColor = (DWORD) RGB(255, 0 , 0); // Red color
}
else
{
cf.crTextColor = (DWORD) RGB(0, 0, 225); // Blue color
}
cf.dwEffects = static_cast<dword>(~CFE_AUTOCOLOR);
cf.dwMask = CFM_COLOR;
long length = m_richEditCtrl.GetTextLength();
m_richEditCtrl.SetSel(length, -1);
m_richEditCtrl.ReplaceSel(strings[i]);
long newLength = m_richEditCtrl.GetTextLength();
m_richEditCtrl.SetSel(length, newLength );
m_richEditCtrl.SetSelectionCharFormat(cf);
}
When I used RichEdit1 the program works perfect, but after I used RichEdit2 the color of text shows weird.
Accordding to the code, "Apple" should show red color, "Orange" should show blue color, "Pear" should show red color again. However, the actual text color are: letters "Apple" are red, "O" is red too, "range pe" are blue , and "ar" are red. That doesn't make any sense....
Is there anyone can help me on that?
Thanks!
David Zuo
|
|
|
|
|
Should this line
m_richEditCtrl.SetSel(length, newLength );
be
m_richEditCtrl.SetSel(length, newLength - 1 );
??
|
|
|
|
|
I tried m_richEditCtrl.SetSel(length, newLength - 1 ), but it still doesn't work well. Actually, what I found is RichEdit2 considers '\n' as two symbols - "\r\n", so if we use
m_richEditCtrl.SetWindowText("12345\n");
int length = richEditCtrl.GetWindowText(); // the actual value of length equals to 7, not 6.
Again, if we have
m_richEditCtrl.SetWindowText("12345\n67890");
int length = richEditCtrl.GetWindowText(); // equals to 12, not 11.
richEditCtrl.SetSel(0, 6);
m_richEditCtrl.SetSelColor(Red); // pseudo-code
m_richEditCtrl.SetSel(7, -1); // This function doesn't set correct text
m_richEditCtrl.SetSelColor(Blue); // pseudo-code
/// The actual text color is, "123456" is red, "7890" is blue
/// If you put more letters and '\n' into the string, you will find the text color shifts more than you think
but, if we use
m_richEditCtrl.SetWindowText("12345\n67890");
int length = richEditCtrl.GetWindowText(); // equals to 12, not 11.
richEditCtrl.SetSel(0, 5);
m_richEditCtrl.SetSelColor(Red); // pseudo-code
m_richEditCtrl.SetSel(6, -1);
m_richEditCtrl.SetSelColor(Blue); // pseudo-code
/// program now works well
What I found is, the number of the selected text SetSel() function shifts that equals to the number of '\n' being used in the string. Is it weird?
Most time I cann't understand why Microsoft still recommand us to use Visual C++, MFC is too old to use. They always use very weird way to do some crazy things. Doesn't make any sense! Furthermore, so manys bugs are found in MFC library, it seems Microsoft never tested their APIs before they released them.
David Zuo
|
|
|
|
|
Glad you got it working. I never saw any newlines (\n) in your original code
David.YueZuo wrote: Furthermore, so manys bugs are found in MFC library, it seems Microsoft never tested their APIs before they released them.
Wow what MFC version are you using? MFC works as documented for me (Version 7.11).
David.YueZuo wrote: MFC is too old to use
So use .NET! Better yet, use Windows APIs directly!
I didn't know Microsoft "recommand us to use Visual C++" either.
This is all news to me, thanks!
Mark
|
|
|
|
|
LOL..thx for your suggestions, i will keep that in my mind.
Unfortunately, my team have to use VC++ since they started using it at 1998.
Maybe I should get my job changed, how about become to a java developer, would be better?
hahaha...
David Zuo
|
|
|
|
|
Hi all,
Using VC++ 6 with MFC.
What I'm trying to do is have a secondary modeless dialog which can be attached to the main dialog and detached again, similar to winamp. The way I'm thinking of implementing this is having two dialog classes for the main and modeless dialogs, and one dialog resource with the actual controls etc (child, no title bar etc.), similar to the way you use a CTabCtrl.
I want the 'Screen' dialog resource to be loaded into either the secondary or primary dialog based on user input, possibly by replacing a static control?
How can I implement this?
Thanks
Bob
|
|
|
|
|
Some helpful APIs for this are
ShowWindow() to hide/show windows/dialogs
MoveWindow() to resize/reposition child windows
GetWindowRect() to get a window's position relative to screen
MapWindowPoints() to translate screen coordinates to parent-window-relative coordinates
SetParent() to "move" a child window between parents
Using an invisible (no WS_VISIBLE style) static control is an easy way to find the rect for
positioning a child window on a dialog.
Mark
|
|
|
|
|
Im not sure its helpful for you or no but you can see an example of david crow about resources
|
|
|
|
|
Hi,
I have a cdialog window which contains a webbrowser activex control. I want to be able to select some text from a control on the dialog (but not inside the webbrowser), and drag it into a textarea element within the webbrowser control. How do I do this? Can someone point me in the right direction?
Thanks,
derek
|
|
|
|
|
Hi there,
I have an application that uses TCP/IP socket connection to another application and I was wondering how I can check if the connection is up or not in the other word I need to notify a 3rd application if the connection between the first two has droped for any reasons. I tested today that if I am connecting to the second application that sits in another computer and I turn off the wireless connection button on the second computer so that the connection would be dropped, when I run the netstat command in dos command window, it shows that the connection is still up and my application does not recognises that the connection is actually dropped until I physically close the second application.
Could any one inform me that how these things work and how can I make my application underestands that the connection between the sockets is dropped do to wireless or network problem and so on?
I really appreciate any suggestions.
Best reagards,
Nahi
|
|
|
|
|
What state is the connection in (according to netstat)? CLOSE_WAIT?
When the connection drops, recv() will either return 0 or SOCKET_ERROR (WSAGetLastError() will get
the error code) - I can't remember which right off hand (brain in screen-saver mode). Either
way, when you get an error on send() or recv() you can notify the 3rd application that the
connection dropped. A breakpoint right after a recv() call will show you which occurs when you
switch off the connection.
Lost connections will linger (you'll see them in netstat) until you officially close the socket or the
application. Therefore, when you detect the network down you should close the socket when unrecoverable
error codes are returned (they are listed in the send()/recv() API specs).
Hope this helps a little
Mark
|
|
|
|
|
Thanks for the tip, as I mentioned before when I disconnect the wireless network of the computer so that the connection ids dropped, netstat still shows that the connection is stablished!? until I close one of the application. and as my application should receive messages from the other application through the socket, I do not understand that the connection is down. Only when IN close the second application, I get the socket closed message and in netstat I can see close_wait.
Thanks,
|
|
|
|
|
Yes, you'll see the connection in netstat because the socket is still allocated even though it
may be disconnected physically. It will remain in CLOSE_WAIT (waiting for close as the name
implies) until you call closesocket(). Even after calling closesocket(), if there is/was pending
data on the connection it will "linger" by default for I think 120 seconds (so you'll see it in
netstat for that long). To force it to close immediately you can turn off the linger option for
the socket, something like:
linger Linger;
Linger.l_onoff = 1;
Linger.l_linger = 0;
::setsockopt(hSocket, SOL_SOCKET, SO_LINGER, (const char *)&Linger, sizeof(linger));
::closesocket(hSocket);
hSocket = INVALID_SOCKET;
|
|
|
|
|
Send a ping packet to the other IP address. If it doesnt come back, youknow the link is dead.
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
You could wait until the TCP/IP stack reports that the connection is down (can take very long). Alternatively send a small connection testing packet (e.g. smilar to IRC's PING/PONG mechnism), sometimes you will receive immediately an error saying that the connection is down... or you can timeout the connection if you haven't received a connection test packets from the other peer for a while.
[corrected typos]
|
|
|
|
|
Why does the mousewheel event not scroll the window in a CRichEditView?
Mark
|
|
|
|
|
CRichEditView class doesn't handle the WM_MOUSEWHEEL event.
You can derive a class from CRichEditView and handle it yourself.
Mark
|
|
|
|
|
It works on Win98 machines. Trying it on XP machines I find that the mouse wheel button doesn't scroll the view window. Anyway, I fixed it by handling the OnMouseWheel() event.
BOOL CMyEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
CRichEditCtrl & rc = GetRichEditCtrl();
if( zDelta < 0 )
rc.LineScroll(3, 0);
else
rc.LineScroll(-3, 0);
return CRichEditView::OnMouseWheel(nFlags, zDelta, pt);
}
-- modified at 21:19 Monday 23rd October, 2006
Mark
|
|
|
|
|
Mark F. wrote: It works on Win98 machines. Trying it on XP machines I find that the mouse wheel button doesn't scroll the view window.
Oh ok - At first I thought maybe different common controls library. Checked and it's feature
from Rich Edit 1.0 on.
All I can think of off hand is the control doesn't have focus. Does it still not scroll if you
click in the control somewhere then turn the wheel?
Mark
|
|
|
|
|
Which is the best to use? char*, vector or std::string
I'm searching for the best way to manipulate strings. I've historically used char* with strstr, strtok, etc. I've also used CStrings, but trying to get away from them.
I'm hoping to join the present and use containers whenever possible. I'm wondering if I can use a vector instead or is it best to use std::string.
I have to do all the standard string stuff, copying, searching, parsing, etc.
Ideas?
-C
|
|
|
|
|
That all depends on what you are doing. Use char* as little as possible. string is nice when you don't have to worry about multithreaded issues. If you are passing strings between threads, use vector<char> since it isn't reference counted.
For more descriptive details, check out Effective C++ and Effective STL by Scott Meyers.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: since it isn't reference counted.
So how does that solve all the synchronization issues? Depending on the use-model you could create just as many problems using a vector.
led mike
|
|
|
|
|
led mike wrote: So how does that solve all the synchronization issues?
Reference counting is not multithreading-friendly by default Having said that, not all versions aof std::string are reference counted - for instance the Dinkumware one that ships with VC++ is not. Of course, relying on a particular internal implementation is generally a bad idea.
|
|
|
|
|
Nemanja Trifunovic wrote: for instance the Dinkumware one that ships with VC++ is not.
Last time I checked, it was. Link
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|