Click to See Complete Forum and Search --> : C++ PopUpMenu


NLscotty
July 28th, 2010, 06:43 AM
Hello,

I'm trying to create a PopUpMenu, I'm not sure that's the real name. I mean the window that appears when u right click at this site for example. I want to have such a thing, which API should I use?

And I want to create 2 seperates things, one when u right click in the ListView, and one when u click at another ListView.

Thanks,

NM

hoxsiew
July 28th, 2010, 07:32 AM
First you need the menu resource. Then you'll want to handle the WM_CONTEXTMENU message in your message loop. From there, it depends on your framework. Are you using MFC, some other framework, or straight WinAPI?

VictorN
July 28th, 2010, 07:51 AM
Also have a look at TrackPopupMenu(Ex) and other menu functions in MSDN.
There is an MFC example of Context menu (http://www.functionx.com/visualc/howto/contextmenu.htm) but you could very easy to adopt it to the plain Win32 type.

NLscotty
July 28th, 2010, 11:41 AM
First you need the menu resource. Then you'll want to handle the WM_CONTEXTMENU message in your message loop. From there, it depends on your framework. Are you using MFC, some other framework, or straight WinAPI?

I code in pure api, what kind of resource do you mean? I dont use a .rc file to create my window.

Thanjks, ill take a look at that.

I can only find some things about recourse file with it, none in pure code.

VictorN
July 28th, 2010, 11:46 AM
Then you must use Menu APIs to create context menu.

NLscotty
July 28th, 2010, 01:50 PM
I came up with this

case WM_CREATE:
hmenu = CreatePopupMenu();
memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Copy");
emii.cch = 4;
InsertMenuItem(hmenu, 0, TRUE, (LPCMENUITEMINFO) &emii);


if(wParam == IDC_BLOCK)
{
TrackPopupMenu(hmenu,TPM_LEFTBUTTON,100,100,0,hWnd,0);
x = GetLastError();

if i use GetLasterror at the second code, error 1401:Invalid menu handle.

hoxsiew
July 28th, 2010, 02:30 PM
Where is hmenu declared? It is going to have to be global if you assign it in WM_CREATE then use it later in a different message handler.

VictorN
July 28th, 2010, 02:33 PM
And where does your second code block come from? And what is IDC_BLOCK? :confused:

Note that you should NOT call GetLastError unless an API called just before has failed.

NLscotty
July 28th, 2010, 03:12 PM
hemnu is declared in my wndproc (main window loop), so that shoudl be fine.

IDC_BLOCK is name of a button of mine, so if its clicked, it should show me the popupmenu.
It should not work at a button alter, but this was for test prupose.

VictorN
July 28th, 2010, 03:29 PM
hemnu is declared in my wndproc (main window loop), so that shoudl be fine..Sorry, but we cannot believe...
Please, show your code (snippets) with all that declarations/definitions...

NLscotty
July 28th, 2010, 04:16 PM
HINSTANCE hInstance = NULL;
LPCWSTR g_szClassName = TEXT("myWindowClassPEsend");
LPCWSTR g_szClassName1 = TEXT("myWindowClassPErecv");

HWND hWnd = 0;

HWND RecvListView,hHookBut,hSendButton,hSendEdit,hIngBloc,hClean,hBlocIng,hBlock,hIngore,hBlcEd,hIngEd,hBlorIg;
HWND RecvListView2,hHookBut2,hSendButton2,hSendEdit2,hUnhook2,hClean2;

#define IDC_HOOK 101
#define IDC_SEND 102
#define IDC_EDITSEND 103
#define IDC_INBL 106
#define IDC_CLEAN 105
#define IDC_LIST 107
#define IDC_IGNOR 108
#define IDC_BLIN 109
#define IDC_BLOCK 110
#define IDC_INGORE 111
#define IDC_INGED 112
#define IDC_BLCED 113

#define IDC_HOOK2 101
#define IDC_SEND2 102
#define IDC_EDITSEND2 103
#define IDC_UNHOOK2 106
#define IDC_CLEAN2 105
#define IDC_LIST2 107
wchar_t szIgnored[MAX_PACKET_LEN], szBlocked[MAX_PACKET_LEN];

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;
HMENU hmenu;
MENUITEMINFO emii;
int x = 0;
switch(msg)
{
case WM_CREATE:
hmenu = CreatePopupMenu();
x = GetLastError();
memset(&emii, 0, sizeof(MENUITEMINFO));
emii.cbSize = sizeof(MENUITEMINFO);
emii.fMask = MIIM_STRING | MIIM_FTYPE;
emii.fType = MIIM_STRING;
emii.dwTypeData = TEXT("Copy");
emii.cch = 4;
InsertMenuItem(hmenu, 0, TRUE, (LPCMENUITEMINFO) &emii);





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 );
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 );
for (int i = 1; i <= 4; i++)
{
InsertLVColumn(RecvListView, i, i, szColumnHeadings[i - 1], iColumnWidths[i - 1], (i == 4 ? false : true));
}
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));
break;


