|
Hello,
I want to link my application with a file extension.
I already make it works, but each double-click on a my file make a new instance of my program.
It is possible to make an unique session and get a windows message or else to open my file as i want to?
My project is a CDialog based.
Thanks.
|
|
|
|
|
There are many ways of doing it - searching for "single instance" on CodeProject will yield several articles - here's one[^] for example.
|
|
|
|
|
Member 4020995 wrote: It is possible to make an unique session...
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
I've found everything i need, and it works just fine
Thanks to your both answers.
|
|
|
|
|
hi guys,
i am developing a simple worm scanner using VC++ 2008 pro. when the user click on scanning type ( Lets say Auto Scan ) from the main form, the program need to open the auto scan form. My question will be how can i close the main form and open the auto scan form.
i added the button to be click but i dont know the command to close current form and open the autoscan form. i try to use system::windowsform::autoscan; but its showing system is not declared and i added using namespace System to the .h file. yet its showing systme does not exist in namespace.
Kindly help me please.
|
|
|
|
|
Closing the main form ends the process.
So I would recommend hiding the main form and then showing the sub form.
After the sub form is closed you can either show the main form or close it.
«_Superman_»
|
|
|
|
|
but how to call the sub form.. i having problem with calling the sub form.
Thank you.
|
|
|
|
|
Have look at the following discussion from a few days ago:
http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=2898321[^]
The actual question took a little decoding, but hopefully the answers will help you a bit!
They're based on MFC's CDialog, but hopefully the approach will help you.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
i am facing a new problem now...
void Spartamenu::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
//OnCancel();
}
even after i disable the onCancel and run it. when i click on the button its still closing the application.
________________________________________________________________________
void Spartamenu::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CDialog::SetTimer(IDD_AUTO,1,NULL);
}
for open a subform i use this command but when i click on it nuthing happen...
i am so confused.. kidly help me plz ya..
|
|
|
|
|
OnCancel and OnOK are slightly special - other commands need to be in the message map, but not for IDOK / IDCANCEL.
If you look in the documentation for CDialog::OnCancel, you'll see that it is a virtual method.
So, override OnCancel, and make it do nothing.
ie:
void SpartaMenu::OnCancel ()
{
}
I do this for my modeless dialogs - in fact I have an overriden base class for them all (CModelessDialog ) that does this, so I don't have to remember each time.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
ok.. so hows i should call the other form..
Below is the coding for the first form and second form.. i need to call the form 2 from this form when i click Button1. help me plz...
______________________________________________________________________
Form 1
// Spartamenu.cpp : implementation file
//
#include "stdafx.h"
#include "Sparta.h"
#include "Spartamenu.h"
IMPLEMENT_DYNAMIC(Spartamenu, CDialog)
Spartamenu::Spartamenu(CWnd* pParent /*=NULL*/)
: CDialog(Spartamenu::IDD, pParent)
{
}
Spartamenu::~Spartamenu()
{
}
void Spartamenu::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Spartamenu, CDialog)
ON_BN_CLICKED(IDCANCEL, &Spartamenu::OnBnClickedCancel)
ON_BN_CLICKED(IDC_BUTTON1, &Spartamenu::OnBnClickedButton1)
END_MESSAGE_MAP()
void Spartamenu::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
OnCancel();
}
void Spartamenu::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
CDialog::SetTimer(IDD_AUTO,1,NULL);
DestroyWindow();
}
____________________________________________________________________
Form2
// Auto.cpp : implementation file
//
#include "stdafx.h"
#include "Sparta.h"
#include "Auto.h"
// Auto dialog
IMPLEMENT_DYNAMIC(Auto, CDialog)
Auto::Auto(CWnd* pParent /*=NULL*/)
: CDialog(Auto::IDD, pParent)
{
}
Auto::~Auto()
{
}
void Auto::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(Auto, CDialog)
ON_BN_CLICKED(IDCANCEL, &Auto::OnBnClickedCancel)
ON_BN_CLICKED(IDOK, &Auto::OnBnClickedOk)
ON_LBN_SELCHANGE(IDC_LIST1, &Auto::OnLbnSelchangeList1)
END_MESSAGE_MAP()
// Auto message handlers
int Auto::DoModal()
{
}
void Auto::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
OnCancel();
}
void Auto::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
OnOK();
}
void Auto::OnLbnSelchangeList1()
{
// TODO: Add your control notification handler code here
}
_____________________________________________________________________
|
|
|
|
|
Please read the other Q&A session I linked you to. I gave the answer to an identical question there. And it's too long to type again.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Hi all,
How can I know the number of lines of my file, and I want to read any perticular line ?
plz gv me solution..thx
|
|
|
|
|
There is no specific API for getting the number of lines in a file. you need to write your own code for that.
And what do u mean by saying "read a perticular line"?
|
|
|
|
|
ok...I meant, I want to read only 10 and 12 number lines from the file.
|
|
|
|
|
CStdioFile will be better to use... with that you can read line by line.
- ns ami -
|
|
|
|
|
As already suggested by ns ami, CStdioFile is a better choice, since it provides the ReadString [^] method (to read the file line by line).
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
[My articles]
|
|
|
|
|
By using CStdioFile prob is solved....thnx a lot
|
|
|
|
|
Hi,
I want to append a line to file i tried like this:
CString strNewWord (_T(" Test line to write"));
CStdioFile file;
file.Open(strSystemPath,CFile::modeWrite|CFile::modeNoTruncate,NULL);
file.SeekToEnd();
CString strWriteData("\\n ");
strWriteData+=strNewWord;
file.WriteString(strWriteData);
file.Close();
this code appends data but in single line (assume no compile time errors):
\n Test line to write\n Test line to write\n Test line to write
I want like this:
Test line to write
Test line to write
Test line to write
|
|
|
|
|
Looking at the documentation[^](gasp), it says "Any newline character in lpsz is written to the file as a carriage return–linefeed pair".
I can never remember whether \n or \r is a newline character, and which is linefeed - so try either single stepping into the WriteString command and looking, or guess and try \r .
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Iain Clarke wrote: I can never remember whether \n or \r is a newline character
On windows none of them (the sequence \r\n is newline), see, for instance http://en.wikipedia.org/wiki/Newline[^].
I suppose that 'any newline' means \r or \n or \r\n (but I didn't make a test).
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
[My articles]
|
|
|
|
|
That's why I'd step in and get an authoriative answer! I don't trust me either.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Please don't trust me: from the same article:
To facilitate the creation of portable programs, programming languages provide some abstractions to deal with the different types of newline sequences used in different environments.
The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:
1. Each of these escape sequences maps to a unique implementation-defined number that can be stored in a single char value.
2. When writing a file in text mode, '\n' is transparently translated to the native newline sequence used by the system, which may be longer than one character. (Note that a C implementation is allowed not to store newline characters in files. For example, the lines of a text file could be stored as rows of a SQL table or as fixed-length records.) When reading in text mode, the native newline sequence is translated back to '\n'. In binary mode, the second mode of I/O supported by the C library, no translation is performed, and the internal representation of any escape sequence is output directly.
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
[My articles]
|
|
|
|
|
crazy_sam wrote: CString strWriteData("\\n ");
....
\n Test line to write\n Test line to write\n Test line to write
Of course, it does exactly what you told it to do....
Hint: double backslashes.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi all,
In my vc++ application I am performing some operations using the Registry functionality but in Vista , registry virtualisation is coming in to picture and is creating the keys in virtual store instead of the path which i gave.I have gone through some of the material on this topic and found that if the user is not an admin then this will happen.But for my laptop I am holding the admin previlages then how come I am not able to create the keys in the correct location.
Thanks in Advance.....
|
|
|
|