الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

شرح كود لتلوين ListeView

بدأه aderfiad في 2 ديسمبر 2009 · 2 رد · 1,323 مشاهدة · في أرشيف قسم الـــ Assembly
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

وجدت هدا الكود في برنامج للاخ GM وهو لتلوين الكتابة في ListeView

.elseif Msg == WM_NOTIFY ; capture notify routine
		mov esi, LParam
		assume esi : ptr NMLVCUSTOMDRAW
		;capture custom draw and make sure we are going to draw our listview
		.if ([esi].nmcd.hdr.code == NM_CUSTOMDRAW && [esi].nmcd.hdr.idFrom == 1005) 
			.if ([esi].nmcd.dwDrawStage == CDDS_PREPAINT) 
				; before painting, aquire subitems draw notify
				mov eax, CDRF_NOTIFYITEMDRAW
			.elseif ([esi].nmcd.dwDrawStage == CDDS_ITEMPREPAINT) 
				; same
				mov eax, CDRF_NOTIFYITEMDRAW
			.elseif ([esi].nmcd.dwDrawStage == (CDDS_ITEMPREPAINT or CDDS_SUBITEM)) 
				; drawing subitems, we are doing our job here
				; remember that we want to custom draw the "instruction" subitems only and not the whole rows ;)

				.if ([esi].iSubItem == 0) ; the PiD column
					; get the instruction string 
					invoke RtlZeroMemory, addr text, sizeof text
					invoke RtlZeroMemory, addr lvi, sizeof lvi
					m2m lvi.iItem, [esi].nmcd.dwItemSpec
					mov lvi.iSubItem, 2
					mov lvi.imask, LVIF_TEXT
					lea eax, text
					mov lvi.pszText, eax
					mov lvi.cchTextMax, sizeof text
					invoke SendMessage, [esi].nmcd.hdr.hwndFrom, LVM_GETITEM, NULL, addr lvi
					; is it a "Ahmed18/AT4RE" instruction ??
					invoke crt_strncmp, addr text, CTXT("Ahmed18/AT4RE"),13
					.if (!eax)
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						; set the "Ahmed18/AT4RE" instruction prefered color (RGB system)
						mov [esi].clrText, 0A00000h
						mov eax, CDRF_NEWFONT
					.endif
				.endif	

				.if ([esi].iSubItem == 1) ; the Parent PID column
					; get the Parent PID string 
					invoke RtlZeroMemory, addr text, sizeof text
					invoke RtlZeroMemory, addr lvi, sizeof lvi
					m2m lvi.iItem, [esi].nmcd.dwItemSpec
					mov lvi.iSubItem,0
					mov lvi.imask, LVIF_TEXT
					lea eax, text
					mov lvi.pszText, eax
					mov lvi.cchTextMax, sizeof text
					invoke SendMessage, [esi].nmcd.hdr.hwndFrom, LVM_GETITEM, NULL, addr lvi
					invoke crt_strncmp, addr text, CTXT("Ahm"),3
					.if (!eax)
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						; set the "Ahm" instruction prefered color (RGB system)
						mov [esi].clrText, 080808h
						mov eax, CDRF_NEWFONT
					.endif
				.endif
				.if ([esi].iSubItem == 2) ; the Priority column
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						mov [esi].clrText, 08FFFFh
						mov eax, CDRF_NEWFONT
				.endif
			.else	 
				mov eax, CDRF_DODEFAULT
			.endif
			;send the custom draw result
			invoke SetWindowLong, Hwnd, DWL_MSGRESULT, eax
			xor eax, eax
			inc eax
			ret
		.endif
		assume esi : nothing
		xor eax, eax
		ret

كنت سابقا استعمل هدا الماكرو لتلوين النصوص

	RGB macro red,bleu,green
 mov ah,green
 shl eax,8
 mov ah,bleu
 mov al,bleu
endm

تم اسناد الرسالة

 RGB 50,50,188
	invoke SendMessage,hListeViewp,LVM_SETTEXTCOLOR,0,eax

لكن عيب هده الطريقة انها تلون جميع خانات ListeView بنفس اللون .

