|
Move all WM_PAINT code to WM_ERASEBKGND? or what?
|
|
|
|
|
Yes. Since you are painting a custom background color, do it in WM_ERASEBKGND.
--Mike--
http://home.inreach.com/mdunn/
We've secretly replaced the msdn.microsoft.com servers with Atari 800XLs. Let's see if anyone notices....
|
|
|
|
|
>We've secretly replaced the msdn.microsoft.com servers with Atari 800XLs. Let's see >if anyone notices....
I thought MSDN online seemed a bit quicker than normal!
|
|
|
|
|
Micahel is absolutely right, but I'll also point out that when you call CPaintDC the screen is blanked, so if you ever have to draw anything in OnPaint and have trouble with flicker, don't create your PaintDC until you're about to copy the memDC over the top of it. Otherwise you may stop tearing, but you won't do a thing about flicker.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I don't understand this piece of code...
Where do you get CMemDC from? I don't have it?
Also, why are you not calling BitBlt to eliminate flickering?
Thx,
/Tommy
|
|
|
|
|
Hello,
Im having some troubles with CString commands.. I have a text file that I am opening with CFile and reading into a CString called strSource... There is a line in the text file like this for example (This is a line in line of text in my "text file" test test) ..
Im trying to search the CString strSource and find "my" then pull the information out of the "" just to the right of "my".. so that I end up with a string with a value of "text file".. in this text file "my" is a unique line of text..
Thanks in advance for you help!
Rob
Rob Jones
|
|
|
|
|
Nothing terribly difficult about it
int nMyIndex, nFirstQuoteIndex, nSecondQuoteIndex;
nMyIndex = strSource.Find ( _T("my") );
nFirstQuoteIndex = strSource.Find ( '"', nMyIndex );
nSecondQuoteIndex = strSource.Find ( '"', nFirstQuoteIndex+1 );
CString strFilename = strSource.Mid ( nFirstQuoteIndex+1, nSecondQuoteIndex-nFirstQuoteIndex-1 ); Naturally, error-checking would be a Good Thing to add to this.
--Mike--
http://home.inreach.com/mdunn/
We've secretly replaced the msdn.microsoft.com servers with Atari 800XLs. Let's see if anyone notices....
|
|
|
|
|
|
Does anyone know of a simple way to ensure that an application has only a single instance running?
When the app is clicked again the running instance should be restored and activated. I am doing all this now with an event and a background thread. It works fine but I seem to recall that there is a simpler way of doing this and I can't find it anywhere.
Apropos, is it possible to send a windows message, like WM_SHOWWINDOW, between applications rather than within an application?
By the way I have no problem getting the PID or the window handle if they are needed for the solution.
Have Fun all.
|
|
|
|
|
Re Q1:
In 16 bit windows, which was an 'all one process' affair, you could check the hInstance param passed to the entry fn to do this.
Nowadays, the de jure standard is to use shared memory - a named memory mapped file (see CreateFileMapping and MapViewOfFile ) that the app creates on startup - if it already exists, exit, perhaps passing control to the first instance.
There was an excellent intro to this stuff in Jeff Prosise's Wicked Code MSJ November 1998.
A background thread approach sounds interesting though.
|
|
|
|
|
and remember we went through the mutex idea here a whiles ago
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
This is the way I've done it for about 100 years now, works like a charm :
// Global declaration in CWinApp:
LPCTSTR lpszUniqueClass = _T("MyUnigueClassName");
CMyWinApp::OnInitInstance()
{
// Check status of class name...
if( DoIExist())
{
return( FALSE );
}
.
.
.
// Register our unique class name that we wish to use
WNDCLASS wndcls;
.
.
.
// Specify our own class name for using FindWindow later
wndcls.lpszClassName = lpszUniqueClass;
// Register new class and exit if it fails
if(!AfxRegisterClass(&wndcls))
{
TRACE("Class Registration Failed\n");
return FALSE;
}
.
.
.
}
BOOL CMyWinApp::DoIExist()
{
CWnd *pWndPrev, *pWndChild;
if(( pWndPrev = CWnd::FindWindow(lpszUniqueClass, NULL ) ))
{
if( pWndPrev->IsIconic() )
{
// If iconic, restore the main window
pWndPrev->ShowWindow(SW_RESTORE);
}
// if alive, does it have any popups?
if(( pWndChild = pWndPrev->GetLastActivePopup()) != NULL )
{
pWndChild->SetForegroundWindow();
}
return TRUE;
}
return FALSE;
}
|
|
|
|
|
Hi!
I tried your example, but failed to get the result. the AfxRegisterClass() always returns false. DO you know why?
I use appWizard to make my dialog base application
Thank You very much
Vu
vucsuf
|
|
|
|
|
This is where the answer is:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q243953
I found this out after failing to ask for help on this forum. I guess there are more than 1 way to do it. It just happened to me that all the solutions provided by this forum does not work for me at all.
Vu
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q243953
vucsuf
|
|
|
|
|
Great ideas but just as much work as my original. Pity that hInstance is not atomic across multi-cpu systems but that's asking a lot.
Here is my solution for anyone who is interested. I don't think its very elegant but it works.
At the beginning of xxxApp::InitInstance()look for an event.
BOOL CTestApp::InitInstance()
{
// See if an instance of myself is already running
if (( eDoIExist = OpenEvent( EVENT_ALL_ACCESS, NULL,
"YesIExist" )) != NULL )
{
// Yes. There is someone out there. Wake it up.
SetEvent( eDoIExist );
// And get out
return FALSE;
}
// No. I am the first so set up an event.
eDoIExist = CreateEvent( NULL, TRUE, FALSE, "YesIExist" );
..... Later in the init code when the main window (in my case a dialog) is
..... set up
CTestDlg dlg;
m_pMainWnd = &dlg;
// Create a background thread to look for any other instance and send it
// the main window
::CreateThread( NULL, 0, LookForMyself, m_pMainWnd , 0, NULL );
..... At the end of the same source
DWORD WINAPI LookForMyself( LPVOID lpParameter )
{
// Forever
do
{
WaitForSingleObject( eDoIExist, INFINITE );
// This is just a little flashy way of re-activating the running
// instance
((CDialog *)lpParameter)->ShowWindow( SW_SHOWMINIMIZED );
((CDialog *)lpParameter)->ShowWindow( SW_RESTORE );
// Reset and wait for more intruders
ResetEvent( eDoIExist );
} while ( TRUE );
return 0;
}
Thank you all for your responses!
|
|
|
|
|
You could use a mutex to check if you are the first instance, and if not send a app specific message with BroadcastSystemMessage().
(never actually tried it, but i think it should work and be quite a simple solution)
|
|
|
|
|
Maybe the mutex is not even needed, sending the app specific message with BroadcastSystemMessage() and the flag BSF_QUERY and checking the retval might do the trick.
|
|
|
|
|
Great ideas people! I am going to try all of these just to see what works and what don't.
|
|
|
|
|
If you have a custom mainframe class (RegisterWndClass()) you can just do a FindWindow(clasname, window caption) and then send a message to the HWND that gets returned.
Bret Faller
Odyssey Computing, Inc.
|
|
|
|
|
I'm working on an ATL based control with addition of WTL to support a GUI that will operate within the control's client area. The problem I'm having is getting a regular menu bar to operate within the control. Since ActiveX controls can't support a menu bar, I thought I could use a command bar to contain the menu.
WTL provides a CCommandBarCtrl class that seems to handle this very nicely but the resulting menu bar doesn't handle mouse clicks correctly. Basically the menu bar shows up and each menu highlights as I mouse over them, but they do not respond to mouse clicks. Additonally if I use a keyboard shortcut to select the menu, the application freezes with the menu left flashing. Using Spy++, I can see a continuous flood of WM_NOTIFY messages during the freeze.
I have the command bar operating as a child of a CFrameWindowImpl class which is a child of the control's window. It also integrates with several toolbars within a rebar control. Here's how I create the command bar and setup the menu:
m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE, 0, ATL_IDW_COMMAND_BAR);
m_CmdBar.AttachMenu(LoadMenu(_Module.m_hInst, MAKEINTRESOURCE(IDR_MAINFRAME)));
m_CmdBar.LoadImages(IDR_TBARMAIN);
CreateSimpleReBar(ATL_SIMPLE_REBAR_STYLE);
AddSimpleReBarBand(m_CmdBar, NULL, TRUE);
I believe this works fine in a regular application where the command bar is a child of CMainFrame, but it behaves strangely in my control.
Any help would be appreciated.
- Oliver
|
|
|
|
|
Have you added REFLECT_NOTIFICATIONS and DEFAULT_REFLECTION_HANDLER to the message maps?
|
|
|
|
|
I added those macros as you suggested but they had no effect.
Thanks anyway.
|
|
|
|
|
#include <iostream>
What is wrong with the below code, i can never get this to work:
---------
#include <iostream>
using namespace std;
int main()
{
ofstream s;
s.open("file.txt",ios::out);
return 0;
}
-----------
and here are my errors:
's' uses undefined class 'basic_ofstream<char,struct std::char_traits<char=""> >'
Now, I dont know what anyone else thinks but these error messages arent very intuitive... Can anybody see what I am doing wrong, and more importantly give me some pearls of wisdom when it comes to understanding these kind of messages. I often get a different one about basic_string when trying to use std::string's
Any help/advice appreciated!
ben
|
|
|
|
|
Well, I'm not sure if this is the problem or just a typo, but your #include statement isn't including anything. I believe it should be #include <fstream> Hope that helps.
|
|
|
|
|
Oops. These posts are in HTML aren't they. #include <fstream> is what I meant.
|
|
|
|