Re: Can No Longer Run Phix Apps

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

That got me working. Should I run with it, or is there more to do?

Let's see what the following spits out. Run from anywhere, adjusting the path to Arwen.ew as needed

include demo\arwen\Arwen.ew 
 
constant isDebug = false 
 
constant CD_OPEN=#20050227, -- open file 
         CD_EDITA=#20050228, -- Are you really Edita? 
         CD_PFTP=#20070421  -- Are you really pFTP? 
 
integer cd_what 
sequence cd_text 
 
constant Edita="Edita" 
 
atom Hwnd 
 
constant xGetWindowModuleFileName = link_c_func(user32, "GetWindowModuleFileName", 
            {C_PTR,     --  HWND  hWnd 
             C_PTR,     --  lpszFileName 
             C_INT},    --  UINT cchFileNameMax 
            C_INT),     -- UINT 
         xGetWindowText = link_c_func(user32, "GetWindowTextA", 
            {C_PTR,     --  HWND hWnd, 
             C_PTR,     --  LPTSTR lpString, 
             C_INT},    --  int nMaxCount 
            C_INT),     -- int 
        pszFileName = allocate(500) 
 
function EnumWindowsProc(atom hwnd, atom lParam) 
atom mem, CDS 
integer len, len2 
sequence text 
    if lParam then end if   -- suppress warnings 
if 0 then 
    len = c_func(xGetWindowModuleFileName,{hwnd,pszFileName,500}) 
    if len then 
        string szFileName = peek({pszFileName,len}) 
        printf(1,"module:%s\n",{szFileName}) 
    end if 
else 
    len = c_func(xGetWindowText,{hwnd,pszFileName,500}) 
    if len then 
        string pString = peek({pszFileName,len}) 
        if not find(pString,{"Default IME","MSCTFIME UI"}) then 
            printf(1,"Window title:%s\n",{pString}) 
        end if 
    end if 
end if 
    len = c_func(xSendMessage, {hwnd, WM_GETTEXTLENGTH, 0, 0}) 
    if len>=length(cd_text) then 
        len += 1 
        mem = allocate(len) 
        len2 = c_func(xSendMessage, {hwnd, WM_GETTEXT, len, mem}) 
        if len2+1 != len then ?9/0 end if   -- sanity check 
        text = peek({mem, len}) 
if not find(text,{"MSCTFIME UI\0","Default IME\0"}) then ?{"text",text} end if 
        free(mem) 
        if match(cd_text,text)=1 then 
            -- 
            -- Edita already running? 
            -- 
            CDS = allocate(12) 
            poke4(CDS,{cd_what,0,0}) 
            if c_func(xSendMessage,{hwnd, WM_COPYDATA, NULL, CDS})=cd_what then 
                Hwnd = hwnd 
                if cd_what=CD_EDITA then 
?"EDITA" 
return 1 
                end if 
                -- 
                -- make existing edita topmost 
                -- 
                if c_func(xIsIconic,{hwnd}) then 
                    -- Thanks to Pete Stoner/joel on software 
                    -- If the window is minimised, restore it before  
                    -- trying to make it the foreground window. 
                    c_proc(xShowWindow,{hwnd,SW_RESTORE}) 
                end if 
                c_proc(xSetForegroundWindow,{hwnd}) 
                free(CDS) 
                if cd_what=CD_EDITA then 
                    -- .. and terminate. 
--                  abort(0) 
?"FOUND EDITA... continuing" 
                end if 
--              return 0    -- cease enumeration 
                return 1 
            end if 
            free(CDS) 
        end if 
    end if   
    return 1    -- continue enumeration 
end function 
 
constant cb_ewp = call_back(routine_id("EnumWindowsProc")) 
 
global function checkSingleInstance(integer cwhat)  -- now called from eaini.e 
    cd_what=cwhat 
    if cd_what=CD_EDITA then 
        cd_text=Edita 
    elsif cd_what=CD_PFTP then 
        cd_text="pFTP" 
    else 
        ?9/0 
    end if 
    Hwnd = 0 
    void = c_func(xEnumWindows,{cb_ewp,NULL}) 
    return Hwnd -- 0 if not found else hwnd of window. 
end function 
 
?"begin" 
?checkSingleInstance(CD_EDITA) 
?"done" 
{} = wait_key() 
abort(0) 

If it's not getting to the "done", something ain't playing nice.
Unfortunately it will probably show the window before rather than the one actually in error.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu