|
Use the named mutex method.
This is by default unique per session unless you prefix "Global\" to the mutex name.
|
|
|
|
|
I think you can make your class as singleton by making you contructors and destructor as private and publically expose a static method which will return the same instance once an instance is created. That shud take care of your problem.. Google for singleton class examples ..u will get loads of them ..
-Kushagra
|
|
|
|
|
The singleton pattern is not applicable in this case: its purpose is to have a unique instance of an object for each process.
If you have two or more different instances of the same application, each of them runs on a different process with its own address space, then two applications cannot share the singleton object.
Cheers,
Sauro
|
|
|
|
|
another way, if you are certain about the window caption, is to use FindWindow() API to search for already running application. To make it unique, you may use your own name for your window class, and use it in FindWindow().
|
|
|
|
|
I've used FindWindow before, but I remember it had a lot of issues, for example (I don't remember) but didn't it fail if the window was minimized?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
no.. you can find out minimized windows also.
|
|
|
|
|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi,
I am getting active view (say AV1) attached with main window (MainFrame) using GetActiveView, some other views are member of Av1 view.
If I use GetActiveView() just after initialzation of winow I am getting correct view.
But If I click of some another view then I am not getting Av1 view.
How to get same view at both instance?
|
|
|
|
|
john5632 wrote: But If I click of some another view then I am not getting Av1 view
That is correct, GetActiveView() returns "A pointer to the current CView . If there is no current view, returns NULL .", as described here[^].
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I have drived a class from CStatic control. I am using my own method to set text CMyStatic::SetText().
I am drawing text using
dc.DrawText(strText,&rectWnd,DT_VCENTER| DT_RIGHT | DT_WORDBREAK);
in paint method but If I want to set another string It is getting overlapped. So I am not able to see the extact string.
How to solve this refreshing problem?
|
|
|
|
|
From where do you get the strText? The problem might be because the underlying CStatic controls window text is set (and drawn). In your SetText(), you might have to clear this by calling SetWindowText(_T("")).
Depending on what you mean by overlapping, another reason could be that your rectangle isn't large enough to fit the text, in which case you can use the flag DT_CALCRECT to get the size needed.
|
|
|
|
|
I am passing text from outside using SetText function.
This static control is drawn over a custome dialog which is having some color, If I use SetWindowText(_T()) I am getting window native color.
Overlapping means , One test is drawn on anothet text.
I am giving enough size to draw.
|
|
|
|
|
|
Are you erasing the background properly when your control is refreshed?
|
|
|
|
|
|
I am trying to decalare a CArray in side a CMap
CMap<CString,LPCSTR,CArray,&CArray> m_abc
But I get error C2955: 'CArray' : use of class template requires template argument list
Can you please help me!
Thanks
|
|
|
|
|
Try something like this:
CMap<CString,LPCTSTR,CArray<int,int>,&CArray<int,int>> m_abc
Please note:
the collections (nested - especially) can be faster and lower priced,
when they use the pointers inside, not the instances...
virtual void BeHappy() = 0;
|
|
|
|
|
I tried
CMap<CString,LPCTSTR,*CArray<CString,LPCTSTR>,&CArray<CString,LPCTSTR>> m_abc;
I get error C2275: 'CArray<TYPE,ARG_TYPE>' : illegal use of this type as an expression
|
|
|
|
|
And now ? :
CMap<CString,LPCTSTR,CArray<CString,LPCTSTR>*,CArray<CString,LPCTSTR>*> m_abc;
CMap<CString,LPCTSTR,CStringArray*,CStringArray*> m_abcd;
virtual void BeHappy() = 0;
|
|
|
|
|
why don't you simple put the CArray inside another class ? Me think it will make thing easier in the long run.
Watched code never compiles.
|
|
|
|
|
You can't write:
CArray myArray;
and expect it to compile without without telling it what you want to put in your array. You have to write something like:
CArray<int> myIntArray;
So the question is what type of data are you trying to store in your nested CArrays? Once you know that you can explicitly specify the type of your data in CMap. When you've done that you'll probably run into trouble because CArray hasn't got a copy constructor and I think the types supplied as arguments to CMap need to be copy constructable.
As a complete aside, how about binning this last century MFC collection class rubbish and use the standard library classes std::map and std::vector? They can do what you want with much less farting around than MFC.
Cheers,
Ash
PS: Thanks for Paul below pointing out the faux pas in the original post!
modified on Saturday, September 25, 2010 7:05 AM
|
|
|
|
|
Ash, I'm sure you meant:
CArray<int> myIntArray ...Though this syntax might be an interesting proposal for the 'central comitee' Otherwise I completely agree with the preferable usage of the std elements. My experience shows that an investment into refactoring code which uses custom (own or other non-standard) containers pays off really quickly...
|
|
|
|
|
Thanks for spotting the error, I should never write code without pairing these days!
Cheers,
Ash
|
|
|
|
|
Hi guys, I am writing project for bank operation in MFC, before running my application i have to check the username and password. But i have some problem in my code, my main frame window is closed after enter username and password.Any one tell me the reason.....
class CLoginDialog : public CDialog
{
};
CBankFrameWnd : public CFrameWnd
{
};
class CBankApp : public CWinApp
{
public:
CBankApp();
~CBankApp();
BOOL InitInstance();
};
CBankApp::CBankApp
{
}
CBankApp::~CBankApp()
{
}
BOOL CBankApp::InitInstance()
{
CLoginDialog *pDlg = new CLoginDialog();
m_pMainWnd = pDlg;
if(pDlg->DoModal() == IDOK)
{
if Valid User then assign frame window in m_pMainwnd and return TRUE ...
CBankFrameWnd *pWnd = new CBankFrameWnd();
m_pMainWnd = pWnd;
pWnd -> ShowWindow(m_nCmdShow);
pWnd -> UpdateWindow();
return TRUE;
}
else
return FALSE;
}
Thanks in Advance
|
|
|
|
|
Maybe the constructor of the window does not create it ?
virtual void BeHappy() = 0;
modified on Friday, September 24, 2010 2:19 AM
|
|
|
|