F.A.Q. - There is no icon next to the shaped form's title in the taskbar. How do I add one?
The problem is that if you have no titlebar then you can't have a control box, and if you don't have a control box, you can't have an icon. So, the solution is to set the form's borderstyle property to 1 - Fixed Single, which will then give you a titlebar. Then set the ControlBox property to True to get one of those, which will allow an icon to be shown by setting the icon property.
The only problem now is that the titlebar shifts the entire window downwards, and the shape is offset from where you designed it to be. The shape must therefore be shifted downwards to compensate. To do this just edit the CreateFormRegion line in the Form_Load event to add the offsets.
Unfortunately you can never tell how strange the system that your program is run on will be, so specifying the offset in pixels is no good, you have to find out how big the titlebar and border is for the system it is being run on. This can be done with the GetSystemMetrics API call. Replacing the
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion(1, 1, 0, 0, True)
with
nRet = SetWindowRgn(Me.hWnd, CreateFormRegion(1, 1, GetSystemMetrics(SM_CXFIXEDFRAME), GetSystemMetrics(SM_CYFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION)), True)
in the Form_Load event should do the job. You will also have to declare the functions and constants in the (general) section:
Private Declare Function GetSystemMetrics Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Private Const SM_CYCAPTION = 4
SM_CXFIXEDFRAME = 7
SM_CYFIXEDFRAME = 8