كيفية التعامل مع حدث NM_CUSTOMDRAW لاسترداد العناصر القائمة

StackOverflow https://stackoverflow.com//questions/10649836

سؤال

أنا أعمل على مشروع Win32 / MFC. لدي عنصر تحكم Clistctrl مخصص يجب أن أضيفه، من وقت لآخر، بعض سلاسل الأحرف. أحتاج تماما إلى أداء بعض التلاعب على العناصر التي تمت إضافتها بشكل حيوي إلى CLISTCTRL الخاص بي.

الترا أساسا، أحتاج إلى:

  1. اكتشاف إضافة عناصر واحدة؛
  2. استرجاع _single_ مباشرة بعد (من الناحية المثالية، بعد فترة وجيزة بعد إدراجها ()؛
  3. تخزين قيم العناصر الفردية في خريطة، والتي سوف تستخدمها لأداء التلاعب الأخرى.

    فكرت في القيام بهذا تجاوز طريقة Drawitem (). ولكن يبدو ondraw حدث لا تكون متاحة لبلدي clistctrl.

    لم يتم إنشاء الحدث أبدا.

    مهم: يرجى ملاحظة أن mycustomclistctrl لديها " على رسم ثابت " مجموعة الممتلكات True ، ولكن " عرض "الخاصية هي لم يتم تعيين كإبلاغ .

    لذلك، لقد قررت التعامل مع حدث nw_customdraw، وكتابة معالج CustomDraw، كما هو موضح هنا و هنا :

    p> هنا يمكنك عرض مثال رمز آخر.

    بعد ذلك، أحتاج إلى وسيلة لاسترداد عناصر واحدة من clistctrl الخاص بي.
    وبحل أدق، أحتاج إلى وسيلة للحصول على معرفات عنصر واحد من بنية NMHDR .

    كيف يمكنني القيام بذلك؟ أنا قادر فقط على الحصول على معرف عنصر الأخير الذي أضفته. أنا متأكد من أنه خطأ بسيط لا يمكنني العثور عليه.

    جزء من التعليمات البرمجية أدناه:

    مصدر الحوار الذي يحتوي على clist ctrl: giveacodicetagpre.

    بلدي clist clist ctrl المصدر: giveacodicetagpre.

    أي مساعدة موضع تقدير!

    p.s. من فضلك لا تعطيني نصائح مثل:

    1. اضبط خاصية "السحب الخاصة" الخاصة بك إلى True؛
    2. تحقق من إدراج السطر "on_wmdrawitem ()
    3. تحويل clistctrl الخاص بك كتقرير؛

      لقد حاولت بالفعل كل شيء ...: -)

      شكرا للجميع!

      it

هل كانت مفيدة؟

المحلول 2

first of all... Thank you wasted your precious time with this stupid question. I never found anything about LVN_INSERT event. I write scientific software(most on Linux platform); I am not a long-time Win32 developer, so I don't know Win32 APIs in depth. I have modified source file of MyCustomCListCtrl class, as you have suggested. Code below seems to be the best( and faster )way to achieve what I want:

    /* file MyCustomCListCtrl.cpp */

    #include "stdafx.h"
    #include "MyCustomCListCtrl.h"

    MyCustomCListCtrl::MyCustomCListCtrl()
    {
    }

    MyCustomCListCtrl::~MyCustomCListCtrl()
    {
    }

    BEGIN_MESSAGE_MAP(MyCustomCListCtrl, CListCtrl)
        //{{AFX_MSG_MAP(MyCustomCListCtrl)
        //}}AFX_MSG_MAP
        ON_NOTIFY_REFLECT(LVN_INSERTITEM, OnLvnInsertItem)
    END_MESSAGE_MAP()

    ...

    afx_msg void CTranslatedListCtrl::OnLvnInsertItem(NMHDR* pNMHDR, LRESULT* pResult)
    {
        LPNMLISTVIEW plvInfo = (LPNMLISTVIEW)pNMHDR;
        CString str = this->GetItemText(plvInfo->iItem, 0);

        // Add Some Logic

        *pResult = 0;
    }

Can You confirm? From what I can see, it seems to work. :-) Thanks again!

IT

نصائح أخرى

First, if you need to detect adding of single items, why don't you handle the LVN_INSERTITEM message? I mean, that's what that message is for. Handling NM_CUSTOMDRAW instead is the wrong way, since you won't necessarily get that notification if the control is hidden, your window minimized, ...

In your OnCustomDraw() you always get the same ID: that's because the list control always draws all visible items, so you get the ID of the first visible item. If you set a breakpoint there, then on the next run the control gets refreshed and the drawing starts again from the first visible item.

Note: since you're handling NM_CUSTOMDRAW, you won't get any notification of added items that are not inserted into the visible part of the control! So as I mentioned, you should handle LVN_INSERTITEM instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top