|
call Invalidate() or InvalidateRect
|
|
|
|
|
The problem ns has is that dc2 has not been assigned to a device context.
You are right however that after drawing you need to invalidate.
Ant.
|
|
|
|
|
You can get the DC at anytime by calling GetDC(). But unless you want the line to be overdrawn the next time the OnDraw() is called then you should just set a flag when the button is pushed and invalidate the area being drawn to.
if( bFlag )
INTP
|
|
|
|
|
The right way to do this is to maintain a data structure that contains a collection of linked points. The data structure is updated in your button's handler. Your view's OnDraw() handler should paint itself (i.e. draw lines) based on the points in the data structure.
See the MFC "Scribble" demo app to see how this is done.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Appreciate the help. Many thanks,
ns
|
|
|
|
|
I've been playing with a CString implementation I found here (Thanks, Joe!)[^] and it collides with another header I use. Compiling my app produces the following warning:
Warning C4065: switch statement contains 'default' but no 'case' labels and points to this section (and another like it) in Joe's StdString.h header:
inline void ssasn(std::wstring& sDst, const int nNull)<br />
{<br />
UNUSED(nNull);<br />
ASSERT(nNull==0);<br />
sDst.assign(L"");<br />
}
I've found UNUSED defined in several ways, in a lot of headers. Here's how it looks in ...\VC98\MFC\Include\AFX.h:
#ifdef _DEBUG<br />
#define UNUSED(x)<br />
#else<br />
#define UNUSED(x) x<br />
#endif<br />
#define UNUSED_ALWAYS(x) x
but in a third-party header I need, it gets defined thus:
#ifndef UNUSED<br />
#ifdef _CVI_<br />
#define UNUSED(a)<br />
#else<br />
#define UNUSED(a) switch((int)&a){default:break;} /* bypass bogus warnings on external compilers */<br />
#endif
It's this last definition that seems to be getting used in the compilation and generates the warning.
Any ideas what this is for? Can I remove the offending references to it without some weird side effect?
Thanks in advance for all your help.
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
It's actually in place to squelch another compiler warning: C4101. A variable was declared, but never used. You can add a #pragma warning(disable:4507) statement if you don't like the C4065 warning.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Thanks, David!
I think you meant disable:4065, but that was enough to overcome my issue.
BTW, why is this sprinkled all over Microsoft's code? Shouldn't one simply remove the reference to the unused variable?
Long Live CodeProject!
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
> Shouldn't one simply remove the
> reference to the unused variable?
It depends. Consider this:
void myfunc1(LPVOID p)<br />
{<br />
ASSERT(p);<br />
}<br />
It's a bit non-natural, but it give you an idea - item can be used in one configuration, but unused in another.
Or maybe this one is better:
void myfunc2(LPVOID p)<br />
{<br />
#ifdef _UNICODE<br />
#else<br />
UNUSED_ALWAYS(p);<br />
#endif<br />
}
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
Jesse Evans wrote:
I think you meant disable:4065, but that was enough to overcome my issue.
You're right. How I got C4507 is anyone's guess.
Jesse Evans wrote:
BTW, why is this sprinkled all over Microsoft's code? Shouldn't one simply remove the reference to the unused variable?
I'm not sure. Have a look at the USES_CONVERSION preprocessor directive. It will declare a variable and then use that variable all by itself in a statement just to keep the compiler from complaining about an unreferenced variable.
There's also the case of unreferenced function parameters. With C++, you can declare a function and omit the names of any unused parameters. With C that was not possible, so inside of the function, you could use the UNUSED() macro to get ride of the C4101 warning. Make sense?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Thanks, Igor and David. Makes sense, now.
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
Hi all,
I need to monitor the NT/2000/XP network environment for files that I have created and files that I have renamed.
I based my program on the FWATCH example of MSDN, i.e., I'm using ReadDirectoryChangesW and IO Completion Port to receive the notification.
The problem is that I also get notified when some other user (not me) creates or renames a file on the directory that I am monitoring.
Is there any way to filter the notifications so that I only get notified when I create or rename files? If not, is there any way to know which user caused the notification?
Thanks.
|
|
|
|
|
LKogut wrote:
Is there any way to filter the notifications so that I only get notified when I create or rename files? If not, is there any way to know which user caused the notification?
When a file is created, you can use GetNamedSecurityInfo() and LookupAccountSid() to see if the current owner of the file is you. Also, if renaming a file causes the owner to change, this will work too.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Thanks David, this will help me for sure!
But, unfortunately, not 100%. Looking for the functions on the help, they only work on an NTFS file system. Any clue for non NTFS file system?
|
|
|
|
|
How do I resize my PropertySheet and all pages based on size of the Main Dialog ?
I derived a class from PropertySheet and tried to implement an OnInitDialog .
Here's what i tried but didnt come out good
BOOL CMainSheet::OnInitDialog() {<br />
CPropertySheet::OnInitDialog();<br />
CWnd *parentWnd = this->GetOwner();<br />
ASSERT(parentWnd);<br />
parentWnd->GetClientRect(&parentRect);<br />
CTabCtrl *pTab = GetTabControl();<br />
ASSERT(pTab);<br />
this->SetWindowPos(0,parentRect.left,parentRect.top,200,200,0);<br />
pTab->SetWindowPos(0,parentRect.left,parentRect.top,200,30,0);<br />
<br />
<br />
CPropertyPage *page = GetActivePage();<br />
ASSERT(page);<br />
this->GetClientRect(&r);<br />
page->SetWindowPos(0,r.left,r.top,180,180,0)<br />
return TRUE ;<br />
}
Please advise
|
|
|
|
|
Is there any way to create a CArray object on the heap rather than on the stack?
Thanks
|
|
|
|
|
Yes, but why would you want to? As you add items to the array, memory is allocated from the heap to hold the individual items. The array object itself consumes very little memory.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
My guess is he wants it to exist outside the scope of the creating block.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Simple:
CArray<int> *theArray = new CArray<int>;
theArray->Add(1);
theArray->Add(42);
theArray->SetAt(0, 1337);
Or am I missing something?
Remember, even if you win the rat race, you're still a rat.
|
|
|
|
|
Hi guys
I've got this
CString file;
HANDLE hFile = CreateFile( ?????,........
What I have to put in ????? to get a valid value in hfile,all my tries have finished with a -1.
LPCSTR(file) doesn't work and I don't know what to do.
Thanks
Doc
|
|
|
|
|
|
Already read,but sorry, I can't see the solution.
My question is, how can I convert a CString to the right parameter to the CreateFile method?
Thanks
Doc
|
|
|
|
|
CString strFile = _T("C:\\myfile.txt");
HANDLE hFile = CreateFile (strFile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Sorry, it has been my fault.
My problem comes maybe from the point that I can't assign my file directly putting double \\.
// My Code
TCHAR m_szDrive[10];
TCHAR m_szDir[MAX_PATH];
TCHAR m_szFullPath[MAX_PATH];
CString sFile;
// Application Path
::GetModuleFileName(NULL,m_szFullPath,MAX_PATH);
_splitpath(m_szFullPath,m_szDrive,m_szDir,NULL,NULL);
sFile=m_szDrive;
sFile+=m_szDir;
sFile+=_T("myfile.txt");
CreateFile(sFile,.... THAT DOESN'T WORK
Do you know how can I convert my string to the right parameter?
Thanks for your patience.
Doc
|
|
|
|
|
TCHAR* pSlash = NULL;
TCHAR szFilespec [_MAX_PATH];
::GetModuleFileName (AfxGetInstanceHandle(), szFilespec, _MAX_PATH);
pSlash = _tcsrchr (szFilespec, _T('\\'));
ASSERT (pSlash != NULL);
pSlash++;
*pSlash = _T('\0');
CString strFilename = szFilespec + _T("myFile.txt");
hFile = Create (strFilename, ...)
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|