|
In short, the first declaration is C and the second is C++. Actually you can use the second form of declaration in C, but then you must repeat the struct keyword in every definition using the type.
|
|
|
|
|
|
I'm having trouble figuring out how to save data to a disk in a MFC dialog app project. Normally when I do this, I'm using the SDI or MDI framework which does all serialization and file handling and all I do is make my data serialize itself when the framework requests it.
Unfortunatly dialog apps aren't as user friendly for me at least when it comes to this. Most of the stuff I've been able to find deal with SDI or MDI. If anyone can point to a resource that will allow me to do this I would appreciate it.
Thanks in advance friends.
|
|
|
|
|
serialization is pretty much up to you, when you're outside the Doc/View world. but, it's pretty easy to do. you can create a CFile object for the data, attach a CArchive object to it, then use the same old "<<" operations to write your data.
you'll have to provide your own file open dialogs, and you'll have to track the "modified" flag yourself, too. but that's all easy.
-c
Aiei i ea eio aoa i e eio e aigoa
|
|
|
|
|
Chris Losinger wrote:
you can create a CFile object for the data, attach a CArchive object to it, then use the same old "<<" operations to write your data.
Do you know of anyplace that has demos of this? I checked msdn, but it is only the Doc/view stuff.
|
|
|
|
|
here's something i use for one of my apps:
BOOL CMapFile::Write(const char *csFileName)
{
CFile theFile;
try
{
if (!theFile.Open(csFileName, CFile::modeWrite | CFile::modeCreate))
{
return FALSE;
}
}
catch (CException *e)
{
e->ReportError();
e->Delete();
return FALSE;
}
BOOL bOK = TRUE;
CArchive archive(&theFile, CArchive::store);
try
{
archive << m_csVersion;
m_data.Serialize(archive);
archive.Close();
}
catch (CException *e)
{
e->ReportError();
e->Delete();
bOK= FALSE;
}
catch (...)
{
bOK= FALSE;
}
theFile.Close();
return bOK;
}
inside the 2nd try/catch, i'm doing your standard archive stuff. everything around it is setup and cleanup. reading is almost identical.
-c
Aiei i ea eio aoa i e eio e aigoa
|
|
|
|
|
|
Is there any way to know the session id of a given process ?
thanx
|
|
|
|
|
the function CDC::LPtoDP
logical unit is used in case of a view. But, i don't know what the meaning of physical unit is.
for ex: LPtoDP(CPoint(0, -850)) returns the constant result (0, 540) when using MM_LOENGLISH. So, what is the screen coordinate?
there are 3 levels of coordinates: logical, physical, "?"??
thank you in advance.
|
|
|
|
|
The device points are determined by the physical size and resolution of the display device (which can be the monitor or the printer, for instance). The logical points are measured in the scaled units you define yourself by means of the mapping mode and calls to SetWindowExt/SetViewportExt (and related functions, se MSDN).
Do not confuse with client/screen coordinates: Client coordinates are relative to the client area of your window, screen coordinates are relative to the screen (and not your window).
In your example, LPtoDP will yield the same result until you change the mapping mode or the scaling.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
is there any difference between minimize and switch off between applications'windows?
for example, a document/view application has an extra dialog box loaded in the CMainFrame::OnCreate(). it is an modeless. i make it the top-level window. i use WM_ACTIVATEAPP to force the dialog to hide on minimizing the main window. When debugging, i realize that there are 2 time at which the OnActivateApp is called. WHy?
if the dialog is hidden when being minimized, it will be still hidden (showwindow(SW_HIDE)) when being maximized. BUT, there are some cases in which it is shown!!!! despite showwindow(SW_HIDE) statement. Can you explain it for me?
thank you in advance
|
|
|
|
|
I have an MFC program (view are derived from CFormView) with some validations done in the OnKillFocus() event handlers for each control on the form. If an error is detected, I display a MessageBox(). When someone hits the Ok button on the MessageBox(), the OnKillFocus() event is repeated again! and Again. and Again. until a stack overflow occurs. The only way I can figure out how to prevent this recursive thing is to have a static bool at the top of the function and use it something like shown below. Anyone have a better method of dealing with this problem?
void MyForm::OnKillFocusLastName()
{
static bool bInside = false;
if( bInside == false)
{
bInside = true;
// blabla
if(m_ctrlLastName.GetWindowTextLength() == 0)
{
MessageBox("Last name cannot be empty","Error",MB_OK | MB_ICONSTOP | MB_TOPMOST);
m_ctrlLastName.SetFocus();
}
bInside = false;
}
}
|
|
|
|
|
You could use PostMessage (not SendMessage) with some (WM_APP + n) identifier. The message would travel through message queue. EN_KILLFOCUS processing would be completed before executing handler for posted message.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Hello,
I'm trying to sort a list of file by name with IShellFolder::CompareIDs. I noticed that the order is not exactly like Windows Explorer. For example, Windows Explorer list "-!!!abc.jpg" first but CompareIDs put "!a.jpg" first. Any idea?
Thanks,
Hiusing
|
|
|
|
|
Hi,
I have a really tough problem relating to MFC and DLL. I have developed a MFC Dll that displays a dialog when it is called by a MFC MDI application. What I did was that first I dynamically created a button on the SDI toolbar by passing the toolbar pointer to the Dll. Then I clicked on the button and a modeless dialog poped up. The modeless dialog contains a 'CMonthCalCtrl' calendar control, an 'insert' button, and a 'cancel' button. When I clicked on the 'insert' button, the Dll should insert the selected date into an already opened MDI edit view. However, I have no idea how to bridge the gap between the MDI view and the Dll (i.e. I do not know how to pass back the date to the view). I have tried to search for related resource on the net but gained no clue and I need the solution desperately.
You have any neat solution??
Thanks in advance.
leonwoo
|
|
|
|
|
Pass in whatever function you call from the DLL a reference to a variable. In the DLL, assign whatever you want to that variable, which in this case is a date.
Kuphryn
|
|
|
|
|
Thanks for the prompt reply. Another question is how do I detect button click from the dialog? I need to insert the date into the view whenever i click on the 'insert' button. The MDI application somehow has to detect the button click and then return the reference variable.
thanks.
leonwoo
|
|
|
|
|
I would pass the handle of the view to the dialog and then send a private message to the view from the dialog. In the LPARAM I would pass the relevant information. If your data does not fit into the four bytes I would use an automatic structure to hold the data and call SendMessage. Do not allocate the struct with new in the dll and delete it with delete in the main app, that will corrupt the heaps.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I am new to using the appwizard with the "Windows Explorer" option for how it looks.
I have set up my tree view on the left hand side and that is working fine. Including adding and removing branches of it.
The issue I am having now is getting the right hand List to change what it displays according to what is selected in the tree view.
Can anyone out there point me in the right direction. Or show me a relevant example.
It is very much appreciated.
|
|
|
|
|
You need to add a handler to the CLeftView Class (the one controlling the tree list)
void CLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult);
This gets called whenever the selected item in the tree changes...
Then use "CDocument::UpdateAllViews" to let the other views (the right hand) know about the change.
/sad joke alert.../
Its just a matter of letting the right hand know what the left hand is doing...
Blade[DMS]
|
|
|
|
|
I have a CListCtrl that is dynamically created. I am trying to add the columnclick event to it, but it doesn't seem to work. Any ideas why? this is what I am doing? Another question I have is how do you tell OnColumnClick which control you are refering to? I noticed that there are not IDs passed to it.
in my .h I have this:
//{{AFX_MSG(CFileView)
...
afx_msg void OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult);
...
//}}AFX_MSG
in my .cpp
BEGIN_MESSAGE_MAP(CFileView, CListCtrl)
//{{AFX_MSG_MAP(CDetailsView)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDoubleClick)
//}}AFX_MSG_MAP
void CControllerSelection::OnColumnClick(NMHDR * pNMHDR, LRESULT * pResult)
{
NM_LISTVIEW * pNMListView = (NM_LISTVIEW*) pNMHDR;
m_ControllerList.SortItems(CompareFunc, pNMListView->iSubItem);
*pResult = 0;
}
|
|
|
|
|
First of all, decide if you're using CFileView, CControllerSelection or CDetailsView.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
I'm having trouble with my MFC applications. Recently I've moved my projects from using the old Visual Studio 6.0 to Visual Studio .NET. I've also changed my operating system from Windows 2000 to Windows XP.
However, after I re-compiled and re-distributed my projects in Visual C++ .NET, I was informed by many of my clients that the applications will not open on their platforms (which they do not have Visual Studio installed). The errors being that there are several DLL files missing, including mfc70.dll and msvcr70.dll and a few others. I've tried to include those DLL files in the distribution packages, but that will increase the size of packages from less than 100K to over 1M. I've also tried to build my application using MFC in a static library instead of in a shared DLL. But that will still increase the size of my applications significantly.
But even with the above solutions, there are still problems. While my applications open on my clients' platform, some of the functionalities are loss (for example, the CFileDialog class doesn't work anymore).
This should be a common problem for many developers, I wonder if there's a better solution. Most of my clients are using Windows 2000 and Windows 98. Only a few of them are using Windows XP.
Thank you to anyone who can give me some advice.
J.
|
|
|
|
|
these are just the problems we gladly accept, in order to use the latest goodies from MS.
i always build with MFC statically linked, to avoid these kinds of problems. yes, it will increase the app size, but the app won't break when someone decides to change their version of the MFC DLLs.
1M really isn't that big. distributing a .Net app, now that's a big install package. but 1M will still fit on a floppy - no big deal.
not sure about the CFileDIalog problem. i haven't seen that one yet.
-c
Aiei i ea eio aoa i e eio e aigoa
|
|
|
|
|
I too am finding the same problems as "theorion16"
I don't necessarily agree that we should put up with a 1MB distributable when we can do the same reliably with a 100K distributable. Especially if dealing with certain apps that are widely distributed via the net/email etc...
I am in the process of finding a way to link a VC.NET app to older MFC DLL's.
Will post results when found.
Rick Eastes.
------------
|
|
|
|