IE default CSS/Color per process or instance in Windows
IE default CSS/Color per process or instance in Windows
On Windows only:
One can change the default CSS colors for IE for all applications using Internet Options -> Colors or Internet Options -> Accessibility.
This change is instant for all loaded IE instances, including PureBasic WEB container.
How can one do the same (apply colors or CSS to IE) only for own application / process or embedded instance?
One can change the default CSS colors for IE for all applications using Internet Options -> Colors or Internet Options -> Accessibility.
This change is instant for all loaded IE instances, including PureBasic WEB container.
How can one do the same (apply colors or CSS to IE) only for own application / process or embedded instance?
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
what version of windows are you using?
you could try using sysinternals Process Monitor to see if you can track the registry changes as you apply the setting
but I don't know where I find the settings your referring to on win 11
you could try using sysinternals Process Monitor to see if you can track the registry changes as you apply the setting
but I don't know where I find the settings your referring to on win 11
Re: IE default CSS/Color per process or instance in Windows
Hi Idle,
Internet Options -> colors works on all windows versions from XPSp3 to 11, if you have at least IE 8, but this is per user applied globally - not usable.
The issue is, an application should not change global registry settings - just per process / per instance of IE settings.
I know CodeJock does this somehow in its skinning engine (applies CSS to instances of IE in a *single* application).
If you change it globally, then, for example PB help file will not be legible.
So - how to change default CSS for IE 8+ on per-process basis?
Internet Options -> colors works on all windows versions from XPSp3 to 11, if you have at least IE 8, but this is per user applied globally - not usable.
The issue is, an application should not change global registry settings - just per process / per instance of IE settings.
I know CodeJock does this somehow in its skinning engine (applies CSS to instances of IE in a *single* application).
If you change it globally, then, for example PB help file will not be legible.
So - how to change default CSS for IE 8+ on per-process basis?
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
sorry, I didn't get the per process or instance part.
Re: IE default CSS/Color per process or instance in Windows
Ok,
if one changes the internet options -> colors to for example black background and white text:
All instances of Internet Explorer in all applications will have black background and white text, unless the web page defines it already.
My question is how to do the same but only for single, onw application - the PureBasic application hosting IE in a WEBGadget.
if one changes the internet options -> colors to for example black background and white text:
All instances of Internet Explorer in all applications will have black background and white text, unless the web page defines it already.
My question is how to do the same but only for single, onw application - the PureBasic application hosting IE in a WEBGadget.
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
I will have a look today sometime.
Re: IE default CSS/Color per process or instance in Windows
I looked at different options,
none is reliable,
the best one thus is to parse every html and exchange CSS with own one.
At least it works some of the time nicely.
matter closed until all browsers, email clients and so on support dark modes or coloring correctly.
none is reliable,
the best one thus is to parse every html and exchange CSS with own one.
At least it works some of the time nicely.
matter closed until all browsers, email clients and so on support dark modes or coloring correctly.
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
You have to implement the IDocHostUIHandler interface, in the GetHostInfo method you can supply a css in the DOCHOSTUIINFO structure.
https://learn.microsoft.com/en-us/previ ... 7(v=vs.85)
You will need to be familiar with COM, I can't provide you with a working example.
Search the forum for IDocHostUIHandler, there a some examples.
https://learn.microsoft.com/en-us/previ ... 7(v=vs.85)
You will need to be familiar with COM, I can't provide you with a working example.
Search the forum for IDocHostUIHandler, there a some examples.
Re: IE default CSS/Color per process or instance in Windows
Thank you very much Justin
I found it already it does work, but as my app is on Win/Mac/Linux - I can only do on on Windows.
Manual adjustment, which I have to do anyway (filter out scripts, add my own, filter styles, MSO rubbish, security threads on external images, links and so on)
Is very tedious but at the end - platform independent.
I found it already it does work, but as my app is on Win/Mac/Linux - I can only do on on Windows.
Manual adjustment, which I have to do anyway (filter out scripts, add my own, filter styles, MSO rubbish, security threads on external images, links and so on)
Is very tedious but at the end - platform independent.
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
Thank you.
I cannot find an option flag for setting CSS on MS docs, InternetSetOption handles mostly connectivity and security, maybe I'm missing something.
In any case setting CSS is a poor solution - most HTML files from the Internet I process have fixed colours, so text becomes unreadable with CSS - for example defining background black and foreground white may change the background but not foreground (text style is set on the table / dvi / paragraph level).
So I rather discover colours used via text parsing.
This way most/all the colours used in different variations (hex, some named colors and RGB) are replaced with blended colours, according to my main background/foreground/Link colours. it is not 100% reliable, but works in 80-90% cases, whereas Setting Internet options (via control Panel) works in some 40% cases.
I cannot find an option flag for setting CSS on MS docs, InternetSetOption handles mostly connectivity and security, maybe I'm missing something.
In any case setting CSS is a poor solution - most HTML files from the Internet I process have fixed colours, so text becomes unreadable with CSS - for example defining background black and foreground white may change the background but not foreground (text style is set on the table / dvi / paragraph level).
So I rather discover colours used via text parsing.
This way most/all the colours used in different variations (hex, some named colors and RGB) are replaced with blended colours, according to my main background/foreground/Link colours. it is not 100% reliable, but works in 80-90% cases, whereas Setting Internet options (via control Panel) works in some 40% cases.
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
Hi pamen,
You can't do it with InternetSetOption(). I did a quick test from an IDocHostUIHandler example from here:
https://www.purebasic.fr/english/viewtopic.php?t=69149
And it works, i just filled the IDocHostUIHandler_GetHostInfo() procedure. But setting all the colors you want with css can be tricky.
This simply sets '* {color: blue}'
You can't do it with InternetSetOption(). I did a quick test from an IDocHostUIHandler example from here:
https://www.purebasic.fr/english/viewtopic.php?t=69149
And it works, i just filled the IDocHostUIHandler_GetHostInfo() procedure. But setting all the colors you want with css can be tricky.
This simply sets '* {color: blue}'
Code: Select all
EnableExplicit
;- enum DOCHOSTUIFLAG
#DOCHOSTUIFLAG_DIALOG = $1
#DOCHOSTUIFLAG_DISABLE_HELP_MENU = $2
#DOCHOSTUIFLAG_NO3DBORDER = $4
#DOCHOSTUIFLAG_SCROLL_NO = $8
#DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = $10
#DOCHOSTUIFLAG_OPENNEWWIN = $20
#DOCHOSTUIFLAG_DISABLE_OFFSCREEN = $40
#DOCHOSTUIFLAG_FLAT_SCROLLBAR = $80
#DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = $100
#DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = $200
#DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = $400
#DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = $800
#DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = $1000
#DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = $2000
#DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = $4000
#DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = $10000
#DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = $20000
#DOCHOSTUIFLAG_THEME = $40000
#DOCHOSTUIFLAG_NOTHEME = $80000
#DOCHOSTUIFLAG_NOPICS = $100000
#DOCHOSTUIFLAG_NO3DOUTERBORDER = $200000
#DOCHOSTUIFLAG_DISABLE_EDIT_NS_FIXUP = $400000
#DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK = $800000
#DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL = $1000000
#DOCHOSTUIFLAG_HOST_NAVIGATES = $2000000
#DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION = $4000000
#DOCHOSTUIFLAG_USE_WINDOWLESS_SELECTCONTROL = $8000000
#DOCHOSTUIFLAG_USE_WINDOWED_SELECTCONTROL = $10000000
#DOCHOSTUIFLAG_ENABLE_ACTIVEX_INACTIVATE_MODE = $20000000
#DOCHOSTUIFLAG_DPI_AWARE = $40000000
;- DOCHOSTUIINFO
Structure DOCHOSTUIINFO Align #PB_Structure_AlignC
cbSize.l
dwFlags.l
dwDoubleClick.l
pchHostCss.i
pchHostNS.i
EndStructure
Structure _IDocHostUIHandler
*vTable
ref.i
iDocHostUiHandler.iDocHostUiHandler
EndStructure
;/////////////////////////////////////////////////////////////////////////////////
;Return a HRESULT value (#S_OK if successful).
Procedure.i SetCustomDocHostUIHandler(id, vTableAddress)
Protected result=#E_FAIL, hWnd, iBrowser.IWebBrowser2, iDispatch.IDispatch, iDocument.IHTMLDocument2, iOLE.IOleObject, iDocHostUIHandler.IDocHostUIHandler
Protected iCustomDoc.ICustomDoc, iOLEClientSite.IOleClientSite, *this._IDocHostUIHandler
hWnd = GadgetID(id)
If hWnd
iBrowser = GetWindowLong_(hWnd, #GWL_USERDATA)
If iBrowser
If iBrowser\get_Document(@iDispatch) = #S_OK
If iDispatch\QueryInterface(?IID_IHTMLDocument2, @iDocument) = #S_OK
If iDocument\QueryInterface(?IID_IOleObject, @iOLE) = #S_OK
If iOLE\GetClientSite(@iOLEClientSite) = #S_OK
If iOLEClientSite\QueryInterface(?IID_IDocHostUIHandler, @iDocHostUIHandler) = #S_OK
If iDocument\QueryInterface(?IID_ICustomDoc, @iCustomDoc) = #S_OK
*this = AllocateMemory(SizeOf(_IDocHostUIHandler))
If *this
*this\vTable = vTableAddress
*this\iDocHostUiHandler = iDocHostUIHandler
iCustomDoc\SetUIHandler(*this)
result = #S_OK
Else
iDocHostUIHandler\Release()
EndIf
iCustomDoc\Release()
Else
iDocHostUIHandler\Release()
EndIf
EndIf
IOleClientSite\Release()
EndIf
iOLE\Release()
EndIf
iDocument\Release()
EndIf
iDispatch\Release()
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
Procedure win_onSize()
ResizeGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
;-TEST CODE.
;/////////////////////////////////////////////////////////////////////////////////
Define.i Event
If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
WebGadget(0, 0, 0, 600, 300, "http://www.purebasic.com")
BindEvent(#PB_Event_SizeWindow, @win_onSize())
SetCustomDocHostUIHandler(0, ?IDocHostUIHandlerFunctionTable)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
End
;/////////////////////////////////////////////////////////////////////////////////
;-CUSTOM iDocHostUIHandler IMPLEMENTATION.
;/////////////////////////////////////////////////////////////////////////////////
;iUnknown.
Procedure.i IDocHostUIHandler_QueryInterface(*this._IDocHostUIHandler, riid, *ppObj.INTEGER)
Protected hResult = #E_NOINTERFACE, iunk.iUnknown
If *ppObj And riid
*ppObj\i = 0
If CompareMemory(riid, ?IID_IUnknown, SizeOf(IID)) Or CompareMemory(riid, ?IID_IDocHostUIHandler, SizeOf(IID))
*ppObj\i = *this
*this\ref+1
hResult = #S_OK
EndIf
EndIf
ProcedureReturn hResult
EndProcedure
;iUnknown.
Procedure.i IDocHostUIHandler_AddRef(*this._IDocHostUIHandler)
*this\ref = *this\ref + 1
ProcedureReturn *this\ref
EndProcedure
;iUnknown.
Procedure.i IDocHostUIHandler_Release(*this._IDocHostUIHandler)
Protected refCount
*this\ref = *this\ref - 1
refCount = *this\ref
If *this\ref = 0
*this\iDocHostUiHandler\Release()
FreeMemory(*this)
EndIf
ProcedureReturn refCount
EndProcedure
Procedure.i IDocHostUIHandler_ShowContextMenu(*this._IDocHostUIHandler, dwID, ppt, pcmdTarget, pdispReserved)
ProcedureReturn *this\iDocHostUiHandler\ShowContextMenu(dwID, ppt, pcmdTarget, pdispReserved)
EndProcedure
Procedure.i IDocHostUIHandler_GetHostInfo(*this._IDocHostUIHandler, *pInfo.DOCHOSTUIINFO)
Protected.s scss
Protected.i bcss
scss = "* {color: blue}"
bcss = CoTaskMemAlloc_(StringByteLength(scss + SizeOf(CHARACTER)))
PokeS(bcss, scss)
*pInfo\dwFlags = #DOCHOSTUIFLAG_DPI_AWARE
*pInfo\pchHostCss = bcss
ProcedureReturn #S_OK
EndProcedure
Procedure.i IDocHostUIHandler_ShowUI(*this._IDocHostUIHandler, dwID, pActiveObject, pCommandTarget, pFrame, pDoc)
ProcedureReturn *this\iDocHostUiHandler\ShowUI(dwID, pActiveObject, pCommandTarget, pFrame, pDoc)
EndProcedure
Procedure.i IDocHostUIHandler_HideUI(*this._IDocHostUIHandler)
ProcedureReturn *this\iDocHostUiHandler\HideUI()
EndProcedure
Procedure.i IDocHostUIHandler_UpdateUI(*this._IDocHostUIHandler)
ProcedureReturn *this\iDocHostUiHandler\UpdateUI()
EndProcedure
Procedure.i IDocHostUIHandler_EnableModeless(*this._IDocHostUIHandler, fEnable)
ProcedureReturn *this\iDocHostUiHandler\EnableModeless(fEnable)
EndProcedure
Procedure.i IDocHostUIHandler_OnDocWindowActivate(*this._IDocHostUIHandler, fActivate)
ProcedureReturn *this\iDocHostUiHandler\OnDocWindowActivate(fActivate)
EndProcedure
Procedure.i IDocHostUIHandler_OnFrameWindowActivate(*this._IDocHostUIHandler, fActivate)
ProcedureReturn *this\iDocHostUiHandler\OnFrameWindowActivate(fActivate)
EndProcedure
Procedure.i IDocHostUIHandler_ResizeBorder(*this._IDocHostUIHandler, prcBorder, pUIWindow, fFrameWindow)
ProcedureReturn *this\iDocHostUiHandler\ResizeBorder(prcBorder, pUIWindow, fFrameWindow)
EndProcedure
Procedure.i IDocHostUIHandler_TranslateAccelerator(*this._IDocHostUIHandler, *lpMsg.MSG, pguidCmdGroup, nCmdID)
ProcedureReturn *this\iDocHostUiHandler\TranslateAccelerator(*lpMsg, pguidCmdGroup, nCmdID)
EndProcedure
Procedure.i IDocHostUIHandler_GetOptionKeyPath(*this._IDocHostUIHandler, pchKey, DW)
ProcedureReturn *this\iDocHostUiHandler\GetOptionKeyPath(pchKey, DW)
EndProcedure
Procedure.i IDocHostUIHandler_GetDropTarget(*this._IDocHostUIHandler, pDropTarget, ppDropTarget)
ProcedureReturn *this\iDocHostUiHandler\GetDropTarget(pDropTarget, ppDropTarget)
EndProcedure
Procedure.i IDocHostUIHandler_GetExternal(*this._IDocHostUIHandler, ppDispatch.i)
ProcedureReturn *this\iDocHostUiHandler\GetExternal(ppDispatch.i)
EndProcedure
Procedure.i IDocHostUIHandler_TranslateUrl(*this._IDocHostUIHandler, dwTranslate, pchURLIn, ppchURLOut)
ProcedureReturn *this\iDocHostUiHandler\TranslateUrl(dwTranslate, pchURLIn, ppchURLOut)
EndProcedure
Procedure.i IDocHostUIHandler_FilterDataObject(*this._IDocHostUIHandler, pDO, ppDORet)
ProcedureReturn *this\iDocHostUiHandler\FilterDataObject(pDO, ppDORet)
EndProcedure
DataSection
IID_IUnknown: ; 00000000-0000-0000-C000-000000000046
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IHTMLDocument2: ; 332C4425-26CB-11D0-B483-00C04FD90119
Data.l $332C4425
Data.w $26CB, $11D0
Data.b $B4, $83, $00, $C0, $4F, $D9, $01, $19
IID_IOleObject: ; 00000112-0000-0000-C000-000000000046
Data.l $00000112
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IDocHostUIHandler: ; BD3F23C0-D43E-11CF-893B-00AA00BDCE1A
Data.l $BD3F23C0
Data.w $D43E, $11CF
Data.b $89, $3B, $00, $AA, $00, $BD, $CE, $1A
IID_ICustomDoc: ; 3050F3F0-98B5-11CF-BB82-00AA00BDCE0B
Data.l $3050F3F0
Data.w $98B5, $11CF
Data.b $BB, $82, $00, $AA, $00, $BD, $CE, $0B
IDocHostUIHandlerFunctionTable:
Data.i @IDocHostUIHandler_QueryInterface()
Data.i @IDocHostUIHandler_AddRef()
Data.i @IDocHostUIHandler_Release()
Data.i @IDocHostUIHandler_ShowContextMenu()
Data.i @IDocHostUIHandler_GetHostInfo()
Data.i @IDocHostUIHandler_ShowUI()
Data.i @IDocHostUIHandler_HideUI()
Data.i @IDocHostUIHandler_UpdateUI()
Data.i @IDocHostUIHandler_EnableModeless()
Data.i @IDocHostUIHandler_OnDocWindowActivate()
Data.i @IDocHostUIHandler_OnFrameWindowActivate()
Data.i @IDocHostUIHandler_ResizeBorder()
Data.i @IDocHostUIHandler_TranslateAccelerator()
Data.i @IDocHostUIHandler_GetOptionKeyPath()
Data.i @IDocHostUIHandler_GetDropTarget()
Data.i @IDocHostUIHandler_GetExternal()
Data.i @IDocHostUIHandler_TranslateUrl()
Data.i @IDocHostUIHandler_FilterDataObject()
EndDataSection
;/////////////////////////////////////////////////////////////////////////////////
Re: IE default CSS/Color per process or instance in Windows
Splendid, thank you Justin very much!
I will see if this can be better than handling raw html text, at least for Windows (I do need to handle Mac and Linux as well)
By any chance - do you know how to intercept link clicks (not navigation, but , for example email URL) in IE?
I will see if this can be better than handling raw html text, at least for Windows (I do need to handle Mac and Linux as well)
By any chance - do you know how to intercept link clicks (not navigation, but , for example email URL) in IE?
S.T.V.B.E.E.V.
Re: IE default CSS/Color per process or instance in Windows
The standard webgadget navigation callback also intercepts email links, any reason not to use it?
Code: Select all
EnableExplicit
#PAGE1 = "<!DOCTYPE html> <html <body>" +
~"<p><a href=\"mailto:someone@example.com\">Send email</a></p>" +
"</body></html>"
Procedure win_onSize()
ResizeGadget(0, 0, 0, WindowWidth(0), WindowHeight(0))
EndProcedure
Procedure NavigationCallback(Gadget.i, url.s)
Debug url
ProcedureReturn #False
EndProcedure
Define.i Event
OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
WebGadget(0, 0, 0, 600, 300, "") ;http://www.purebasic.com
SetGadgetItemText(0, #PB_Web_HtmlCode, #PAGE1)
SetGadgetAttribute(0, #PB_Web_NavigationCallback, @NavigationCallback())
BindEvent(#PB_Event_SizeWindow, @win_onSize())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Re: IE default CSS/Color per process or instance in Windows
Yes, my bad, Thank You
I filtered out protocols and forgot to filter "mailto:" correctly.
I filtered out protocols and forgot to filter "mailto:" correctly.
S.T.V.B.E.E.V.


