|
Hi
Would like to know, how to check the check boxes recursively in a CTreeCtrl, which is placed in a dialog.
If any sample code or link exists, would be helpful.
Thanks
Vairamuthu.G.
|
|
|
|
|
Try something like this:
------------------------
void CTreeDlg::TickSubtree(HTREEITEM hRootItem)
{
// Tick the root item.
m_Tree.SetCheck(hRootItem);
// Now do the entire subtree depth first.
HTREEITEM hItem = m_Tree.GetChildItem(hRootItem);
while ( hItem!=NULL )
{
// Tick the item.
m_Tree.SetCheck(hItem);
// Move to the first child.
HTREEITEM hNextItem = m_Tree.GetChildItem(hItem);
// No child? If not try the next sibling.
if ( hNextItem==NULL )
{
hNextItem = m_Tree.GetNextSiblingItem(hItem);
// No more siblings? Try the nearest next sibling of an ancestor.
if ( hNextItem==NULL )
{
do
{
hItem = m_Tree.GetParentItem(hItem);
// We're done if we reach the root.
if ( hItem==hRootItem || hItem == NULL )
{
return;
}
hNextItem = m_Tree.GetNextSiblingItem(hItem);
}
while (hNextItem==NULL);
}
}
hItem = hNextItem;
}
}
void CTreeDlg::OnButton1()
{
// Populate tree.
HTREEITEM h1 = m_Tree.InsertItem(_T("1"));
HTREEITEM h2 = m_Tree.InsertItem(_T("1-1"), h1);
HTREEITEM h3 = m_Tree.InsertItem(_T("1-2"), h1);
HTREEITEM h4 = m_Tree.InsertItem(_T("1-2-1"), h3);
HTREEITEM h5 = m_Tree.InsertItem(_T("1-2-1-1"), h4);
HTREEITEM h6 = m_Tree.InsertItem(_T("1-2-1-2"), h4);
HTREEITEM h7 = m_Tree.InsertItem(_T("1-2-2"), h3);
HTREEITEM h8 = m_Tree.InsertItem(_T("1-2-2-1"), h7);
HTREEITEM h9 = m_Tree.InsertItem(_T("1-2-2-2"), h7);
HTREEITEM h10 = m_Tree.InsertItem(_T("1-2-3"), h3);
HTREEITEM h11 = m_Tree.InsertItem(_T("1-2-3-1"), h10);
HTREEITEM h12 = m_Tree.InsertItem(_T("1-2-3-2"), h10);
HTREEITEM h13 = m_Tree.InsertItem(_T("1-2-4"), h3);
HTREEITEM h14 = m_Tree.InsertItem(_T("1-2-4-1"), h13);
HTREEITEM h15 = m_Tree.InsertItem(_T("1-2-4-2"), h13);
HTREEITEM h16 = m_Tree.InsertItem(_T("1-3"), h1);
HTREEITEM h17 = m_Tree.InsertItem(_T("1-4"), h1);
// Tick h3 and all its children.
TickSubtree(h3);
}
Steve
|
|
|
|
|
Hi Steve
The code given for recursive check is okay. But the functionality I wanted to implement is, whenever the user selects the root node and presses spacebar, the selected node and its siblings should get selected. Whenever space bar is clicked, what event will get fired?
Could you please tell me the event. So that I can write the code happily in that event.
PS: CTreeCtrl I placed it in a dialog.
Kindly try out a example and let me know.
Thanks
Vairamuthu.G.
|
|
|
|
|
A WM_KEYDOWN or WM_CHAR would do the trick - But these messages will be posted to the tree control so if you're using a raw CTreeCtrl (which I assume you are) you will have to use the PreTranslateMessage function to handle these messages. You can use the ClassWizard to add the handler. It should look something like this:
BOOL CTreeDlg::PreTranslateMessage(MSG* pMsg)
{
if ( pMsg->message==WM_CHAR && pMsg->hwnd==m_Tree.GetSafeHwnd() )
{
// We've got a WM_CHAR message for our tree.
if ( pMsg->wParam == ' ' ) // Is it a space?
{
// It's the space key.
HTREEITEM hSelected = m_Tree.GetSelectedItem();
if ( hSelected != NULL )
{
TickSubtree(hSelected);
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Steve
|
|
|
|
|
Lots of help can be found on
Code Project![^]
but the best way to do that is to retrieve a HTREEITEM (say hitem) with GetRootItem( ) , then GetNextItem(hitem,TVGN_NEXT) with hitem the HTREEITEM returned by the function (here is the recursion) and for each hitem SetCheck(hitem,TRUE):
HTREEITEM hitem = m_Tree.GetRootItem();
while(hitem != NULL)
{
SetCheck(hitem,TRUE);
hitem = GetNextItem(hitem,TVGN_NEXT);
}
~RaGE();
|
|
|
|
|
This will not work. TVGN_NEXT gets the next sibling item. It will not select the children or children's children and such.
Steve
|
|
|
|
|
From MSDN :
TVGN_NEXT Retrieves the next sibling item.
Steve 1 - Rage 0.
~RaGE();
|
|
|
|
|
Hi gurus,
How do we get the ip address of computer using MFC?
Any clues? Ideas?
Thanks,
Wax
|
|
|
|
|
See the following from which u can get the IP address of the local machine
gethostname(szHostName, strlen( szHostName ) ); //returns machine name
strFullName="\\\\"+szHostName;
host = gethostbyname(strFullName); //returns hostent*
if(host!=NULL)
{
ptr = (struct in_addr *) host->h_addr_list[0];
int a = ptr->S_un.S_un_b.s_b1; // Eg. 211.40.35.76 split up like this.
int b = ptr->S_un.S_un_b.s_b2; // 40
int c = ptr->S_un.S_un_b.s_b3; // 35
int d = ptr->S_un.S_un_b.s_b4; // 76
strTemp.Format("%d.%d.%d.%d",a,b,c,d);
AfxMessageBox("IP:="+strTemp);
}
Thanks and Regards
Laxman
FAILURE is the first step towards SUCCESS
-- modified at 23:45 Friday 20th January, 2006
|
|
|
|
|
|
Yes, MFC. I'm not using .NET. just pure visual c++.
waxie
|
|
|
|
|
|
Yeah. It's in .NET. I just want to retrieve IP address and then store it in a string.
waxie
|
|
|
|
|
waxie wrote: It's in .NET
It's not in .Net. It's in SDK.
Anyway it will work smoothly so don't worry.
Anyway why are you reposting the same question again. I guess Laxman already answered you.
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
I've tried using the code but it still does not work.
I'm making some tweaks. Hopefully this will work.
waxie
|
|
|
|
|
I'm getting these errors when linking:
error LNK2001: unresolved external symbol __imp__gethostbyname@4
error LNK2001: unresolved external symbol __imp__gethostname@8
you have any idea what causes these errors? I guess the linker is looking for a lib file or something..
waxie
|
|
|
|
|
|
Yes I have included winsock.h in my project - else it would produce symbol not found errors. I'm using VC6.
|
|
|
|
|
|
Yes, I have. I don't have errors now but it really doesn't output anything. If it's alright with you, can you check if this code works fine in your pc and outputs your IP ad?
Thanks so much.
waxie
|
|
|
|
|
Try this one....
You may have to modify it a bit to suit your needs....
void CHostNameAndIpDlg::OnBnClickedFind()
{
WSADATA WSAData;
::ZeroMemory(&WSAData, sizeof(WSAData));
::WSAStartup(MAKEWORD(1,0), &WSAData);
char szHostName[MAX_PATH];
::gethostname(szHostName, MAX_PATH);
AfxMessageBox(szHostName);
char szIps[128];
struct sockaddr_in sckAddr;
struct hostent *pHost;
pHost = ::gethostbyname(szHostName);
for(int index=0; pHost->h_addr_list[index] != NULL;index++)
{
memcpy(&sckAddr.sin_addr, pHost->h_addr_list[index], pHost->h_length);
strcpy(szIps, inet_ntoa(sckAddr.sin_addr));
strcat(szIps, ", ");
AfxMessageBox(szIps);
szIps[0] = 0;
}
::WSACleanup();
}
AfxMessageBox denotes output. You can replace it with your own output procedure. I have commented my output procedure.
First it will display a message box containing host name, second it will display message boxes for each IP found(If there are more that one).
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
Thank you very much. I think you deserve a 10.
|
|
|
|
|
|
Okiems. Thank you very much Owner drawn! I really appreciate your help.
waxie
|
|
|
|
|
Hi!
Can anyone point me to the solution of the following problem :
i want to retrieve information about the gfx card installed in the system (driver, driverversion, physical ram, chip type, etc) as well as information about other hardware-components and drivers.
For the display i currently use
INT cnt = 0;
FLAG ret = TRUE;
while (ret)
{
DISPLAY_DEVICE ddev;
ddev.cb = sizeof(DISPLAY_DEVICE);
ret = EnumDisplayDevices(NULL, cnt,&ddev,0);
if ((ret) && (!(ddev.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER)))
{ // no need for mirroring drivers (ex. netmeeting driver)
DEVMODE devMode;
devMode.dmSize = sizeof(DEVMODE);
EnumDisplaySettings(ddev.DeviceName,ENUM_CURRENT_SETTINGS,&devMode);
/*
Process device Info
*/
} // if (ret)
cnt++;
} // while (ret)
but the gathered information here is insufficient...
My application is a non-MFC application, so i am looking for plain SDK mechanisms
Thanks in advance
-- modified at 6:07 Friday 20th January, 2006
|
|
|
|