|
Your example is longer than it needs to be, because you can do a using std::vector prior. Having done that, I'd regard the first example as looking better. Which goes to show that it's all a matter of opinion, as I'm sure you were not expecting me to say that
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
OK, perhaps my example wasn't compelling enough. How's this one:
std::map<std::string, std::vector<std::string>*> m_mapNameToFriends;
void GetMap(std::map<std::string, std::vector<std::string>*>& mapNameToFriends);
vs
typedef std::vector<std::string> NameVector;
typedef std::map<std::string, NameVector*> NameToNameVectorPtrMap;
NameToNameVectorPtrMap m_mapNameToFriends;
void GetMap(NameToNameVectorPtrMap& mapNameToFriends);
I'm not expecting to convince you here either, just proving my point that typedefs can be good in good hands.
Regards,
Alvaro
Give a man a fish, he owes you one fish. Teach a man to fish, you give up your monopoly on fisheries.
|
|
|
|
|
You're still using std:: to make things look more complex than they need to.
using std::map;
using std::string;
using std::vector;
map<string, vector<string>*> m_mapNameToFriends;
void GetMap(map<string, vector<string>*>& mapNameToFriends);
See what a huge difference that makes ?
std::map<std::string, std::vector<std::string>*> m_mapNameToFriends;
void GetMap(std::map<std::string, std::vector<std::string>*>& mapNameToFriends);
I vastly prefer this to either example that you gave. I fully accept that my own bad experiences slant my views and make me prefer to have the code tell me what is going on, but the only reason I have a leg to stand on at this point is that you deliberatly obsfucated the code in your example
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
How do you get the coordinates of a control on a dialog relative to the upper-left corner of the dialog? I've tried using the GetClientRect & GetWindowRect functions of the control I want the coords for, but neither returns the right value. Any help is appreciated. Thanks.
- Aaron
|
|
|
|
|
CRect rect;
GetDlgItem(IDC_CONTROLNAME)->GetWindowRect(&rect);
ScreenToClient(&rect);
You should then be able to take the values of rect.
"You know "that look" women get when they want sex? Me neither."
--Steve Martin
|
|
|
|
|
I got it working using GetWindowRect of the control and ScreenToClient of the dialog. Is this the best way to do it?
[EDIT]
Guess I should have refreshed before I posted Thanks for the help though
[/EDIT]
- Aaron
|
|
|
|
|
Off the top of my head.
GetClientRect(): is the rectangular area that represents the area where drawing is to occur, with (0,0) representing the upper left courner of the client area within the window.
GetWindowRect(): is the rectangular area that represents the area where the window is draw in screen coordinates and must be converted to client coordinates to be useful.
Therefore, you need to get the screen coordinates via GetWindowRect() and then convert them to the dialog coordinates via ScreenToClient().
Now is there a better way or a function that does the needed conversion for you? I am not sure, there is one function whose usage is a bit confusing so I keep forgetting its' name and all I remeber (at the moment) is that it converts from one coordinate system to anoghter (a.k.a. client to screen or screen to client). Basicaly, it is less confusing to do it your self (with two simple function calls), than to call some function that (based on the arguments) makes the same function calls.
INTP
|
|
|
|
|
I need to find out the Domain name in which my computer is at the moment not using GetComputerNameEx if possible. How?
|
|
|
|
|
You can use LookupAccountName
<br />
DWORD dwDomain = DNLEN + 1;<br />
char szDomain[DNLEN + 1];<br />
<br />
memset(&szDomain, 0, DNLEN + 1);<br />
<br />
PSID pSid = NULL;<br />
DWORD cbSid = SID_SIZE;<br />
SID_NAME_USE peUse;<br />
<br />
pSid = (PSID)HeapAlloc(GetProcessHeap(), 0, cbSid);<br />
ASSERT(pSid != NULL);<br />
<br />
if (LookupAccountName(NULL, szUserName, pSid, &cbSid, szDomain, &dwDomain, &peUse)) <br />
{<br />
}<br />
<br />
if (pSid != NULL)<br />
HeapFree(GetProcessHeap(), 0, pSid);
This may help you, note that if the computer is not joined to a domain it returns the computer name!
Ant.
|
|
|
|
|
Wait a minute!
what is szUserName as the second parameter?
It look like it wants full domain\user path, but if I knew that I wouldn't need to call this on the first place.
So at the moment I get only computer name as when it's not joined to a domain, but it is.
|
|
|
|
|
Um fair points. However you do not need the full qualifying 'domain\username' you can pass just 'username'.
The reason you get the local machine is probably because the szUserName is a local account name also. You could set the szUserName to a domain account name and this should then find the domain that that account resides.
I wish I'd thought a bit longer before posting this as it is not ideal
Ant.
|
|
|
|
|
Ok. For now I'll use GetComputerNameEx and/or NetGetJoinInformation.
But those are just on 2000, XP and 2003.
<dreaming>
Still would be nice to figure out the domain name on like NT and 98.
</dreaming>
|
|
|
|
|
I need to dump data to my SDI window as I read it from a socket. What's the easiest way to do that ?
Thanks !!
|
|
|
|
|
Stick a RichEdit control in the middle of your window and dump all the input into it?
It's dirty, but it works.
|
|
|
|
|
Can you give me an example of how to add it and how to dump to it ?
Thanks !
|
|
|
|
|
Depends on what framework you are using. Since you referred to "SDI", I assume you're doing MFC or WTL. There are a ton of articles on this site which can should you how to add a RichEdit control to either of those windows. Just look around a bit. (Or check out msdn.)
|
|
|
|
|
How about TextOut() ?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
David
Any example of using TextOut() ?
Thanks !
|
|
|
|
|
The documentation is pretty self-explanatory. Here's another example.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
|
You don't. It's passed as a parameter to the OnDraw() method.
void CMyView::OnDraw( CDC *pDC )
{
pDC->TextOut(...);
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Thanks for the info but I'm getting confused.
I have a have a ClientSocket::OnReceive() method that reads a CString from a socket(). I want to print this CString directly to my SDI (CView) window. Do I call OnDraw() from this method ??
Thanks again !
|
|
|
|
|
You never call OnDraw() manually. It is called by the framework when drawing needs to take place. At this point, the framework is basically asking, "What do you want to draw?".
It might be wise to read up on the relationship between the document and the view. In a nutshell, the document holds the data that the view renders, or to put it another way, the view renders the data that the document holds.
So, when you receive data via a socket, the document needs to be updated with the received data. The document, in turn, tells the view that something has changed and that a redraw is needed.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Derive your view from CEditView . Then, each time you want to append a line of text to the view, do this:
CString strTextReadBySocket = ...;
CString strText;
myEditView.GetEditCtrl().GetWindowText (strText);
strText += _T("\r\n") + strTextReadBySocket;
myEditView.GetEditCtrl().SetWindowText (strText);
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi
Thanks, this works but after a while of printing text to the window I get an Out of memory errors. Is there a limit to how much data can be written to the window ??
Thanks
Gary
|
|
|
|