case WM_COMMAND:
if(wParam == IDC_HOOK)
{
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&InstallMapleStorySendHook, 0, 0, 0);
SetDlgItemTextA(hWnd,IDC_HOOK,"Unhook");
}
if(wParam == IDC_SEND)
{
char buffer[5000];
GetDlgItemTextA(hWnd,IDC_EDITSEND ,buffer,5000);
eraseAllBlanks(buffer);
msSendPacketA(buffer);
}
if(wParam == IDC_BLOCK)
{
TrackPopupMenu(hmenu,TPM_LEFTBUTTON,100,100,0,hWnd,0);
GetDlgItemText(hWnd, IDC_BLCED,szBlocked, MAX_PACKET_LEN);
LVITEM lvi;

ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iItem = SendMessage(RecvListView, LVM_GETITEMCOUNT, 0, 0); /* or set to 0 for testing */
lvi.iSubItem = 0;
lvi.pszText = szBlocked;
lvi.cchTextMax = lstrlen(lvi.pszText) + 1;
ListView_InsertItem(hBlocIng, &lvi);
}

VladimirF
July 28th, 2010, 05:10 PM
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
...
HMENU hmenu;
Please re-read hoxsiew post # 7 above.
When your WndProc is called with WM_COMMAND message, that hmenu contains garbage.

NLscotty
July 28th, 2010, 06:06 PM
thanks that worked, which i define as weird, but well it works:)

Next problem is that when i add 2 lines, they are next each other, and not under each other, it looks weird, and how can i make it that if people right clcik at a treeview, the window appears and that when they hit ignore, the value of the third colum in a char gets?

Igor Vartanov
July 29th, 2010, 03:03 AM
thanks that worked, which i define as weirdWeird was your declaring it in function scope. Right after processing WM_CREATE the function returns, and your menu handle gets lost. Next time when you process button click you use uninitialized variable value and fail with no doubt.

NLscotty
July 29th, 2010, 04:00 AM
I see, thanks for all the help, but

How can i make it like that, when someone right click at a listview box, the window appears, and when they click at something the char from that colum gets in a char.

Grz
NM

VictorN
July 29th, 2010, 04:06 AM
To handle a "right click" you should handle WM_CONTEXTMENU message (note that hoxsiew already pointed it out in the post#2!)

NLscotty
July 29th, 2010, 07:57 AM
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?

VictorN
July 29th, 2010, 08:01 AM
Please, explain more clear and with normal words rather than abbreviations what you want and what for.

NLscotty
July 29th, 2010, 08:03 AM
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.

hoxsiew
July 29th, 2010, 08:18 AM
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.

NLscotty
July 29th, 2010, 09:00 AM
Could you explain me that a bit more? Its not really clear for me

VictorN
July 29th, 2010, 09:09 AM
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.

hoxsiew
July 29th, 2010, 09:33 AM
See this article from MSDN too:

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

NLscotty
July 29th, 2010, 10:48 AM
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);
}

Tahts my new Proc

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;

In the last line i call it, but it doesnt work, i set a breakpoint at the ListViewProc, never gets there.

VictorN
July 29th, 2010, 11:31 AM
1. Where did you set a break point?

2. case WM_CONTEXTMENU:
if(WM_RBUTTONDOWN) {

POINT p;
GetCursorPos(&p);
TrackPopupMenu(hmenu,TPM_LEFTBUTTON,p.x,p.y,0,hWnd,0);
}
This line in read does not make any sense, because WM_RBUTTONDOWN is defined as a number not equaled to zero.
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)

NLscotty
July 29th, 2010, 12:14 PM
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.

VictorN
July 29th, 2010, 12:41 PM
2. Hmm, it worked, now you say it doesnt make sense, this confuses me a little.What "worked"? You've just written it didn't! :confused:

3. Oee but i was told this was how i should do it, to obtain the char value of the colum that is clicked.Could you more clear define what "the char value of the colum that is clicked" means?

NLscotty
July 29th, 2010, 01:20 PM
What "worked"? You've just written it didn't! :confused:

Could you more clear define what "the char value of the colum that is clicked" means?

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?

VictorN
July 29th, 2010, 01:49 PM
Have a look at LVM_HITTEST Message (http://msdn.microsoft.com/en-us/library/bb761099(v=VS.85).aspx) and LVM_SUBITEMHITTEST Message (http://msdn.microsoft.com/en-us/library/bb761229(v=VS.85).aspx)

NLscotty
July 30th, 2010, 08:45 AM
Thanks all i got it working now