I did a bunch of searches in PB for "Owner Drawn Status", "Draw Status", and other variations for an Owner Drawn Status bar, and the only usable result is Jose Roca's EXCELLENT example Statusbar wrapper.
code to place in your Window Callback
and the wrapper function itself
Although an excellent wrapper and great example to work with, (worked perfect without having to modify code), I wanted to take things a step farther and more generic (if only to understand how the code works).
According to Docs (If I read them right) then WPARAM = the control you want to change, and LPARAM = DRAWITEMSTRUCT
Breaking down to not use the callback, but a function directly called, so far I have come up with
However I am having a lil' bit of trouble understanding each of the elements of the UDT for DrawItemStruct, that I hope someone can help clear up.
I tried checking values of each from the original working code, but nothing matches up with the defined values in Win32Api.Inc, so I am TOTALLY confused
My thoughts on the elements are:
type DRAWITEMSTRUCT
End Type
Hopefully not toooooo confusing, but I am just trying to understand the docs when the docs do not even state anything to do with a statusbar.....which also makes me wonder, if it works, does it mean I am using the right api? or just lucking out that it works?
code to place in your Window Callback
Code:
CASE %WM_DRAWITEM ' Ownerdraw statusbar IF WPARAM = %ID_STATUSBAR THEN DSS_StatusbarDrawItem hWnd, LPARAM '<--- See Jose Roca's statusbar wrapper
Code:
SUB DSS_StatusbarDrawItem (BYVAL hDlg AS DWORD, BYVAL lParam AS LONG) LOCAL lpdis AS DRAWITEMSTRUCT PTR LOCAL zp AS ASCIIZ PTR LOCAL hBrush AS DWORD LOCAL clrFg AS DWORD LOCAL clrBk AS DWORD lpdis = lParam ''msgbox str$(@lpdis.CtlType) ' InflateRect @lpdis.rcItem, -1, -1 'test with smaller rect for "better" look DECR @lpdis.rcItem.nRight 'or maybe this is better..? DECR @lpdis.rcItem.nBottom clrBk = %BLUE clrFg = %WHITE SELECT CASE @lpdis.itemID CASE 1 : clrBk = %YELLOW : clrFg = %RED CASE 2 : clrBk = %RED : clrFg = %YELLOW CASE 3 : clrBk = RGB(0,160,0) : clrFg = %WHITE END SELECT hBrush = CreateSolidBrush(clrBk) FillRect @lpdis.hDC, @lpdis.rcItem, hBrush SetBkColor @lpdis.hDC, clrBk SetTextColor @lpdis.hDC, clrFg DeleteObject hBrush zp = @lpdis.itemData ' DrawText @lpdis.hDC, @zp, LEN(@zp), @lpdis.rcItem, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER DrawText @lpdis.hDC, @zp, LEN(@zp), @lpdis.rcItem, %DT_SINGLELINE OR %DT_VCENTER END SUB ' ==========================================================================
According to Docs (If I read them right) then WPARAM = the control you want to change, and LPARAM = DRAWITEMSTRUCT
Breaking down to not use the callback, but a function directly called, so far I have come up with
Code:
SUB DSS_StatusbarDrawItem (BYVAL HwndWindow AS DWORD, BYVAL DrawItem AS DRAWITEMSTRUCT, ForeGroundColor AS DWORD, BackGroundColor AS DWORD) LOCAL hBrush AS DWORD LOCAL zp AS ASCIIZ PTR ' InflateRect @lpdis.rcItem, -1, -1 'test with smaller rect for "better" look DECR DrawItem.rcItem.nRight 'or maybe this is better..? DECR DrawItem.rcItem.nBottom hBrush = CreateSolidBrush(BackGroundColor) FillRect DrawItem.hDC, DrawItem.rcItem, hBrush SetBkColor DrawItem.hDC, BackGroundColor SetTextColor DrawItem.hDC, ForeGroundColor DeleteObject hBrush zp = DrawItem.itemData ' DrawText @lpdis.hDC, @zp, LEN(@zp), @lpdis.rcItem, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER DrawText DrawItem.hDC, @zp, LEN(DrawItem.itemData), DrawItem.rcItem, %DT_SINGLELINE OR %DT_VCENTER END SUB ' ==========================================================================
I tried checking values of each from the original working code, but nothing matches up with the defined values in Win32Api.Inc, so I am TOTALLY confused
My thoughts on the elements are:
type DRAWITEMSTRUCT
CtlType = ODT_BUTTON, 'Owner-drawn button
ODT_COMBOBOX 'Owner-drawn combo box
ODT_LISTBOX 'Owner-drawn list box
ODT_LISTVIEW 'List view control
ODT_MENU 'Owner-drawn menu item
ODT_STATIC 'Owner-drawn static control
ODT_TAB 'Tab control
'<--- CtlType shows absolutely nothing for StatusBar, so I am guessing Static label is used in statusbar?
ODT_COMBOBOX 'Owner-drawn combo box
ODT_LISTBOX 'Owner-drawn list box
ODT_LISTVIEW 'List view control
ODT_MENU 'Owner-drawn menu item
ODT_STATIC 'Owner-drawn static control
ODT_TAB 'Tab control
'<--- CtlType shows absolutely nothing for StatusBar, so I am guessing Static label is used in statusbar?
CtlID = Specifies the identifier of the combo box, list box, button, or static control. This member is not used for a menu item.
'<--- So if I declare HwndStatus = 1000 then is CtlId 1000? or the Windows handle that results from creation? or 0 since not a combo, list, button, or label?
'<--- So if I declare HwndStatus = 1000 then is CtlId 1000? or the Windows handle that results from creation? or 0 since not a combo, list, button, or label?
itemID = Specifies the menu item identifier for a menu item (it goes on from there, but no mention of a statusbar
'<--- In this case if I split the statusbar into parts, is this the value I plug in for say part 8?????
'<--- In this case if I split the statusbar into parts, is this the value I plug in for say part 8?????
itemAction = ODA_DRAWENTIRE 'The entire control needs to be drawn.
ODA_FOCUS 'Check if has focus
ODA_SELECT 'The selection status has changed.
'<--- Since I am not setting focus or selecting, but just changing colors, I assume I have to pass ODA_DRAWENTIRE?
ODA_FOCUS 'Check if has focus
ODA_SELECT 'The selection status has changed.
'<--- Since I am not setting focus or selecting, but just changing colors, I assume I have to pass ODA_DRAWENTIRE?
itemState = ODS_CHECKED 'The menu item is to be checked. This bit is used only in a menu.
ODS_COMBOBOXEDIT The drawing takes place in the selection field (edit control) of an ownerdrawn combo box.
ODS_DEFAULT The item is the default item.
ODS_DISABLED The item is to be drawn as disabled.
ODS_FOCUS The item has the keyboard focus.
ODS_GRAYED The item is to be grayed. This bit is used only in a menu.
ODS_SELECTED The menu item's status is selected.
ODS_COMBOBOXEDIT The drawing takes place in the selection field (edit control) of an ownerdrawn combo box.
ODS_DEFAULT The item is the default item.
ODS_DISABLED The item is to be drawn as disabled.
ODS_FOCUS The item has the keyboard focus.
ODS_GRAYED The item is to be grayed. This bit is used only in a menu.
ODS_SELECTED The menu item's status is selected.
hwndItem = Identifies the control for combo boxes, list boxes, buttons, and static controls. For menus, this member identifies the menu containing the item.
'<--- So is this the value I plug in for my part of the statusbar?????
'<--- So is this the value I plug in for my part of the statusbar?????
HDC hDC;
'<--- For the time being until I clear up the other parts, I assume this is the Hdc of the statusbar? (or would it be a part of the statusbar?
'<--- For the time being until I clear up the other parts, I assume this is the Hdc of the statusbar? (or would it be a part of the statusbar?
RECT rcItem; <--- For the time being I assume this will be the rect of the part I wish to change
DWORD itemData; '<---Not sure if this will be my text? or some other value?
Hopefully not toooooo confusing, but I am just trying to understand the docs when the docs do not even state anything to do with a statusbar.....which also makes me wonder, if it works, does it mean I am using the right api? or just lucking out that it works?
Comment