|
The question I ask today is very simple: how do I load icons and text into a ListView control with MFC? I know how to do it in Win32 but as far as I can tell, it's not compatible with MFC ListView control functions.
-- Steve
|
|
|
|
|
|
Thanks! One more question though. How do I get a floating menu to appear when I right-click on the ListView? It always ends up in the top left corner because I have to use ON_NOTIFY(NM_RCLICK...) to give it the message. What do I do?
-- Steve
|
|
|
|
|
Do you mean a simple popup menu? If yes, I can give you some sample code
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yes, I need a floating menu to appear when I right-click the ListView control. That's it
-- Steve
|
|
|
|
|
here we go:
POINT point;
GetCursorPos(&point);
CMenu menu;
CMenu *submenu;
menu.LoadMenu(IDR_POPUP);
submenu = menu.GetSubMenu(0);
submenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,GetActiveWindow(),NULL);
hope this helps
modified 12-Sep-18 21:01pm.
|
|
|
|
|
How can one determine if the local machine or a machine on the local network is running an SMTP server? I was thinking I could just check to see if a specific port (#25) was open, but it could be set up to use a different one. Is there any way to check?
David Wulff Born and Bred.
|
|
|
|
|
Dont think so...
The only way I can think of, is to try every 65535 ports, and when you find an open one, see if it understand SMTP
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
If the port 25 is open, you can telnet into it and send the command HELO <<yourmachinename>>(for SMTP) or EHLO <<yourmachinename>>(for ESMTP), if you get a response back starting with 250, you can be sure it is running an (E)SMTP server. Normally when you connect, the mail server itself sends you a welcome string telling you about it. Don't forget to send a QUIT after you are done though. If you are not telnetting on port 25, you can write a socket program that connects to port 25 on the other machine and does the same thing.
Simple isn't it? If it's an SMTP server, it must be able to speak SMTP, so that's the way you can test it.
Regards,
Rohit Sinha
|
|
|
|
|
I think he might be worried about black hats
installing SMTP servers on non-standard ports
on machines somewhere in his network and using
his domain for sending spam, porn, warez or
what-have-you? In that case, you can try
connecting to ports (all of them) and talking
SMTP, looking for a server. Or you can watch
traffic on the network and try to sniff out
culprits.
(of course, would they make it stand out as
what it is by speaking plain ol' SMTP? I dunno.)
I wonder what the goal was?
|
|
|
|
|
I have a dialog based application that includes a modal dialog that has a CComboBox in it. I have attached a control variable (through the class wizard in MFC) to the CComboBox because I need the strings in the box to change dynamically depending on other settings in the program. The combo box works fine the first time the dialog is opened, but if I re-open the dialog the control variable causes a crash (assertion error) because it is no longer pointing to the combo.
Can anyone help me with this problem? I need that control variable to point to the combo every time the dialog opens.
|
|
|
|
|
Hi,
I am populating a treeview with some data and since there are too many and too long items my app requires even more and more memory.
To avoid this I decided to use single select mode and add only those items to the tree which belong to the CURRENTLY expanded node.
If this node gets collapsed all items are removed from this node. In that way the app's footprint might be significantly reduced.
Problem: the whole tree must be kept in and read in from a file according to a certain algorithm.
I need your advice as to how you would do this.
Thanks in advance.
Bunburry
|
|
|
|
|
// CollapseBranch - Collapses a branch completely
// hti - Handle of the tree item to collapse
void CTreeCtrlX::CollapseBranch( HTREEITEM hti)
{
if( ItemHasChildren( hti ) ){
Expand( hti, TVE_COLLAPSE );
hti = GetChildItem( hti );
do{
CollapseBranch( hti );
}while( (hti = GetNextSiblingItem( hti )) != NULL );
}
}
Expanding a branch
--------------------------------------------------------------------------------
The treeview has built in support for expanding expanding the outline one level at a time. If you want to completely expand a branch, the code below will help. It uses recursion to expand all items. The last line, that is, the call to EnsureVisible() is useful when this code is hooked up to a user interface. After expanding the outline branch, the previously selected item may have scrolled off and calling EnsureVisible() brings it back.
// ExpandBranch - Expands a branch completely
// hti - Handle of the tree item to expand
void CTreeCtrlX::ExpandBranch( HTREEITEM hti )
{
if( ItemHasChildren( hti ) ){
Expand( hti, TVE_EXPAND );
hti = GetChildItem( hti );
do{
ExpandBranch( hti );
}while( (hti = GetNextSiblingItem( hti )) != NULL );
}
EnsureVisible( GetSelectedItem() );
}
search more in codeguru and codeproject
|
|
|
|
|
I must have asked in the wrong way:
The real question is how can I serialize a treeview into a file so that I can retrieve its nodes any time.
When I expand an item, I have to read in its childs from the file, when I collapse delete all items in this node because all subitems are saved in the file in question.
Anyway thanks for the feedback.
Bunburry
|
|
|
|
|
I need to be able to create some controls as the user needs them. They are all the same control. I will need to be able to still get access to each controls messages etc. At the time the appliction starts to run I will not know how many controls the users will be using, but there will be a max number of controls that the user can create.
How can I do this in VC++? If anyone can point me in the right direction I will be happy to do the research. I looked over at MSDN but could only find examples for VB.
Thanks,
-Eric
|
|
|
|
|
Option 1: You could create all controls with the dialog editor in the non visible state, and show/hide them according to user input with ShowWindow(SW_SHOW/ShowWindow(SW_HIDE)
Option 2: Create them dinamically with the controls Create method.
Bunburry
|
|
|
|
|
Bunburry wrote:
Option 2: Create them dinamically with the controls Create method.
Bunburry,
This is the option that I was hoping for. The question is how can I do this? Do I just declare a and array like I normally would of the control type that I want?
int MAX_CONTROLS = 50;
CEdit EditArray[MAX_CONTROLS];
for(int i = 0; i < 50; i++)
{
EditArray[i].Create();
}
Is this similar to how it work? How do I know which array element has been clicked on or text entered etc?
Thanks,
-Eric
|
|
|
|
|
VanHlebar wrote:
Is this similar to how it work?
Yes, that may not be the exact syntax, but that is how you would set up your array of Edit controls.
VanHlebar wrote:
How do I know which array element has been clicked on or text entered etc?
There is no mechanism in C++ that allows you to handle the controls based on an index. However you can set this up yourself. First off, you can set the same handler for each of the controls. If you need to know the index of hte control in your array, you can do one of two things:
1) Search for the current object in your array, and when you find the object you will know the index.
2) Is a little bit more complicated, but you can use SetWindowLong with the GWL_USERDATA flag, and set the index there. That way whenever your window needs to know which index it possesses you can simpy query GetWindowLong.
3) And I just thought of a third, you can create a derived class from CEdit that has a place where you can store the index ID that you want to give your control.
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
When you process the control's notification message do something like this:
For example, it is and edit control and then message sent to the parent window is EN_CHANGE:
case EN_CHANGE:
iControl = GetWindowLong((HWND) lParam, GWL_ID);
switch(LOWORD (wParam))
{
/* code of what you want to do using the arrayname and for an index
* use iControl
*/
}
...
|
|
|
|
|
m_btnFirst.Create("Button1", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, rect1, pWnd, IDC_BUTTON_FIRST);
m_btnSecond.Create("Button2", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, rect2, pWnd, IDC_BUTTON_FIRST + 1);
m_btnThird.Create("Button3", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, rect3, pWnd, IDC_BUTTON_FIRST + 2);
...
Message map:
BEGIN_MESSAGE_MAP(CYourDlg, CDialog)
ON_CONTROL_RANGE(BN_CLICKED, IDC_BUTTON_FIRST, IDC_BUTTON_FIRST + nNumberOfButtons,OnRange)
END_MESSAGE_MAP()
OnRange(UINT nID) is the dialogs function that gets called when any of the buttons is pressed. the Button's ID will be in the nID variable.
Important: make sure your IDC_BUTTON_FIRST is defined in resource.h with a unique value, and that there are no other controls in the IDC_BUTTON_FIRST + nNumberOFButtons range.
Bunburry
|
|
|
|
|
Hi I have word automated application...
It takes input document (.doc) file name from the command line, then open it, format it, print it, and close the MS Word application with MSWord9...
Another dialog-based application calling wordAutomation application passing with filename as an argument. Once wordAutomation gets the document file name, it open, format, and print the file.
Here the problem comes, wordAutomation takes so long to close the MSWord application... it takes 3 mins to close up MSWord application..
There isn't such kind of problem using wordAutomation itself ( not calling from another application). It does all its jobs (open,format,print, and close) very fast ... but why it takes so long to close the MSWord program if it got called from another application?
here the code how I close MS Word in wordAutomation program.
<br />
document.PrintOut(COleVariant((short)false), vOpt, vOpt, vOpt, vOpt, vOpt ,vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, COleVariant((short)12240), COleVariant((short)15840));<br />
<br />
document.Close(COleVariant((short)false), vOpt, vOpt);<br />
documents.ReleaseDispatch();<br />
<font color = red> here I think is a problem at closing the MSWord when wordAutomation program is called from another application. I used "I think " coz I don't know how to debug at run time. </font><br />
app.Quit(covFalse,covFalse,covFalse);// quiting the MSWord application.<br />
app.ReleaseDispatch();<br />
<br />
|
|
|
|
|
I have some threads in my app. I want one to run to use max cpu which it does quite nicely already, I want another to use 10%-20% cpu, how can I say "Thread #2, you can only use 20%, not 50%" without the thread getting angry?
I have already tried tweaking the thread priority in real time, but this doesn't work very well, any other ideas would be great...
|
|
|
|
|
|
VC6, SP5
I have a CListCtrl in a CDialog. In ClassWizard, I turned on "Show Selection Always", and in OnInitDialog, I've turned on the LVS_EX_FULLROWSELECT | LVS_EX_ONECLICKACTIVATE extended styles for the list control.
After clicking on an item, it highlights (as expected). When I click on an area of the listcontrol that does not have an item, the highlight goes away for the last selected item, but the program still thinks it's selected.
If I click a number of times in the empty area, the highlight comes and goes. If I click on the item again, the highlight comes back.
I want to do one of two things:
1) Do not allow the highlight to be removed from the selected item when I click on the empty control area (this is the preferred method).
2) Un-select the item when I click on the empty control area.
I'm trying to avoid subclassing the CListCtrl because there's a lot more issues involved with doing so.
Opinion - MFC's CListCtrl class SUCKS.
------- signature starts
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
Please review the Legal Disclaimer in my bio.
------- signature ends
|
|
|
|
|
These aren't problems with CListCtrl per se, but the Windows list-view control underneath, which is an A-number-1 mother-batch when it comes to handling selections. The essence of modifying the selection behavior is to handle the LVN_ITEMCHANGING and LVN_ITEMCHANGED notifications.
LVN_ITEMCHANGING lets you decide whether or not to permit a state change in a list view item. In this case, you could find out where the user clicked and use that to make the decision. LVN_ITEMCHANGED tells you after an item's state changed.
Software Zen: delete this;
|
|
|
|
|