|
|
Now I have all the "iamge pieces" conected together, I checked the original code I am working and now it is obvious what it does and how.
Thank you all again!
Melsi
|
|
|
|
|
Can me somebody give an example of an simple iterator (such as STL but simple) ?
Thanks.
-:KNOX:-
|
|
|
|
|
list<char> charList;
for( int i=0; i < 10; i++ ) {
charList.push_front( i + 65 );
}
list<char>::iterator theIterator;
for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) {
cout << *theIterator;
}
SaRath.
"It is your attitude, not your aptitude, that determines your altitude - Zig Ziglar."
My Blog | Understanding State Pattern in C++
|
|
|
|
|
An example of what an iterator class looks like or how to use them?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Yes an class example.
-:KNOX:-
-- modified at 13:39 Thursday 29th June, 2006
|
|
|
|
|
The most basic example of an iterator is just a pointer:
char buffer[100] = "0";
char* it = buffer;
for (int i = 0; i < 100; ++i)
{
*(it++) = 'a';
}
A more indepth example would include writing a basic container class and an iterator class (iterators don't mean much without a corresponding container).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hey guys I am having a bit of syntax problem
File: ObjectRoot.h
Class ObjectRoot {<br />
<br />
static RTI::RTIambassador* ObjectRoot::ms_rtiAmb; <br />
...............<br />
.........<br />
}
I was just wondering why you would have ObjectRoot:: included in the declaration.
Thanks
|
|
|
|
|
|
Most likely (and you see this a LOT in the RTI codebases), it is a copy-paste thing. When initializing a static member variable, you have to specify the class it belongs to:
static RTI::RTIambassador* ObjectRoot::ms_rtiAmb = NULL;
Someone probably wrote the initialization prior to adding the member to the class and just copied it.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Maybe they have ObjectRoot:: in the class because ms_rtiAmb might be used as a global variable and didn't want it mixed up. That could be a possibility
Thanks for your reply Zac
|
|
|
|
|
The compiler would not get mixed up. Did you mean a maintenance engineer?
If a member variable and a global variable share the same type and name, the member variable takes precedendce within the member functions of the same class. To access the global variable you would need to put the :: in front of the name.
I've seen better runs in my shorts! - Patches O'Houlihan
|
|
|
|
|
I want to change my dialog window class name dynamically, please tell me how, thanks.
virtual
|
|
|
|
|
VC 6.0
- right-click on the top level node in "ResourceView" window and choose "Properties" menu item
- in the "Resource File Properties" dialog, uncheck "Enable MFC features".
- right-click on dialog template and choose "Properties".
- in "Dialog Properties" dialog, type the class name, e.g. "Mama Leone"; NOTE: unless the first two steps "Class name" field is disabled.
- in InitInstance of your application add the following
WNDCLASS wc;
::GetClassInfo(AfxGetInstanceHandle(), _T("#32770"), &wc);
wc.lpszClassName = _T("Mama Leone");
AfxRegisterClass(&wc);
VC .NET
Like in VC6.0 except, instead of type the new dialog's class name in resource editor/"Dialog Properties", you have to add by hand CLASS statement in resource file:
IDD_MY_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SHELLFONT | WS_POPUP | WS_VISIBLE | WS_CAPTION
| DS_MODALFRAME
| WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "My Dialog"
CLASS "Mama Leone"
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Wow. I did not know one could do that. But, please can you tell me in what situation would one need to change a window class name?
Fortitudine Vincimus!
|
|
|
|
|
All the life we have many occasions to find out many wonderful new things...
Well, let's say we have a dialog-based application, and from another application I have to retrieve its handle to say it "Hello!".
What we gonna do? An easy way is to call FindWindow passing class name or window name or both.
Got it?
"#32770" class name no use, since other dialogs can have the same class name.
The window name (window text / caption text)? For some reason may be changed.
So a class name like ("Mama Leone" was just an example ) "class_99AFD5EC_1AE5_45F0_8ECD_594F4E6653CB" built using a GUID, guarantees to be unique if not in the known part of universe at least on Earth...
And of course would be not a happier ideea to put something like "99AFD5EC_1AE5_45F0_8ECD_594F4E6653CB" on the caption.
And this is just an example.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks a lot.
Fortitudine Vincimus!
|
|
|
|
|
But how to make the class name be different at every running?
for example, the class name is "loki" when the program is running at first time, and then "ace" at second time, how to do that? Thanks a lot.
virtual
|
|
|
|
|
Thank you very much, in fact I did not express clearly, it's my fault. In my opinion, this method is a static method to change the class name, I know this way, now I describle the situation what I meet, I created a dialog box with a registered class name,e.g."boost", but someone else cracked my product, they knew my class name now, so they can use "FindWindow()" to find my dialog, and then they can control my dialog, but as you know, I don't want they can find my dialog by
"FindWindow()", one way to avoid this is to change my class name randomly when my program are running, but I don't know how, please tell me how to do that, thank you very much.
virtual
|
|
|
|
|
Ugh, those hackercrackers controlling poor dialogs found with FindWindow...
Even I have not entirely got the point or even for fun or for sake of code digging, here is a solution.
Override CDialog::DoModal to modyfy DLGTEMPLATE structure passed to CreateDlgIndirect function.
Copy/paste the code from default CDialog::DoModal implementation then make some cosmetics.
Below is a trivial example which makes some assumptions, to simplify code and be easier to get the idea.
You must read carefully the DLGTEMPLATEEX structure documentation, focusing on menu and windowClass members that have variable length and modify my example to take care of each case (has a menu or not, and so on...).
- we have a DIALOGEX resource.
- the dialog has attached a menu with ID in the .rc file (not a name).
- a CLASS statement was inserted in .rc file, that we'll replace with a class name with the same length.
#include <AFXPRIV.H>
#include <AFXIMPL.H>
#define DELETE_EXCEPTION(e) do { e->Delete(); } while (0)
int CMyDialog::DoModal()
{
TRY
{
AfxHookWindowCreate(this);
DLGTEMPLATEEX* lpDlgTemplateEx = (DLGTEMPLATEEX*)lpDialogTemplate;
WCHAR* pClassName = ((WCHAR*)lpDlgTemplateEx
+ sizeof(DLGTEMPLATEEX) / sizeof(WCHAR)
+ 2 * sizeof(WORD) / sizeof(WCHAR));
wcscpy(pClassName, L"Tata Leone");
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), hInst))
}
Of course "Mama Leone" is defined in resources CLASS statement, and "Tata Leone" is a registered class.
And of course the class name can be randomly generated or using a GUID.
Ovidiu Cucu
Microsoft MVP - Visual C++
-- modified at 5:41 Friday 30th June, 2006
|
|
|
|
|
En, Thank you very much for your new way to solve my trouble, but if I want to create modeless dialog, how to do that?
maybe override create() is not a practical way, because it will call "CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd, HINSTANCE hInst)" after some steps, but this function is not a virtual one.
BOOL CMainDlg::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
//omit some original code
//call function
HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, lpszTemplateName, RT_DIALOG);
HGLOBAL hTemplate = LoadResource(hInst, hResource);
BOOL bResult = CreateIndirect(hTemplate, pParentWnd, hInst);
FreeResource(hTemplate);
return bResult;
}
BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,
CWnd* pParentWnd, HINSTANCE hInst)
{
//omit some original code
// create modeless dialog
AfxHookWindowCreate(this);
hWnd = ::CreateDialogIndirect(hInst, lpDialogTemplate, pParentWnd->GetSafeHwnd(),
AfxDlgProc);
//omit some original code
}
can you tell me how to do that? thank you very much.
virtual
|
|
|
|
|
How nasty! No virtual, no override...
Well, no problem. Write your own Create function as well:
class CMyDialog : public CDialog
{
BOOL Create(UINT nResID, CWnd* pParent)
{ return Create(MAKEINTRESOURCE(nResID), pParent);}
BOOL Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd);
};
#include <AFXIMPL.H>
BOOL CMyDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
ASSERT(HIWORD(lpszTemplateName) == 0 ||
AfxIsValidString(lpszTemplateName));
m_lpszTemplateName = lpszTemplateName;
if (HIWORD(m_lpszTemplateName) == 0 && m_nIDHelp == 0)
m_nIDHelp = LOWORD((DWORD)m_lpszTemplateName);
HINSTANCE hInst = AfxFindResourceHandle(lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, lpszTemplateName, RT_DIALOG);
HGLOBAL hTemplate = LoadResource(hInst, hResource);
ASSERT(hTemplate != NULL);
DLGTEMPLATEEX* lpDialogTemplate = (DLGTEMPLATEEX*)LockResource(hTemplate);
WCHAR* pClassName = ((WCHAR*)lpDialogTemplate
+ sizeof(DLGTEMPLATEEX) / sizeof(WCHAR)
+ 2 * sizeof(WORD) / sizeof(WCHAR));
wcscpy(pClassName, L"Tata Leone");
BOOL bResult = CreateIndirect((LPCDLGTEMPLATE)lpDialogTemplate,
pParentWnd, NULL, hInst);
UnlockResource(hTemplate);
FreeResource(hTemplate);
return bResult;
}
Ovidiu Cucu
Microsoft MVP - Visual C++
-- modified at 4:39 Sunday 2nd July, 2006
|
|
|
|
|
Thank you very much, I will do a test.
virtual
|
|
|
|
|
Can not open header file "AFXIMPL.H", so...
thanks.
|
|
|
|
|
You have to add the folder where AFXIMPL.H is situated
or easier remove #include <AFXIMPL.H> and define DLGTEMPLATEEX yourself, as follows:
#pragma pack(push, 1)
typedef struct
{
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cDlgItems;
short x;
short y;
short cx;
short cy;
} DLGTEMPLATEEX;
#pragma pack(pop)
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|