|
IS IT POSSIBLE
It is. The function to use is gethostbyname , which returns the IP address corresponding to a symbolic name. Of course, the success of this function depends on the resolution mechanism available (DNS most of the times).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
But how will I do that with that function??
You said something
Joaquín M López Muñoz wrote:
Of course, the success of this function depends on the resolution mechanism available (DNS most of the times).
What do you mean... can you tell me in big steps how to go through this!?
YES YOU CAN!!
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
OK... So if you're writting a client/server app, then you surely must be using Winsock under some form or another, aren't you? If you are not, then you have to initialize Winsock, as gethostbyname is a function within this library. See the Winsock Programmer's FAQ for details.
Now that you have WInsock properly initialized, all you have to do is call gethostbyname with the name of the server you want to resolve and extract the IP address from the return data. Something like this: (Warning: this has not even been compiled, typos expected)
CString strAddr;
struct hostent *phe = gethostbyname(lpszServerName);
if(!phe||!phe->h_addr_list[0]){
}
else{
struct in_addr addr;
memcpy(&addr,phe->h_addr_list[0],sizeof(addr));
strAddr=inet_ntoa(addr);
}
Hope this helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I am new to MFC and I have couple questions about how it handles its hWnds. I have a formview that is the only view in my app. A store a pointer to it in the FrameWnd class. Whenever I try to call controls on the form from other parts of the application it crashes. Why is this and what is the best way to access a form controls from other parts of the app?
|
|
|
|
|
post your code! for where you store the pointer, and the bits where you try and access it and it crashes.
Its impossible for people to help you if you don't post your code. and remember to enclose it in html style <PRE> ... </PRE> tags!
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Sorry.
I have a form that was created in the form editor. It has an edit control IDC_EDIT_LOG.
then I have
class MyClass
{
void func();
};
func is
void MyClass::func()
{
CEdit *edit = (CEdit *)GetDlgItem(IDC_EDIT_LOG);
edit->SetWindowText(_T("Some Text"));
}
this code asserts and produces an access violation.
Any help would be much appreciated.
Steve
|
|
|
|
|
If that asserts, look at the assert. If you hit "debug", then a comment in the MFC source code near the assert will normally give you more clues.
However, the most likely problem is that your CEdit *edit; is not a pointer to a created edit control. This could be for a couple of reasons....
1. is class MyClass a class representing your form (CDialog or CFormView), assigned to your dialog resource in classwizard??? If it's not, then GetDlgItem will be returned something wrong.
2. Are you sure that the edit control is created before myfunc gets called? what calls myfunc? if you're calling it in some of the form startup procedures, it would not be a good idea to use it before OnInitialUpdate().
If those pointers don't help, post your entire (proper) class definition.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
What is MyClass derived from?
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
E.g. I have a toolbar to which I can add buttons. Each button has a menu with two menu items: "Configure" and "Remove". The menu is displayed when the right mouse button is clicked on the button.
The menu is a child of the toolbar, thus having the message routing taken care of in the toolbar.
The question is, how can I tell which button the menu was invoked on, in order to know which button to remove when the user selects "Remove"? Is my design all wrong or what?
I am going (more) insane over this...
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
I'm not 100% sure about this, but maybe GetFocus on the command handler will do...
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
FOrget about my first reply (it won't work). Best way is to store on some well known variable a pointer to the button that last issued the popmenu.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You can the id of the item selected by capturing the WM_MENUSELECT message.
|
|
|
|
|
The menu is already working fine. What I need to know is which button that invoked the menu. The button has a OnRButtonDown handler which displays the menu. When the user selects an item in the menu the command handling is taken care of in the parent toolbar. How do I make the toolbar aware of which button it was that issued the menu?
E.g.
CDynamicButton.cpp
void CDynamicButton::OnRButtonDown(UINT nFlags, CPoint point)
{
if (m_hMenu)
{
HMENU hSubMenu = NULL;
CRect rWnd;
hSubMenu = ::GetSubMenu(m_hMenu, 0);
GetWindowRect(rWnd);
::TrackPopupMenuEx(hSubMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON, rWnd.left, rWnd.bottom, m_hParentWndMenu, NULL);
}
CButton::OnRButtonDown(nFlags, point);
}
CMacroToolBarCtrl.cpp:
BEGIN_MESSAGE_MAP(CMacroToolBarCtrl, CDialogBar)
ON_UPDATE_COMMAND_UI(ID_MENU_REMOVE, OnMenuRemove)
END_MESSAGE_MAP()
void CMacroToolBarCtrl::OnMenuRemove(CCmdUI* pCmdUI)
{
}
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
(1) Use GetItemRect to get the RECTs of all the buttons in your toolbar.
(2) In your OnRButtonDown you can get the CPoint of the area where the mouse was clicked
(3) Now figure out from these two, where the mouse was clicked
Regards
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Well, that works for a CToolBar, but I am using a CDialogBar.
I think I have seen something somewhere about replacing original bitmap buttons in a CToolBar with all kinds of controls. Could this be an option?
(I want to use my own button class with only text on)
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
Ok, I have solved it now.
Thanks for pointing me in the right direction!
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
Hi ,
How do I edit/modify a control,
that is contained by some window
that runs in different process
I used the following code ( or something like this ):
CWin* win = desktop_window->FindWindow( NULL, "window caption" );
CEdit* edit = win->GetDlgItem( RESOURCE_ITEM_ID );
edit->SetWindowText("some text");
but the GetDlgItem returns NULL,
where is my mistake ?
thanks in advance,
Daniel Mark.
|
|
|
|
|
This is the correct way:
<br> CEdit* edit = (CEdit*)win->GetDlgItem( RESOURCE_ID ); <br>
It's very strange that the compiler didn't said anything about this!
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
Hi
I thing you got me wrong.
My question is not about the syntax of
the code I attached to the message.
My question is about the way to get the CEdit control
I got the RESOUCE_ID using the Spy++ utility
|
|
|
|
|
Let's say that you have an edit on a dialog in another app with ID 1245.
First we have to find the window that the edit is on:
CWnd* hWnd = FindWindow(classname, NULL); // Or try find the window by using the title
then we have to get the edit control:
CEdit* edit = (CEdit*)hWnd->GetDLgItem(1245);
set the text "Hello" in the edit box:
edit->SetWindowText("Hello");
If it still retur NULL it perhaps can be a view the edit is putted on. I don't think this would work then.
Then you have to find the window (view) and the find the edit in that window (view).
Wasn't this right?
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
I am trying to implement a hex editor. I need a strategy to keep track of the modifications a user might be making in an open file.I thought of allocating a buffer of the size of the file , but this only works for small files.For large files this is highly inefficient.
Any suggestions as to how this can be done efficiently?
vimal
|
|
|
|
|
can you not keep track of the new data, the old data and a file offset and length?
---
"every year we invent better idiot proof systems and every year they invent better idiots ... and the linux zealots still aren't being sterilized"
|
|
|
|
|
I Want Changing a Cursor Icon In Visual c++ ?
thanks for your help
|
|
|
|
|
SetCursor()
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
--------------------------------------------------------------------------------
Can anybody upload or send me (fayegolf@hotmail.com) full working example,
which will create shortcut of DUN entry(.lnk) to it on the desktop.
Thank you!
|
|
|
|