|
Toby Opferman wrote: I wouldn't write a GINA unless nessecary since it will not be portable to Windows Vista.
I wouldn't either. I was just offering suggestions.
Care to offer help on this one?
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
I created one dialog and also a global function in my coding, i have to control that dialogue from this global function....
(Im doing EnableWindow function in tht Global function...)
How can i access tht dialogue from global function?
Thanx in advance
|
|
|
|
|
That depends a lot of your code. Firstly, if your dialog is a modal dialog, then you can't because the program flow will stop to redirect all inputs to the dialog.
Then, if your dialog instance is declared inside a function, then you won't be able to access it (because the scope of the variable is just the function), you'll have to make the dialog global too.
Then, I will finish by saying that global functions are in general not a good programming practice in OO programming. They must be avoided if possible (sometimes it just not possible but there is other to get around it then)
|
|
|
|
|
I think you can pass a pointer on your dialog to your function (However I am not sure about that).
void MyGlobal(CMyDialog *pmydiag)
{
pmydiag->DoStuff();
}
And in your dialog classes :
MyGlobal(this);
But I am not sure about that, and this is no good code practice (see Cedric's post).
~RaGE();
|
|
|
|
|
Every time hte dialog is active, set a globla pointer to this. When the dialog closes, set the global pointer to NULL.
You can access this global pointer from anywhere in your code, and call any of the public members.
I do this alot in MFC when I use CreateThread.
eg:
CreateThread(NULL, 0, <br />
&ConnectThread,
this,
0,
0);
<br />
DWORD WINAPI ConnectThread(LPVOID lpParameter)<br />
{<br />
CNicCPAppDlg * dlg = (CNicCPAppDlg *) lpParameter;<br />
<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState());<br />
<br />
while(dlg->stayalive)<br />
{<br />
}<br />
return 0;<br />
}
Nunc est bibendum
|
|
|
|
|
Hi.
I'm trying to understand how printing works in GDI+ (poor me), and i'm facing a problem...
I started building a simple mfc app (c++, visual studio 6), wich prints a rectangle over the printing border...say:
<br />
void CBasicView::OnPrint(CDC* pDC, CPrintInfo* pInfo) <br />
{<br />
CView::OnPrint(pDC, pInfo);<br />
Graphics gr(pDC->m_hDC);<br />
RectF rf(0, 0,<br />
(float)pInfo->m_rectDraw.Width(),<br />
(float)pInfo->m_rectDraw.Height());<br />
gr.DrawRectangle(&Pen(Color::Red), rf);<br />
}<br />
fairly simple, but it doesn't work...it shows ok in print preview, but it doesn't print the entire rectangle (actually, it prints a rectangle about 36 times bigger, the result is that the right border or the bottom one doesn't get printed).
Ok...thinking it was me (as usual), i redraw it this way:
<br />
void CBasicView::OnPrint(CDC* pDC, CPrintInfo* pInfo) <br />
{<br />
CView::OnPrint(pDC, pInfo);<br />
pDC->Rectangle(0, 0,<br />
pInfo->m_rectDraw.Width(),<br />
pInfo->m_rectDraw.Height());<br />
}<br />
and...it prints and show OK...in fact, when i draw the two of them overlapped, the print preview shows them that way, but it only prints the second one...
Any hints?
Thanks!
|
|
|
|
|
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.
|
|
|
|
|