Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0125· OpenAIAi2 WildChat-4.8M (AI2)

I have the following typedef struct with the OPTIONSTYPE mopttype = OPTIONSMAX and two…

  1. User

    I have the following typedef struct with the OPTIONS_TYPE m_opttype = OPTIONS_MAX and two functions. How can i move OPTIONS_TYPE m_opttype = OPTIONS_MAX out of the typedef struct and add them directly to the tow function?

    typedef struct { const char *m_lpTitle; // Folder Title const char *short_name; // for saving in the .ini UINT m_nFolderId; // ID UINT m_nIconId; // if >= 0, resource id of icon (IDI_xxx), otherwise index in image list DWORD m_dwUnset; // Excluded filters DWORD m_dwSet; // Implied filters BOOL m_process; // (not used yet) void (*m_pfnCreateFolders)(int parent_index); // Constructor for special folders BOOL (*m_pfnQuery)(uint32_t nDriver); // Query function BOOL m_bExpectedResult; // Expected query result OPTIONS_TYPE m_opttype = OPTIONS_MAX; // Has an ini file (vector.ini, etc) } FOLDERDATA, *LPFOLDERDATA;


    Function 1:

    static BOOL FolderHasIni(LPTREEFOLDER lpFolder) { LPCFOLDERDATA data = FindFilter(lpFolder->m_nFolderId); if (data) if (data->m_opttype < OPTIONS_MAX) return true;

    if (lpFolder->m_nParent != -1 && FOLDER_SOURCE == treeFolders[lpFolder->m_nParent]->m_nFolderId) 
    	return true;
    
    return false;
    

    }


    Function 2:

    case ID_FOLDER_PROPERTIES:
    	{
    		folder = GetSelectedFolder();
    		if (folder)
    			if (folder->m_dwFlags & F_INIEDIT)
    			{
    				LPCFOLDERDATA data = FindFilter(folder->m_nFolderId);
    				if (data)
    					if (data->m_opttype < OPTIONS_MAX)
    						InitPropertyPage(hInst, hwnd, GetSelectedFolderIcon(), data->m_opttype, folder->m_nFolderId, -1);
    			}
    	}
    	UpdateStatusBar();
    	break;
    

  2. Assistant

    To move OPTIONS_TYPE m_opttype = OPTIONS_MAX out of the typedef struct and add them directly to the two functions, you can declare a global variable OPTIONS_TYPE g_opttype = OPTIONS_MAX; outside of the typedef struct. Then, update the two functions to reference this global variable instead of the struct member.

    Here is the updated code:

    typedef struct
    {
    	const char *m_lpTitle; 									// Folder Title
    	const char *short_name;  								// for saving in the .ini
    	UINT        m_nFolderId; 								// ID
    	UINT        m_nIconId; 									// if >= 0, resource id of icon (IDI_xxx), otherwise index in image list
    	DWORD       m_dwUnset; 									// Excluded filters
    	DWORD       m_dwSet;   									// Implied filters
    	BOOL        m_process;      // (not used yet)
    	void        (*m_pfnCreateFolders)(int parent_index); 	// Constructor for special folders
    	BOOL        (*m_pfnQuery)(uint32_t nDriver);              // Query function
    	BOOL        m_bExpectedResult;					   	// Expected query result
    } FOLDERDATA, *LPFOLDERDATA;
    
    OPTIONS_TYPE g_opttype = OPTIONS_MAX; // Global variable for m_opttype
    
    ---
    
    Function 1:
    
    static BOOL FolderHasIni(LPTREEFOLDER lpFolder)
    {
    	LPCFOLDERDATA data = FindFilter(lpFolder->m_nFolderId);
    	if (data)
    		if (g_opttype < OPTIONS_MAX)
    			return true;
    
    	if (lpFolder->m_nParent != -1 && FOLDER_SOURCE == treeFolders[lpFolder->m_nParent]->m_nFolderId) 
    		return true;
    
    	return false;
    }
    
    ---
    
    Function 2:
    
    case ID_FOLDER_PROPERTIES:
    {
        folder = GetSelectedFolder();
        if (folder)
            if (folder->m_dwFlags & F_INIEDIT)
            {
                LPCFOLDERDATA data = FindFilter(folder->m_nFolderId);
                if (data)
                    if (g_opttype < OPTIONS_MAX)
                        InitPropertyPage(hInst, hwnd, GetSelectedFolderIcon(), g_opttype, folder->m_nFolderId, -1);
            }
    }
    UpdateStatusBar();
    break;
    
  3. User

    It works! Many thanks!

  4. Assistant

    You're welcome! If you have any more questions or need further assistance, feel free to ask. Happy coding!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.