في كود الاخ GM بالامكان التلاعب بالالوان واسناد عدة الوان مختلفة

اريد تطبيق الكود مع تغيير clrText بـ clrTextBk

لكني لم افهم الكود من الاول

السطور الاولى مفهومة

فقط هدا الشطر غير واضح

.if ([esi].iSubItem == 0) ; the PiD column
					; get the instruction string 
					invoke RtlZeroMemory, addr text, sizeof text
					invoke RtlZeroMemory, addr lvi, sizeof lvi
					m2m lvi.iItem, [esi].nmcd.dwItemSpec
					mov lvi.iSubItem, 2
					mov lvi.imask, LVIF_TEXT
					lea eax, text
					mov lvi.pszText, eax
					mov lvi.cchTextMax, sizeof text
					invoke SendMessage, [esi].nmcd.hdr.hwndFrom, LVM_GETITEM, NULL, addr lvi
					; is it a "Ahmed18/AT4RE" instruction ??
					invoke crt_strncmp, addr text, CTXT("Ahmed18/AT4RE"),13
					.if (!eax)
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						; set the "Ahmed18/AT4RE" instruction prefered color (RGB system)
						mov [esi].clrText, 0A00000h
						mov eax, CDRF_NEWFONT
					.endif
				.endif	

				.if ([esi].iSubItem == 1) ; the Parent PID column
					; get the Parent PID string 
					invoke RtlZeroMemory, addr text, sizeof text
					invoke RtlZeroMemory, addr lvi, sizeof lvi
					m2m lvi.iItem, [esi].nmcd.dwItemSpec
					mov lvi.iSubItem,0
					mov lvi.imask, LVIF_TEXT
					lea eax, text
					mov lvi.pszText, eax
					mov lvi.cchTextMax, sizeof text
					invoke SendMessage, [esi].nmcd.hdr.hwndFrom, LVM_GETITEM, NULL, addr lvi
					invoke crt_strncmp, addr text, CTXT("Ahm"),3
					.if (!eax)
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						; set the "Ahm" instruction prefered color (RGB system)
						mov [esi].clrText, 080808h
						mov eax, CDRF_NEWFONT
					.endif
				.endif
				.if ([esi].iSubItem == 2) ; the Priority column
						; select our prefered font object
						invoke SelectObject, [esi].nmcd.hdc, DisasmFont
						mov [esi].clrText, 08FFFFh
						mov eax, CDRF_NEWFONT
				.endif
			.else	 
				mov eax, CDRF_DODEFAULT
			.endif
			;send the custom draw result
			invoke SetWindowLong, Hwnd, DWL_MSGRESULT, eax
			xor eax, eax
			inc eax
			ret
		.endif
		assume esi : nothing
		xor eax, eax
		ret

ومادا تعني CDRF_NOTIFYITEMDRAW فلم اجدها هنا

http://msdn.microsoft.com/en-us/library/bb774778(VS.85).aspx

ايضا هدا السطر لاحظت انه استعمل كلمة غريبة m2m ??

m2m lvi.iItem, [esi].nmcd.dwItemSpec

تم تعديل هذه المشاركة بواسطة aderfiad في 2 ديسمبر 2009 في 04:35

#2

بالمناسبة ال ListView هي أعقد كونترول في الويندوز

في حال اردت حل اسهل لتنفيذ هدفك استخدم RaGrid الموجود في محرر Radasm

سهل ومرن في التعامل .

#3
اقتباس

ومادا تعني CDRF_NOTIFYITEMDRAW فلم اجدها هنا

شاهد هذا الموضوع

http://www.asmcommunity.net/board/index.php?topic=13356.0

اقتباس

ايضا هدا السطر لاحظت انه استعمل كلمة غريبة m2m ??

هذا ماكرو موجود داخل ال macros.asm وهو ملف نقوم باستدعائة في مشروع الاسمبلي لتسهيل كتابة و اختصار بعض الاوامر

وظيفتة مثل MOV سيقوم بنسخ القيمة الموجودة في [esi].nmcd.dwItemSpec الي lvi.iItem

مواضيع مشابهة