Re: How to add to Edit Text default context menu

new topic     » goto parent     » topic index » view thread      » older message » newer message
penpal0andrew said...

I am writing a program with edit fields using win32lib version "0.70.20" Windows has a right click context menu used on EditText fields with (Undo, Cut, Copy, Paste, Delete, Select all). I would like to keep that functionality intact, and add more items. How can this be done? Thank you in advance.

Hi

i do not use win32lib regulary, so i wrote a quick and dirty solution with tinewg, hopefully this gives you enough hints for a solution with win32lib.
there are maybe better solutions, but i'am sure you have to subclass your editcontrol (maybe handling WM_CONTEXTMENU)

I think the code is not to complicated and small enough.
MSDN is your friend ;)
Andreas

include tinewg.exw 
include std/dll.e 
 
-- create your own popup  
 
atom popup=CreatePopupMenu() 
AppendTextItem(popup,101,"Copy") 
AppendTextItem(popup,102,"Paste") 
AppendTextItem(popup,103,"Cut") 
AppendTextItem(popup,104,"Delete") 
AppendTextItem(popup,105,"Select All") 
AppendSeparator(popup) 
AppendTextItem(popup,106,"CloseApp") 
 
-- Create a Window and a EditControl 
 
Window("test") 
SetClientRect(WinHwnd,400,200) 
constant edit=Control(MultiEdit,"",50,0,350,200) 
 
-- SubClass the EditControl and handle the WM_RBUTTONDOWN yourself  
 
function EditWndProc(atom hwnd,atom msg,atom wParam,atom lParam) 
sequence rect 
    if equal(msg,WM_RBUTTONDOWN) then 
		rect=GetWindowRect(edit) 
		TrackPopupMenu(popup,rect[1]+LoWord(lParam),rect[2]+HiWord(lParam),WinHwnd) 
	return 0 -- WM_RBUTTONDOWN never reaches the original EditWindowProc  
		   -- so the default menu never appears 
    end if 
    return  CallWindowProc(OldWndProc,hwnd,msg,wParam,lParam) 
end function 
 
constant OldWndProc=GetWindowLong(edit,GWL_WNDPROC) 
SetWindowLong(edit,GWL_WNDPROC,call_back(routine_id("EditWndProc"))) 
 
-- Your handler for your menu 
 
procedure menuhandler() 
	switch EventItem do 
		case 101 then  
			SendMessage(edit,WM_COPY,0,0) 
		case 102 then 
			SendMessage(edit,WM_PASTE,0,0) 
		case 103 then 
			SendMessage(edit,WM_CUT,0,0) 
		case 104 then 
			SendMessage(edit,WM_CLEAR,0,0) 
		case 105 then 
			SendMessage(edit,EM_SETSEL,0,-1) 
		case 106 then 
			CloseApp() 
		-- and so on ... 
	end switch 
end procedure 
SetHandler(WinHwnd,Menu,routine_id("menuhandler")) 
 
WinMain() 
 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu