|
Here is a snippet of some documentation I found about this
"
The default implementation performs accelerator-key translation, so you must call the CWinApp::PreTranslateMessage member function in your overridden version.
"
I am intercepting ( in MFC main frame) a user message (WM_ xxx) to initialize my application multiple views and the message gets interpreted by the PreTranslateMessage twice due to the call to
return CMDIFrameWnd::PreTranslateMessage(pMsg);
as implemented by MFC.
I "fixed" it by setting a pass flag so it does not get processed twice.
I am not looking forward to do this for every message I will post to the main frame.
Is that OK?
Thanks for your comments.
Vaclav
|
|
|
|
|
Hi,
I have a use case to validate an path that is given as an input to my application.
I tried to create a file in the path with fopen and added the following check :
FILE *fp= fopen(Input path, "w");
if( fp == NULL)
{
//Invalid path
}
else
{
//Valid path
}
This works well for cases when the input path is invalid or not present.
But in certain cases, when UAC is enabled, a file cannot be created in the C:\Program files location. So in that scenario, if my input path is C:\Program files, fopen doesnt return any error and above code executes the else part, which is wrong.
Can anyone please provide suggestions about this issue?
Sindhu
|
|
|
|
|
How about using PathIsDirectory[^]?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
Thanks. But PathIsDirectory() might not tell me if the user has write access to that path right?
|
|
|
|
|
Ah, you didn't mention that, or i missed it, in which case, sorry. Read this[^], maybe you are hitting the same thing.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
sindhumahe wrote: if my input path is C:\Program files, fopen doesnt return any error and above code executes the else part, which is wrong.
Just for grins, have you tried using fp in the else part?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Perhaps you are simplifying your code example, but the condition of fp == NULL could be true for many more reasons than just invalid path. You might want to make a call to GetLastError[^]. The returned error number will allow you to detect all manor of error conditions.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Chris Meech wrote: You might want to make a call to GetLastError[^].
Does fopen() call SetLastError() ? I would have thought it would use errno instead.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Good point. I've become so used to calling GetLastError to solve things, but you may be correct that errno could be checked instead.
[EDIT]
And now that I've checked fopen[^] in MSDN, it does set errno. :slaps head:
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
You could be right, too, if fopen() is simply a wrapper around CreateFile() .
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Whenever something is different when UAC is enabled, the first question to ask is "does your application have a security manifest?" and if so, "is it setup properly?"
In a nutshell, the presence of the security manifest will prevent things like "file virtualization" and "registry virtualization" and when setup properly will make your application act like it did before UAC was ever invented (i.e. intuitive when code works and doesn't work and why).
|
|
|
|
|
I have a MFC MDI (logging) application developed in VS2005 in Windows XP which gets logs from another Process(using pipes) and logs them into view. i have a View derived from CEditView. There is so much of logging is done to MFC application for every sec and works good in XP.
when the same application is running in Windows 7. initally it seems to be good but when the logging data is becoming more and more we can se the MFC application is logging data very slowly when compared to XP.
On analysis it was found that operation on Edit Ctrl is making the logging slow
these are the line of code which is making the application slow .
int nLen = GetWindowTextLength();
GetEditCtrl().SetSel(nLen,nLen); // tested GetEditCtrl().SetSel(-1,-1); as well
GetEditCtrl().ReplaceSel(strTemp); // strTemp is the Cstring data which is read from pipe
Is there any better way to make application not to get slow in Window 7 ?
|
|
|
|
|
If this is a logging system why are you using an edit control; do you expect the user to be able to change the content?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Yes and at the same the logs can be saved as File for analysis purposes if at all if there is any issue.
|
|
|
|
|
Well you are stuck with slow processing because as the edit control grows in size it will become slower to manage and display. Using a simple CScrollView would be a much better choice.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks Richard. My MFC Application is very old application which is we are using for years. Dont want to change any class inheritances. except to find an alternative to solve the issue.
|
|
|
|
|
Vijjuuu. wrote: Dont want to change any class inheritances.
Well I'm afraid you are stuck with the problem, unless you can figure out some way to speed up your edit control updates.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Yes i am stuck Thanks for your time for replying.
|
|
|
|
|
As an alternative, 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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks David. My MFC Application is very old application which is we are using for years. Dont want to change any class inheritances. except to find an alternative to solve the issue.
|
|
|
|
|
Another solution might be to separate the logging from the data acquisition. In other words, instead of receiving data from the pipe(s) and immedialtely log it to a control, how about adding the data to some type of container (e.g., string, vector, list) and let the edit control update itself from that container in a separate thread?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Ya i tried that as well but that making my application more slow
|
|
|
|
|
Hi All,
I am using shared memory functions, to write data into file.
Problem:
When I want to write the buffer 10MB, to file using below function, i am able to write only in first iteration, second iteration i could not write buffer next part in to memory. please help me if any suggestion. or any wrong in the below code. i have only control on this part. i dont have control in other part which has CreateFileMapping.
any thing i need to change in "dwFileOffsetLow" or "dwFileOffsetHigh". from second iteration onwards the
"MapViewOfFile" returning null. Some place i got input as I need to repeate call MapViewOfFile different ranges. But how to call, any help?
WriteBuffer function i defined as follows:
BOOL CWriter::Write(char* pMemName,char* pBinary,long lBuffSize)
{
long lUnitSize = MEM_UNIT_SIZE;
if( lBuffSize <= 0 && lUnitSize <=0 )
return FALSE;
HANDLE hFileMMF = OpenFileMapping(FILE_MAP_WRITE,FALSE,pMemName);
if(hFileMMF == NULL)
{
DWORD dwErr = GetLastError();
return (FALSE);
}
int nCount = 0;
nCount = (int)(lBuffSize / lUnitSize) + 1;
for(int n =0; n<nCount; ++n)
{
DWORD dwFileOffsetHigh = 0;
DWORD dwFileOffsetLow = lUnitSize*n;
LPVOID pViewMMFFile = MapViewOfFile(hFileMMF,
FILE_MAP_WRITE,
dwFileOffsetHigh,
dwFileOffsetLow,
MEM_UNIT_SIZE);
if( pViewMMFFile == NULL )
return (FALSE);
CMutex mutex (FALSE, _T("MIPSMMMutexWriter"));
CString strTemp;
strTemp.Format("%s",pBinary);
mutex.Lock();
try
{
CopyMemory(pViewMMFFile,pBinary,lUnitSize); }
catch(CException e)
{
DWORD dw = ::GetLastError();
TRACE1("%d",dw);
}
mutex.Unlock(); UnmapViewOfFile(pViewMMFFile);
}
return (TRUE);
}
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
modified 10-Nov-11 0:02am.
|
|
|
|
|
Probably your MEM_UNIT_SIZE is not a multiple of the page size, which is required[^] by MapViewofFile.
You can determine the page size of the current system by calling GetSystemInfo[^] and retrieve the dwPageSize member.
Helped?
modified 10-Nov-11 5:32am.
|
|
|
|
|
Thanks for your reply.
Hi I tried the same way, and changed approach. Added for loop, and used getsysteminfo and assigned the granularity at unitsize place. But first time the mapview was success and memory copy also success.
In second iteration it is just failing.
modified code as follows...
GetSystemInfo(&systemInfo);
dwGranularity = systemInfo.dwAllocationGranularity;
....
for( int n = 0; n < nCount; ++n )
{
if(n+1 == nCount)
dwLength = lBuffSize - n*dwGranularity;
pViewMMFFile = MapViewOfFile( hFileMMF,
FILE_MAP_WRITE,
dwOffsetStart,
dwOffsetStart + dwGranularity,
dwGranularity);
...
Granularity is getting as 65536, and the output of GetLastError is 5.(AccessDenied).
Nice talking to you. If you judge people, you have no time to love them. -- Mother Teresa
modified 15-Nov-11 3:37am.
|
|
|
|