Re: MleText window does not show text
- Posted by sergelli Nov 11, 2012
- 1451 views
petelomax said...
I would try adding an onpaint routine, and do all drawing from there.
Thanks, Pete
I used w32HKeyUp and made some changes in procedure "afterKeyUp" and the program worked well.
But it seems that this code does not work, if I use w32HKeyPress and w32KeyDown, without making special code
Following, is the code that is now working. Perhaps it is useful for someone who wants to know about syntax coloring
-- 11/11/12 sintaxColor.exw -- separa e coloriza trecho digitado em lista de opções include WIN32lib.ew constant version="1.1" -- ,FONTWH={12,12} ,WIN1 =create(Window,"Pedido - "&version,0,00,00,900,720,0) -- col,lin ,NOMBOX=create(MleText ,"",WIN1,240,03,420,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FINDNOM=create(MleText ,"",WIN1,220,55,626,240, -- *8 Para font default { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ,FONE =create(MleText ,"",WIN1,680,03,160,30, -- cx entrada nome cliente { WS_CLIPPINGCHILD, WS_VISIBLE,WS_TABSTOP, ES_SAVESEL ,WS_BORDER } ) ----------------------------------------------------------------------------------- setWindowBackColor( WIN1,{200,255,230}) setFont({FINDNOM,FONE,NOMBOX},"Courier New", 12, Bold ) -- setVisible(FINDNOM,0) setFocus(NOMBOX) ----------------------------------------------------------------------------------- atom Li1,Choice Li1=1 Choice=2 sequence LisCli,Linhas LisCli={"0001|sem cadastro |11 97222-6461" ,"0002|Dudu e Isa |11 91234-1234" ,"0003|Jerry |12 91234-1234" ,"0004|Alcindo e Silvana |12 91234-1234" ,"0005|Sergio Gelli |11 97222-6461" ,"0006|Jose Inacio |11 91234-1234"} -- ------------------------------------------teste linha formatada ------------------------ cor text, cor fundo, zero inutil, mas nao da erro -- block={ { { "aaaaaaa" }, {BrightWhite},{Blue},{0} } -- linha 1 c/1 palavra -- , { { "aaaaaaa" }, {Blue},{BrightWhite} } -- linha 1 c/1 palavra ----------------------- text1 text2 fund 1 fund2 -- , { { "AAAAAAA","bbBB" }, {Blue,BrightWhite},{BrightWhite ,Red } } -- linha 2 c/2 palavras ----------------------- text1 text2 text3 fund 1 fund2 fund3 -- , { { "AAAAAAA","bbBB","ccCC" }, {Blue,BrightWhite,0},{BrightWhite,0,Red } } -- linha 2 c/3 palavras -- } -- ------------------------------------------fim teste ---------------------------------------------------------------------------------------------------------- procedure printText(integer id,sequence block,integer colunaX, integer linhaY ) integer colTempX, fontwidth, fontheight atom hdc, result, pstr sequence BBox, comboline, textline, text, colourline, backcolour, data -- early out? if length( block ) = 0 then -- block=bloco usando o texto formatado c/TextToAnalysedLine(junk) return end if -- data = getFontSize(id) -- -- if length(data)=0 then data={10,10} end if data={10,18} fontwidth = data[1] fontheight = data[2] hdc = getDC( id ) -- ORIGINAL get the device context -- hdc = getDC( WIN2 ) -- ORIGINAL get the device context result= assignFont( {id,hdc}) -- Gets the device context for id with the current font installed. -- result= assignFont( {WIN2,hdc}) -- Gets the device context for id with the current font installed. ------------------- ------------------- -- display the text ------------------- ------------------- for i = 1 to length(block) do comboline = block[i] -- extract data for the current line textline = comboline[1] -- extract text for the current line colourline = comboline[2] -- extract color text for the current line backcolour = comboline[3] -- extract backGround for the current line colTempX = colunaX for j = 1 to length(textline) do text = textline[j] -- set the Pen Position BBox = convPctToPixel(id, colTempX,linhaY, 0, 0) result = w32Func( xSetTextColor, {hdc, colourline[j] } ) result = w32Func( xSetBkColor, {hdc, backcolour[j] } ) result = w32Func( xSetBkMode, {hdc, OPAQUE } ) -- copy string to memory pstr = w32acquire_mem(0,text ) -- write out string to window/device w32Proc( xTextOut, { hdc, BBox[1], BBox[2], pstr, length( text ) } ) -- advance column pointer to next start pos colTempX += length(text) * fontwidth -- Free the string w32release_mem(pstr) end for -- advance row to next position linhaY += fontheight end for -- replace the font with the default again replaceObject( id, kFontObject, hdc,-1,ForProgram) -- -1 = DefaultFontID -- release the device context -- copyBlt(id, 250, 250, id) releaseDC( id ) end procedure ------------------------------------------------------------------------------------------------------- procedure fazLinha(sequence preDigi,sequence digi2,sequence posDigi,sequence data4) sequence spc spc={} while length(spc&preDigi&digi2&posDigi&data4)<60 do spc&=" " -- p/completar nome c/espaços end while --Linhas={ { { "aaaaaaa" }, {12345679},{987654321} } -- linha 1 c/1 palavra -- -- -- -- -- -- cores texto cores fundo -- , { { "AAAAAAA","bbBB","ccCC" }, { 65200,12582911,0},{0,65200,12582911 } } -- linha 2 c/3 palavras if Li1=Choice then Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{Yellow,Red,Yellow,Yellow},{Red,Yellow,Red,Red} } ) else Linhas=append (Linhas,{ {preDigi,digi2,posDigi,spc&data4},{65200,Blue,65200,65200},{Blue,65200,Blue,Blue} } ) end if Li1+=1 end procedure -------------------------------------------------------------------------------------------------------------- procedure afterKeyUp(integer id, integer event, sequence parms) atom zzz sequence text1 zzz=0 if id!=NOMBOX then return end if clearWindow (FINDNOM) if not match(sprintf("%s",{parms[1]}),"1234567890_- +/\\&@#%*()ABCDEFGHIJKLMNOPQRSTUVXYZ_abcdefghijklmnopqrstuvxyz") then if parms[1]=8 then -- do nothing else return -- printable key em NOMBOX end if end if text1=getText(NOMBOX) if length(text1)=0 then return end if setVisible(FINDNOM,1) repaintWindow( FINDNOM ) Linhas={} Li1=1 for i=1 to length(LisCli) do event=match(upper(text1),upper(LisCli[i])) -- event>0 = encontrou nome com texto digitado if event>0 then -- encontrou texto digitado zzz=1 parms=w32trim( LisCli[i]) -- linha que contém o texto fazLinha(parms[1..event-1] -- antes do digitado ,text1 -- texto digitado ,parms[event+length(text1)..length(parms)] -- depois do digitado ,"" ) -- telefone end if end for if zzz=0 then setVisible(FINDNOM,0) else printText(FINDNOM,Linhas,03, 03) -- procedure em resources.ew copyBlt(FINDNOM, 1,1, FINDNOM) end if end procedure ----------------------------------------------------------------------------------------------------------- setHandler( NOMBOX, w32HKeyUp,routine_id("afterKeyUp")) ----------------------------------------------------------------------------------------------------------- WinMain(WIN1,Normal)