|
Are you sure you provided the smallest amount of code required to understand your problem?
From "How to get an answer to your question":
#4 Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
led mike
|
|
|
|
|
It's not a easy simple C++ Question.
Scott
Scott Dolan
Jernie Corporation
Engineering & Manufacturing
Software, Hardware, & Enclosures
|
|
|
|
|
|
|
Mark Salsbery wrote: See what I've done here?
No, but I can picture you flopping all around inside his boat.
led mike
|
|
|
|
|
|
Mark Salsbery wrote: We need a fish smiley!
That would be so great, I'd ask Chris for one if I thought there was any chance of getting it.
led mike
|
|
|
|
|
Hello. there is the variable app.previnstance in visualbasic 6 to know if the application is already open. How can i do that using Win32 API?
i saw there's a variable in the winmain() function called hPrevInstance, but i do not know how to use it.
Any help would be welcome.
thanks 
|
|
|
|
|
I use a semaphore to detect if there is already an instance of the application running.
Heres what I use:
CString szGuid;
szGuid= _T("Create your own unique GUID here, I used guidgen.exe");
m_hSem=CreateSemaphore(NULL, 1, 1, szGuid);
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
TCHAR szCaption[_MAX_FNAME];
LoadString(m_hInstance,AFX_IDS_APP_TITLE,szCaption,_MAX_FNAME);
CWnd* pwndFirst = CWnd::FindWindow(NULL,szCaption);
if (pwndFirst)
{
CWnd* pwndPopup = pwndFirst->GetLastActivePopup();
pwndFirst->SetForegroundWindow();
if (pwndFirst->IsIconic())
{
pwndFirst->ShowWindow(SW_SHOWNORMAL);
pwndFirst->PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
if (pwndFirst != pwndPopup)
{
pwndPopup->SetForegroundWindow();
pwndPopup->PostMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
}
CloseHandle(m_hSem);
return FALSE;
}
Note that this code will bring the previous instance to the foreground.
Don't forget to CloseHandle(m_hSem) when your application exits.
-Randor (David Delaune)
|
|
|
|
|
|
You cannot use hPrevInstance , the reason why is here.
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
|
|
|
|
|
There's only one way I know of that is bullet proof:
http://www.flounder.com/nomultiples.htm[^]
The other ways may fail if certain conditions are not satisfied. You can the reasons why in the article above.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I am a total stranger to windows service development.
I needed to understand the limitations .
1. Is it possible to have MFC support in Service code?
2. Can I create a hidden window in a Service ?
My basic requirement is to intercept WM_DEVICE_CHANGE notifications to process this message.
Engineering is the effort !
|
|
|
|
|
Yes, you can (1 and 2), you must set the service to be able to interact with the desktop.
Moreover you can use XYNTService (you can easily find it here) in order to use any app as a service.
Hope this helps.
|
|
|
|
|
No need to interact with the desktop for hidden windows.
That's only if you want a user to see the windows, which is really frowned upon
from services going forward with Vista+.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hello,
long title, short story: a rather old third-party library uses the following code to register its own edit control class:
static const TCHAR BASED_CODE szEdit[] = _T("GXEDIT");<br />
WNDCLASS wcls;<br />
if (!::GetClassInfo(hResource, szEdit, &wcls))<br />
{<br />
VERIFY(::GetClassInfo(NULL, _T("edit"), &wcls));<br />
<br />
wcls.style |= GX_GLOBALCLASS;<br />
wcls.hInstance = hResource;<br />
wcls.lpszClassName = szEdit;<br />
<br />
AfxRegisterClass(&wcls);
This works fine unless XP themes are enabled.
If they are and I use GetWindowText(CString-variable) with this edit control, the CString destructor causes a heap corruption because ::GetWindowTextLength reports less bytes than ::GetWindowText actually receives, and thus CString::GetBufferSetLength allocates not enough memory.
Is there a simple solution to change the above code so that this GXEDIT works with XP themes?
I already tried rewriting it using WNDCLASSEX instead, but that didn't help.
adTHANKSvance, Jens
|
|
|
|
|
Are you sure there is such a bug affecting GetWindowTextLength ? I cannot find related info.
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
|
|
|
|
|
Part of this third-party library is a grid control, and the problems occurs when a GXEDIT control is created in-place to edit the contents of a cell.
The cell contains a 4-digit number, and the value returned by GetWindowTextLength is 12.
But only if I discard this value and reserve 25 bytes or more in CString::GetBufferSetLength, the heap doesn't get corrupted.
It's strange, but I think this is only a side effect of some error in the class registration.
If I don't use the XP visual styles for this app (no manifest file), everything works fine.
Other edit controls that are of the systems standard "edit" class type, work ok with or without styles enabled...
Regards, Jens
|
|
|
|
|
Maybe its a Unicode/ANSI issue.
The third party control may be using Unicode. Windows Unicode (UTF-16) uses 2 bytes to represent each character.
Try changing your GetWindowText to GetWindowTextW and see what happens, perhaps you need a CStringW.
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
The control does not use unicode, I have checked that. As I wrote, the problem only occurs if I enable XP visual styles and themes for the application by including a manifest file in the executables directory.
I already tried to write replacements for Get/SetWindowText:
void CGXEditControl::GetWindowText(CString& s)<br />
{<br />
if (IsThemeActive())<br />
{<br />
const int nLen = ::GetWindowTextLengthW(m_hWnd);<br />
CStringW sW;<br />
::GetWindowTextW(m_hWnd, sW.GetBufferSetLength(nLen), nLen+1);<br />
sW.ReleaseBuffer();<br />
<br />
s = sW;<br />
}<br />
else<br />
{<br />
CEdit::GetWindowText(s);<br />
}<br />
}<br />
<br />
void CGXEditControl::SetWindowText(const CString& s)<br />
{<br />
if (IsThemeActive())<br />
{<br />
CStringW sW(s);<br />
::SetWindowTextW(GetSafeHwnd(), sW);<br />
}<br />
else<br />
{<br />
CEdit::SetWindowText(s);<br />
}<br />
}
This prevents the heap corruption, but then the edit control contains a lot of unreadable stuff like arabic letters even though the debugger shows that sW seems to contain a correct string like "1120".
The problem seems to be the registration process of the class GXEDIT.
In CGXEditControl::CreateControl, if I replace the class name "GXEDIT" with the standard "edit" class in the call to CEdit::Create, everything works!
But I don't know what side effects this will have for the rest of the library , so I want to avoid this workaround if possible.
BTW, this library is a very antique version of Stingray's Objective Grid, dated 1997 .
Regards, Jens
|
|
|
|
|
Friends,
Do you have any smart idea to display animated gif on the status bar,
Thax
|
|
|
|
|
you'd better search for using AVIs rather than GIFs...
|
|
|
|
|
|
Search! There's lots of samples out there for rendering animated GIFs.
For example: Adding GIF-animation using GDI+[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|