MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / StatusBar

Method StatusBar

source/script2.cpp:15195–15273  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15193
15194
15195ResultType GuiControlType::StatusBar(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
15196{
15197 GuiType& gui = *this->gui;
15198 HWND control_hwnd = this->hwnd;
15199 LPTSTR buf = _f_number_buf;
15200
15201 HICON hicon;
15202 switch (aID)
15203 {
15204 case FID_SB_SetText:
15205 _o_return(SendMessage(control_hwnd, SB_SETTEXT
15206 , (WPARAM)((ParamIndexIsOmitted(1) ? 0 : ParamIndexToInt64(1) - 1) // The Part# param is present.
15207 | (ParamIndexIsOmitted(2) ? 0 : ParamIndexToInt64(2) << 8)) // The uType parameter is present.
15208 , (LPARAM)ParamIndexToString(0, buf))); // Caller has ensured that there's at least one param in this mode.
15209
15210 case FID_SB_SetParts:
15211 LRESULT old_part_count, new_part_count;
15212 int edge, part[256]; // Load-time validation has ensured aParamCount is under 255, so it shouldn't overflow.
15213 for (edge = 0, new_part_count = 0; new_part_count < aParamCount; ++new_part_count)
15214 {
15215 edge += gui.Scale(ParamIndexToInt(new_part_count)); // For code simplicity, no check for negative (seems fairly harmless since the bar will simply show up with the wrong number of parts to indicate the problem).
15216 part[new_part_count] = edge;
15217 }
15218 // For code simplicity, there is currently no means to have the last part of the bar use less than
15219 // all of the bar's remaining width. The desire to do so seems rare, especially since the script can
15220 // add an extra/unused part at the end to achieve nearly (or perhaps exactly) the same effect.
15221 part[new_part_count++] = -1; // Make the last part use the remaining width of the bar.
15222
15223 old_part_count = SendMessage(control_hwnd, SB_GETPARTS, 0, NULL); // MSDN: "This message always returns the number of parts in the status bar [regardless of how it is called]".
15224 if (old_part_count > new_part_count) // Some parts are being deleted, so destroy their icons. See other notes in GuiType::Destroy() for explanation.
15225 for (LRESULT i = new_part_count; i < old_part_count; ++i) // Verified correct.
15226 if (hicon = (HICON)SendMessage(control_hwnd, SB_GETICON, i, 0))
15227 DestroyIcon(hicon);
15228
15229 _o_return(SendMessage(control_hwnd, SB_SETPARTS, new_part_count, (LPARAM)part)
15230 ? (__int64)control_hwnd : 0); // Return HWND to provide an easy means for the script to get the bar's HWND.
15231
15232 //case FID_SB_SetIcon:
15233 default:
15234 int unused, icon_number;
15235 icon_number = ParamIndexToOptionalInt(1, 1);
15236 if (icon_number == 0) // Must be != 0 to tell LoadPicture that "icon must be loaded, never a bitmap".
15237 icon_number = 1;
15238 if (hicon = (HICON)LoadPicture(ParamIndexToString(0, buf) // Load-time validation has ensured there is at least one parameter.
15239 , GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON) // Apparently the bar won't scale them for us.
15240 , unused, icon_number, false)) // Defaulting to "false" for "use GDIplus" provides more consistent appearance across multiple OSes.
15241 {
15242 WPARAM part_index = ParamIndexIsOmitted(2) ? 0 : (WPARAM)ParamIndexToInt64(2) - 1;
15243 HICON hicon_old = (HICON)SendMessage(control_hwnd, SB_GETICON, part_index, 0); // Get the old one before setting the new one.
15244 // For code simplicity, the script is responsible for destroying the hicon later, if it ever destroys
15245 // the window. Though in practice, most people probably won't do this, which is usually okay (if the
15246 // script doesn't load too many) since they're all destroyed by the system upon program termination.
15247 if (SendMessage(control_hwnd, SB_SETICON, part_index, (LPARAM)hicon))
15248 {
15249 if (hicon_old)
15250 // Although the old icon is automatically destroyed here, the script can call SendMessage(SB_SETICON)
15251 // itself if it wants to work with HICONs directly (for performance reasons, etc.)
15252 DestroyIcon(hicon_old);

Callers

nothing calls this directly

Calls 2

LoadPictureFunction · 0.85
ScaleMethod · 0.80

Tested by

no test coverage detected