Mega Code Archive

 
Categories / Delphi / Ide Indy
 

DESIGNING SKINNED DELPHI APPS

Title: DESIGNING 'SKINNED' DELPHI APPS Question: How to design skinned Delphi apps? Answer: DESIGNING 'SKINNED' DELPHI APPS Hi there folks. I wrote this tiny tutorial for people who are trying to write a skinned Delphi application. Why would you want to do this? Well, take WinAmp for instance, an MP3 player most of us know. The program is 100% skinned, and although it is probably written in C/C++ you can tell right away that there are no TButtons on the main form. Obviously, this is done because it looks great. But unfortunately, it also greatly increases file (and download) size. Therefore, you should only skin your app when it really adds up to the program. For every button and label and anything else, you have to make an image. Then another one for the OnClick, and perhaps yet another one for the OnMouseMove. Again, when not nessecary, don't skin your app. But if you think 'blah blah let's get to the code' I won't bother you with advice any more. If you want to skin your app, you may also want to get rid of Windows' standard rectangular window shape. That can be done rather easily by specifying a number of points (X,Y) and inserting the SetWindowRgn procedure: const RgnPoints : array[1..12] of TPoint = ((X:9;Y:6), (X:177;Y:6), (X:184;Y:13), (X:9;Y:49),(X:4;Y:43), (X:4;Y:11)); { Just a sample: this will probably look like hell :) } var Rgn : HRGN; begin Rgn := CreatePolygonRgn(RgnPoints, High(RgnPoints), ALTERNATE); SetWindowRgn(Handle, Rgn, True); end; Now, this code shouldn't be hard to understand. For every RgnPoint a line is drawn from RgnPoints[I-1] to RgnPoints[I]. From the last coordinate, in this case 4,11, a line is drawn back to the first one (9,6). This may be a bit hard to understand, but just copy it and paste the last part in the FormCreate event (the RgnPoints array should be where Form1 is declarated). Back to the actual skinning. When (if) I skin an app, I simply put a TImage on the form with the background image, and then place all components on it. You may also want to consider a TImage, on top of it a TPanel, and on top of the panel all your components. This may come in hand with some things. Ofcourse, when doing this, you won't be able to resize the form. But that can also be fixed easily. You just take seperate pictures for the top left, the top right, bottom left and bottom right. Then you use the OnPaint event to draw all nessecary inbetween those images. Well, that's it for this time folks, I hope I can find the time to write more useful tutorials. If you have any questions about this one, feel free to mail me at charl@atomasoft.com. Also, be sure to visit my site at www.FutureAI.com, it's about Artificial Intelligence. Cya! // Charl