Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
Here is the code I have used but i am not getting the proper message

C++
//creating the list view
hListView=CreateWindowEx(0,L"SysListView32",NULL,
				WS_CHILD|WS_VISIBLE|LVS_REPORT|WS_BORDER|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP|WS_GROUP|LVS_AUTOARRANGE|LVS_ALIGNLEFT,10,50,rc.right-10,rc.bottom-50,hWnd,(HMENU)DISP_LISTVIEW,(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),NULL);
 
//for extended style
int estyle=LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES| LVS_EX_HEADERDRAGDROP;
ListView_SetExtendedListViewStyle(hListView,estyle);
 
//in the WndProc function

case WM_NOTIFY:
	NMHDR *nmhdr;
	nmhdr=(NMHDR*)lParam;
	switch(wParam)
	{
	case DISP_LISTVIEW:
	if(nmhdr->code==NM_CUSTOMDRAW)
	{
		LONG l=(LONG)TableDraw(lParam);
		SetWindowLong(hWnd, DWL_MSGRESULT, l);
                return TRUE;
	}
	else
        ...
     	...
 
//function to color row. copied from code project
LRESULT TableDraw (LPARAM lParam)
{
	int iRow;
	LPNMLVCUSTOMDRAW pListDraw = (LPNMLVCUSTOMDRAW)lParam;
	switch(pListDraw->nmcd.dwDrawStage)
	{
	case CDDS_ITEMPREPAINT:
//it never reach here
		iRow = (int)pListDraw->nmcd.dwItemSpec;
		if(iRow%2 == 0)
		{
			pListDraw->clrTextBk = RGB(202, 221,250);
			return CDRF_NEWFONT;
		}
	case CDDS_PREPAINT:
		return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW);
	default:
		break;
	}
	return CDRF_DODEFAULT;
}


The application is a Multi-document interface application. and the HWND passed to SetWindow long is a child window of application. The Error code I am getting from GetLastError Function is 1413

Would you please let me know what I can do? where I am doing wrong?
Posted
Updated 5-Feb-20 21:02pm
v5

You should be checking for NM_CUSTOMDRAW every time you receive a WM_NOTIFY message. What is the test for DISP_LISTVIEW used for?
 
Share this answer
 
Comments
[no name] 13-Jun-12 20:54pm    
DISP_LISTVIEW is the Id of Listview, thats how I know the requested ListView control. And I am using the NM_CUSTOMDRAW but I am not getting the message. instead I am getting error 1413
Richard MacCutchan 14-Jun-12 4:20am    
Where are you getting the 1413 error?
Richard MacCutchan 14-Jun-12 4:23am    
Also, take a look at the comments here with reference to the contents of the wParam values.
I had the same problem and solve it by avoiding the SetWindowLong call and returning directly the procedure result:

LONG l=(LONG)TableDraw(lParam);
SetWindowLong(hWnd, DWL_MSGRESULT, l);
return TRUE;


Now is
return (LRESULT )TableDraw (lParam);                


I hope this may help
 
Share this answer
 
Comments
Stefan_Lang 6-Feb-20 3:33am    
You're using incompatible types in both examples: the first assigns a 64 bit pointer to a 32 bit long, and the second replaces a TRUE return value with a 64 bit pointer.
This line:
C++
LONG l=(LONG)TableDraw(lParam);
stores a 64 bit pointer value into a 32 bit integral variable! You're probably losing information.

Hint: never use C-style type casts! They tend to hide dramatical errors from your sight. Without the typecast, the compiler would have issued an error message, and told you what is wrong.

Rule of thumb: if the compiler tells you something about types not fitting, then
- either one of the types is badly chosen (fix: change type of variable)
- or the statement does not use the correct variables (fix: find the correct variable to use)
- or the statement doesn't make sense and actually contains a semantical error that needs to be fixed. (fix: whatever it takes to correct the semantics)

Either way, casting the type merely shuts up the compiler, but it won't resolve the actual problem!


P.S.: SetWindowLong() has been superseded by the SetWindowLongPtr() function to make it independent of the target platform (32 or 64 bit).

P.P.S.: If you can't avoid type casts (e. g. with the Windows API and it's LPARAM/WPARAM/LRESULT types) you should still prefer static_cast or reinterpret_cast over C-style. Then you get at least some checks and corresponding error messages.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900