|
Hi all,
Actually i am a VC++(6.0) programmer and recenty started working on vc 2005 and i am not getting Class wizard in VC 2005 like i have got how to add a variable how to add event handler for a particular control but what if i want to add a OnLButtonDown code for my dialog box....
Can anybody please help me with this...
Thanks in advance
|
|
|
|
|
There's no more class wizard (probably the #1 complaint )
It's now split in 2 windows. From the view menu, open the class view window.
Right-click the dialog class (or highlight and use f4) to get the properties window.
The properties window has tabs for messages, overrides, etc.
On the messages tab, you can scroll to the message you want to handle and click in
the right column to add a handler method.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I got it.....
Thanks for your reply....
It really helped me a lot.
|
|
|
|
|
actually there are 3 ways to achieve that,
1) use the class view tab of ur solution explorer and right click select properties, where all ur control ids exist from which u can add a function. and also u can add function overrides.
2) use the resource view and open the dialog, select control and properties of it and add functions likewise.
3) double click the control, it auto adds the handler.
Prasann
who else.
|
|
|
|
|
Prasann Mayekar wrote: who else.
ME!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Recently, after rewriting a part of my code for multithreading, I noticed that after return from main(), the program doesn't quit. So I added ExitProcess() there. Doesn't work. TerminateThread(). Doesn't work. Doesn't return control. Then I tried to manually kill all the threads I started ( it wasn't necessary before, they should never hang ). Also doesn't return.
Furthermore, the process cannot be killed in any way. Advanced Process Terminator can't do it.
Any clue?
|
|
|
|
|
If you break in the debugger when it's hanging, where is the instruction pointer
and how many threads are still active at that point?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Unable to attach a debugger.
-- modified at 3:18 Saturday 24th November, 2007
Checked the currently running ones with Process Explorer. 19-139 threads. The newer instance-the more threads. How many did I create in total? One for each open file handle, system-wide. I noticed that each running copy of my program leaves some handles unclosed...and number of them is close to the number of threads left...(didn't count precisely, every 5-6 versions I have to restart computer, then I have a problem with resource allocation. And windows (XP SP2 BTW) also has some problems with killing them - closing system is ridiculously slow).
|
|
|
|
|
maciu2020 wrote: Unable to attach a debugger
hmm...why?
It really sounds like you have active threads left running.
Closing a thread handle does not eliminate the thread.
All threads should terminate themselves by returning.
Some thread, usually the "main" thread, should wait for all the threads to terminate.
If you're resorting to TerminateThread() and other abnormal ways of stopping a thread,
chances are you've got a bad design. You shouldn't ever need to terminate a thread or
process forcefully.
Also, make sure you use the proper thread creation functions, depending on what
the thread uses:
straight Win32 APIs, use CreateThread()
C runtime (CRT), which includes using new/delete, use _beginthread[ex]()
MFC (which uses all of the above), use AfxBeginThread()
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: maciu2020 wrote:
Unable to attach a debugger
hmm...why?
This is what OllyDbg tells me..
Mark Salsbery wrote: It really sounds like you have active threads left running.
Closing a thread handle does not eliminate the thread.
All threads should terminate themselves by returning.
Sure. All threads should do it as they have no loops or infinite waits. And when I run one at the time, they all return.
Mark Salsbery wrote: You shouldn't ever need to terminate a thread or
process forcefully.
Yep. And I didn't do it until this strange case.
Mark Salsbery wrote: Also, make sure you use the proper thread creation functions, depending on what
the thread uses:
I use the correct one.
I thing it would be good to post the code. It's a slightly modified part of Zoltan Csizmadia's SystemInfo library.
My ThreadProc just calls GetFileName() as below. For readability, I stripped security checks and cleanup.
<br />
BOOL SystemHandleInformation::GetFileName( HANDLE h, CString& str, DWORD processId ) throw()<br />
{<br />
ULONG size = 0x8000;<br />
UCHAR* lpBuffer = NULL;<br />
BOOL ret = FALSE;<br />
<br />
HANDLE handle;<br />
HANDLE hRemoteProcess;<br />
BOOL remote = processId != GetCurrentProcessId();<br />
DWORD dwId = 0;<br />
HANDLE hHeap;<br />
<br />
<br />
if ( remote )<br />
{<br />
hRemoteProcess = ::OpenProcess( PROCESS_DUP_HANDLE, TRUE, processId );<br />
<br />
handle = DuplicateHandle( hRemoteProcess, h );<br />
}<br />
else<br />
handle = h;<br />
<br />
<br />
ret = GetFileNameHelper( handle, str );<br />
<br />
INtDll::NtQueryObject ( handle, 1, NULL, 0, &size );<br />
<br />
lpBuffer = (UCHAR*)HeapAlloc(hHeap = GetProcessHeap(), 0, sizeof(UCHAR)*size);<br />
<br />
if ( INtDll::NtQueryObject( handle, 1, lpBuffer, size, NULL ) == 0 )<br />
{<br />
SystemInfoUtils::Unicode2CString( (UNICODE_STRING*)lpBuffer, str );<br />
ret = TRUE;<br />
}<br />
<br />
<br />
return ret;<br />
}<br />
<br />
#define FILE_NAME_INFORMATION 9<br />
<br />
void __cdecl SystemHandleInformation::GetFileNameThread( PVOID pParam ) throw()<br />
{<br />
GetFileNameThreadParam* p = (GetFileNameThreadParam*)pParam;<br />
<br />
UCHAR *lpBuffer = (UCHAR*)<br />
VirtualAlloc( NULL, 0x1000*sizeof(UCHAR), MEM_COMMIT, PAGE_READWRITE );<br />
DWORD iob[2];<br />
<br />
p->rc = INtDll::NtQueryInformationFile( p->hFile, iob, lpBuffer, sizeof(lpBuffer), FILE_NAME_INFORMATION );<br />
<br />
if ( p->rc == 0 )<br />
*p->pName = lpBuffer;<br />
<br />
VirtualFree( lpBuffer, 0, MEM_RELEASE );<br />
}<br />
<br />
BOOL SystemHandleInformation::GetFileNameHelper( HANDLE handle, CString& str, DWORD processId ) throw()<br />
{<br />
BOOL ret=FALSE;<br />
HANDLE hThread;<br />
GetFileNameThreadParam tp; <br />
<br />
<br />
tp.hFile = handle;<br />
tp.pName = &str;<br />
tp.rc = 0;<br />
<br />
hThread = (HANDLE)_beginthread( GetFileNameThread, 0, &tp );<br />
<br />
if ( hThread == NULL )<br />
goto cleanup;<br />
<br />
if ( WaitForSingleObject( hThread, 80 ) == WAIT_TIMEOUT )<br />
{ <br />
TerminateThread( hThread, 0 );<br />
<br />
str = _T("");<br />
<br />
ret = TRUE;<br />
<br />
}<br />
else<br />
ret = ( tp.rc == 0 );<br />
<br />
return ret;<br />
}<br />
|
|
|
|
|
maciu2020 wrote: Sure. All threads should do it as they have no loops or infinite waits. And when I run one at the time, they all return.
"Should"?? No, they MUST. Your process cannot exit until they do.
maciu2020 wrote: // Wait for finishing the thread
if ( WaitForSingleObject( hThread, 80 ) == WAIT_TIMEOUT )
{
// Access denied
// Terminate the thread
TerminateThread( hThread, 0 );
Why did you pick 80ms to wait here? What if it takes 81ms?
I'm not sure what to say here, there's just no thread synchronization that I see.
If you have a function that never returns under certain conditions, and this is the
only solution, then all I can think of is trying _endthread() instead of TerminateThread().
Note that even if it works, this is still a kludge - You have no idea what state the system is
left in.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
Why did you pick 80ms to wait here? What if it takes 81ms?
Under normal conditions, it shouldn't take even 3ms on a fairly modern machine.
Why is it implemented this way? Because with insufficient access rights, NtQueryInformationFile doesn't return...at least not in reasonable time (I didn't write this code, but WAIT_TIMEOUT happens here up to 77 times on my machine. Also with 100 ms which was the default set several years ago by the author of this part).
_endthread() would need to be called by the thread itself, which is impossible when NtQueryInformationFile doesn't return. Yes, this can cause a resource leak, I need to rewrite it to use CreateThread instead.
Anyway, it's not the case. After a few hours of restarting my computer, I found where is the problem.
INtDll::NtQueryObject ( handle, 1, NULL, 0, &size );<br />
<br />
if ( size == 0 )<br />
size = 0x8000;<br />
<br />
lpBuffer = (UCHAR*)HeapAlloc(hHeap = GetProcessHeap(), 0, sizeof(UCHAR)*size);<br />
<br />
if ( INtDll::NtQueryObject( handle, 1, lpBuffer, size, NULL ) == 0 )<br />
{<br />
SystemInfoUtils::Unicode2CString( (UNICODE_STRING*)lpBuffer, str );<br />
ret = TRUE;<br />
}
Neither MSDN nor ntinternals.net write about thread security issues in NtQueryObject.
I'm going to try to put it in a critical section and see what happens. Need another restart though
-- modified at 15:13 Saturday 24th November, 2007
When there's a hung process in memory, it becomes totally unpredictable.
Even the single treaded, well tested version can hang here.
I'm leaving it for today, I'm too tired.
|
|
|
|
|
maciu2020 wrote: _endthread() would need to be called by the thread itself
Oops, yeah, sorry about that
maciu2020 wrote: Because with insufficient access rights, NtQueryInformationFile doesn't return
That's a bummer, as you well know Isn't there a way to do what you're trying to do using
documented/supported APIs?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Isn't there a way to do what you're trying to do using
documented/supported APIs?
Unfortunately, there isn't.
What I'm doing is making Zoltan Csizmadia's ForceDel (a tool that deletes locked files) more usable. Improved performance (originally-very poor, especially when trying to delete multiple files), GUI, some more features.
AFAIK there are 2 ways of doing it. The first is what Zoltan does - enumerating all handles and closing the right ones with CreateRemoteThread(CloseHandle).
No documented API gives these handles...
There's one more method, implemented in Unlocker. It's not open source and I had no time to reverse it..but it's a kernel mode hack. I guess, a kind of hook...and I think it's even worse than what I'm working at. It works faster though and maybe I'll decide to try to do the same.
|
|
|
|
|
Cool
I've never played around with that stuff before.
Good luck!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks that you tried to help.
|
|
|
|
|
In .net (VS2003 ),C# can create a dialog with localizable attribute which can put the control outside the dialog and show it with two scroll bar .
But in VC 7.1,I didn't know how to realize it?
===========================
http://begtostudy.blogspot.com/
email:begtostudy@gmail.com
MSN:begtostudy@gmail.com
|
|
|
|
|
??????????
You can always use CFormView, make it very big in the resource editor and then override the CChildFrm to make the frame smaller than the real surface. That will make you the scrollbars and put your control outside the "First sight".
Is something like that what you wanted?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
ChildFrm ?That is MDI .
What can I do in dialog of MFC dll .
Thanks .
===========================
http://begtostudy.blogspot.com/
email:begtostudy@gmail.com
MSN:begtostudy@gmail.com
|
|
|
|
|
i've added onidle plus invalidate the win and set the onidle to 0; as this option allows playing of the sound.
I am very much a begginer and I'm sorta testing things out.
Could any one tell me whats going on with this approach?
Thanks very much..
Simon
-- modified at 19:58 Friday 23rd November, 2007
|
|
|
|
|
Can you post some relevant code? I'm not clear where and how you
are calling PlaySound() and what OnIdle() has to do with it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am trying to create a game in mfc
in the OnDraw, I am calling ---- PlaySound("c:\\sound.wav",0,SND_FILENAME | SND_ASYNC); -----
the OnIdle is called when there is no mouse or keyboard activity
and with in onidle the invalidate is called for ondraw
--- AfxGetMainWnd()->Invalidate(false); ---
so the draw is called a number of times,
I know that the playsound is called a number of times, sofor I would expect
odd behavior, so I have set the onidle return value to 0, so it is only called after keyboard or mouse interuption has ended as aposed of the call to be continuse
as I mentioned the sound only plays when there is no keyboard or mouse acticvity
what I am after Is a soloution, or a structered method to go about this,
I have looked around on the internet, an d things seem very complcated
this playsound is all I can go about
if you can refer me to any relevant articles, it would very much be a appreciated
simon
|
|
|
|
|
simon alec smith wrote: as I mentioned the sound only plays when there is no keyboard or mouse acticvity
That's the only time you'll get OnIdle() calls!
Ok I understand now, thanks for the explanation.
You may want to look into using a timer, either a regular windows timer
if resolution isn't important, or a multimedia timer for more precise timing.
I think you'll find this will work much better than trying to do periodic stuff
in OnIdle()
Using Timers[^]
Multimedia Timers[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi, for some reason i can only call ON_COMMAND in my main dialog, how can i call it in a child dialog?
Any ideas would be much apreciated!
|
|
|
|
|
How can you call ON_COMMAND? ON_COMMAND is not a function or method AFAIK.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|