Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string.h>
- #include "resource.h"
- #include <shlobj.h>
- #include <objbase.h>
- #pragma comment(lib, "shell32.lib")
- #pragma comment(lib, "ole32.lib")
- #define BROWSE_REGISTRY_ROOT HKEY_CURRENT_USER
- #define BROWSE_REGISTRY_PATH "Software\\Connector"
- void launchMW2(HWND hWnd, char* args)
- {
- char* buf;
- buf = (char*)GlobalAlloc(GPTR, 100);
- GetDlgItemText(hWnd, IDC_TPATH, buf, 100);
- strcat(buf,"\\iw4mp.exe");
- ShellExecute( NULL, NULL, buf, args, NULL, SW_SHOW );
- }
- void SaveConfig(HWND hWnd)
- {
- char* buf;
- char Value[MAX_PATH];
- HKEY Key = NULL;
- //Open or create the registry before closing
- if(RegCreateKeyEx(BROWSE_REGISTRY_ROOT, BROWSE_REGISTRY_PATH, NULL, NULL, NULL, KEY_ALL_ACCESS, NULL, &Key, NULL)!=ERROR_SUCCESS)
- return;
- buf = (char*)GlobalAlloc(GPTR, 100);
- GetDlgItemText(hWnd, IDC_TPATH, buf, 100);
- //Now delete all the old entries
- strcpy(Value,"MW2 PATH");
- RegDeleteValue(Key, Value);
- RegSetValueEx(Key, Value, NULL, REG_SZ, (LPBYTE)buf, strlen(buf));
- //Now close it
- RegCloseKey(Key);
- }
- void ReadConfig(HWND hWnd)
- {
- HKEY Key = NULL;
- char Value[MAX_PATH];
- char szData[MAX_PATH];
- DWORD cbData=sizeof(DWORD);
- DWORD Data;
- //Open the key, return if it does not exists
- if(RegOpenKeyEx(BROWSE_REGISTRY_ROOT, BROWSE_REGISTRY_PATH, NULL, KEY_ALL_ACCESS, &Key)!=ERROR_SUCCESS)
- return;
- //Variables to store data
- cbData = sizeof(szData);
- strcpy(Value,"MW2 PATH");
- //Read the registry and check if it is valid or leave
- if(RegQueryValueEx( Key, Value, NULL, NULL, (LPBYTE)&szData, &cbData)==ERROR_SUCCESS)
- {
- SetDlgItemText(hWnd, IDC_TPATH, szData);
- }
- //Now close the key
- RegCloseKey(Key);
- }
- BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
- {
- switch(Message)
- {
- case WM_INITDIALOG:
- // This is where we set up the dialog box, and initialise any default values
- SetDlgItemText(hwnd, IDC_TEXT, "IP:PORT");
- SetDlgItemText(hwnd, IDC_TPATH, "Select your MW2 PATH");
- ReadConfig(hwnd);
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam))
- {
- case IDC_CONNECT:
- {
- int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT));
- if(len > 0)
- {
- char* buf;
- char argument[100];
- buf = (char*)GlobalAlloc(GPTR, len + 1);
- GetDlgItemText(hwnd, IDC_TEXT, buf, len + 1);
- strcpy(argument,"\"aiw://connect/");
- strcat(argument,buf);
- strcat(argument,"\"");
- launchMW2(hwnd,argument);
- //ShellExecute( NULL, NULL, buf, argument, NULL, SW_SHOW );
- GlobalFree((HANDLE)buf);
- }
- else
- {
- MessageBox(hwnd, "Enter IP:PORT to connect", "Warning", MB_OK);
- }
- }
- break;
- case IDC_PLM:
- {
- launchMW2(hwnd,"\"aiw://connect/192.168.56.1:28961\"");
- }
- break;
- case IDC_Legion:
- {
- launchMW2(hwnd,"\"aiw://connect/192.168.56.1:28961\"");
- }
- break;
- case IDC_PATH:
- {
- TCHAR szFolder[MAX_PATH];
- CoInitialize(NULL);
- if (GetFolderSelection(NULL, szFolder, TEXT("Please select a folder.")))
- {
- SetDlgItemText(hwnd, IDC_TPATH, szFolder);
- SaveConfig(hwnd);
- }
- else
- {
- SetDlgItemText(hwnd, IDC_TPATH, "Failed to select a folder");
- }
- CoUninitialize();
- }
- break;
- }
- break;
- case WM_CLOSE:
- EndDialog(hwnd, 0);
- break;
- default:
- return FALSE;
- }
- return TRUE;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
- }
- BOOL GetFolderSelection(HWND hWnd, LPTSTR szBuf, LPCTSTR szTitle)
- {
- LPITEMIDLIST pidl = NULL;
- BROWSEINFO bi = { 0 };
- BOOL bResult = FALSE;
- bi.hwndOwner = hWnd;
- bi.pszDisplayName = szBuf;
- bi.pidlRoot = NULL;
- bi.lpszTitle = szTitle;
- bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI;
- if ((pidl = SHBrowseForFolder(&bi)) != NULL)
- {
- bResult = SHGetPathFromIDList(pidl, szBuf);
- CoTaskMemFree(pidl);
- }
- return bResult;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement