|
the constrols are not constructed yet in the dialog constructor. you have to do all this in the OnInitDialog() method...
|
|
|
|
|
piul wrote: CDlg Dialog ;
Dialog.AddOpc() ;
Dialog.DoModal() ;
The second line is wrong since the dialog isn't yet created.
Since (due to modal nature of the dialog) you need to add strings before the DoDialog call but you can't add them directly to the combo box that isn't yet alive, hence you should modify AddOpc method to store passed strings inside a string array and use the latter to initilize the combo box inside the OnInitDialog method.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok!
How do I include that in OnInitDialog?? Where's that method? Do I have to overload it somehow?
(As you can tell I'm not very experienced in dialog... it's all very confusing..)
|
|
|
|
|
I give you a simple example:
void CDlg::CDlg()
{
m_iItemCount=0;
}
void CDlg::AddOpc(CString szItem)
{
if ( m_iItemCount < 10)
{
m_szItem[m_iItemCount] = szItem;
m_iItemCount;
}
}
BOOL CDlg::OnInitDialog()
{
for (int i=0; i<m_iitemcount; i++)<br="" mode="hold" /> {
m_cbDropList.AddString(m_szItem[i]);
}
return TRUE;
}
Where m_iItemCount is a CDlg int member variable and m_szItem is an array CStrings having 10 elements, also member of CDlg .
(I used a fixed size array to keep things simple).
The calling code will be
CDlg Dialog;
Dialog.AddOpc("foo");
Dialog.AddOpc("piul");
Dialog.DoModal()
To override OnInitDialog , select your CDlg class, go to the properties pane, click the overrides button, and choose <add>OnInitDialog</add> .
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ooops! It works if I call AddOpc() from an event handler of a button, for example
|
|
|
|
|
How to let CPropertyPage look like 3d?
http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/sheetandpage.rar
I put my source code in the web.
There are two project in the rar file.
First project called "C25 ListProperty" has 3d-look property-page. That is sample of a book about vc++ 6.0 MFC(chinese tradition lang)
Second project called "ShadowTool" has flat-look property-page.
I create "ShadowTool" in vc++ 2005.
The difference between the two projects is that the "ShadowTool" use the sheet is inherited from CPropertySheet.
|
|
|
|
|
akira32 wrote: http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/sheetandpage.rar
I put my source code in the web.
And you expect us to go there and wade through it all?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I want you to download it and see the picture about 3d and flat-look PropertySheet. Of course, the rar file include the complete source code about two projects.
|
|
|
|
|
Hy everyone again,
Thanks for the ones who responded me earlyer (Hamid, Pallini), but unfortunately that doesn't helped.
I need to get somehow informations about some files stored on my PC (name, size, last modified, etc.).
I am using Visual C++ 2005 and I can't use CFile or other functions that are using other windows dll-s and witch requires Windows only (so MSDN doesn't help ).
That's because my console application must be converted in a dll and be used into an XPCOM component (like Mozilla's ones) and work on any platform windows, linux, mac.
is there any class or function made by someone?
Thanks very much !
|
|
|
|
|
dude, what's wrong with the answers you got there[^] ?
don't repost ! this is NOT A CHAT !
|
|
|
|
|
If you want your code to be portable and to be able to do things with files, like examine them, then you probably need to write it against the POSIX standard interface. All 3 platforms you mention have a degree of support for this, there will however be differences in implementation that might still require you to have platform specific code in places. You'll need a reasonably up to date POSIX spec, the last free one I came across was part of the Single Unix Specification Version 3 SUSV3. You'd probably also benefit from having a look at the code for the Microsoft Visual C Runtime MSVCRT??.dll which should be installed with Visual Studio probably under /CRT/Src. That where MS implement a lot of the standard POSIX like file related stuff, stdio.h should be your first port of call and <stdio> without the .h from the standard library as well. Anything you call their is likely to be available to call in the same named headers from glibc under Linux and somewhere ( I'm not fruity ) on the Mac.
Good luck.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
cuesdean florin wrote: is there any class or function made by someone?
Yes, Microsoft has made such functions available.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
But I think you can use of them,did you try?
|
|
|
|
|
Hi,
I wrote this code in the Timer which is giving an error while it is running.
char *wFile = new char[22];
wFile = "010B000304140601000000";
WriteFile(HD,wFile,strlen(wFile),&Bytes,NULL);
delete[] wFile;
I know that delete operator causes this error.How can I solve this?
Thanks
|
|
|
|
|
iayd wrote: is giving an error
WHICH error ?
how can we guess if you don't tell us all we need to know ?
|
|
|
|
|
Woaw, that's very bad code
First, you allocate a buffer of 22 characters and tries to assign 22 characters in it (you didn't take into consideration the terminating zero).
BUT, you in fact don't copy the string into your buffer. You simply just assign a pointer into wFile (your string is in fact a pointer). Later you try to delete this pointer, which of course will fail because your string was not allocated on the heap (not allocated with new).
So, two things to take into consideration:
1) Always make your buffer 1 place larger to be able to store the null-terminating zero
2) Use strcpy whenever you want to copy a string. This will copy the contents of your string and not simply make a pointer assignement.
|
|
|
|
|
strlen is expecting a null terminated string, your new statement allocates 22 entries, your assignment fills all 22 places with non null data, I think you have to make the first line something like char[23] enough space to include the terminating null character.
|
|
|
|
|
iayd wrote: wFile = "010B000304140601000000";
The above line is a mistake. You should do
char *wFile = new char[23];
strcpy(wFile, "010B000304140601000000");
BTW even correct, the above code is wasteful, using a two lines you can do all the stuff:
const char * pStr = "010B000304140601000000";
WriteFile(HD,(LPVOID) pStr , strlen(pStr),&Bytes,NULL);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
modified on Friday, May 16, 2008 10:49 AM
|
|
|
|
|
iayd wrote: char *wFile = new char[22];
wFile points to an address that can hold 22 characters.
iayd wrote: wFile = "010B000304140601000000";
You've now assigned wFile to a different address.
iayd wrote: delete[] wFile;
delete is expecting to delete from the address returned from new , but will fail because wFile points someplace else.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi,
I have a wierd problem that I hope someone here can help me out with. And if I posted in the wrong forum please redirect me.
Anyway, I have a program where I load a Dll, which then loads a bunch of other dlls. I recently did some changes so that the program would support unicode. After the changes I got these wierd problems:
One of the dlls causes a debug assertion failed when loading from it's resource, and another doesn't. They both use the following code:
HRESULT CPictureWnd::LoadResource(WORD wId, LANGID wLangId) {
LPCTSTR sTemplateName = MAKEINTRESOURCE(wId);
HINSTANCE hInst = AfxFindResourceHandle(sTemplateName, _T("GIF_IMAGE"));
HRSRC hResInfo = ::FindResourceEx(hInst, _T("GIF_IMAGE"), sTemplateName, wLangId);
if (!hResInfo) hResInfo = ::FindResourceEx(hInst, _T("GIF_IMAGE"), sTemplateName, 0x409);
...(other code)
return hr;
}
The Dll that manages to call the function uses this code:
CTM_MODULE_API BOOL module_mtype_init(LPMODULE_MTYPE_DATA mtype)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
mtype->pUserData = (_MODULE_MTYPE_USER_DATA*)calloc(sizeof(_MODULE_MTYPE_USER_DATA),1);
mtype->pUserData->m_picIcon = new CPictureWnd;
mtype->pUserData->m_picIcon->LoadResource(IDB_PATHICON,mtype->langId);
return TRUE;
}
And the one who gets the assertion uses this:
CTM_MODULE_API BOOL module_mtype_init(LPMODULE_MTYPE_DATA mtype)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
mtype->pUserData = (_MODULE_MTYPE_USER_DATA*)calloc(sizeof(_MODULE_MTYPE_USER_DATA),1);
mtype->pUserData->m_picIcon = new CPictureWnd;
mtype->pUserData->m_picIcon->LoadResource(IDB_PATHICON,mtype->langId);
return TRUE;
}
I get the debug assertion failes at the following row:
HINSTANCE hInst = AfxFindResourceHandle(sTemplateName, _T("GIF_IMAGE"));
I also get an assertion failure in my dll which loads the other dlls in the following code:
Cctm::Cctm(void)
:m_lock("Cctm::lock")
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_initialized=FALSE;
...other code
CString sFile;
GetModuleFileName(AfxGetResourceHandle(), sFile.GetBuffer(_MAX_PATH + 1), _MAX_PATH);
...other code
}
The last row causes an assertion. If I comment out AFX_MANAGE_STATE(AfxGetStaticModuleState()); things seems to work better, but then it fetches texts from the wrong resource files and I got some wierd krasch.
All this worked before I switched to Unicode. Anyone have any idea of whats going on? I really need to get this stuff to work and I don't understand why it doesn't.
Environment: VS 2003, C++, XP Pro, MFC in shared dll to the program and all the dlls.
|
|
|
|
|
Is it possible one or more pieces might have been missed in the UNICODE conversion?
Another issue might be string sizes, possibly in your _MODULE_MTYPE_USER_DATA structure. If one of the DLL's has that structure with _TCHAR arrays for strings, and the other has char arrays, that would make the structures different sizes, causing all sorts of Bad Things to happen due to buffer overruns.
Did you redeclare your strings as arrays of _TCHAR 's, or do you use CString 's everywhere?
|
|
|
|
|
It's possible that I missed to redeclare some of the char s to TCHAR s and messed up the sizing. Thanks for the tip, I'll have to check on that. But I don't understand why the GetModuleFileName casues an assetion when AFX_MANAGE_STATE(AfxGetStaticModuleState()) is used. As far as I can see that error shouldn't depend on any TCHAR/char mismatch.
Cctm::Cctm(void)
:m_lock("Cctm::lock")
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_initialized=FALSE;
m_session=NULL;
m_sModuleStatus[0]=0;
m_iApprovedModuleStatus = 0;
m_sActivityStatus[0]=0;
m_iApprovedActivityStatus = 0;
m_showCode=TRUE;
m_moduleTypes=NULL;
m_usedDisplayMasks=0;
m_dbinfo=NULL;
std_functions_init();
HINSTANCE l = afxCurrentResourceHandle;
CString sFile;
GetModuleFileName(AfxGetResourceHandle(), sFile.GetBuffer(_MAX_PATH + 1), _MAX_PATH);
Or could it have something to do with the sFile.GetBuffer(_MAX_PATH + 1) ? Could that cause some wierd behaviout now when it's unicode?
|
|
|
|
|
The other possibility is the AfxGetResourceHandle() call. Have you tried stepping into the method with the debugger?
|
|
|
|
|
I tried to do that, I have a vague memory that I've managed to that before, but now the debugger couldn't find any source code, so I had to go to disassembly. Anyway, I managed to figure out that it uses afxCurrentResourceHandle , and when I use it in my code it return null, and thats probably why AfxGetResourceHandle() causes assrt failure.
Isn't AFX_MANAGE_STATE(AfxGetStaticModuleState()) supposed to set me to the right resource?
Do you know how can I get the handle to be a valid handle to my dll?
|
|
|
|