MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / GetGuiControlEvent

Method GetGuiControlEvent

Source/script.cpp:11282–11351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11280
11281
11282VarSizeType Script::GetGuiControlEvent(char *aBuf)
11283// We're returning the length of the var's contents, not the size.
11284{
11285 if (g.GuiEvent == GUI_EVENT_DROPFILES)
11286 {
11287 GuiType *pgui;
11288 UINT u, file_count;
11289 // GUI_EVENT_DROPFILES should mean that g.GuiWindowIndex < MAX_GUI_WINDOWS, but the below will double check
11290 // that in case g.GuiEvent can ever be set to that value as a result of receiving a bogus message in the queue.
11291 if (g.GuiWindowIndex >= MAX_GUI_WINDOWS // The current thread was not launched as a result of GUI action or this is a bogus msg.
11292 || !(pgui = g_gui[g.GuiWindowIndex]) // Gui window no longer exists. Relies on short-circuit boolean.
11293 || !pgui->mHdrop // No HDROP (probably impossible unless g.GuiEvent was given a bogus value somehow).
11294 || !(file_count = DragQueryFile(pgui->mHdrop, 0xFFFFFFFF, NULL, 0))) // No files in the drop (not sure if this is possible).
11295 // All of the above rely on short-circuit boolean order.
11296 {
11297 // Make the dropped-files list blank since there is no HDROP to query (or no files in it).
11298 if (aBuf)
11299 *aBuf = '\0';
11300 return 0;
11301 }
11302 // Above has ensured that file_count > 0
11303 if (aBuf)
11304 {
11305 char *cp = aBuf;
11306 for (u = 0; u < file_count; ++u)
11307 {
11308 cp += DragQueryFile(pgui->mHdrop, u, cp, MAX_PATH); // MAX_PATH is arbitrary since aBuf is already known to be large enough.
11309 if (u < file_count - 1) // i.e omit the LF after the last file to make parsing via "Loop, Parse" easier.
11310 *cp++ = '\n';
11311 // Although the transcription of files on the clipboard into their text filenames is done
11312 // with \r\n (so that they're in the right format to be pasted to other apps as a plain text
11313 // list), it seems best to use a plain linefeed for dropped files since they won't be going
11314 // onto the clipboard nearly as often, and `n is easier to parse. Also, a script array isn't
11315 // used because large file lists would then consume a lot more of memory because arrays
11316 // are permanent once created, and also there would be wasted space due to the part of each
11317 // variable's capacity not used by the filename.
11318 }
11319 // No need for final termination of string because the last item lacks a newline.
11320 return (VarSizeType)(cp - aBuf); // This is the length of what's in the buffer.
11321 }
11322 else
11323 {
11324 VarSizeType total_length = 0;
11325 for (u = 0; u < file_count; ++u)
11326 total_length += DragQueryFile(pgui->mHdrop, u, NULL, 0);
11327 // Above: MSDN: "If the lpszFile buffer address is NULL, the return value is the required size,
11328 // in characters, of the buffer, not including the terminating null character."
11329 return total_length + file_count - 1; // Include space for a linefeed after each filename except the last.
11330 }
11331 // Don't call DragFinish() because this variable might be referred to again before this thread
11332 // is done. DragFinish() is called by MsgSleep() when the current thread finishes.
11333 }
11334
11335 // Otherwise, this event is not GUI_EVENT_DROPFILES, so use standard modes of operation.
11336 static char *names[] = GUI_EVENT_NAMES;
11337 if (!aBuf)
11338 return (g.GuiEvent < GUI_EVENT_ILLEGAL) ? (VarSizeType)strlen(names[g.GuiEvent]) : 1;
11339 // Otherwise:

Callers 1

GetMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected