// ------------------------------------------------ // // FUNCTION: sys_GetRegKey( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegKey( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr, dataSize, arraySize, expandDataSize; LONG_PTR i, len; char regSub[MAXBUF]; char regName[MAXBUF]; char *returnDataBuffer, *ptrData; HKEY hRootKey; HKEY hOpenKey; DWORD dwDataType; DWORD dwReturnLong; PA_Variable paReturnArray; // AMS2 12/9/14 #41400 Initalized the dataSize variable. In 64 bit environments this can be randomly initalized to a size in bytes // that is larger than malloc can allot, causing it to return null and crash when returning to 4D. Remember to always initialize your size variables. dataSize = 0; returnValue = regKey = retErr = arraySize = expandDataSize = 0; hRootKey = hOpenKey = 0; ptrData = returnDataBuffer = NULL; memset(regSub, 0, MAXBUF); memset(regName, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); PA_GetTextParameter( params, 3, regName ); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_READ, &hOpenKey); if(retErr == ERROR_SUCCESS){ // Get the value type and size. retErr = RegQueryValueEx(hOpenKey, regName, NULL, &dwDataType, NULL, &dataSize); if(retErr == ERROR_SUCCESS){ switch(dwDataType){ case REG_BINARY: returnDataBuffer = malloc(dataSize); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, (LPBYTE) returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetBlobParameter(params, 4, returnDataBuffer, dataSize); returnValue = 1; } free(returnDataBuffer); break; case REG_DWORD: case REG_DWORD_BIG_ENDIAN: dataSize = sizeof(dwReturnLong); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, (LPBYTE) &dwReturnLong, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetLongParameter(params, 4, dwReturnLong); returnValue = 1; } break; case REG_EXPAND_SZ: returnDataBuffer = malloc(dataSize); retErr = RegQueryValueEx (hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS) { regExpandStr(&returnDataBuffer); PA_SetTextParameter(params, 4, returnDataBuffer, strlen(returnDataBuffer)); returnValue = 1; } free(returnDataBuffer); break; case REG_MULTI_SZ: returnDataBuffer = malloc(dataSize); paReturnArray = PA_GetVariableParameter( params, 4 ); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS) { arraySize = regGetNumElements(returnDataBuffer); PA_ResizeArray(&paReturnArray, arraySize); for(i = 1, ptrData = returnDataBuffer; i <= arraySize; i++) { len = strlen(ptrData); PA_SetTextInArray(paReturnArray, i, ptrData, len); ptrData+=len+1; } returnValue = 1; PA_SetVariableParameter( params, 4, paReturnArray, 0 ); } free(returnDataBuffer); break; case REG_SZ: returnDataBuffer = (char*)malloc(dataSize); retErr = RegQueryValueEx(hOpenKey, regName, NULL, NULL, returnDataBuffer, &dataSize); if(retErr == ERROR_SUCCESS){ PA_SetTextParameter(params, 4, returnDataBuffer, dataSize-1); returnValue = 1; } free(returnDataBuffer); break; } } } RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }
void sys_KillProcessByID( PA_PluginParameters params ) { HANDLE hProcess; // Handle to the process itself INT_PTR lPID; // Integer to hold the processID ($1) BOOL bCleanFirst = FALSE; // Boolean to see if we should try to cleanly close the app // before killing it mercilessly ($2) // Get the function parameters. lPID = PA_GetLongParameter(params, 1); bCleanFirst = (PA_GetLongParameter(params, 2) == 1 ? TRUE : FALSE); // Open a handle to the process hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, lPID); // Check to see if we got it, and return an error if we didn't if(hProcess == NULL) { PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } if(bCleanFirst) { // TerminateClean() posts WM_CLOSE to all windows whose PID // matches your process's. EnumWindows((WNDENUMPROC)TerminateClean, (LPARAM) lPID) ; if(WaitForSingleObject(hProcess, 500)!=WAIT_OBJECT_0) { bCleanFirst = TRUE; PA_ReturnLong(params, -1); } } // end if bCleanFirst if(!bCleanFirst) { // Kill the process if (TerminateProcess(hProcess, 1)) { // Success! Return 0 PA_ReturnLong(params, 0); } else { // Fail! Return the error PA_ReturnLong(params, (LONG_PTR)GetLastError()); } } // end if !bCleanFirst // Clean up CloseHandle(hProcess); }
// ------------------------------------------------ // // FUNCTION: gui_GetSysColor( PA_PluginParameters params ) // // PURPOSE: Get the current color of the specified display element. // // DATE: MJG 12/1/03 (3.5.6) // void gui_GetSysColor( PA_PluginParameters params ) { LONG_PTR returnValue; LONG_PTR displayElement; LONG_PTR retRValue, retGValue, retBValue; DWORD dwResult; returnValue = 0; displayElement = PA_GetLongParameter( params, 1); retRValue = retGValue = retBValue = 0; if(displayElement >= COLOR_SCROLLBAR && displayElement <= COLOR_GRADIENTINACTIVECAPTION && displayElement != COLOR_UNUSED){ dwResult = GetSysColor(displayElement); retRValue = GetRValue(dwResult); retGValue = GetGValue(dwResult); retBValue = GetBValue(dwResult); returnValue = 1; } PA_SetLongParameter( params, 2, retRValue ); PA_SetLongParameter( params, 3, retGValue ); PA_SetLongParameter( params, 4, retBValue ); PA_ReturnLong( params, returnValue ); }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowState( PA_PluginParameters params) // // PURPOSE: Determine if window is minimized or maximized // // COMMENTS: Returns 0 if window is normal, 1 if minimized // and 2 if maximized. // // DATE: dcc 07/20/02 dcc // // MODIFICATIONS: // void gui_GetWindowState(PA_PluginParameters params, BOOL isEx) { HWND hWnd; LONG hWndIndex; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG returnValue = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array if (isEx){ // WJF 9/16/15 #43731 hWnd = handleArray_retrieve((DWORD)hWndIndex); } else { hWnd = (HWND)hWndIndex; } if (IsWindow(hWnd)) { if (IsIconic(hWnd)) { returnValue = IS_ICONIC; } else if (IsZoomed(hWnd)) { returnValue = IS_ZOOMED; } } PA_ReturnLong(params, returnValue); }
// FUNCTION: sys_LoggingStart(PA_PluginParameters params) // // PURPOSE: Start logging Win32API commands // // COMMENTS: // // DATE: 7/11/16 Win-20 void sys_LoggingStart(PA_PluginParameters params) { LONG returnValue = 0; // WJF 7/11/16 Win-20 PA_GetTextParameter(params, 1, szLogsPath); lNumDays = PA_GetLongParameter(params, 2); returnValue = logOpenFile(); PA_ReturnLong(params, returnValue); // WJF 7/11/16 Win-20 }
// ------------------------------------------------ // // FUNCTION: gui_SetSysColor( PA_PluginParameters params ) // // PURPOSE: Set the color of the specified display element. // // DATE: MJG 12/1/03 (3.5.6) // void gui_SetSysColor( PA_PluginParameters params ) { LONG_PTR returnValue; INT_PTR displayElement[1]; COLORREF rgbValue[1]; BYTE rValue, gValue, bValue; returnValue = 0; displayElement[0] = (INT_PTR) PA_GetLongParameter( params, 1); rValue = (BYTE) PA_GetLongParameter( params, 2); gValue = (BYTE) PA_GetLongParameter( params, 3); bValue = (BYTE) PA_GetLongParameter( params, 4); rgbValue[0] = RGB(rValue, gValue, bValue); returnValue = SetSysColors(1, displayElement, rgbValue); if(returnValue != 0) returnValue = 1; PA_ReturnLong( params, returnValue ); }
LONG_PTR getTrayIconParams( PA_PluginParameters params, LONG_PTR *pAction, LONG_PTR *pFlags, LONG_PTR *pIconID, LONG_PTR *pProcessNbr, LONG_PTR *pIconHndl, char* szTipParam, char* szBalloonInfo, char* szBalloonTitle ) { LONG_PTR szTipParam_len, szBalloonInfo_len, szBalloonTitle_len, returnValue = 0; *pAction = PA_GetLongParameter( params, 1 ); if (*pAction != 0) returnValue++; *pFlags = PA_GetLongParameter( params, 2 ); if (*pFlags != 0) returnValue++; *pIconID = PA_GetLongParameter( params, 3 ); if (*pIconID != 0) returnValue++; *pProcessNbr = PA_GetLongParameter( params, 4 ); if (*pProcessNbr != 0) returnValue++; *pIconHndl = PA_GetLongParameter( params, 5 ); if (*pIconHndl != 0) returnValue++; szTipParam_len = PA_GetTextParameter( params, 6, szTipParam ); if (szTipParam_len > 59) { szTipParam_len = 60; } szTipParam[szTipParam_len] = '\0'; if (szTipParam_len) returnValue++; szBalloonInfo_len = PA_GetTextParameter( params, 7, szBalloonInfo ); if (szBalloonInfo_len > 254) { szBalloonInfo_len = 255; } szBalloonInfo[szBalloonInfo_len] = '\0'; if (szBalloonInfo_len) returnValue++; szBalloonTitle_len = PA_GetTextParameter( params, 8, szBalloonTitle ); if (szBalloonTitle_len > 59) { szBalloonTitle_len = 60; } szBalloonTitle[szBalloonTitle_len] = '\0'; if (szBalloonTitle_len) returnValue++; return returnValue; }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowState( PA_PluginParameters params) // // PURPOSE: Determine if window is minimized or maximized // // COMMENTS: Returns 0 if window is normal, 1 if minimized // and 2 if maximized. // // DATE: dcc 07/20/02 dcc // // MODIFICATIONS: // void gui_GetWindowState( PA_PluginParameters params ) { HWND hWnd; LONG_PTR returnValue = 0; hWnd = (HWND) PA_GetLongParameter( params, 1); if (IsWindow(hWnd)) { if (IsIconic(hWnd)) { returnValue = IS_ICONIC; } else if (IsZoomed(hWnd)) { returnValue = IS_ZOOMED; } } PA_ReturnLong( params, returnValue ); }
void gui_SubClassInit( PA_PluginParameters params ) { LONG_PTR returnValue = 0, action = 0; //WNDCLASSEX wndClassEx; //LPWNDCLASSEX lpWndClassEx = &wndClassEx; //char className[] = "ProToolsSubMDIWndClass"; //HINSTANCE hInst; // Put NDEBUF flag back into Preprocessor definitions action = PA_GetLongParameter( params, 1); toolBarRestrictions.toolBarOnDeck = 0; // added for gui_RespectToolBar 01/16/03 if (action != RW_RELEASE) { if (processHandles.wpProToolsOrigProc == NULL) { processHandles.wpProToolsOrigProc = (WNDPROC) SetClassLongPtr(windowHandles.MDIs_4DhWnd, GCLP_WNDPROC, (LONG_PTR)ProToolsProc); returnValue = (LONG_PTR) processHandles.wpProToolsOrigProc; /* //hInst = (HINSTANCE) PA_Get4DHInstance(); // this doesn't work for 4D 6.5 hInst = (HINSTANCE) GetWindowLong(windowHandles.fourDhWnd, GWL_HINSTANCE); // 09/10/02 //hInst = (HINSTANCE)GetWindowLongPtr(windowHandles.MDIhWnd, GWL_HINSTANCE); wndClassEx.cbSize = sizeof(WNDCLASSEX); if (GetClassInfoEx(hInst, className, lpWndClassEx)) { wndClassEx.lpfnWndProc = &ProToolsProc; processHandles.wpProToolsOrigProc = (WNDPROC) SetClassLongPtr(windowHandles.MDIs_4DhWnd, GCLP_WNDPROC, (LONG_PTR)ProToolsProc); returnValue = (LONG_PTR) processHandles.wpProToolsOrigProc; } */ } } else { if (processHandles.wpProToolsOrigProc != NULL) { //SetClassLongPtr(windowHandles.fourDhWnd, GCLP_WNDPROC, (LONG_PTR)processHandles.wpProToolsOrigProc); SetClassLongPtr(windowHandles.MDIs_4DhWnd, GCLP_WNDPROC, (LONG_PTR)processHandles.wpProToolsOrigProc); processHandles.wpProToolsOrigProc = NULL; returnValue = 1; } clear_list(&startOfList); } PA_ReturnLong( params, returnValue ); }
// ------------------------------------------------ // // FUNCTION: sys_GetRegType( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegType( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr; char regSub[MAXBUF]; char regName[MAXBUF]; char *returnDataBuffer; HKEY hRootKey; HKEY hOpenKey; DWORD dwDataType; returnValue = regKey = retErr = 0; hRootKey = hOpenKey = 0; returnDataBuffer = NULL; memset(regSub, 0, MAXBUF); memset(regName, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); PA_GetTextParameter( params, 3, regName ); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_READ, &hOpenKey); if(retErr == ERROR_SUCCESS){ // Get the value type and size. retErr = RegQueryValueEx(hOpenKey, regName, NULL, &dwDataType, NULL, NULL); if(retErr == ERROR_SUCCESS){ returnValue = get4dRegType(dwDataType); } } RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }
void sys_SetPluginLanguage( PA_PluginParameters params ) { LONG_PTR language; // Get the function parameters. language = PA_GetLongParameter( params, 1 ); switch( language ) { case LANG_ENGLISH : message = &message_list_english; break; case LANG_DUTCH: message = &message_list_dutch; break; default : language = LANG_ENGLISH; message = &message_list_english; break; } PA_ReturnLong( params, language ); }
// ------------------------------------------------ // // FUNCTION: sys_GetCommandLine( PA_PluginParameters params) // // PURPOSE: Gets command line used to start 4D // // COMMENTS: Parse command line. Ends at a negative character value. // Returns an array of parameters. // Params should be passed unquoted. There can be a space or NULL // between parameters. 1st param is delimited by space. Rest are NULL. // // DATE: dcc 04/03/02 dcc // // MODIFICATIONS: Rewritten 06/20/02 to make more concise, less convoluted, etc. // Modified 7/29/03 void sys_GetCommandLine(PA_PluginParameters params) { char commandLineStr[MAXBUF]; char paramElement[MAXBUF]; char executableString[MAXBUF]; char *pMarker; LONG returnValue = 0, commandLine_len = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG_PTR charsToCopy; LPTSTR pCommandLineStr, pTemp; PA_Variable parameters; BOOL bInQuotes = FALSE, bDone = FALSE; LONG paramCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG action = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG memset(commandLineStr, 0, MAXBUF); memset(paramElement, 0, MAXBUF); memset(executableString, 0, MAXBUF); parameters = PA_GetVariableParameter(params, 1); action = PA_GetLongParameter(params, 2); pCommandLineStr = GetCommandLine(); if (pCommandLineStr == NULL) { returnValue = 0; } else { pMarker = pTemp = pCommandLineStr; //if first char a doublequote, skip it if (*pMarker == '"') { pMarker++; bInQuotes = TRUE; } // Find the executable name. while (!((*(++pTemp) == ' ' && !bInQuotes) || (*pTemp == '"' && bInQuotes) || *pTemp == '\0')); charsToCopy = (pTemp - pMarker); strncpy(executableString, pMarker, charsToCopy); commandLine_len = (LONG)charsToCopy; // WJF 6/30/16 Win-21 Cast to LONG executableString[charsToCopy] = '\0'; //skip next quotes and spaces if they are there while ((*pTemp == '"') || (*pTemp == ' ')) { if ((*pTemp == '"') && (action == CL_DRAGDROP)) { bInQuotes = !bInQuotes; // toggle flag } commandLine_len += 1; pTemp++; } pMarker = pTemp; if (action == CL_DRAGDROP) { if (bInQuotes) { while ((*pTemp != '"') || ((*pTemp != '\0') && (*(pTemp + 1) != '\0'))) { pTemp++; } } else { while (*pTemp != '\0') { pTemp++; } } strncpy(paramElement, pMarker, pTemp - pMarker); paramElement[pTemp - pMarker] = '\0'; if (strlen(paramElement) == 0) { PA_ResizeArray(¶meters, 1); strcpy(commandLineStr, executableString); returnValue = 1; } else { PA_ResizeArray(¶meters, 2); PA_SetTextInArray(parameters, 2, paramElement, strlen(paramElement)); strcpy(commandLineStr, executableString); strcat(commandLineStr, " "); strcat(commandLineStr, paramElement); returnValue = 2; } } else { paramCount = 1; strcpy(commandLineStr, executableString); PA_ResizeArray(¶meters, paramCount); while (!bDone) { strcpy(paramElement, ""); while (*pTemp >= 0) { pTemp++; //two nulls in a row also end //replace nulls with spaces if ((*(pTemp) == '\0') || (*(pTemp) == ' ')) { if ((*(pTemp + 1) == '\0') || (*(pTemp + 1) == ' ')){ bDone = TRUE; paramCount++; break; } else { paramCount++; break; } } } // end while strncpy(paramElement, pMarker, pTemp - pMarker); paramElement[pTemp - pMarker] = '\0'; if (strlen(paramElement) > 0) { PA_ResizeArray(¶meters, paramCount); PA_SetTextInArray(parameters, paramCount, paramElement, strlen(paramElement)); pMarker = pTemp + 1; strcat(commandLineStr, " "); strcat(commandLineStr, paramElement); } else { bDone = TRUE; } } // end while !done returnValue = PA_GetArrayNbElements(parameters); } PA_SetTextInArray(parameters, 1, executableString, strlen(executableString)); PA_SetTextInArray(parameters, 0, commandLineStr, strlen(commandLineStr)); PA_SetVariableParameter(params, 1, parameters, 0); } // (pCommandLineStr == NULL) PA_ReturnLong(params, returnValue); }
void gui_RestrictWindow(PA_PluginParameters params, BOOL isEx) { LONG action = 0, returnValue = 0, styleChg = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG HWND hWnd = NULL; HMENU hSysMenu; pLL thisLink = NULL, previousLink = NULL; LONG hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG // subClass procedure must be in place if (processHandles.wpProToolsOrigProc == NULL) { PA_ReturnLong(params, -2); return; } hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array action = PA_GetLongParameter(params, 2); if (isEx){ // WJF 9/16/15 #43731 hWnd = handleArray_retrieve((DWORD)hWndIndex); } else { hWnd = (HWND)hWndIndex; } if (IsWindow(hWnd)) { // 09/09/02 more action values now so removed restriction returnValue = GetWindowLong(hWnd, GWL_STYLE); // eliminate sizing cursor and Window's sizing border switch (action) { case (RW_NO_MIN) : if ((returnValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { styleChg = returnValue ^ WS_MINIMIZEBOX; returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg); } break; case (RW_NO_MAX) : if ((returnValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { styleChg = returnValue ^ WS_MAXIMIZEBOX; returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg); } break; case (RW_NO_CLOSE) : hSysMenu = GetSystemMenu(hWnd, 0); if (hSysMenu != NULL) { EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); } break; case (RW_RESTORE_CLOSE) : hSysMenu = GetSystemMenu(hWnd, 0); if (hSysMenu != NULL) { EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); } break; } if (startOfList == NULL) { init_list(&startOfList); } // insert item in linked list -- if not already there if (!search_list(&startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd)) { thisLink = (pLL)insert_list(&startOfList); if (thisLink == NULL) { PA_ReturnLong(params, -1); // could not add to list - get out return; } } else { PA_ReturnLong(params, (LONG)hWnd); // return window handle if already in list // WJF 6/30/16 Win-21 Changed cast from LONG_PTR -> LONG return; } thisLink->hWnd = hWnd; thisLink->dataLong1 = action; thisLink->type = LL_Restrict; thisLink->wpProc = processHandles.wpProToolsOrigProc; returnValue = length_list(startOfList); } PA_ReturnLong(params, returnValue); }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowStyle( PA_PluginParameters params) // // PURPOSE: Get window styles // // COMMENTS: outputs in array the applicable styles for the window // Returns via return code the LONG_PTR representing the value // // DATE: dcc 07/18/02 dcc // // MODIFICATIONS: // void gui_GetWindowStyle(PA_PluginParameters params, BOOL isEx) { PA_Variable styles; LONG returnValue = 0, testValue = 0, i; // WJF 6/30/16 Win-21 LONG_PTR -> LONG HWND hWnd; char styleText[40]; BOOL bFoundOne; LONG hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array if (isEx){ // WJF 9/16/15 #43731 hWnd = handleArray_retrieve((DWORD)hWndIndex); } else { hWnd = (HWND)hWndIndex; } if (IsWindow(hWnd)) { styles = PA_GetVariableParameter(params, 2); returnValue = GetWindowLong(hWnd, GWL_STYLE); testValue = returnValue; //and all styles to see what the window uses i = 1; while ((testValue != 0) && (i <= NUMBER_STYLES)) { bFoundOne = FALSE; if ((testValue & WS_THICKFRAME) == WS_THICKFRAME) { strcpy(styleText, "WS_THICKFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_THICKFRAME; } else if ((testValue & WS_POPUP) == WS_POPUP) { strcpy(styleText, "WS_POPUP"); bFoundOne = TRUE; testValue = testValue ^ WS_POPUP; } else if ((testValue & WS_CHILD) == WS_CHILD) { strcpy(styleText, "WS_CHILD"); bFoundOne = TRUE; testValue = testValue ^ WS_CHILD; } else if ((testValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { strcpy(styleText, "WS_MINIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MINIMIZEBOX; } else if ((testValue & WS_VISIBLE) == WS_VISIBLE) { strcpy(styleText, "WS_VISIBLE"); bFoundOne = TRUE; testValue = testValue ^ WS_VISIBLE; } else if ((testValue & WS_DISABLED) == WS_DISABLED) { strcpy(styleText, "WS_DISABLED"); bFoundOne = TRUE; testValue = testValue ^ WS_DISABLED; } else if ((testValue & WS_CLIPSIBLINGS) == WS_CLIPSIBLINGS) { strcpy(styleText, "WS_CLIPSIBLINGS"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPSIBLINGS; } else if ((testValue & WS_CLIPCHILDREN) == WS_CLIPCHILDREN) { strcpy(styleText, "WS_CLIPCHILDREN"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPCHILDREN; } else if ((testValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { strcpy(styleText, "WS_MAXIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MAXIMIZEBOX; } else if ((testValue & WS_CAPTION) == WS_CAPTION) { strcpy(styleText, "WS_CAPTION"); bFoundOne = TRUE; testValue = testValue ^ WS_CAPTION; } else if ((testValue & WS_BORDER) == WS_BORDER) { strcpy(styleText, "WS_BORDER"); bFoundOne = TRUE; testValue = testValue ^ WS_BORDER; } else if ((testValue & WS_DLGFRAME) == WS_DLGFRAME) { strcpy(styleText, "WS_DLGFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_DLGFRAME; } else if ((testValue & WS_VSCROLL) == WS_VSCROLL) { strcpy(styleText, "WS_VSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_VSCROLL; } else if ((testValue & WS_HSCROLL) == WS_HSCROLL) { strcpy(styleText, "WS_HSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_HSCROLL; } else if ((testValue & WS_SYSMENU) == WS_SYSMENU) { strcpy(styleText, "WS_SYSMENU"); bFoundOne = TRUE; testValue = testValue ^ WS_SYSMENU; } if (bFoundOne) { PA_ResizeArray(&styles, i); PA_SetTextInArray(styles, i, styleText, strlen(styleText)); } i++; } // end while if (testValue == 0) { strcpy(styleText, "WS_OVERLAPPED"); PA_ResizeArray(&styles, i); PA_SetTextInArray(styles, i, styleText, strlen(styleText)); } PA_SetVariableParameter(params, 2, styles, 0); } PA_ReturnLong(params, returnValue); }
// ------------------------------------------------ // // FUNCTION: sys_GetDocumentList( PA_PluginParameters params ) // // PURPOSE: Return a list of files in a directory. // // DATE: MJG 6/4/04 (3.6) // // UPDATES: MJG 7/5/05 (3.6.2) Updated to set the 4D variable, Error, // when an error occurs. // // AMS 9/16/14 #40405 (6.4) Updated to return the oldest entries first // and take in a starting index for specifying // where the list of returned files begins. // // // ------------------------------------------------ void sys_GetDocumentList(PA_PluginParameters params) { LONG lReturnValue = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lFileCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lArraySize = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lEndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG lCount = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG const LONG lFileLimit = 1000; char fullPath[MAXBUF]; WIN32_FIND_DATA fFindData; DWORD ret = 0; DWORD lastError = 0; HANDLE NextFind = 0; BOOL bGetAllFiles = FALSE; WIN32_FIND_DATA fileList[1000]; // parameter variables char *patPathName = NULL; char *patFilePattern = NULL; LONG palMaxFilesToReturn = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG palFileSort = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG LONG palStartIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG PA_Variable paReturnFileList; // Get the function parameters. patPathName = getTextParameter(params, 1); patFilePattern = getTextParameter(params, 2); paReturnFileList = PA_GetVariableParameter(params, 3); palMaxFilesToReturn = PA_GetLongParameter(params, 4); palFileSort = PA_GetLongParameter(params, 5); // AMS2 9/30/14 #40405 Moved the sort parameter to be before start index palStartIndex = PA_GetLongParameter(params, 6); // AMS2 9/16/14 #40405 // Clear out the return array. PA_ResizeArray(&paReturnFileList, 0); // AMS2 9/19/14 #40405 Passing in the start index is optional, if a value is passed in then it is assumed that the user put in a number relative to a starting index of 1 instead of 0 for c/c++ arrays if ((palStartIndex != 0) || (palStartIndex > 0)) // WJF 6/24/16 Win-21 NULL -> 0 { palStartIndex--; } else{ palStartIndex = 0; } // WJF 4/7/15 #41624 If they haven't chosen a valid sort option, set to default if ((palFileSort != 1) && (palFileSort != 2)) { palFileSort = 0; } if (patPathName != NULL && patFilePattern != NULL) { // Check if the path is valid. ret = GetFileAttributes(patPathName); if ((ret & FILE_ATTRIBUTE_DIRECTORY) != 0 && ret != INVALID_DIRECTORY) { // Build the full path name. if (patFilePattern[0] == '\0') { snprintf(fullPath, MAXBUF, "%s%s*.*", patPathName, patPathName[strlen(patPathName) - 1] == PATHCHAR ? "" : PATHSTR); } else { snprintf(fullPath, MAXBUF, "%s%s%s", patPathName, patPathName[strlen(patPathName) - 1] == PATHCHAR ? "" : PATHSTR, patFilePattern); } // Get the first file. NextFind = FindFirstFile(fullPath, &fFindData); if (NextFind != INVALID_HANDLE_VALUE) { // AMS2 9/18/14 #40405 Loop through the files in the directory and build a list to sort. Currently the max files that can be stored from a directory is 1000. lastError = ERROR_NO_MORE_FILES; bGetAllFiles = (palMaxFilesToReturn <= 0); while ((NextFind != INVALID_HANDLE_VALUE) && (lFileCount < lFileLimit)) { if ((fFindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { // AMS2 9/19/14 #40405 When a file match is found, insert it into the file list array. fileList[lFileCount] = fFindData; lFileCount++; // Count the number of files that match the pattern. } if (!FindNextFile(NextFind, &fFindData)) { lastError = GetLastError(); break; } } // end while // AMS2 9/18/14 #40405 Sort the array using compareFileTimeCreation which takes in two win32 find data variables and compares their creation dates. if (palFileSort == 1) { qsort(fileList, lFileCount, sizeof(WIN32_FIND_DATA), (int(*)(const void*, const void*))compareFileTimeCreation); } else if (palFileSort == 2) // WJF 4/7/15 #41624 Sorty by alphabetical order { qsort(fileList, lFileCount, sizeof(WIN32_FIND_DATA), (int(*)(const void*, const void*))compareAlphabetical); } // AMS2 9/18/14 #40405 Get all of the files if 0 is passed for the max files parameter. if (palMaxFilesToReturn == 0) { palMaxFilesToReturn = lFileCount; } // AMS2 9/18/14 #40405 If the start index or end index is out of range, then set them to the file count. if (palStartIndex > lFileCount) { palStartIndex = lFileCount; } lEndIndex = palMaxFilesToReturn + palStartIndex; if (lEndIndex > lFileCount) { lEndIndex = lFileCount; } // AMS2 9/22/14 #40405 As long as the end index is within the file limit, insert the requested file names into the return array // starting at the specified start index and end at the start index + the max number of files to return. if (lEndIndex <= lFileLimit) { for (int i = palStartIndex; i < lEndIndex; i++) { lCount++; if (lCount > lArraySize) { // Increase the size of the array. lArraySize = lCount + ARRAY_LOAD_VALUE; PA_ResizeArray(&paReturnFileList, lArraySize); } PA_SetTextInArray(paReturnFileList, lCount, fileList[i].cFileName, strlen(fileList[i].cFileName)); } } } else { lastError = GetLastError(); } FindClose(NextFind); } else { lastError = GetLastError(); } } if (lastError == ERROR_NO_MORE_FILES || lastError == ERROR_FILE_NOT_FOUND) { setError(0); PA_ResizeArray(&paReturnFileList, lCount); // AMS2 9/22/14 #40405 When the file selection has finished with no more files in the dir or a file has not been found, resize the return array to the number of files inserted into the array. lReturnValue = 1; } else { setError(lastError); PA_ResizeArray(&paReturnFileList, 0); } PA_SetVariableParameter(params, 3, paReturnFileList, 0); freeTextParameter(patPathName); freeTextParameter(patFilePattern); PA_ReturnLong(params, lReturnValue); }
// ------------------------------------------------ // // FUNCTION: sys_GetRegEnum( PA_PluginParameters params ) // // PURPOSE: Get a key from the registry. // // DATE: MJG 12/4/03 (3.5.6) // void sys_GetRegEnum( PA_PluginParameters params ) { LONG_PTR returnValue, regKey, retErr; char regSub[MAXBUF]; LONG_PTR regBufSize = MAX_REG_SIZE; CHAR regBuf[MAX_REG_SIZE]; FILETIME ftLastWriteTime; HKEY hRootKey; HKEY hOpenKey; DWORD dwSubKeys; DWORD dwValues; DWORD i, j; PA_Variable paReturnArray1; PA_Variable paReturnArray2; dwSubKeys = dwValues = 0; returnValue = regKey = retErr = 0; hRootKey = hOpenKey = 0; memset(regSub, 0, MAXBUF); // Get the function parameters. regKey = PA_GetLongParameter( params, 1 ); PA_GetTextParameter( params, 2, regSub ); paReturnArray1 = PA_GetVariableParameter( params, 3 ); paReturnArray2 = PA_GetVariableParameter( params, 4 ); PA_ResizeArray(&paReturnArray1, 0); PA_ResizeArray(&paReturnArray2, 0); // Convert the 4d registry constant into a Windows registry key. hRootKey = getRootKey( regKey ); // Open the registry key. retErr = RegOpenKeyEx(hRootKey, regSub, 0, KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE , &hOpenKey); if(retErr == ERROR_SUCCESS){ retErr = RegQueryInfoKey(hOpenKey, NULL, NULL, NULL, &dwSubKeys, NULL, NULL, &dwValues, NULL, NULL, NULL, NULL); if( retErr == ERROR_SUCCESS) { // Enumerate the subkey names. if (dwSubKeys) { retErr = ERROR_SUCCESS; PA_ResizeArray(&paReturnArray1, dwSubKeys); for (i=0,j=0; i<dwSubKeys; i++) { regBufSize = MAX_REG_SIZE; retErr = RegEnumKeyEx(hOpenKey, i, regBuf, ®BufSize, NULL, NULL, NULL, &ftLastWriteTime); if (retErr == ERROR_SUCCESS) { PA_SetTextInArray(paReturnArray1, ++j, regBuf, regBufSize); } } } // Enumerate the key value names. if (dwValues) { retErr = ERROR_SUCCESS; PA_ResizeArray(&paReturnArray2, dwValues); for (i=0,j=0; i<dwValues; i++) { regBufSize = MAX_REG_SIZE; regBuf[0] = '\0'; retErr = RegEnumValue(hOpenKey, i, regBuf, ®BufSize, NULL, NULL, NULL, NULL); if (retErr == ERROR_SUCCESS ) { PA_SetTextInArray(paReturnArray2, ++j, regBuf, regBufSize); } } } returnValue = 1; } } PA_SetVariableParameter( params, 3, paReturnArray1, 0 ); PA_SetVariableParameter( params, 4, paReturnArray2, 0 ); RegCloseKey( hOpenKey ); PA_ReturnLong( params, returnValue ); }
void sys_ShellExecute( PA_PluginParameters params ) { LONG_PTR returnValue = 0; LONG_PTR len = 0; char returnText[255]; // MWD & Mark De Wever #12225 INT_PTR howToShow; //char *pChar; //char *operation = NULL; //char *file = NULL; //char *parameters = NULL; //char *directory = NULL; PA_Unistring *UnistringFile; PA_Unistring *UnistringOperation; PA_Unistring *UnistringParameters; PA_Unistring *UnistringDirectory; PA_Unichar *file; PA_Unichar *operation; PA_Unichar *parameters; PA_Unichar *directory; PA_Unichar *pChar; // Get the function parameters. //operation = getTextParameter(params, 1); //file = getTextParameter(params, 2); //parameters = getTextParameter(params, 3); //directory = getTextParameter(params, 4); UnistringOperation = PA_GetStringParameter( params, 1); UnistringFile = PA_GetStringParameter( params, 2); UnistringParameters = PA_GetStringParameter( params, 3); UnistringDirectory = PA_GetStringParameter( params, 4); howToShow = PA_GetLongParameter( params, 5 ); operation = PA_GetUnistring(UnistringOperation); // AMS /28/14 file = PA_GetUnistring(UnistringFile); // AMS 2/28/14 len = (PA_GetUnistringLength(UnistringFile) + 1); // AMS 2/28/14 parameters = PA_GetUnistring(UnistringParameters); // AMS 2/28/14 directory = PA_GetUnistring(UnistringDirectory); // AMS 2/28/14 //if ((strcmp(_strlwr(operation), "open") != 0) && // (strcmp(_strlwr(operation), "explore") != 0) && // (strcmp(_strlwr(operation), "print") != 0) && // (file == NULL || strlen(file) == 0)) { // //strcpy(returnText, "Invalid Operation"); // strncpy(returnText, message->InvalidOperation, 255); // Mark De Wever #12225 replaced the line above //} if((lstrcmpiW(operation, L"open") != 0) && (lstrcmpiW(operation, L"explore") != 0) && (lstrcmpiW(operation, L"print") != 0) && (file == NULL || len == 0)) { strncpy(returnText, message->InvalidOperation, 255); } else if (howToShow > 11) { //strcpy(returnText, "Invalid HowToShow Constant"); strncpy(returnText, message->InvalidShowConstant, 255); // Mark De Wever #12225 replaced the line above } else { pChar = file; // added 10/28/02 shellExecute wants backslashes do { if (*pChar == '/') { *pChar = '\\'; } } while (*pChar++ != '\0') ; if (directory != NULL) { pChar = directory; do { if (*pChar == '/') { *pChar = '\\'; } } while (*pChar++ != '\0'); } CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); // AMS 5/6/14 #38727 returnValue = (LONG_PTR) ShellExecuteW(NULL, operation, file, parameters, directory, howToShow); strcpy(returnText, ""); if (returnValue <= 32) { // error occurred switch (returnValue) { case ERROR_FILE_NOT_FOUND : //strcpy(returnText, "File Not Found"); strncpy(returnText, message->FileNotFound, 255); // Mark De Wever #12225 replaced line above break; case ERROR_PATH_NOT_FOUND : //strcpy(returnText, "Path Not Found"); strncpy(returnText, message->PathNotFound, 255); // Mark De Wever #12225 Replaced line above break; case ERROR_BAD_FORMAT : //strcpy(returnText, ".EXE File is Invalid"); strncpy(returnText, message->BadFormat, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_ACCESSDENIED : //strcpy(returnText, "OS Denied Access to File"); strncpy(returnText, message->AccessDenied, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_ASSOCINCOMPLETE : //strcpy(returnText, "File Name Association is Incomplete or Invalid"); strncpy(returnText, message->AssocIncomplete, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_DDEBUSY : case SE_ERR_DDEFAIL : //strcpy(returnText, "DDE Transaction Could Not be Completed"); strncpy(returnText, message->DDEFail, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_DDETIMEOUT : //strcpy(returnText, "DDE Request Timed Out"); strncpy(returnText, message->DDETimeOut, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_DLLNOTFOUND : //strcpy(returnText, "DLL Libray Not Found"); strncpy(returnText, message->DLLNotFound, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_NOASSOC : //strcpy(returnText, "No Application Associated with File Extenstion"); strncpy(returnText, message->NoAssoc, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_OOM : //strcpy(returnText, "Insufficient Memory"); strncpy(returnText, message->OOM, 255); // Mark De Wever #12225 Replaced line above break; case SE_ERR_SHARE : //strcpy(returnText, "Sharing Violation Occurred"); strncpy(returnText, message->ShareViolation, 255); // Mark De Wever #12225 Replaced line above break; default: //strcpy(returnText, "Unknown error occurred"); strncpy(returnText, message->Default, 255); // Mark De Wever #12225 Replaced line above break; } } } //freeTextParameter(operation); //freeTextParameter(file); //freeTextParameter(parameters); //freeTextParameter(directory); PA_ReturnText( params, returnText, strlen(returnText)); }
// ------------------------------------------------ // // FUNCTION: gui_GetWindowStyle( PA_PluginParameters params) // // PURPOSE: Get window styles // // COMMENTS: outputs in array the applicable styles for the window // Returns via return code the LONG_PTR representing the value // // DATE: dcc 07/18/02 dcc // // MODIFICATIONS: // void gui_GetWindowStyle ( PA_PluginParameters params ) { PA_Variable styles; LONG_PTR returnValue = 0, testValue = 0, i; HWND hWnd; char styleText[40]; BOOL bFoundOne; hWnd = (HWND) PA_GetLongParameter( params, 1); if (IsWindow(hWnd)) { styles = PA_GetVariableParameter( params, 2 ); returnValue = GetWindowLong(hWnd, GWL_STYLE); testValue = returnValue; //and all styles to see what the window uses i = 1; while ((testValue != 0) && (i <= NUMBER_STYLES)) { bFoundOne = FALSE; if ((testValue & WS_THICKFRAME) == WS_THICKFRAME) { strcpy(styleText, "WS_THICKFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_THICKFRAME; } else if ((testValue & WS_POPUP) == WS_POPUP) { strcpy(styleText, "WS_POPUP"); bFoundOne = TRUE; testValue = testValue ^ WS_POPUP; } else if ((testValue & WS_CHILD) == WS_CHILD) { strcpy(styleText, "WS_CHILD"); bFoundOne = TRUE; testValue = testValue ^ WS_CHILD; } else if ((testValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { strcpy(styleText, "WS_MINIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MINIMIZEBOX; } else if ((testValue & WS_VISIBLE) == WS_VISIBLE) { strcpy(styleText, "WS_VISIBLE"); bFoundOne = TRUE; testValue = testValue ^ WS_VISIBLE; } else if ((testValue & WS_DISABLED) == WS_DISABLED) { strcpy(styleText, "WS_DISABLED"); bFoundOne = TRUE; testValue = testValue ^ WS_DISABLED; } else if ((testValue & WS_CLIPSIBLINGS) == WS_CLIPSIBLINGS) { strcpy(styleText, "WS_CLIPSIBLINGS"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPSIBLINGS; } else if ((testValue & WS_CLIPCHILDREN) == WS_CLIPCHILDREN) { strcpy(styleText, "WS_CLIPCHILDREN"); bFoundOne = TRUE; testValue = testValue ^ WS_CLIPCHILDREN; } else if ((testValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { strcpy(styleText, "WS_MAXIMIZEBOX"); bFoundOne = TRUE; testValue = testValue ^ WS_MAXIMIZEBOX; } else if ((testValue & WS_CAPTION) == WS_CAPTION) { strcpy(styleText, "WS_CAPTION"); bFoundOne = TRUE; testValue = testValue ^ WS_CAPTION; } else if ((testValue & WS_BORDER) == WS_BORDER) { strcpy(styleText, "WS_BORDER"); bFoundOne = TRUE; testValue = testValue ^ WS_BORDER; } else if ((testValue & WS_DLGFRAME) == WS_DLGFRAME) { strcpy(styleText, "WS_DLGFRAME"); bFoundOne = TRUE; testValue = testValue ^ WS_DLGFRAME; } else if ((testValue & WS_VSCROLL) == WS_VSCROLL) { strcpy(styleText, "WS_VSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_VSCROLL; } else if ((testValue & WS_HSCROLL) == WS_HSCROLL) { strcpy(styleText, "WS_HSCROLL"); bFoundOne = TRUE; testValue = testValue ^ WS_HSCROLL; } else if ((testValue & WS_SYSMENU) == WS_SYSMENU) { strcpy(styleText, "WS_SYSMENU"); bFoundOne = TRUE; testValue = testValue ^ WS_SYSMENU; } if (bFoundOne) { PA_ResizeArray (&styles, i); PA_SetTextInArray (styles, i, styleText, strlen(styleText)); } i++; } // end while if (testValue == 0) { strcpy(styleText, "WS_OVERLAPPED"); PA_ResizeArray (&styles, i); PA_SetTextInArray (styles, i, styleText, strlen(styleText)); } PA_SetVariableParameter( params, 2, styles, 0 ); } PA_ReturnLong( params, returnValue ); }
// ------------------------------------------------ // // FUNCTION: gui_RespectToolBar( PA_PluginParameters params ) // // PURPOSE: Function to intecept maximize event in the // ProToolsProc. There the window maximized // size is reduced by the number of pixels // passed into the function. // // COMMENTS: This has been experimented with but should be tested // more thoroughly. Some situations still cause a max'd // window to resize under a toolbar. Noticed in particular // when a new process window pops up over another process's // max'd window. This is left for an excersize for some adventurous // soul. // // DATE: dcc 01/16/03 (3.5.4) // // MODIFICATIONS: // void gui_RespectToolBar( PA_PluginParameters params ) { LONG_PTR position_len = 0, tbRestriction = 0; LONG_PTR trackingRestriction = 0, processNbr; char position[2]; INT_PTR theChar; tbRestriction = PA_GetLongParameter( params, 1); position_len = PA_GetTextParameter( params, 2, position ); position[position_len] = '\0'; if (position_len > 1) { position[1] = '\0'; } _strlwr(position); if (position_len == 0) { // pass a negative in and turns it all off toolBarRestrictions.toolBarOnDeck = 0; //restoreOrig4DWindowProcess(); // MJG 3/26/04 The 4D window will remain subclassed until the plug-in is unloaded. PA_ReturnLong( params, toolBarRestrictions.toolBarOnDeck); return; } trackingRestriction = PA_GetLongParameter( params, 3); toolBarRestrictions.trackingRestriction = trackingRestriction; if ((tbRestriction != 0) && (strpbrk(position, "ltrb") != NULL)) { toolBarRestrictions.toolBarOnDeck = 1; theChar = (INT_PTR) position[0]; } processNbr = PA_GetCurrentProcessNumber(); switch (theChar) { case 'l' : toolBarRestrictions.left = tbRestriction; toolBarRestrictions.leftProcessNbr = processNbr; break; case 't' : toolBarRestrictions.top = tbRestriction; toolBarRestrictions.topProcessNbr = processNbr; break; case 'r' : toolBarRestrictions.right = tbRestriction; toolBarRestrictions.rightProcessNbr = processNbr; break; case 'b' : toolBarRestrictions.bottom = tbRestriction; toolBarRestrictions.bottomProcessNbr = processNbr; break; } toolBarRestrictions.appBeingMaxed = 0; //if (processHandles.wpFourDOrigProc == NULL) { // processHandles.wpFourDOrigProc = (WNDPROC) SetWindowLong(windowHandles.fourDhWnd, GWL_WNDPROC, (LONG) newProc); //} // MJG 3/26/04 Replaced code above with function call. subclass4DWindowProcess(); PA_ReturnLong( params, toolBarRestrictions.toolBarOnDeck); }
// ------------------------------------------------ // // FUNCTION: gui_SelectColor( PA_PluginParameters params) // // PURPOSE: Displays the color common dialog // // COMMENTS: // // // DATE: dcc 11/25/02 (3.5.3) // // MODIFICATIONS: // void gui_SelectColor( PA_PluginParameters params) { CHOOSECOLOR cColor; static COLORREF acrCustColor[16]; static DWORD rgbCurrent; LONG_PTR rParam, gParam, bParam, returnValue = 0, i, hasCustom; PA_Variable custColorArray; rParam = PA_GetLongParameter( params, 1); gParam = PA_GetLongParameter( params, 2); bParam = PA_GetLongParameter( params, 3); hasCustom = PA_GetLongParameter( params, 4); if (rParam > 255) rParam = 0; if (gParam > 255) gParam = 0; if (bParam > 255) bParam = 0; if (hasCustom == 1) { custColorArray = PA_GetVariableParameter( params, 5 ); if(PA_GetVariableKind(custColorArray) == eVK_ArrayLongint) { for (i = 0; i < PA_GetArrayNbElements(custColorArray); i++) { acrCustColor[i] = PA_GetLongintInArray(custColorArray, i + 1); } } } ZeroMemory(&cColor, sizeof(CHOOSECOLOR)); cColor.lStructSize = sizeof(CHOOSECOLOR); cColor.hwndOwner = windowHandles.fourDhWnd; cColor.lpCustColors = (LPDWORD) acrCustColor; cColor.rgbResult = rgbCurrent; if ((rParam > 0) || (gParam > 0) || (bParam > 0)) { cColor.rgbResult = RGB(rParam, gParam, bParam); cColor.Flags = CC_FULLOPEN | CC_RGBINIT; } else { cColor.Flags = CC_FULLOPEN; } if (ChooseColor(&cColor)== TRUE) { rgbCurrent = cColor.rgbResult; rParam = GetRValue(rgbCurrent); gParam = GetGValue(rgbCurrent); bParam = GetBValue(rgbCurrent); PA_SetLongParameter( params, 1, rParam ); PA_SetLongParameter( params, 2, gParam ); PA_SetLongParameter( params, 3, bParam ); if (hasCustom == 1) { PA_ResizeArray(&custColorArray, 16); for (i = 0; i < 16; i++) { PA_SetLongintInArray(custColorArray, i + 1, acrCustColor[i]); } PA_SetVariableParameter( params, 5, custColorArray, 0); } returnValue = 1; } PA_ReturnLong( params, returnValue); }
void gui_RestrictWindow( PA_PluginParameters params ) { LONG_PTR action = 0, returnValue = 0, styleChg = 0, numDeleted = 0; HWND hWnd = NULL; HMENU hSysMenu; WNDPROC wpProc = NULL; pLL thisLink = NULL, previousLink = NULL; // subClass procedure must be in place if (processHandles.wpProToolsOrigProc == NULL) { PA_ReturnLong( params, -2 ); return; } hWnd = (HWND) PA_GetLongParameter( params, 1 ); action = PA_GetLongParameter( params, 2); if (IsWindow(hWnd)) { // 09/09/02 more action values now so removed restriction returnValue = GetWindowLong(hWnd, GWL_STYLE); // eliminate sizing cursor and Window's sizing border switch (action) { case (RW_NO_MIN) : if ((returnValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) { styleChg = returnValue ^ WS_MINIMIZEBOX; returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg); } break; case (RW_NO_MAX) : if ((returnValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) { styleChg = returnValue ^ WS_MAXIMIZEBOX; returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg); } break; case (RW_NO_CLOSE) : hSysMenu = GetSystemMenu(hWnd,0); if (hSysMenu != NULL) { EnableMenuItem (hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); } break; case (RW_RESTORE_CLOSE) : hSysMenu = GetSystemMenu(hWnd,0); if (hSysMenu != NULL) { EnableMenuItem (hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); } break; } if (startOfList == NULL) { init_list(&startOfList); } // insert item in linked list -- if not already there if (!search_list( &startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *) &hWnd)) { thisLink = (pLL) insert_list(&startOfList); if (thisLink == NULL) { PA_ReturnLong( params, -1 ); // could not add to list - get out return; } } else { PA_ReturnLong( params, (LONG_PTR)hWnd ); // return window handle if already in list return; } thisLink->hWnd = hWnd; thisLink->dataLong1 = action; thisLink->type = LL_Restrict; thisLink->wpProc = processHandles.wpProToolsOrigProc; returnValue = length_list(startOfList); } PA_ReturnLong( params, returnValue ); }
void gui_SetWindowStyle(PA_PluginParameters params, BOOL isEx) { LONG StyleCurr = 0, StyleNew = 0, action = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG HWND hWnd = NULL; HMENU hSysMenu; pLL thisLink = NULL, previousLink = NULL; LONG hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal handle array action = PA_GetLongParameter(params, 2); if (isEx){ // WJF 9/16/15 #43731 hWnd = handleArray_retrieve((DWORD)hWndIndex); } else { hWnd = (HWND)hWndIndex; } if (IsWindow(hWnd)) { StyleCurr = GetWindowLong(hWnd, GWL_STYLE); StyleNew = StyleCurr; if (0 != (action & RW_DISABLE_MIN)){ StyleNew = StyleNew & ~WS_MINIMIZEBOX; } if (0 != (action & RW_ENABLE_MIN)){ StyleNew = StyleNew | WS_MINIMIZEBOX; } if (0 != (action & RW_DISABLE_MAX)){ StyleNew = StyleNew & ~WS_MAXIMIZEBOX; } if (0 != (action & RW_ENABLE_MAX)){ StyleNew = StyleNew | WS_MAXIMIZEBOX; } if (0 != (action & RW_DISABLE_CLOSE)){ hSysMenu = GetSystemMenu(hWnd, 0); if (hSysMenu != NULL) { EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED); } } if (0 != (action & RW_ENABLE_CLOSE)){ hSysMenu = GetSystemMenu(hWnd, 0); if (hSysMenu != NULL) { EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); } } if (0 != (action & RW_DISABLE_RESIZE)){ // subClass procedure must be in place if (processHandles.wpProToolsOrigProc == NULL) { PA_ReturnLong(params, -2); return; } if (startOfList == NULL) { init_list(&startOfList); } // insert item in linked list -- if not already there if (!search_list(&startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd)) { thisLink = (pLL)insert_list(&startOfList); if (thisLink == NULL) { PA_ReturnLong(params, -2); return; } else { thisLink->hWnd = hWnd; thisLink->dataLong1 = RW_NO_SIZE; // sub proc uses other number thisLink->type = LL_Restrict; thisLink->wpProc = processHandles.wpProToolsOrigProc; } } } if (0 != (action & RW_ENABLE_RESIZE)){ // no subclass or no list head, we're done if ((NULL != processHandles.wpProToolsOrigProc) && (NULL != startOfList)) { delete_list(&startOfList, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd); } } if (StyleNew != StyleCurr){ if (0 == SetWindowLong(hWnd, GWL_STYLE, StyleNew)){ PA_ReturnLong(params, -2); return; } else { // notify windows we changed the style SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } } } // when we end up here all is oke PA_ReturnLong(params, 0); }
void sys_KillProcessByName( PA_PluginParameters params ) { HANDLE hProcessSnap; // Handle to the process snapshot HANDLE hProcess; // Handle to the process itself PROCESSENTRY32 pe32; // ProcessEntry to get info about processes char processName[MAXBUF] = ""; // String to hold the printerName param ($1) LONG_PTR lMode = 1; // Long to hold the working mode ($2) // 1 = just first process matching name // 2 = all processes matching name BOOL bCleanFirst = FALSE; // Boolean to see if we should try to cleanly close the app // before killing it mercilessly BOOL bOrigCleanFirst = FALSE; // Keeps track of original bCleanFirst value // to reset between loop iterations ($3) BOOL bDone = FALSE; // This will keep track of whether or not we are finished // Looping through processes. // Get the function parameters. PA_GetTextParameter(params, 1, processName); lMode = PA_GetLongParameter(params, 2); bOrigCleanFirst = (PA_GetLongParameter(params, 3) == 1 ? TRUE : FALSE); // Take a snapshot of all processes in the system. // If we fail, return the error code hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } // Set the size of the structure before using it. pe32.dwSize = sizeof( PROCESSENTRY32 ); // Retrieve information about the first process, // If we can't do it, then return the error code if(!Process32First( hProcessSnap, &pe32)) { CloseHandle( hProcessSnap ); // Must clean up the snapshot object! PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } // Now walk the snapshot of processes, and // display information about each process in turn do { // Check the name if (strcmp(pe32.szExeFile, processName) == 0) { bCleanFirst = bOrigCleanFirst; // Get the process // We need to make sure that we have the TERMINATE right hProcess = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pe32.th32ProcessID); // Couldn't get the process // Clean up the handle // and return the error if(hProcess == NULL) { CloseHandle(hProcessSnap); PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } if(bCleanFirst) { // TerminateClean() posts WM_CLOSE to all windows whose PID // matches your process's. EnumWindows((WNDENUMPROC)TerminateClean, (LPARAM) pe32.th32ProcessID) ; if(WaitForSingleObject(hProcess, 500)!=WAIT_OBJECT_0) { bCleanFirst = TRUE; } } if(!bCleanFirst) { // Kill the process if(TerminateProcess(hProcess, 1)) {; // Success! // If we're in mode 1 then we are finished // If not, then we will need to keep going if(lMode == 1) { bDone = TRUE; } // end } else { // Fail! // Clean up and return the error CloseHandle(hProcess); CloseHandle(hProcessSnap); PA_ReturnLong(params, (LONG_PTR)GetLastError()); return; } } // Close our handle CloseHandle(hProcess); } // end if Process32Next(hProcessSnap, &pe32); // WJF 6/2/15 #42839 Moved out of while condition } while((GetLastError()!=18) && (!bDone)); // WJF 6/2/15 #42839 Added GetLastError Check, corrected logical or syntax, and added inversion to bDone // Close the handle and return success CloseHandle(hProcessSnap); PA_ReturnLong(params, -1 * (LONG_PTR)bCleanFirst); }