|
For your extension use "*."
This will now find all extensionless files AND
directories (including . and .. ) so put ...
if (!finder.IsDirectory()){
pListBox->AddString((LPCTSTR)finder.GetFileTitle());
}
...in your loop to prevent adding diectory names to
the list.
Steve T.
|
|
|
|
|
I have 2 classes CMainFrame and CDevice that need access to the same variable (bConnected) to tell whether I am connected to a device or not. How do I do that without creating a whole seperate function to gain access to that variable? I though just declaring it publicly should have done the trick....guess not
- John
|
|
|
|
|
Put the variable in the CWinApp.
Declare the BOOL m_bConnect; variable in the protected Section
And add these inline functions in the Public section of the Header of the CWinApp Class
void SetConnect(BOOL bRet){m_bConnect = bRet;};
BOOL GetConnect() {return m_bConnect;};
Cheers!!
Carlos Antollini.
|
|
|
|
|
I asked this question last week (I think). Noone answered, but I think it was a sunday so I figured everyone was watching the tube and relaxing. So, here goes again...
I have a docking window that creates a ListCtrl of type CListCtrl as its child. The listCtrl is created in the docking windows OnCreate function. I can add items to the list from within that OnCreate Function, BUT when I try to get a pointer to that listctrl from another class I always ASSERT in function IsWindow.
Obviously, because there isnt a valid m_hWnd attached to the pointer. BUT how do you define and then use a pointer to a listctrl from outside its own class.
Any help would be appreciated. I've never really grasped pointers 100%. So, maybe this will finally enlighten me.
Frank
|
|
|
|
|
The only thing I can think of is that you might be tring to use the control before it gets created. Also it is not enought to check whether the pointer to the list box is valid, you must check that it has been created(IsWindow will do, or set a flag in the docking window class).
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic" ![Wink | ;)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_wink.gif)
|
|
|
|
|
Thanks Benner,
My calls to add items to the list are done after the application has started, ie by a menu command.
My guess is (and I just had this revelation) that the variable that Is supposed to be storing the reference to my list ctrl is not holding it.
So...
If I'm creating a list ctrl by setting a public member like:
CListCtrl m_wndListCtrl;
And...that list ctrl get created in OnCreate...how do I get hold of it from another class? Yikes...I'm confusing the hell out of myself here.
Thanks,
Frank
|
|
|
|
|
Assuming the list control has been created, then it's just
pMyClass->m_wndListCtrl;
The m_hWnd member will not be valid unless Create has been called, so that the list control is visible. As has been said ::IsWindow() will check this for you.
A pointer is a variable that holds the memory address where something is stored, as opposed to the object itself. What don't you grasp about them ( I'm not being sarcastic, I'm asking so I can offer a reply ).
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Thanks Christian,
Pointers...and what I don't understand about them by /me:
I can grasp that a pointer defined as CClass* pointer is a pointer to an uninitialized variable. And, that a pointer defined as CClass& pointer is a reference to an initialized object...however I don't understand when you use one over the other. And, don't get me started on why you don't have to use & or * when using CDialog ie: CMyDialog dlg; dlg.DoModal();
As far as using pMyClass->m_wndListCtrl. OK, now if I'm understanding this correctly, the -> means that I must define pMyClass as CMyClass* pMyClass = (Something*)Something.
Where I'm getting confused is the Somethings above...(I hope I'm making sense here.)
Am I totally WRONG?
Calmly yours, and many thanks,
Frank
|
|
|
|
|
OK, here goes.
If you mean you CAN'T grasp that a CClass * pointer is uninitialised, consider this. By declaring this variable, you've declared your intention to store the address of a CClass and allocated enough space to store that memory address. When you call new is when you actually create the object. This is necessary, because sometimes you don't want to call new, for example when a function returns a pointer, or when you're using STL and have a container full of pointers ( the container owns the pointers, but does not call delete on them when it lets them go, so you need to ).
>And, that a pointer defined as CClass& pointer is a reference to an initialized object...however I don't understand when you use one over the other.
A reference is NOT a pointer. A reference allows you to pass an object without making a copy. You'd use this to pass an object into a function where the object either
a. has no copy constructor, or
b. is large and you don't want the overhead of making a copy
A reference cannot be dealt with like a pointer, for starters you can't use ++ to iterate through an array by starting with a reference to item 1.
>And, don't get me started on why you don't have to use & or * when using CDialog ie: CMyDialog dlg; dlg.DoModal();
I don't understand - why would you ? You can't use &, because there is nothing to refer to, you're creating the object. Having created it, you have a pointer to it (&dlg), although you'll lose it because when it goes out of scope the object will be deleted.
>OK, now if I'm understanding this correctly, the -> means that I must define pMyClass as CMyClass* pMyClass = (Something*)Something.
Yes, if it is your CMainFrame class, then it would be
CMainframe * pMain = (CMainframe*) AfxGetMainWnd();
This is a good place to store variables that you need across multiple classes, because it's so easy to get a pointer to. Note this is an example of why CMainframe * pMain creates nothing - you're not creating anything here, just storing a memory address for an object that exists already.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Ok...now you see why I didnt get pointers.
>I don't understand - why would you ? You can't use &, because there is >nothing to refer to, you're creating the object. Having created it, you have >a pointer to it (&dlg), although you'll lose it because when it goes out of >scope the object will be deleted.
I think I understand that now.
>By declaring this variable, you've declared your intention to store the >address of a CClass and allocated enough space to store that memory address.
Gotcha. But, if the object is already created, ie by calling Create() and there is no function like AfxGetMainWnd() how do you get a pointer to the memory address holding the variable you want to access? ie, a window created outside of the CMainFrame class.
For the love of Mike...I think I'm getting this...I just hope that everyone doesnt think I'm a dolt or something like that!
Thanks Christian, I know this is elementary stuff. Chapter 1, but I never read that book.
Less Confused but still inquisitive:
Frank
{
There are no stupid questions. But there are alot of inquisitive idiots.
}
|
|
|
|
|
>Gotcha. But, if the object is already created, ie by calling Create() and there is no function like AfxGetMainWnd() how do you get a pointer to the memory address holding the variable you want to access? ie, a window created outside of the CMainFrame class.
Ah.. No, you use a function like this to get hold of the class that holds the variable, you still get the listctrl by accessing the variable within the class. So if the listctrl was in a dialog box, I'd make the dialog box a member of the CMainFrame class, make it a pointer if it's modeless ( it would have to be or there's no point trying to access it elsewhere ) and then if in my view I wanted to access it, I would do this:
CMainframe * pMain = (CMainframe *) AfxGetMainWnd();
pMain->m_pDialog->m_ListBox.Somefunction();
>For the love of Mike...I think I'm getting this...I just hope that everyone doesnt think I'm a dolt or something like that!
Not at all - I've had some impressive memory blocks myself, sometimes you just need someone to verbalise it for you so you can get another slant on how it all works.
>Thanks Christian, I know this is elementary stuff. Chapter 1, but I never read that book.
I have Stroustrup 'The C++ Programming Language' by my desk all the time ( I actually referred to it to refresh my mind on the first question I answered for you ). You should definately get it and read it if you're serious about C++ - it is THE core reference IMHO.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Many Thanks Christian. (Brief Pause for effect). Many, Many Thanks.
Frank
You see, its all very clear to me now... Something's going to happen.
Dave Bowman - 2010
|
|
|
|
|
Frank,
You have asked two different questions - a specfic issue on why you are getting an ASSERT when accessing a CLIstCtrl, and the genreal question about pointers.
1. The ASSERT is almost certainly because you are accessing the 'wrapper' object (the CListCtrl) before the underlying window has been created. The best place to do what you want is 'OnInitDialog' - this is a function that allows you to do 'initialisation' of child controls and internal variables after the dialog has been created, but before the dialog his visible. You need to do a 'm_wndListCtrl.Create(...);' in 'OInInitDialog', then fill the control with items. After this, you should be able to access the listCtrl form anywhere that you access the CDialog object.
2. Pointers. It would take a while to work through all of this! As Christian says, a reference is not a pointer - although in many cases they can be used interchangeably. I don't thiunk anyone is going to be able to give you a concise and precise description of objects, pinters and references (and all the details and issues relating to them) in this forum. It sounds like you need to refer to a few C++ books. The Scott Meyers 'Effective C++' is a good place to go for details of issues like references versus pointers. Stan Lippmans 'C++ Primer' is a very good start for the details of practical C++.
Having just said this is all too much to condense into a short forum post, there are a few things that you should be aware of. In general (and all general rules have exceptions!) you should try to use references rather than pointers. This is because references always refer to something, so you do not have to concern yourself with testing for 'uninitialised variables'. The main use for pointers in modern C++ is when you need to refer to a number of different objects via the same variable - a reference cannot do this, but a pointer can.
There's a lot more thatn can be said, but this is already long enough!
|
|
|
|
|
And many thanks to you Mike.
I think I've got a basic understanding of this stuff now.
And, hopefully this helped some of the other *pointer newbies out there.
Frank
|
|
|
|
|
I ask it before ant this is the answer that I gets:
look in help for main, wmain etc. - they return int
t!
Who can explain me it ???
|
|
|
|
|
If you have a console app, the value returned from main() is the exit code of the program.
For GUI apps, the return from WinMain() is the exit code. Normally you return the wParam of the WM_QUIT message, which itself is the parameter passed to PostQuitMessage(), however this is not a requirement.
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|
something very simple, I want to have two sets of radio buttons, I cant for the life of me seperate them. I always thoguht it woul be a matter of putting them in a group contorl but no luck. I was told to try putting the taborder so they are sequential but this doesnt work either
thanks
|
|
|
|
|
You also have to set the Group style on the first radio button in the group, and turn that style off for the remaining buttons.
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|
I just had the same problem. Open the .rc file in text mode then cut and paste so that the radio control buttons are all bunched together, and then make sure the group box follows. I believe that should do it even though there probably is an easier way.
Ex: I had a dialog for selecting comm ports and a device type, 1 group box for each...the correct .rc file looks like so:
CONTROL "DEVICE1",IDC_DEVICE1,"Button", BS_AUTORADIOBUTTON,23,34,70,10
CONTROL "DEVICE2",IDC_DEVICE2,"Button", BS_AUTORADIOBUTTON,23,48,70,10
CONTROL "DEVICE3",IDC_DEVICE3,"Button", BS_AUTORADIOBUTTON,23,62,70,10
GROUPBOX "Device Type:",IDC_DEVICE_SELECT,19,24,78,52,BS_LEFT | WS_GROUP
CONTROL "1",IDC_COM1,"Button",BS_AUTORADIOBUTTON,137,29,22,10
CONTROL "2",IDC_COM2,"Button",BS_AUTORADIOBUTTON,137,43,22,10
CONTROL "3",IDC_COM3,"Button",BS_AUTORADIOBUTTON,137,57,22,10
CONTROL "4",IDC_COM4,"Button",BS_AUTORADIOBUTTON,137,71,22,10
CONTROL "5",IDC_COM5,"Button",BS_AUTORADIOBUTTON,168,29,20,10
CONTROL "6",IDC_COM6,"Button",BS_AUTORADIOBUTTON,168,43,20,10
CONTROL "7",IDC_COM7,"Button",BS_AUTORADIOBUTTON,168,57,20,10
CONTROL "8",IDC_COM8,"Button",BS_AUTORADIOBUTTON,168,71,20,10
GROUPBOX "COM Port:",IDC_COM_PORT,131,19,63,65
- John
|
|
|
|
|
You need to do both the things that have been said already. First, go to the first radio button of each group and check the 'group' property. Then go into the resources unless you are sure the groups are together - if you created three radio buttons, a listCtrl ( or anything else ) and another button, the last button will not be in the group until it gets moved under the others in the resource file.
Another warning. You can now add a variable of type int for the 'group' radio button. It is a zero based index of which button is pressed. I have found that using this sometimes ( like right now ) causes the item selected to jump when I click another control in the window. I have no idea why, although it happens more if you initialise the value to something other than -1. Set it to 0 and UpdateData(false) in your OnInit, not your constructor.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
The easy way to think of it is that a group of radio buttons will start with a radio button that has its "group" property checked and will include all subsequent radio buttons with unchecked group property (by tab order) up to BUT NOT INCLUDING the next control that has its group property checked. This last control can be, but does not have to be another radio button.
The way I usually implement for simlicity - for each group of radio buttons I make a surrounding group box. I make that group box follow the last radio button in the tab order, then I set its group property to checked.
Steve T
|
|
|
|
|
Hi!
I am trying to set the text color for a RichEditCtrl, and here is what I have been using:
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.crTextColor=RGB(255,0,0);
SetCharFormat(cf);
I have not used the CFM_COLOR flag, since it seems that it would override my color selection.
The code above does not work for some reason.
avneesh
|
|
|
|
|
For apply this you need to select a text, or if you need to write in some color from a point to ahead, select that point and apply the color.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
yes, I do select the text, in the control, before invoking these calls..
Any other suggestion?
ab
|
|
|
|
|
If you want to set the color for text you add later, use SetDefaultCharFormat().
--Mike--
http://home.inreach.com/mdunn/
"You named the Borg... Hugh?"
-- Guinan
|
|
|
|
|