sách gpt4 ai đã đi

listview - TListView 检测 ESC 或未更改的编辑

In lại 作者:行者123 更新时间:2023-12-02 09:12:30 30 4
mua khóa gpt4 Nike

Tôi đang cố gắng TListView của WindowProc 进行子类化,以在编辑 TListView 标题后检测 ESC 键按下情况(如果用户取消编辑)。 ListViewWndProc 被明确调用,但应该检测的代码参数永远不会获取 LVN_ENDLABELEDIT 值。为什么注释部分永远不会被调用?我看不到错误,它应该发生。

TWndMethod OldWndProc;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
OldWndProc = ListView1->WindowProc;
ListView1->WindowProc = ListViewWndProc;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::ListViewWndProc(TMessage &Message)
{
if (Message.Msg == CN_NOTIFY)
{
LPNMHDR pnmh = reinterpret_cast(Message.LParam);

if (pnmh->code == LVN_ENDLABELEDIT) // UPDATE: if LVN_ENDLABELEDIT is replaced with 4294967120 it works
{

// !!! THE FOLLOWING NEVER HAPPENS !!!

// UPDATE: Looks like LVN_ENDLABELEDIT is incorrectly defined in C++ Builder 2010
// if LVN_ENDLABELEDIT is replaced with 4294967120 the code works

LV_DISPINFO *pdi = reinterpret_cast(Message.LParam);
if (pdi->item.pszText == NULL)
{
Edit1->Text = "Cancelled";
return;
}
}
}

OldWndProc(Message);
}

//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1Editing(TObject *Sender, TListItem *Item, bool &AllowEdit)
{
Edit1->Text = "Editing";
}

//---------------------------------------------------------------------------

void __fastcall TForm1::ListView1Edited(TObject *Sender, TListItem *Item, UnicodeString &S)
{
Edit1->Text = "Done";
}

1 Câu trả lời

在 C++ 中,LVN_ENDLABELEDEDIT 的值取决于项目的TCHAR_Mapping ,可以通过 "_TCHAR maps to" 在项目设置中进行更改配置项。默认情况下,_TCHARĐặt thànhwchar_t在 C++Builder 2009 及更高版本中,除非您从早期版本迁移项目,在这种情况下它是 char默认情况下。

LVN_ENDLABELEDIT是一个映射到 LVN_ENDLABELEDITA 的宏(4294967190)当_TCHARĐúng char ,并发送至 LVN_ENDLABELEDITW (4294967120)当_TCHARĐúng wchar_t .

检查两个常量 LVN_ENDLABELEDEDITALVN_ENDLABELEDEDITW ,就像在Delphi源代码中所做的那样,应该没问题。

void __fastcall TForm1::ListViewWndProc(TMessage &Message)
{
if (Message.Msg == CN_NOTIFY)
{
LPNMHDR pnmh = reinterpret_cast(Message.LParam);

if ((pnmh->code == LVN_ENDLABELEDITA) || (pnmh->code == LVN_ENDLABELEDITW))
{
LV_DISPINFO *pdi = reinterpret_cast(Message.LParam);
if (pdi->item.pszText == NULL)
{
Edit1->Text = "Cancelled";
return;
}
}
}

OldWndProc(Message);
}

关于listview - TListView 检测 ESC 或未更改的编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50547701/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com