What you see in the background behind all application windows is called the 'root window' in X11 terminology.
Without KDE (or similar), any program could draw on that "window". Before I switched to KDE, I used the 'xv' image viewer to set an image in the root window, but there are countless alternatives.
Even screensavers or video players could run within the root window, behind your applications! I was pretty impressed by that when I made my first steps with Linux.
However, with KDE running, KDE's kdesktop component "overpaints" this area.
Have a look at KDE's DCOP (Desktop COmmunication Protocol). This is KDE's powerful and easy-to-use Inter-Process-Communication subsystem.
Most KDE applications expose parts of their functionality through this interface.
I am not a programmer at all, but with this, even I can hack together some very nifty things to make KDE do what I want.
I don't know which language you want to implement your program, but there are DCOP-hooks available for pretty much all languages...
If you want to put together a simple shell script, there is a command line utility named 'dcop'.
Without arguments, it shows all registered DCOP services. Use that or use kdcop to browse them graphically, and play around with it. It is pretty self-explanatory.
dcop kdesktop KBackgroundIface
at a terminal to see all functions that control background drawing.
I guess, setWallpaper
is the function you are looking for.
Alas, I cannot help you with your second question...