|
Ive gotten this much. Its a dialog app, I dont know if that matters.
void CCursorCreatorDlg::OnFileSave()
{
CFileDialog fileDlg(FALSE, NULL, "Untitled",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Some Files(*.fil)|*.fil||",
NULL );
fileDlg.m_ofn.lpstrDefExt = "cur";
if( fileDlg.DoModal()==IDOK )
{
CString fileName;
fileName = fileDlg.GetPathName();
CFile file( fileName, CFile::modeReadWrite | CFile::modeCreate );
CArchive ar( &file, CArchive::store );
Serialize( ar );
}
}
void CCursorCreatorDlg::OnFileOpen()
{
CFileDialog fileDlg(TRUE, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Some Files(*.fil)|*.fil||",
NULL );
if( fileDlg.DoModal()==IDOK )
{
CString fileName;
fileName = fileDlg.GetPathName();
CFile file(fileName, CFile::modeReadWrite | CFile::modeCreate );
CArchive ar( &file, CArchive::load );
Serialize( ar );
}
}
void CCursorCreatorDlg::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar << someVariable;
}
else
{
ar >> someVariable;
}
}
I have the DECLARE_SERIAL and IMPLEMENT_SERIAL macros where they should be.
When I save, it seems to work fine. However, when I open, it works until it gets to the serialize function where a messagebox pops up and says "An attempt was made to access an unnamed file past its end." What's that mean and how do I fix it?
-Raffi
The truth about C++
|
|
|
|
|
Rafi,
This error occurs for two reasons:
(1) if you are sacing the file differently than loading it e.g.:
if (ar.IsStoring())
{ // storing code
ar << someVariable;
}
else
{
// loading code, is trying to read a variable that was not saved.
// So obviously you are trying to read past the file and
ar >> someVariable>>anotherVariable;
}
(2) if you are readin/loading a file that was saved by some other program then there is a strong chance that such an error will occurr (again this is related to reason (1)
(3) If you save the data using Serialize(&ar), and load/read the data using ar>> operator then you will again get the mentioned error.
I think your problem is related to category (1). Make sure you are reading exactly the same (and also in the same order) that you wrote.
Normally I simply copy the saving code in the loading block and simply change the << to >>, to avoid any mistake.
-cheers,
kashif manzoor
peace to all
|
|
|
|
|
I am not sure, but in the file open function
void CCursorCreatorDlg::OnFileOpen()
you open the files with the parameters
CFile::modeReadWrite | CFile::modeCreate.
I think, the CFile::modeCreate is wrong in this case, because you want to read the file, and the modeCreate flag resets the file length to 0.
Remove the modeCreate and try again
-Dominik
|
|
|
|
|
|
I need to make a pointer to a constant memory address, but something like this doesn't work:
int *address = &656623;
VC++ Compiler returns:
error C2101: '&' on constant
I know it is possible, but I don't have a clue how to do it... Probably there is a function of some sort that solves this problem, but I couldn't find it.
Thanks in advance
|
|
|
|
|
It'd be something like
int * address=(int *)656623; But you must know very well what you're doing in order to manage such a pointer safely.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Great!
That did the job perfectly. And it's the problem of the user if he changes wrong values...
|
|
|
|
|
How SendMessge for a particular menu click
i.e I want the the menu click on a button click
|
|
|
|
|
|
I'm wondering which class use this control:
http://digilander.iol.it/ilbanca/fuffa/saveasie.jpg
Any help will be appreciated,
Bye.
|
|
|
|
|
It is probably what is normally refered to as the "Outlook shortcut bar"
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Thanks, this helped me much.
And it's not a so new control as I supposed
|
|
|
|
|
You could create something like that from scratch pretty easily actually. Just a standard formview (coloUred with OnCtlColor() ), with some custom-drawn flat style buttons added at runtime. Somebody has probably already done it though, so take a look around CP and related sites.
Simon
"The more I learn, the more I realize I don't know" - Colin Davies
Sonork ID 100.10024
|
|
|
|
|
Mmm... I'll give a try, thank you for the advice.
|
|
|
|
|
NP. Take a look here for a good button set class. It's a bit overkill for one style though. You'll something like;
CCustomButton::OnDraw()
{
if(bHover)
draw_with_border()
else
draw_without_border()
}
Just use a TRACKMOUSEEVENT structure to determine if the cursor is hovering, and change bHover appropriately.
Simon
"The more I learn, the more I realize I don't know" - Colin Davies
Sonork ID 100.10024
|
|
|
|
|
, CButtonST is too much complex for me, I'll try to work on your idea instead, sounds quite easy to implement, thanks again.
|
|
|
|
|
|
I notice that several apps do use of that, the download manager Reget Deluxe also uses it. It's very similiar to a large toolbar vertically aligned...
|
|
|
|
|
I told you about the outlook shortcut bar expecting that there would be 20 articles on them if you did a search. Took me a while to find one or two.
From CodeGuru
From CodeProject
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I try to compile this code...
CoInitialize(NULL);
HRESULT hr;
IActiveDesktop *pActiveDesktop;
//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
pActiveDesktop->SetWallpaper("C:\\Mina dokument\\Mina bilder\\eros15.gif", 0);
// Call the Release method
pActiveDesktop->Release();
CoUninitialize();
... but when compile:
--------------------Configuration: Wallpaper - Win32 Release--------------------
Compiling...
WallpaperDlg.cpp
c:\PROGRAM\MICROSOFT VISUAL STUDIO\MYPROJECTS\Wallpaper\WallpaperDlg.cpp(115) : error C2027: use of undefined type 'IActiveDesktop'
C:\Program\Microsoft Visual Studio\VC98\INCLUDE\COMDEF.H(507) : see declaration of 'IActiveDesktop'
c:\PROGRAM\MICROSOFT VISUAL STUDIO\MYPROJECTS\Wallpaper\WallpaperDlg.cpp(115) : error C2227: left of '->SetWallpaper' must point to class/struct/union
c:\PROGRAM\MICROSOFT VISUAL STUDIO\MYPROJECTS\Wallpaper\WallpaperDlg.cpp(118) : error C2027: use of undefined type 'IActiveDesktop'
C:\Program\Microsoft Visual Studio\VC98\INCLUDE\COMDEF.H(507) : see declaration of 'IActiveDesktop'
c:\PROGRAM\MICROSOFT VISUAL STUDIO\MYPROJECTS\Wallpaper\WallpaperDlg.cpp(118) : error C2227: left of '->Release' must point to class/struct/union
Error executing cl.exe.
Wallpaper.exe - 4 error(s), 0 warning(s)
Exactly WHAT is wrong!!!
The code is from MSDN Library so it should work....
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Did you include "Shlobj.h"?
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Well, first I did include:
#include <comdef.h>
#include <shlguid.h>
#include <shlobj.h>
because it says "undeclared identifier" to IActiveDesktop interface when only including #include <shlobj.h>.
So I did a search and looked after all files on my computer that had a string "IActiveDesktop" in, and included them... but now I get these errors which says undefined bla bla...
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
|
ok, now it works.... almost!
I want to change the background, but the cde doesn't change the background:
void CWallpaperDlg::OnButton1()
{
CoInitialize(NULL);
HRESULT hr;
IActiveDesktop *pActiveDesktop;
//Create an instance of the Active Desktop
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
if(SUCCEEDED(hr))
{
pActiveDesktop->SetWallpaper((LPCWSTR)"C:\\Mina dokument\\Mina bilder\\eros15.gif", 0);
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
}
else
{
AfxMessageBox("Error o Error");
}
// Call the Release method
pActiveDesktop->Release();
CoUninitialize();
}
------------------------------------
<b><I><B>Rickard Andersson</I></B></b>, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|