|
-
March 16th, 2007, 02:20 PM
#1
ListView control creates 2 threads and other strange behaviour
Hello everybody. Back with a few questions about Windows GUI programming, this time about a ListView control. The program fully works so far, no problems, just a few weird things happening with it.
This ListView control is declared and created by a resource file as follows:
Code:
IDD_TAB_CACHE DIALOGEX 2, 68, 224, 179
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD | WS_CLIPCHILDREN
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_CACHE_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | WS_TABSTOP,0,0,223,161,WS_EX_CLIENTEDGE
PUSHBUTTON "Select All",IDC_CACHE_SELALL,0,164,50,14
PUSHBUTTON "Select None",IDC_CACHE_SELNONE,53,164,50,14
PUSHBUTTON "Move",IDC_CACHE_MOVESEL,107,164,50,14,WS_DISABLED
PUSHBUTTON "Delete",IDC_CACHE_DELSEL,161,164,50,14,WS_DISABLED
END
Now, I'm using OutputDebugString to write some info to VC++'s debug window in my WndMsgHandler, and I've noticed some strange behaviour coming from this control. Take a look at this bit from my debug window:
Code:
--> cUTool2k4::Setup() returned 0.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -12.
Before the cUTool2k4::Setup() function returns, the dialogs are created and the list is populated with a few entries. After the Setup function, I switch to the tab that holds the ListView control, which makes it send a WM_NOTIFY message with code -12 (NM_CUSTOMDRAW). I don't understand why it's sending this message. I don't want to draw it myself, I want to let the system draw it (which it does anyway). So why am I receiving this? Or is it just to let me know that drawing is about to start?
The next bit:
Code:
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -16.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\winmm.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\wintrust.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\crypt32.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\msasn1.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\imagehlp.dll', No symbols loaded.
'UTool2k4.exe': Unloaded 'C:\WINDOWS\system32\setupapi.dll'
'UTool2k4.exe': Unloaded 'C:\WINDOWS\system32\wdmaud.drv'
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\wdmaud.drv', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\setupapi.dll', No symbols loaded.
'UTool2k4.exe': Unloaded 'C:\WINDOWS\system32\setupapi.dll'
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\msacm32.drv', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\msacm32.dll', No symbols loaded.
'UTool2k4.exe': Loaded 'C:\WINDOWS\system32\midimap.dll', No symbols loaded.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -100.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -101.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -12.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -7.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -2.
The above is what happens in my debug window when I left-click an entry in my list. First the ListView control sends WM_NOTIFY with code -16 (NM_RELEASEDCAPTURE). Apparently the control had previously captured mouse input and is now releasing it... I have no idea what this actually means, but I don't think an event like that should start new threads, should it? Because that's what appears to be happening next, with all the symbols not loading (?!). Again, I have no idea what the hell is going on here.
After that, I receive the -100 (LVN_ITEMCHANGING) and -101 (LVN_ITEMCHANGED) notifications to let me know the items appearance is changing (the selection highlight appears).
Then, I receive another -12 (NM_CUSTOMDRAW) notification. Again, I don't want to draw the control myself so I don't know why I am receiving this.
The -7 and -2 notifications are NM_SETFOCUS and NM_CLICK, which are obvious.
Here are some other messages I don't understand:
Code:
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -104.
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -103.
This happens when I'm closing the main window. The -104 notification is LVN_DELETEALLITEMS. MSDN says the following about its return value:
 Originally Posted by MSDN
To suppress subsequent LVN_DELETEITEM notification messages, return TRUE.
To receive subsequent LVN_DELETEITEM notification messages, return FALSE.
My code is this:
Code:
if (((NMHDR *)lParam)->hwndFrom == GetDlgItem(hTabWnd, IDC_CACHE_LIST)) {
if (((NMHDR *)lParam)->code == LVN_DELETEALLITEMS) {
return true;
}
So why do I still receive a -103 (LVN_DELETEITEM) for every item that's deleted?
Moving on:
Code:
--> Tabproc WM_NOTIFY: pNMHDR.idFrom = 1009, pNMHDR.hwndFrom = 0x00050422, pNMHDR.code = -103.
--> cDlgHax::Cleanup() returned 0.
The thread 'Win32 Thread' (0x5a8) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x108) has exited with code 0 (0x0).
The program '[1692] UTool2k4.exe: Native' has exited with code 0 (0x0).
After receiving the last LVN_DELETEITEM notification my Cleanup function is done, and WinMain returns. As you can see, 2 threads are terminated as well. I didn't create these threads. These threads seem to be created when I click an entry in the list (remember a few paragraphs up when the "No symbols loaded" messages appeared in the debug window). The only things I've done with the program at this point is run it, switch to tab with ListView control, click an entry, and close it again. This can't be right, can it? I can't imagine any reason the ListView control can have to start threads... What's more, I don't think controls should start threads period. Or they should atleast inform the owning process of it... So what's wrong here?
Well, this turned out to be another beast of a post, and I'm sorry for that. I'm just trying to be as thorough and clear as possible. Thanks for reading if you made it this far!  
As I've said, the program works as expected, no weird errors, but we all know how it goes. If you leave things you're unsure about just hanging around in there, it's going to come back and bite you in the *** later on. So I'm just trying to tighten up the loose ends.
Who can clarify?
Last edited by Jehjoa; March 16th, 2007 at 02:27 PM.
I am a beginning C++ Win32 programmer with LOTS of questions. Hopefully matching answers can be found here... 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|