Valhalla Legends Forums Archive | C/C++ Programming | ListView notification trouble...

AuthorMessageTime
BreW
[code]
case WM_NOTIFY:
if (LOWORD(wParam) == 80) {
switch (((LPNMHDR)lParam)->code) {
case NM_DBLCLK:
char sdfgtmp[256], asdftemp[64];
int selIndex;
LVITEMA lvitem;
selIndex = SendMessage(hWnd_lvwChannel, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
if (selIndex != -1) {
GetWindowText(hWnd_txtChat, sdfgtmp, sizeof(sdfgtmp));
lvitem.mask = LVIF_TEXT;
lvitem.iSubItem = 0;
lvitem.pszText = asdftemp;
lvitem.cchTextMax = 64;
lvitem.iItem = selIndex;
SendMessage(hWnd_lvwChannel, LVM_GETITEMTEXT, selIndex, (LPARAM)&lvitem);
strcat(sdfgtmp, asdftemp);
SetWindowText(hWnd_txtChat, sdfgtmp);
}
break;
case NM_CUSTOMDRAW:
MessageBox(0, "adsdfgsdfgf", 0, 0);
SetWindowLong(hWnd_lvwChannel, DWL_MSGRESULT, (LONG)ProcessCustomDraw(lParam));
return TRUE;
}
}
break; //  */

LRESULT ProcessCustomDraw (LPARAM lParam) {
    LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
    switch(lplvcd->nmcd.dwDrawStage)  {
case CDDS_PREPAINT:
            return CDRF_NOTIFYITEMDRAW;
case CDDS_ITEMPREPAINT:
            return CDRF_NOTIFYSUBITEMDRAW;
        case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
lplvcd->clrText  = 0x00FFFF00;
            lplvcd->clrTextBk = 0;
            return CDRF_NEWFONT;
    }
    return CDRF_DODEFAULT;
}
[/code]

For some reason this code is making me crash (every time the listview is repainted) and i have no idea where it does crash either. I tried the messagebox method, but it seems to crash before setwindowlong (not sure why) but i do know it is caused by my code. This code was heavily based off of the example from one of the sites mentioned in the other topic, and it works there but not here at all. Any ideas why?
August 24, 2007, 5:01 AM
Explicit[nK]
Have you tried stepping through it to isolate the line causing the crash?
August 24, 2007, 5:59 AM
BreW
Yes, yes I have. Sometimes it crashes before I have a chance to even DO anything (like popup a messagebox, which pauses the thread), and other times it crashes within my code. Because of this, I can't tell what line is crashing it at all.

EDIT* now that I took a better look it seems as if it only crashes when i move my mouse over it. It doesn't even have to send a WM_NOTIFY to crash. :/

EDIT 2*
After setting the listview long it seems if there is a redraw of that control, then it crashes. Hrmmm.....
August 24, 2007, 2:19 PM
laurion
[quote author=brew link=topic=16977.msg171920#msg171920 date=1187965140]
Yes, yes I have. Sometimes it crashes before I have a chance to even DO anything (like popup a messagebox, which pauses the thread), and other times it crashes within my code. Because of this, I can't tell what line is crashing it at all.
[/quote]
try setting breakpoints using your IDE
August 24, 2007, 4:35 PM
l2k-Shadow
[quote author=Tazo link=topic=16977.msg171922#msg171922 date=1187973318]
[quote author=brew link=topic=16977.msg171920#msg171920 date=1187965140]
Yes, yes I have. Sometimes it crashes before I have a chance to even DO anything (like popup a messagebox, which pauses the thread), and other times it crashes within my code. Because of this, I can't tell what line is crashing it at all.
[/quote]
try setting breakpoints using your IDE
[/quote]

yeah, this isn't VB.
August 24, 2007, 10:18 PM
rabbit
The MSVC++ 6 IDE has breakpoint settings too.
August 25, 2007, 3:58 AM
warz
it sure does, and they're very useful in conjunction with other debuggers.
August 25, 2007, 6:03 AM
laurion
[quote author=rabbit link=topic=16977.msg171941#msg171941 date=1188014319]
The MSVC++ 6 IDE has breakpoint settings too.
[/quote]
yep, along with Dev-C++ (i'm not sure what brew is using)

@l2k-shadow: lmao
August 25, 2007, 3:21 PM
BreW
The breakpoints don't really help. Like I said, it crashes before it gets a chance TO send the second WM_NOTIFY. There must be something wrong with the window long i'm setting it to, but i don't know what exactly. Like I said, I heavily based my code off of MSDN's and that other example's code.

EDIT**** I or'd the return of GetWindowLong and what my ProcessCustomDraw function is returning and it seems to make a difference, just that it now does nothing... it doesn't crash anymore either.
August 25, 2007, 3:59 PM
zorm
Did you get this figured out yet?
If not I highly suggest you learn how to use your IDE's debug mode. Then when your program crashes you can get a callstack and look back to see where the crash actually happened at. This will allow you to come to a consensus of what code is causing the problem instead of wildly guessing.
Not to mention that this is an incredibly powerful tool to be able to weild correctly. Once you learn how to use it you won't have to do things like pasting huge chunks of code for people on forums. You'll be able to post a small little chunk, say what the problem is, where the problem is occurring and what you've already tried to resolve it. Its amazing how much faster you'll get a reply if you do this and how much faster you can get back to doing what really matters, programming and making your program rock!
September 10, 2007, 2:35 AM
Camel
Even if you don't want to actually debug your code, you can still benefit from minidump files; they will give you a clue as to what your application was doing the moment it crashed - and if you open it with your debugger, you will get the state of the stack, which would allow you (or your debugger) to reconstruct local variables and a call trace. Running your program in debug mode would give you even more information, because the program will still be in memory when it crashes.
September 10, 2007, 2:33 PM
BreW
Ah, I gave it another shot and I was able to get it work. This mislead me:

[quote]
ListView Colors
You won't believe how much time I took to dig this up to actually work! I mean, 99.99% examples were MFC only!

So here we go, finally, pure WinAPI code for listview colors.

Note: This code is found deeply inside MSDN!

First we handle the WM_NOTIFY message to use a NM_CUSTOMDRAW notification. We don't need to use any owner drawn listview, and since this is custom drawn, we can paint the items/subitems at our will.

if(((LPNMHDR)lParam)->code == NM_CUSTOMDRAW)
{
  SetWindowLong(hWnd, DWL_MSGRESULT,
        (LONG)ProcessCustomDraw(lParam));
  return TRUE;
}
We will set a new style which will be a result of our painting function.
[/quote]

So one would think that you'd have to set the window long, right?
Wrong. I had to return it. Found this out from an old MSDN arcticle i was able to dig up with my newfound msdn searching skills.
@Zorm: The program was crashing because I modified the struct it passes without sending the proper return value, therefore it crashed on painting the window.
December 7, 2007, 11:21 PM

Search