Announcement

Collapse
No announcement yet.

DrawText

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DrawText

    hi all,
    help for this bunction DrawText http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    PHP Code:
    function DrawText(hDCnLeftnRightnTopnBottomstrString)
    local format "DT_END_ELLIPSIS | DT_MODIFYSTRING";
    Memory.OpenLibrary(0"user32.dll")
    local openDrawText Memory.OpenFunction(0"DrawText"DLL_CALL_STDCALLDLL_RETURN_VOID);
    local margin Memory.CreateStructure("int,int,int,int");
      if( 
    margin 0)then
      Memory
    .SetStructureData(margin10nLeft"");
      
    Memory.SetStructureData(margin20nRight"");
      
    Memory.SetStructureData(margin30nTop"");
      
    Memory.SetStructureData(margin40nBottom"");
      
    Memory.CallFunction(openDrawTexthDCstrString, -1marginformat)
      
    end
    Memory
    .CloseLibrary(0); 
    Memory.Free();
    end 

  • #2
    Why are you using the memory plugin when the MemoryEx one is here that is supported?

    Code:
    "DT_END_ELLIPSIS | DT_MODIFYSTRING"
    only makes a string when it needs to be a number so:

    Code:
    CONSTRAINT_1 = 0001
    CONSTRAINT_2 = 0002
    
    format = CONSTRAINT_1 + CONSTRAINT_2
    If you want to swap over to MemoryEx then I can help you further but I'm not learning the Memory plugin as its old but typically with these winapi functions you just create all your structures then create and fill your buffers then call the function from the already loaded library.

    Comment


    • #3
      i do not know much about him, but I tried to do something

      PHP Code:
      DT_END_ELLIPSIS 0x00008000
      DT_MODIFYSTRING 
      0x00010000

      function DrawText(hDCnLeftnRightnTopnBottomstrString)
      local sFormat DT_MODIFYSTRING DT_END_ELLIPSIS
      local nLen 
      String.Length(strString);
      User32 Library.Load("user32.dll");
      local sStruct MemoryEx.DefineStruct{
      INT("Left"   ,1nLeft);
      INT("Top"    ,2nTop);
      INT("Right"  ,3nRight);
      INT("Bottom" ,4nBottom);
      };
      local lpBuff MemoryEx.Allocate(MemoryEx.StructSize(sStruct));
        if 
      lpBuff then
        local hStruct 
      MemoryEx.AssignStruct(lpBuffsStruct);
        
      User32.DrawText(hDCstrStringnLenhStructsFormat)
        
      end
      User32
      :Close_();  
      end 

      Comment


      • #4
        I personally can't help with the Memoy plugin but I use drawtext with MemoryEx for custom drawing controls so the method is not going to be all that different:


        Code:
        [COLOR="#008000"]--Global code[/COLOR]
        
        [COLOR="#008000"]-- Load the library, this loads all functions of user32, no need to free it.[/COLOR]
        User32 [COLOR="#FF0000"]=[/COLOR] Library[COLOR="#FF0000"].[/COLOR]Load([COLOR="#800080"]"user32.dll"[/COLOR])
        
        [COLOR="#008000"]-- Define a RECT structure[/COLOR]
        RECT [COLOR="#FF0000"]=[/COLOR] MemoryEx[COLOR="#FF0000"].[/COLOR]DefineStruct[COLOR="#FF0000"]{[/COLOR]
         INT [COLOR="#800080"]"left"[/COLOR];
         INT [COLOR="#800080"]"top"[/COLOR];
         INT [COLOR="#800080"]"right"[/COLOR];
         INT [COLOR="#800080"]"bottom"[/COLOR];
        [COLOR="#FF0000"]}[/COLOR];
        
        [COLOR="#008000"]-- The draw function[/COLOR]
        DrawText [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](Txt[COLOR="#FF0000"],[/COLOR]HDC[COLOR="#FF0000"],[/COLOR]nLeft[COLOR="#FF0000"],[/COLOR]nRight[COLOR="#FF0000"],[/COLOR]nTop[COLOR="#FF0000"],[/COLOR]nBottom)
         [COLOR="#0000FF"]local[/COLOR] r [COLOR="#FF0000"]=[/COLOR] RECT:New()
         r[COLOR="#FF0000"].[/COLOR]left [COLOR="#FF0000"]=[/COLOR] nLeft
         r[COLOR="#FF0000"].[/COLOR]right [COLOR="#FF0000"]=[/COLOR] nRight
         r[COLOR="#FF0000"].[/COLOR]top [COLOR="#FF0000"]=[/COLOR] nTop
         r[COLOR="#FF0000"].[/COLOR]bottom [COLOR="#FF0000"]=[/COLOR] nBottom
         [COLOR="#0000FF"]local[/COLOR] m [COLOR="#FF0000"]=[/COLOR] MemoryEx[COLOR="#FF0000"].[/COLOR]Allocate(String[COLOR="#FF0000"].[/COLOR]Length(Txt) + [COLOR="#000000"]1[/COLOR])
         MemoryEx[COLOR="#FF0000"].[/COLOR]String(m[COLOR="#FF0000"],[/COLOR]-[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR]MEMEX_ASCII[COLOR="#FF0000"],[/COLOR]Txt)
         User32[COLOR="#FF0000"].[/COLOR]DrawTextA(HDC[COLOR="#FF0000"],[/COLOR]m[COLOR="#FF0000"],[/COLOR]-[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR]r:GetPointer()[COLOR="#FF0000"],[/COLOR]0x8100)
         r:Free()
         MemoryEx[COLOR="#FF0000"].[/COLOR]Free(m)
        [COLOR="#0000FF"]end[/COLOR];
        
        [COLOR="#008000"]-- Note: when using the api functions if you get a choice of ASCII or Unicode pick ASCII eg; DrawTextA[/COLOR]

        Comment


        • #5
          thanks for info and function method Shrek how can i use

          DrawText("My Text",Application.GetWndHandle(),50,50,20,50)

          Comment


          • #6
            If your using the RECT structure more than once or frequently you can use it this way instead:

            Code:
            [COLOR="#008000"]--Global code[/COLOR]
            
            [COLOR="#008000"]-- Load the library, this loads all functions of user32, no need to free it.[/COLOR]
            User32 [COLOR="#FF0000"]=[/COLOR] Library[COLOR="#FF0000"].[/COLOR]Load([COLOR="#800080"]"user32.dll"[/COLOR]);
            
            [COLOR="#008000"]-- Define a RECT structure[/COLOR]
            RECT [COLOR="#FF0000"]=[/COLOR] MemoryEx[COLOR="#FF0000"].[/COLOR]DefineStruct[COLOR="#FF0000"]{[/COLOR]
             INT [COLOR="#800080"]"left"[/COLOR];
             INT [COLOR="#800080"]"top"[/COLOR];
             INT [COLOR="#800080"]"right"[/COLOR];
             INT [COLOR="#800080"]"bottom"[/COLOR];
            [COLOR="#FF0000"]}[/COLOR];
            
            [COLOR="#008000"]-- Create a table to hold structures[/COLOR]
            Struct [COLOR="#FF0000"]=[/COLOR] [COLOR="#FF0000"]{}[/COLOR]
            Struct[COLOR="#FF0000"].[/COLOR]A [COLOR="#FF0000"]=[/COLOR] RECT:New()
            
            [COLOR="#008000"]-- The draw function[/COLOR]
            DrawText [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](Txt[COLOR="#FF0000"],[/COLOR]HDC[COLOR="#FF0000"],[/COLOR]nLeft[COLOR="#FF0000"],[/COLOR]nRight[COLOR="#FF0000"],[/COLOR]nTop[COLOR="#FF0000"],[/COLOR]nBottom)
             Struct[COLOR="#FF0000"].[/COLOR]A[COLOR="#FF0000"].[/COLOR]left [COLOR="#FF0000"]=[/COLOR] nLeft
             Struct[COLOR="#FF0000"].[/COLOR]A[COLOR="#FF0000"].[/COLOR]right [COLOR="#FF0000"]=[/COLOR] nRight
             Struct[COLOR="#FF0000"].[/COLOR]A[COLOR="#FF0000"].[/COLOR]top [COLOR="#FF0000"]=[/COLOR] nTop
             Struct[COLOR="#FF0000"].[/COLOR]A[COLOR="#FF0000"].[/COLOR]bottom [COLOR="#FF0000"]=[/COLOR] nBottom
             [COLOR="#0000FF"]local[/COLOR] m [COLOR="#FF0000"]=[/COLOR] MemoryEx[COLOR="#FF0000"].[/COLOR]Allocate(String[COLOR="#FF0000"].[/COLOR]Length(Txt) + [COLOR="#000000"]1[/COLOR])
             MemoryEx[COLOR="#FF0000"].[/COLOR]String(m[COLOR="#FF0000"],[/COLOR]-[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR]MEMEX_ASCII[COLOR="#FF0000"],[/COLOR]Txt)
             User32[COLOR="#FF0000"].[/COLOR]DrawTextA(HDC[COLOR="#FF0000"],[/COLOR]m[COLOR="#FF0000"],[/COLOR]-[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR]Struct[COLOR="#FF0000"].[/COLOR]A:GetPointer()[COLOR="#FF0000"],[/COLOR]0x8100)
             MemoryEx[COLOR="#FF0000"].[/COLOR]Free(m)
            [COLOR="#0000FF"]end[/COLOR];
            
            [COLOR="#008000"]-- Note: when using the api functions if you get a choice of ASCII or Unicode pick ASCII eg; DrawTextA[/COLOR]
            To draw text on the main page, as it would if you use Application.GetWndHandle, then you need to get the device context for the window handle:

            Code:
            GetDC [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](hdl)
             [COLOR="#0000FF"]return[/COLOR] User32[COLOR="#FF0000"].[/COLOR]GetDC(hdl)
            [COLOR="#0000FF"]end[/COLOR];
            ReleaseDC [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](hdl[COLOR="#FF0000"],[/COLOR]dc)
             [COLOR="#008000"]-- dc is returned from GetDC[/COLOR]
             [COLOR="#0000FF"]return[/COLOR] User32[COLOR="#FF0000"].[/COLOR]ReleaseDC(hdl[COLOR="#FF0000"],[/COLOR]dc)
            [COLOR="#0000FF"]end[/COLOR];
            If your application resizes then you'll need to redraw the text on resize.

            Example calling:

            Code:
            [COLOR="#0000FF"]local[/COLOR] dc [COLOR="#FF0000"]=[/COLOR] GetDC(Application[COLOR="#FF0000"].[/COLOR]GetWndHandle())
            DrawText([COLOR="#800080"]"My Text"[/COLOR][COLOR="#FF0000"],[/COLOR]dc[COLOR="#FF0000"],[/COLOR][COLOR="#000000"]50[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]50[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]20[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]50[/COLOR])
            ReleaseDC(Application[COLOR="#FF0000"].[/COLOR]GetWndHandle()[COLOR="#FF0000"],[/COLOR]dc)
            In the DrawText function example I use 0x8100 as that was just in the code I already wrote so you could replace that with a function variable tailored to what you want.

            Comment


            • #7
              awesome... Shrek way to change font and color or size ? big thanks for the help

              Comment


              • #8
                Originally posted by milano88 View Post
                awesome... Shrek way to change font and color or size ? big thanks for the help
                My understanding is the device context is set by AMS and the options you specify so if you change the device context you need to first get the current values so you can restore them to what they were otherwise all drawing on the window will change to the new values the next time the window is redrawn.

                The font and font size are determined by the font so you need to make a new one, this creates a font in size 16:

                Code:
                Gdi32 = Library.Load("Gdi32.dll");
                FONTA = Gdi32.CreateFontA(16,0,0,0,400,0,0,0,0,0,0,4,0,"Segoe UI")
                to get the text and set the text colors you use the functions here.

                Comment


                • #9
                  ok problem is solved, big..big thanks for the help Shrek :yes

                  PHP Code:
                  local dc GetDC(Application.GetWndHandle())
                  local font Gdi32.CreateFontA(16,0,0,0,400,0,0,0,0,0,0,4,0,"Tahoma")
                  Gdi32.SetBkMode(dc"TRANSPARENT")
                  Gdi32.SelectObject(dc,font)
                  DrawText("DrawText function (Windows)",dc,10,130,10,10)
                  ReleaseDC(Application.GetWndHandle(),dc

                  Comment

                  Working...
                  X