|
A small thing which you can do is as follows.At the beginning of the
program call a small function say init() which creates a mutex ,if that
mutex already exists that means you have another instance running.
BOOL init()
{
HANDLE mutex = CreateMutex(NULL, FALSE, "mutexname");
if(mutex == NULL)
return FALSE;
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
MessageBox("Another instance is already running.");
return FALSE;
}
return TRUE;
}
|
|
|
|
|
Thanks Rachna. I'll try that.
|
|
|
|
|
Hello
You can use this class [from MSDN]
#ifndef LimitSingleInstance_H
#define LimitSingleInstance_H
#include <windows.h>
class CLimitSingleInstance
{
protected:
DWORD m_dwLastError;
HANDLE m_hMutex;
public:
CLimitSingleInstance(TCHAR *strMutexName)
{
m_hMutex = CreateMutex(NULL, FALSE, strMutexName);
m_dwLastError = GetLastError();
}
~CLimitSingleInstance()
{
if (m_hMutex)
{
CloseHandle(m_hMutex);
m_hMutex = NULL;
}
}
BOOL IsAnotherInstanceRunning()
{
return (ERROR_ALREADY_EXISTS == m_dwLastError);
}
};
#endif
hope this helps
Nish
|
|
|
|
|
How to create a string with the identifier "IDS_STR1"?
I use the following statement to declare IDS_STR1.
#define IDS_STR1 1;
Thanks.
Maer
|
|
|
|
|
Are you talking about the string table in resources?
You can use a string table resource with CString via the LoadString method.
CString sTemp = _T("");
sTemp.LoadString(IDS_STR1)
Michael
|
|
|
|
|
|
CString strWhatever(MAKEINTRESOURCE(IDS_STR1));
or
CString strWhatever;
strWhatever.LoadString(IDS_STR1);
|
|
|
|
|
Hello, the codegurus around the world.;)
We can create the string with IDS_STR1 in the string table of the resource section
in Visual studio.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
|
Any idea to compile some HTML files into one file. especially the pictures.;)
|
|
|
|
|
Open the file with IE5+ and save it as a .mht (something like a multipart email message).
As far as I know you can only open such a file with IE5+, however.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
Hello:
In order to display a bmp Image in a dialog box I created a class named "CImageBox" which was derived from CWnd just like "CStatic". "CImageBox" was created with the style "...|WS_HSCROLL|WS_VSCROLL".
Here comes the problem: How to handle the horizontal and vertical scrollbar?
These are my three unsuccessful experiences:
<1>CWnd::GetScrollBarCtrl() always return NULL;
<2>CView::GetScrollBarCtrl() do not seem to be applicative;
<3>I try to handle WM_VSCROLL in "CImageBox":
void CImageBox::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) ;
The parameter "pScrollBar" is always NULL so I can't use the SetScrollPos() member function.
However "CEdit"(MFC) do well in this,but I can't find the source code of CEdit::GetScrollBarCtrl().
Can anybody help me?
Any advice is appreciable.<shawell2000@163.net>
|
|
|
|
|
You don't need scrollbar controls - any window can display scrollbars which are integral parts of it, just like border or caption.
Use Cwnd methods like Get/SetScrollRange, Get/SetScrollPos, handle WM_VSCROLL/WM_HSCROLL and you'll be OK.
Note that scrollbars will not appear until you set range greater than client area size.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
I'm facing a problem with VC++ ver 6.0(MFC), when ever I try to compile rc file it fails giving fatal error RC1015: Cannot open include file 'afxres.h'. Even if I try to create standard simple dialog based application, while compiling the rc file it fails showing above error,I mean to say VC is failing to build all the applications(VC ver 6.0). I checked the environment variables, thinking there might be problem with environment variables setting, ran vcvars32.bat from "program files\Microsoft visual studio\vc98\bin". Even then it gives the same problem saying, "can not open afxres.h".
If any one knows about this problem, please let me know the solution.
Thanks in advance,
Lakshmi.
|
|
|
|
|
A couple of obvious things to check:
- Is
afxres.h still there? Have a look in C:\Program Files\Microsoft Visual Studio\VC98\mfc\include (or your equivalent) and make sure - Your include paths may not be set up correctly. Check to ensure this directory is on the include path inside the IDE
If all else fails, just re-install VC and the problem should go away.
Andy Metcalfe - Sonardyne International Ltd (andy.metcalfe@lineone.net) http://www.resorg.co.uk
"I'm just another 'S' bend in the internet. A ton of stuff goes through my system, and some of the hairer, stickier and lumpier stuff sticks."
- Chris Maunder (I just couldn't let that one past )
|
|
|
|
|
Hi,
I am trying to generate reports in my VC application using Crystal Reports 7. I have created the .rpt file. Now I need to integrate this file with the VC application. How can I do so?
My object is that report should not be directly printed but first It should be displayed (with all print preview options) and when the user selects print option it then prints to default printer.
Please help.....
Thanks for ur time .....
~Statbat( );
|
|
|
|
|
Hello, the codegurs around the world.;)
I think that you use Crystal Report ActiveX control in VC++ project.
And after you insert Crystal Report ActiveX conrol by type library,
you can use its function to show the crystal report file.
I hope that you know how to insert Crystal Report ActiveX control to your project.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
go to the developer web site
http://www.crystaldecisions.com/products/dev_zone/
They have various VC++ samples that show you how to do this
|
|
|
|
|
I would like to be able to determine if a file or directory exists and then delete it.
File: I use CFileFind to determine if the file exists, but what function can I use to delete it?
Directory: Could use CFileFind but is there a function where I just give it the name and it tells me it exist's or it doesn't. I currently use ::SetCurrentDirectory and see if it succeeds or fails but I don't like this approach. _rmdir deletes the directory is there another function I should use instead?
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
if i'm searching / deleting / copying files i usually use the API - functions, cause they work best for me...
::DeleteFile ... deletes a file
::RemoveDirectory ... removes a directory
::FindFirstFile & ::FindNextFile ...to watchup if there's such an directory / File
hope this can help
Bernhard
|
|
|
|
|
You can use SHFileOperation to delete multiple files
This is useful when a directory is not empty
Once you've emptied the directory you can again use SHFileOperation or
RemoveDirectory to delete that directory
Regards
Nish [BusterBoy]
|
|
|
|
|
Hello,
I am working on an appplication in which i need to open MS-EXCEL application on press of a button.
I am doing it as in the code below. I am using the MS-EXCEL type library classes for this purpose.
My problem is, though EXCEL is opened the menu items are not visible.
_Application app;
_Workbook book;
Workbooks boos;
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if(!AfxOleInit()){
AfxMessageBox("Could not intialize com dll");
return FALSE;
}
AfxEnableControlContainer();
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Failed to create Excel.Application");
return FALSE;
}
app.SetVisible(TRUE);
books = app.GetWorkbooks();
And Then How can i use Excel menu items ?
May you help me?
Cheers
|
|
|
|
|
I have this in one of my applications...I get a Menu...take what you need out of it!
<br />
try<br />
{<br />
_Application app;
_Workbook book;<br />
_Worksheet sheet;<br />
_Chart chart;<br />
<br />
Workbooks books;<br />
Worksheets sheets;<br />
Range range;<br />
ChartObjects chartobjects;<br />
Charts charts;<br />
LPDISPATCH lpDisp;<br />
<br />
COleVariant<br />
covTrue((short)TRUE),<br />
covFalse((short)FALSE),<br />
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);<br />
<br />
if(!app.CreateDispatch("Excel.Application"))<br />
{<br />
AfxMessageBox("Couldn't CreateDispatch on Excel");<br />
return;<br />
}<br />
<br />
lpDisp = app.GetWorkbooks();
ASSERT(lpDisp);
books.AttachDispatch( lpDisp );
<br />
app.SetVisible(TRUE);<br />
<br />
lpDisp = books.Open(csFilename,<br />
covOptional, covOptional, covOptional, covOptional,<br />
covOptional, covOptional, covOptional, covOptional,<br />
covOptional, covOptional, covOptional, covOptional<br />
);<br />
ASSERT(lpDisp);
<br />
book.AttachDispatch( lpDisp );
<br />
lpDisp = book.GetSheets();<br />
ASSERT(lpDisp);<br />
sheets.AttachDispatch(lpDisp);<br />
<br />
lpDisp = sheets.GetItem( COleVariant((short)(1)) );<br />
ASSERT(lpDisp);<br />
sheet.AttachDispatch(lpDisp);<br />
<br />
sheet.Activate();<br />
<br />
lpDisp = sheet.GetRange(COleVariant("A3"), COleVariant("G10000"));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);
range.Clear();
<br />
CString csCellData = _T("");<br />
CString csCell = _T("");<br />
<br />
for(int n=0; n<lc.GetItemCount(); n++)<br />
{<br />
<br />
csCellData = lc.GetItemText(n,0);<br />
csCell.Format("C%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,1);<br />
csCell.Format("A%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,2);<br />
csCell.Format("B%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,3);<br />
csCell.Format("D%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,4);<br />
csCell.Format("E%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,5);<br />
csCell.Format("F%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
csCellData = lc.GetItemText(n,6);<br />
csCell.Format("G%i", n+3);<br />
lpDisp = sheet.GetRange(COleVariant(csCell), COleVariant(csCell));<br />
ASSERT(lpDisp);<br />
range.AttachDispatch(lpDisp);<br />
range.SetValue(COleVariant(csCellData));<br />
<br />
}
<br />
sheet.ReleaseDispatch();<br />
<br />
app.SetUserControl(TRUE);<br />
<br />
book.Save();<br />
<br />
}
catch(COleException *e)<br />
{<br />
char buf[1024];<br />
sprintf(buf, "COleException. SCODE: %08lx.", (long)e->m_sc);<br />
::MessageBox(NULL, buf, "COleException", MB_SETFOREGROUND | MB_OK);<br />
}<br />
catch(COleDispatchException *e)<br />
{<br />
char buf[1024];<br />
sprintf(buf, <br />
"COleDispatchException. SCODE: %08lx,Description: \"%s\".",<br />
(long)e->m_wCode, (LPSTR)e->m_strDescription.GetBuffer(1024));<br />
::MessageBox(NULL, buf, "COleDispatchException", MB_SETFOREGROUND | MB_OK);<br />
}<br />
catch(...)<br />
{<br />
::MessageBox(NULL, "General Exception caught.", "Catch-All", MB_SETFOREGROUND | MB_OK);<br />
}<br />
Thanks in advance,
Dan
|
|
|
|
|
I'm working on a namespace extension that represents documents in a repository. It allows the user to copy or cut the documents and paste them to the file system. I'm basically doing the cut/copy by creating an IDataObject instance on the clipboard which returns a reference to the files in CF_HDROP format.
BUT...in the case of a cut and paste, I need to get feedback that the paste was successful so I know whether or not to delete the document object from the repository. I get a "Paste Successful" via IDataObject::SetData(), but if the file already exists where I'm pasting it, I get a "File already exists - overwrite?" dialog box *AFTER* the "Paste Successful" has already been returned!
Is there a way to verify that the paste has actually occured?
Also, is there a way I can add a handler of some sort to the shell that will allow me to paste documents to the file system that are in a custom clipboard format?
Any help would be greatly appreciated.
Thanks,
Tim
Reverend Shoebox
|
|
|
|
|
Hi,
I'm a newbie to STL and have been on this stuff for all day long,
but failed to implement. Plz help!
---My Situation goes---
Say, there is a string like "SP_CALL(~1,~123,~09,455,21)".
I want to extract numbers after '~' character and store it to some container.
Some like MAP, LIST, ...anything that could be used to restore extracted numbers
for later comparison with other numbers.
I've tried with very basic knowledge of STL, but maybe I'm lack much knowledge.
So..If anyone can show some sample code fragments that implements this,
or can point me to similar code, plz help me.
Also, if there are any good books about STL for beginners, let me know.
Thanks a million.
Regards,
Ryan
|
|
|
|
|