The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: stalker on July 30, 2008, 09:04:58 AM

Title: When I right click on a ListBox,which message will the window receives?
Post by: stalker on July 30, 2008, 09:04:58 AM
as the title,how to empty a ListBox(of course in win32asm)
haha,the post work now,I have a new question about ListBox
as the title also,actually,i want my program work like this:when i right click on the ListBox,a pop menu will appear
Title: Re: How to empty a ListBox
Post by: stalker on July 30, 2008, 09:19:57 AM
LB_RESETCONTENT

there has another question on the top :bg
Title: Re: How to empty a ListBox
Post by: hutch-- on July 30, 2008, 10:01:20 AM
No need to apologise, its a reasonable question and you have provided the answer as well.  :U
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: PBrennick on July 30, 2008, 01:26:40 PM
Personally, I always enjoy questions because it keeps my brain working ( and sometimes I even have the right answer ). What is really exciting, though, is to see someone find a solution themselves. It is a credit to a person who just does not sit back and wait for an answer but continues to plug away trying to find an answer themselves.

Good work, stalker.

-- Paul
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: stalker on July 30, 2008, 01:40:14 PM
hey,Paul,nice to meet you
but have you saw my new question?I add a new question in the post
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: PBrennick on July 30, 2008, 02:23:56 PM
stalker,
This is the way to do it.


       .elseif uMsg == WM_RBUTTONDOWN
         invoke  GetCursorPos, ADDR Pt
         invoke  GetSubMenu, hMnu, menu_popup
         mov     hSM, eax
         invoke  TrackPopupMenu, hSM, TPM_LEFTALIGN or TPM_LEFTBUTTON,
                 Pt.x, Pt.y, 0, hWnd, NULL



Where the WM_RBUTTONDOWN and TrackPopupMenu are very important. I am attaching a very old editor I wrote years ago that has this code in it. With it you can see how it is done. The menu is drawn as a copy from the main menu. In this case, I am using the File subMenu, you can use any of them or create an original one with special functions.
If you need more help, just ask.
-- Paul


[attachment deleted by admin]
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: japheth on July 30, 2008, 02:43:10 PM

IIRC the window receives WM_RBUTTONDOWN, the parent window gets a WM_NOTIFY / NM_RCLICK. 

Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: PBrennick on July 30, 2008, 03:07:20 PM
Japheth,
That is possible although the documentation does not mention that. At any rate the menu pops up without processing those messages as you can see in the editor. The only thing I am using WM_NOTIFY for is the processing of ToolTips.

-- Paul
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: japheth on July 30, 2008, 03:52:53 PM
Quote from: PBrennick on July 30, 2008, 03:07:20 PM
Japheth,
That is possible although the documentation does not mention that. At any rate the menu pops up without processing those messages as you can see in the editor. The only thing I am using WM_NOTIFY for is the processing of ToolTips.

-- Paul

Yes, sorry! I meant Common Controls - like ListView - but the OP talked about ListBox, so my comment was a bit off-topic.
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: stalker on July 31, 2008, 01:36:02 AM
thank you  all at first

.elseif uMsg == WM_RBUTTONDOWN
    invoke MessageBox,0,0,0,0


I added the code above in my message process function,but when i right click on the ListBox,nothing happened :(
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: jj2007 on July 31, 2008, 07:41:48 AM
Quote from: stalker on July 31, 2008, 01:36:02 AM
I added the code above in my message process function,but when i right click on the ListBox,nothing happened :(

You may have to subclass the listbox. Here are the necessary elements.

SubList   PROTO:DWORD,:DWORD,:DWORD,:DWORD

opList   dd ? ; handle to listbox

   invoke SetWindowLong, hList, GWL_WNDPROC, SubList
   mov opList, eax

SubList proc hwnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
   SWITCH uMsg
   CASE WM_RBUTTONUP

   CASE WM_RBUTTONDOWN

   ENDSW

  invoke CallWindowProc, opList, hwnd, uMsg, wParam, lParam
  ret
SubList endp
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: evlncrn8 on July 31, 2008, 10:20:57 AM
its a bit over the top subclassing it for that, just use the messaging system, less bother and less potential for bugs...
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: stalker on July 31, 2008, 11:21:33 AM
thank your code jj2007,my problem have solved,thank you all again :bg
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: jj2007 on July 31, 2008, 11:55:36 AM
Quote from: evlncrn8 on July 31, 2008, 10:20:57 AM
its a bit over the top subclassing it for that, just use the messaging system, less bother and less potential for bugs...

I like simple solutions - show me, please!
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: PBrennick on July 31, 2008, 02:50:05 PM
JJ,
Tedd already explained this in another topic. If you add something like the following to the main message loop that usually is in WinMain (doesn't have to be, though):


    invoke  IsDialogMessage, hFind, addr msg  ; Find Dialog box message?


You will add the dialog to the messaging system. In this case, this is processing my FIND dialog in my editor. If the message is for this dialog, acontrol is passed to FindDlgProc and the key is processed.

-- Paul
Title: Re: When I right click on a ListBox,which message will the window receives?
Post by: jj2007 on July 31, 2008, 05:46:20 PM
Quote from: PBrennick on July 31, 2008, 02:50:05 PM
JJ,
Tedd already explained this in another topic. If you add
...
    invoke  IsDialogMessage, hFind, addr msg  ; Find Dialog box message?

Maybe we can ask Stalker to post his code, and then you try to make it work? I tried in my own editor, but the listbox just doesn't care about WM_RBUTTONxx.