To handle a "right click" you should handle WM_CONTEXTMENU message (note that hoxsiew already pointed it out in the post#2!)
Printable View
To handle a "right click" you should handle WM_CONTEXTMENU message (note that hoxsiew already pointed it out in the post#2!)
thanks, i didnt release me that yet... sorry
That's working now, but its at the compelte GUI, i want it specific at the listview, and after that they can choose between Ignore/Block, i can see those, i've to give them the wIDD, but how can i handle those, and how can I get the line and the right colums variab out the lisvtiew?
Please, explain more clear and with normal words rather than abbreviations what you want and what for.
Sorry, I would try to make it clearder:
First: The Pop Up Menu works now, that fine. But it works at the entire gui, I would like it to only work at the specific list View, so i should try to get the HWND from where the click is, thats question 1.
Second, when question 1 is working, Someone can go to listview -> right click -> copy, or w/e, so i need the value from the colum and right line of the listview, how can i do that?
Thanks.
You'll probably want to subclass your listview's wndproc and handle the WM_CONTEXTMENU in it's message loop instead. the listview has messages and notifications more appropriate for what you are trying to do.
Could you explain me that a bit more? Its not really clear for me
Implement your own window procedure for this list control and handle WM_CONTEXTMENU message in this procedure.
It is just the same way like you've implemented the WndProc for your main window.
See this article from MSDN too:
http://msdn.microsoft.com/en-us/libr...83(VS.85).aspx
Tahts my new ProcCode:LRESULT CALLBACK ListViewProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
MENUITEMINFO emii;
switch (uMsg)
{
case WM_CREATE:
hmenu = CreatePopupMenu();
memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE|MIIM_ID;
//emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Block");
emii.cch = 3;
emii.wID = 1;
InsertMenuItem(hmenu, 0, TRUE, (LPCMENUITEMINFO) &emii);
memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
//emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Ignore");
emii.cch = 4;
InsertMenuItem(hmenu, 0, TRUE, (LPCMENUITEMINFO) &emii);
break;
case WM_CONTEXTMENU:
if(WM_RBUTTONDOWN)
{
POINT p;
GetCursorPos(&p);
TrackPopupMenu(hmenu,TPM_LEFTBUTTON,p.x,p.y,0,hWnd,0);
}
}
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
}
In the last line i call it, but it doesnt work, i set a breakpoint at the ListViewProc, never gets there.Code:LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HFONT HhFont = CreateFont(20, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_STRING_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Calibri"));
HFONT hFont = CreateFont(15, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_STRING_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Calibri"));
HFONT sFont = CreateFont(12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_STRING_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, TEXT("Calibri"));
InitCommonControls();
OleInitialize(0);
LV_COLUMN* lvc = new LV_COLUMN;
int x = 0;
switch(msg)
{
case WM_CREATE:
RecvListView = CreateWindowEx(WS_EX_STATICEDGE,WC_LISTVIEW,NULL,WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT ,75, 10, 455, 200,hWnd,(HMENU)IDC_LIST,hInstance,NULL);
hHookBut = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("Hook"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 9, 10, 55, 22, hWnd, (HMENU)IDC_HOOK, hInstance, NULL);
hSendButton = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("Send"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 455, 213, 75, 26, hWnd, (HMENU)IDC_SEND, hInstance, NULL);
hClean = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("Clean"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 9, 32, 55, 22, hWnd, (HMENU)IDC_CLEAN, hInstance, NULL);
hIngBloc = CreateWindowEx(WS_EX_STATICEDGE,WC_LISTVIEW,NULL,WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT ,37, 160, 35, 86,hWnd,(HMENU)IDC_INBL, hInstance, NULL);
hBlocIng = CreateWindowEx(WS_EX_STATICEDGE,WC_LISTVIEW,NULL,WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT ,2, 160, 35, 86,hWnd, (HMENU)IDC_BLIN, hInstance, NULL);
hBlock = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("Block"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 9, 54, 55, 22, hWnd, (HMENU)IDC_BLOCK, hInstance, NULL);
hIngore = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("Ingore"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 9, 97, 55, 22, hWnd, (HMENU)IDC_INGORE, hInstance, NULL);
hSendEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("//Packet"), WS_TILED | WS_VISIBLE | WS_CHILD | ES_UPPERCASE, 76, 216, 365, 20, hWnd, (HMENU)IDC_EDITSEND, hInstance, NULL);
hBlcEd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("00"), WS_TILED | WS_VISIBLE | WS_CHILD | ES_UPPERCASE, 9, 77, 55, 18, hWnd, (HMENU)IDC_BLCED, hInstance, NULL);
hIngEd = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("00"), WS_TILED | WS_VISIBLE | WS_CHILD | ES_UPPERCASE, 9, 120, 55, 18, hWnd, (HMENU)IDC_INGED, hInstance, NULL);
hBlorIg = CreateWindowEx(WS_EX_LEFT, TEXT("Button"), TEXT("ShowBlocked"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 9, 140, 55, 26, hWnd, (HMENU)IDC_IGNOR, hInstance, NULL);
SendMessage(hIngEd, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hBlcEd, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hBlock, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hIngore, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(RecvListView, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hHookBut, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hSendEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hSendButton, WM_SETFONT, (WPARAM)HhFont, TRUE);
SendMessage(hClean, WM_SETFONT, (WPARAM)hFont, TRUE);
SendMessage(hBlocIng, WM_SETFONT, (WPARAM)sFont, TRUE);
SendMessage(hIngBloc, WM_SETFONT, (WPARAM)sFont, TRUE);
ListView_SetExtendedListViewStyle(RecvListView, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | 0x01000000 | LVS_EX_DOUBLEBUFFER | LVS_EX_TWOCLICKACTIVATE );
for (int i = 1; i <= 4; i++)
{
InsertLVColumn(RecvListView, i, i, szColumnHeadings[i - 1], iColumnWidths[i - 1], (i == 4 ? false : true));
}
ListView_SetExtendedListViewStyle(hIngBloc, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | 0x01000000 | LVS_EX_DOUBLEBUFFER | LVS_EX_TWOCLICKACTIVATE );
ListView_SetExtendedListViewStyle(hBlocIng, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | 0x01000000 | LVS_EX_DOUBLEBUFFER | LVS_EX_TWOCLICKACTIVATE );
InsertLVColumn(hBlocIng, 1, 1, TEXT("Blc"), 31, true);
InsertLVColumn(hIngBloc, 1, 1, TEXT("Ign"), 31, true);
SecureZeroMemory(szIgnored, MAX_PACKET_LEN * sizeof(wchar_t));
SecureZeroMemory(szBlocked, MAX_PACKET_LEN * sizeof(wchar_t));
SetWindowSubclass(RecvListView, ListViewProc, 0, 0);
break;
1. Where did you set a break point?
2.This line in read does not make any sense, because WM_RBUTTONDOWN is defined as a number not equaled to zero.Quote:
Originally Posted by NLscotty
Besides, you don't need to call GetCursorPos: LPARAM already contains coordinates you need. Please, read MSDN about WM_CONTEXTMENU message.
3. You can also handle WM_CONTEXTMENU message in the main window procedure and check the WPARAM which contains the window handle of the child control (again, read the MSDN documentation)
1. In my new listview proc, it doesnt cross it.
2. Hmm, it worked, now you say it doesnt make sense, this confuses me a little
3. Oee but i was told this was how i should do it, to obtain the char value of the colum that is clicked.
Well, I posted before that it worked for the entire GUI, with that peice of coded, but now i want to to be specific to the ListView. So it works only there:)
Well, you can double click a listview and the value will be bleu ligned, right? Well every line of me has about 4 values, im only intrested in the third colum value. If some1 clicks at a line in my listview, and right click, this pop up menu should appears, with a choose, block/ignore, and if he clicks ignore, it should copy the value of the listview's third colum into a char ( or wchar_t, which i use). I dont know how I could explain it better, i could show a pic if you would like to?
Have a look at LVM_HITTEST Message and LVM_SUBITEMHITTEST Message
Thanks all i got it working now