Index: base/applications/regedit/hexedit.h =================================================================== --- base/applications/regedit/hexedit.h (revision 49426) +++ base/applications/regedit/hexedit.h (working copy) @@ -8,30 +8,30 @@ UnregisterHexEditorClass(HINSTANCE hInstance); /* styles */ -#define HES_READONLY (0x800) -#define HES_LOWERCASE (0x10) -#define HES_UPPERCASE (0x8) -#define HES_AUTOVSCROLL (0x40) -#define HES_HIDEADDRESS (0x4) +#define HES_READONLY (0x800) +#define HES_LOWERCASE (0x10) +#define HES_UPPERCASE (0x8) +#define HES_AUTOVSCROLL (0x40) +#define HES_HIDEADDRESS (0x4) /* messages */ -#define HEM_BASE (WM_USER + 50) -#define HEM_LOADBUFFER (HEM_BASE + 1) -#define HEM_COPYBUFFER (HEM_BASE + 2) -#define HEM_SETMAXBUFFERSIZE (HEM_BASE + 3) +#define HEM_BASE (WM_USER + 50) +#define HEM_LOADBUFFER (HEM_BASE + 1) +#define HEM_COPYBUFFER (HEM_BASE + 2) +#define HEM_SETMAXBUFFERSIZE (HEM_BASE + 3) /* macros */ #define HexEdit_LoadBuffer(hWnd, Buffer, Size) \ - SendMessage((hWnd), HEM_LOADBUFFER, (WPARAM)(Buffer), (LPARAM)(Size)) + SendMessage((hWnd), HEM_LOADBUFFER, (WPARAM)(Buffer), (LPARAM)(Size)) #define HexEdit_ClearBuffer(hWnd) \ - SendMessage((hWnd), HEM_LOADBUFFER, 0, 0) + SendMessage((hWnd), HEM_LOADBUFFER, 0, 0) #define HexEdit_CopyBuffer(hWnd, Buffer, nMax) \ - SendMessage((hWnd), HEM_COPYBUFFER, (WPARAM)(Buffer), (LPARAM)(nMax)) + SendMessage((hWnd), HEM_COPYBUFFER, (WPARAM)(Buffer), (LPARAM)(nMax)) #define HexEdit_GetBufferSize(hWnd) \ - SendMessage((hWnd), HEM_COPYBUFFER, 0, 0) + SendMessage((hWnd), HEM_COPYBUFFER, 0, 0) #define HexEdit_SetMaxBufferSize(hWnd, Size) \ - SendMessage((hWnd), HEM_SETMAXBUFFERSIZE, 0, (LPARAM)(Size)) + SendMessage((hWnd), HEM_SETMAXBUFFERSIZE, 0, (LPARAM)(Size)) Index: base/applications/regedit/lang/en-US.rc =================================================================== --- base/applications/regedit/lang/en-US.rc (revision 49426) +++ base/applications/regedit/lang/en-US.rc (working copy) @@ -274,6 +274,10 @@ ID_REGISTRY_IMPORTREGISTRYFILE "Imports a text file into the registry" ID_REGISTRY_EXPORTREGISTRYFILE "Exports all or part of the registry to a text file" + ID_REGISTRY_LOADHIVE + "Loads a hive file into the registry" + ID_REGISTRY_UNLOADHIVE + "Unloads a hive from the registry" ID_REGISTRY_CONNECTNETWORKREGISTRY "Connects to a remote computer's registry" ID_REGISTRY_DISCONNECTNETWORKREGISTRY @@ -330,6 +334,8 @@ IDS_MY_COMPUTER "My Computer" IDS_IMPORT_REG_FILE "Import Registry File" IDS_EXPORT_REG_FILE "Export Registry File" + IDS_LOAD_HIVE "Load Hive" + IDS_UNLOAD_HIVE "Unload Hive" IDS_INVALID_DWORD "(invalid DWORD value)" END @@ -392,6 +398,20 @@ EDITTEXT IDC_EXPORT_BRANCH_TEXT,30,34,335,12 END +// +// Dialog resources +// +IDD_LOADHIVE DIALOGEX DISCARDABLE 0, 0, 193, 34 +STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Load Hive" +FONT 8, "Ms Shell Dlg" +{ + LTEXT "&Key:", IDC_STATIC, 4, 4, 15, 8, SS_LEFT + EDITTEXT IDC_EDIT_KEY, 23, 2, 167, 13 + DEFPUSHBUTTON "OK", IDOK, 140, 17, 50, 14 + PUSHBUTTON "Cancel", IDCANCEL, 89, 17, 50, 14 +} + IDD_ADDFAVORITES DIALOGEX DISCARDABLE 0, 0, 186, 46 STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Add to Favorites" Index: base/applications/regedit/regproc.c =================================================================== --- base/applications/regedit/regproc.c (revision 49426) +++ base/applications/regedit/regproc.c (working copy) @@ -30,22 +30,25 @@ */ #define REG_FILE_HEX_LINE_LEN (2 + 25 * 3) -static const CHAR *reg_class_names[] = { - "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT", - "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA" - }; +static const CHAR *reg_class_names[] = +{ + "HKEY_LOCAL_MACHINE", "HKEY_USERS", "HKEY_CLASSES_ROOT", + "HKEY_CURRENT_CONFIG", "HKEY_CURRENT_USER", "HKEY_DYN_DATA" +}; #define REG_CLASS_NUMBER (sizeof(reg_class_names) / sizeof(reg_class_names[0])) -const WCHAR* reg_class_namesW[REG_CLASS_NUMBER] = { +const WCHAR* reg_class_namesW[REG_CLASS_NUMBER] = +{ L"HKEY_LOCAL_MACHINE", L"HKEY_USERS", L"HKEY_CLASSES_ROOT", L"HKEY_CURRENT_CONFIG", L"HKEY_CURRENT_USER", L"HKEY_DYN_DATA" }; -static HKEY reg_class_keys[REG_CLASS_NUMBER] = { - HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, - HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA - }; +static HKEY reg_class_keys[REG_CLASS_NUMBER] = +{ + HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CLASSES_ROOT, + HKEY_CURRENT_CONFIG, HKEY_CURRENT_USER, HKEY_DYN_DATA +}; /* return values */ #define NOT_ENOUGH_MEMORY 1 @@ -149,7 +152,8 @@ char dummy; WideCharToMultiByte(CP_ACP, 0, str, -1, buf, 9, NULL, NULL); - if (lstrlenW(str) > 8 || sscanf(buf, "%lx%c", dw, &dummy) != 1) { + if (lstrlenW(str) > 8 || sscanf(buf, "%lx%c", dw, &dummy) != 1) + { fprintf(stderr,"%s: ERROR, invalid hex value\n", getAppName()); return FALSE; } @@ -172,12 +176,14 @@ s = str; d = data; *size=0; - while (*s != '\0') { + while (*s != '\0') + { UINT wc; WCHAR *end; wc = wcstoul(s,&end, 16); - if (end == s || wc > 0xff || (*end && *end != L',')) { + if (end == s || wc > 0xff || (*end && *end != L',')) + { char* strA = GetMultiByteString(s); fprintf(stderr,"%s: ERROR converting CSV hex stream. Invalid value at '%s'\n", getAppName(), strA); @@ -203,7 +209,13 @@ */ static DWORD getDataType(LPWSTR *lpValue, DWORD* parse_type) { - struct data_type { const WCHAR *tag; int len; int type; int parse_type; }; + struct data_type + { + const WCHAR *tag; + int len; + int type; + int parse_type; + }; static const WCHAR quote[] = {'"'}; static const WCHAR str[] = {'s','t','r',':','"'}; @@ -213,19 +225,20 @@ static const WCHAR hexp[] = {'h','e','x','('}; static const struct data_type data_types[] = { /* actual type */ /* type to assume for parsing */ - { quote, 1, REG_SZ, REG_SZ }, - { str, 5, REG_SZ, REG_SZ }, - { str2, 8, REG_EXPAND_SZ, REG_SZ }, - { hex, 4, REG_BINARY, REG_BINARY }, - { dword, 6, REG_DWORD, REG_DWORD }, - { hexp, 4, -1, REG_BINARY }, - { NULL, 0, 0, 0 } - }; + { quote, 1, REG_SZ, REG_SZ }, + { str, 5, REG_SZ, REG_SZ }, + { str2, 8, REG_EXPAND_SZ, REG_SZ }, + { hex, 4, REG_BINARY, REG_BINARY }, + { dword, 6, REG_DWORD, REG_DWORD }, + { hexp, 4, -1, REG_BINARY }, + { NULL, 0, 0, 0 } + }; const struct data_type *ptr; int type; - for (ptr = data_types; ptr->tag; ptr++) { + for (ptr = data_types; ptr->tag; ptr++) + { if (wcsncmp(ptr->tag, *lpValue, ptr->len)) continue; @@ -233,14 +246,18 @@ *parse_type = ptr->parse_type; type=ptr->type; *lpValue+=ptr->len; - if (type == -1) { + if (type == -1) + { WCHAR* end; /* "hex(xx):" is special */ type = (int)wcstoul( *lpValue , &end, 16 ); - if (**lpValue=='\0' || *end!=')' || *(end+1)!=':') { + if (**lpValue=='\0' || *end!=')' || *(end+1)!=':') + { type=REG_NONE; - } else { + } + else + { *lpValue = end + 2; } } @@ -258,10 +275,13 @@ int str_idx = 0; /* current character under analysis */ int val_idx = 0; /* the last character of the unescaped string */ int len = lstrlenW(str); - for (str_idx = 0; str_idx < len; str_idx++, val_idx++) { - if (str[str_idx] == '\\') { + for (str_idx = 0; str_idx < len; str_idx++, val_idx++) + { + if (str[str_idx] == '\\') + { str_idx++; - switch (str[str_idx]) { + switch (str[str_idx]) + { case 'n': str[val_idx] = '\n'; break; @@ -271,11 +291,13 @@ break; default: fprintf(stderr,"Warning! Unrecognized escape sequence: \\%c'\n", - str[str_idx]); + str[str_idx]); str[val_idx] = str[str_idx]; break; } - } else { + } + else + { str[val_idx] = str[str_idx]; } } @@ -310,9 +332,12 @@ } *hKey = NULL; - for (i = 0; i < REG_CLASS_NUMBER; i++) { - if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, len, reg_class_namesW[i], len) == CSTR_EQUAL && - len == lstrlenW(reg_class_namesW[i])) { + for (i = 0; i < REG_CLASS_NUMBER; i++) + { + if (CompareStringW(LOCALE_USER_DEFAULT, 0, lpKeyName, + len, reg_class_namesW[i], len) == CSTR_EQUAL && + len == lstrlenW(reg_class_namesW[i])) + { *hKey = reg_class_keys[i]; break; } @@ -404,12 +429,12 @@ } res = RegSetValueExW( - currentKeyHandle, - val_name, - 0, /* Reserved */ - dwDataType, - lpbData, - dwLen); + currentKeyHandle, + val_name, + 0, /* Reserved */ + dwDataType, + lpbData, + dwLen); if (dwParseType == REG_BINARY) HeapFree(GetProcessHeap(), 0, lpbData); return res; @@ -435,15 +460,15 @@ return ERROR_INVALID_PARAMETER; res = RegCreateKeyExW( - keyClass, /* Class */ - keyPath, /* Sub Key */ - 0, /* MUST BE 0 */ - NULL, /* object type */ - REG_OPTION_NON_VOLATILE, /* option, REG_OPTION_NON_VOLATILE ... */ - KEY_ALL_ACCESS, /* access mask, KEY_ALL_ACCESS */ - NULL, /* security attribute */ - ¤tKeyHandle, /* result */ - &dwDisp); /* disposition, REG_CREATED_NEW_KEY or + keyClass, /* Class */ + keyPath, /* Sub Key */ + 0, /* MUST BE 0 */ + NULL, /* object type */ + REG_OPTION_NON_VOLATILE, /* option, REG_OPTION_NON_VOLATILE ... */ + KEY_ALL_ACCESS, /* access mask, KEY_ALL_ACCESS */ + NULL, /* security attribute */ + ¤tKeyHandle, /* result */ + &dwDisp); /* disposition, REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY */ if (res == ERROR_SUCCESS) @@ -485,29 +510,39 @@ /* get value name */ while ( iswspace(line[line_idx]) ) line_idx++; - if (line[line_idx] == '@' && line[line_idx + 1] == '=') { + if (line[line_idx] == '@' && line[line_idx + 1] == '=') + { line[line_idx] = '\0'; val_name = line; line_idx++; - } else if (line[line_idx] == '\"') { + } + else if (line[line_idx] == '\"') + { line_idx++; val_name = line + line_idx; - while (TRUE) { + while (TRUE) + { if (line[line_idx] == '\\') /* skip escaped character */ { line_idx += 2; - } else { - if (line[line_idx] == '\"') { + } + else + { + if (line[line_idx] == '\"') + { line[line_idx] = '\0'; line_idx++; break; - } else { + } + else + { line_idx++; } } } while ( iswspace(line[line_idx]) ) line_idx++; - if (line[line_idx] != '=') { + if (line[line_idx] != '=') + { char* lineA; line[line_idx] = '\"'; lineA = GetMultiByteString(line); @@ -516,7 +551,9 @@ return; } - } else { + } + else + { char* lineA = GetMultiByteString(line); fprintf(stderr,"Warning! unrecognized line:\n%s\n", lineA); HeapFree(GetProcessHeap(), 0, lineA); @@ -538,10 +575,10 @@ char* val_nameA = GetMultiByteString(val_name); char* val_dataA = GetMultiByteString(val_data); fprintf(stderr,"%s: ERROR Key %s not created. Value: %s, Data: %s\n", - getAppName(), - currentKeyName, - val_nameA, - val_dataA); + getAppName(), + currentKeyName, + val_nameA, + val_dataA); HeapFree(GetProcessHeap(), 0, val_nameA); HeapFree(GetProcessHeap(), 0, val_dataA); } @@ -558,7 +595,8 @@ * We encountered the end of the file, make sure we * close the opened key and exit */ - if (stdInput == NULL) { + if (stdInput == NULL) + { closeKey(); return; } @@ -578,19 +616,22 @@ if ( stdInput[0] == '-') { delete_registry_key(stdInput + 1); - } else if ( openKeyW(stdInput) != ERROR_SUCCESS ) + } + else if ( openKeyW(stdInput) != ERROR_SUCCESS ) { char* stdInputA = GetMultiByteString(stdInput); fprintf(stderr,"%s: setValue failed to open key %s\n", - getAppName(), stdInputA); + getAppName(), stdInputA); HeapFree(GetProcessHeap(), 0, stdInputA); } - } else if( currentKeyHandle && - (( stdInput[0] == '@') || /* reading a default @=data pair */ - ( stdInput[0] == '\"'))) /* reading a new value=data pair */ + } + else if( currentKeyHandle && + (( stdInput[0] == '@') || /* reading a default @=data pair */ + ( stdInput[0] == '\"'))) /* reading a new value=data pair */ { processSetValue(stdInput, isUnicode); - } else + } + else { /* Since we are assuming that the file format is valid we must be * reading a blank line which indicates the end of this key processing @@ -614,13 +655,15 @@ line = HeapAlloc(GetProcessHeap(), 0, lineSize); CHECK_ENOUGH_MEMORY(line); - while (!feof(in)) { + while (!feof(in)) + { LPSTR s; /* The pointer into line for where the current fgets should read */ LPSTR check; WCHAR* lineW; s = line; - for (;;) { + for (;;) + { size_t size_remaining; int size_to_get; char *s_eol; /* various local uses */ @@ -650,11 +693,15 @@ check = fgets (s, size_to_get, in); - if (check == NULL) { - if (ferror(in)) { + if (check == NULL) + { + if (ferror(in)) + { perror ("While reading input"); exit (IO_ERROR); - } else { + } + else + { assert (feof(in)); *s = '\0'; /* It is not clear to me from the definition that the @@ -666,40 +713,46 @@ /* If we didn't read the eol nor the eof go around for the rest */ s_eol = strchr (s, '\n'); - if (!feof (in) && !s_eol) { + if (!feof (in) && !s_eol) + { s = strchr (s, '\0'); /* It should be s + size_to_get - 1 but this is safer */ continue; } /* If it is a comment line then discard it and go around again */ - if (line [0] == '#') { + if (line [0] == '#') + { s = line; continue; } /* Remove any line feed. Leave s_eol on the \0 */ - if (s_eol) { + if (s_eol) + { *s_eol = '\0'; if (s_eol > line && *(s_eol-1) == '\r') *--s_eol = '\0'; - } else + } + else s_eol = strchr (s, '\0'); /* If there is a concatenating \\ then go around again */ - if (s_eol > line && *(s_eol-1) == '\\') { + if (s_eol > line && *(s_eol-1) == '\\') + { int c; s = s_eol-1; do { c = fgetc(in); - } while(c == ' ' || c == '\t'); + } + while(c == ' ' || c == '\t'); if(c == EOF) { fprintf(stderr,"%s: ERROR - invalid continuation.\n", - getAppName()); + getAppName()); } else { @@ -737,7 +790,8 @@ s = buf; line = buf; - while(!feof(in)) { + while(!feof(in)) + { size_t size_remaining; int size_to_get; WCHAR *s_eol = NULL; /* various local uses */ @@ -769,11 +823,15 @@ CharsInBuf = fread(s, sizeof(WCHAR), size_to_get - 1, in); s[CharsInBuf] = 0; - if (CharsInBuf == 0) { - if (ferror(in)) { + if (CharsInBuf == 0) + { + if (ferror(in)) + { perror ("While reading input"); exit (IO_ERROR); - } else { + } + else + { assert (feof(in)); *s = '\0'; /* It is not clear to me from the definition that the @@ -788,7 +846,8 @@ { s_eol = wcschr(line, '\n'); - if(!s_eol) { + if(!s_eol) + { /* Move the stub of the line to the start of the buffer so * we get the maximum space to read into, and so we don't * have to recalculate 'line' if the buffer expands */ @@ -799,14 +858,16 @@ } /* If it is a comment line then discard it and go around again */ - if (*line == '#') { + if (*line == '#') + { line = s_eol + 1; continue; } /* If there is a concatenating \\ then go around again */ if ((*(s_eol-1) == '\\') || - (*(s_eol-1) == '\r' && *(s_eol-2) == '\\')) { + (*(s_eol-1) == '\r' && *(s_eol-2) == '\\')) + { WCHAR* NextLine = s_eol; while(*(NextLine+1) == ' ' || *(NextLine+1) == '\t') @@ -824,7 +885,8 @@ } /* Remove any line feed. Leave s_eol on the \0 */ - if (s_eol) { + if (s_eol) + { *s_eol = '\0'; if (s_eol > buf && *(s_eol-1) == '\r') *(s_eol-1) = '\0'; @@ -859,10 +921,11 @@ error_code = GetLastError (); status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL); - if (!status) { + NULL, error_code, 0, (LPTSTR) &lpMsgBuf, 0, NULL); + if (!status) + { fprintf(stderr,"%s: Cannot display message for error %ld, status %ld\n", - getAppName(), error_code, GetLastError()); + getAppName(), error_code, GetLastError()); exit(1); } puts(lpMsgBuf); @@ -883,7 +946,8 @@ static void REGPROC_resize_char_buffer(WCHAR **buffer, DWORD *len, DWORD required_len) { required_len++; - if (required_len > *len) { + if (required_len > *len) + { *len = required_len; if (!*buffer) *buffer = HeapAlloc(GetProcessHeap(), 0, *len * sizeof(**buffer)); @@ -903,7 +967,8 @@ */ static void REGPROC_resize_binary_buffer(BYTE **buffer, DWORD *size, DWORD required_size) { - if (required_size > *size) { + if (required_size > *size) + { *size = required_size; if (!*buffer) *buffer = HeapAlloc(GetProcessHeap(), 0, *size); @@ -921,16 +986,20 @@ DWORD i, pos; DWORD extra = 0; - REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + 10); + REGPROC_resize_char_buffer(line_buf, line_buf_size, + *line_len + str_len + 10); /* escaping characters */ pos = *line_len; - for (i = 0; i < str_len; i++) { + for (i = 0; i < str_len; i++) + { WCHAR c = str[i]; - switch (c) { + switch (c) + { case '\n': extra++; - REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra); + REGPROC_resize_char_buffer(line_buf, line_buf_size, + *line_len + str_len + extra); (*line_buf)[pos++] = '\\'; (*line_buf)[pos++] = 'n'; break; @@ -938,7 +1007,8 @@ case '\\': case '"': extra++; - REGPROC_resize_char_buffer(line_buf, line_buf_size, *line_len + str_len + extra); + REGPROC_resize_char_buffer(line_buf, line_buf_size, + *line_len + str_len + extra); (*line_buf)[pos++] = '\\'; /* Fall through */ @@ -951,7 +1021,9 @@ *line_len = pos; } -static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD *line_len, DWORD type, BYTE *value, DWORD value_size, BOOL unicode) +static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, + DWORD *line_len, DWORD type, BYTE *value, + DWORD value_size, BOOL unicode) { DWORD hex_pos, data_pos; const WCHAR *hex_prefix; @@ -962,15 +1034,20 @@ const WCHAR newline[] = {'\n',0}; CHAR* value_multibyte = NULL; - if (type == REG_BINARY) { + if (type == REG_BINARY) + { hex_prefix = hex; - } else { + } + else + { const WCHAR hex_format[] = {'h','e','x','(','%','u',')',':',0}; hex_prefix = hex_buf; wsprintfW(hex_buf, hex_format, type); - if ((type == REG_SZ || type == REG_EXPAND_SZ || type == REG_MULTI_SZ) && !unicode) + if ((type == REG_SZ || type == REG_EXPAND_SZ || + type == REG_MULTI_SZ) && !unicode) { - value_multibyte = GetMultiByteStringN((WCHAR*)value, value_size / sizeof(WCHAR), &value_size); + value_multibyte = GetMultiByteStringN((WCHAR*)value, + value_size / sizeof(WCHAR), &value_size); value = (BYTE*)value_multibyte; } } @@ -1011,7 +1088,8 @@ column += 3; /* wrap the line */ - if (column >= REG_FILE_HEX_LINE_LEN) { + if (column >= REG_FILE_HEX_LINE_LEN) + { lstrcpyW(*line_buf + data_pos, concat); data_pos += concat_len; column = concat_prefix; @@ -1062,11 +1140,11 @@ * val_size - size of the buffer for storing values in bytes. */ static void export_hkey(FILE *file, HKEY key, - WCHAR **reg_key_name_buf, DWORD *reg_key_name_size, - WCHAR **val_name_buf, DWORD *val_name_size, - BYTE **val_buf, DWORD *val_size, - WCHAR **line_buf, DWORD *line_buf_size, - BOOL unicode) +WCHAR **reg_key_name_buf, DWORD *reg_key_name_size, +WCHAR **val_name_buf, DWORD *val_name_size, +BYTE **val_buf, DWORD *val_size, +WCHAR **line_buf, DWORD *line_buf_size, +BOOL unicode) { DWORD max_sub_key_len; DWORD max_val_name_len; @@ -1079,18 +1157,20 @@ /* get size information and resize the buffers if necessary */ if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, - &max_sub_key_len, NULL, - NULL, &max_val_name_len, &max_val_size, NULL, NULL - ) != ERROR_SUCCESS) { + &max_sub_key_len, NULL, + NULL, &max_val_name_len, &max_val_size, NULL, NULL + ) != ERROR_SUCCESS) + { REGPROC_print_error(); } curr_len = lstrlenW(*reg_key_name_buf); REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size, - max_sub_key_len + curr_len + 1); + max_sub_key_len + curr_len + 1); REGPROC_resize_char_buffer(val_name_buf, val_name_size, - max_val_name_len); + max_val_name_len); REGPROC_resize_binary_buffer(val_buf, val_size, max_val_size); - REGPROC_resize_char_buffer(line_buf, line_buf_size, lstrlenW(*reg_key_name_buf) + 4); + REGPROC_resize_char_buffer(line_buf, line_buf_size, + lstrlenW(*reg_key_name_buf) + 4); /* output data for the current key */ wsprintfW(*line_buf, key_format, *reg_key_name_buf); REGPROC_write_line(file, *line_buf, unicode); @@ -1098,52 +1178,69 @@ /* print all the values */ i = 0; more_data = TRUE; - while(more_data) { + while(more_data) + { DWORD value_type; DWORD val_name_size1 = *val_name_size; DWORD val_size1 = *val_size; ret = RegEnumValueW(key, i, *val_name_buf, &val_name_size1, NULL, - &value_type, *val_buf, &val_size1); - if (ret == ERROR_MORE_DATA) { + &value_type, *val_buf, &val_size1); + if (ret == ERROR_MORE_DATA) + { /* Increase the size of the buffers and retry */ REGPROC_resize_char_buffer(val_name_buf, val_name_size, val_name_size1); REGPROC_resize_binary_buffer(val_buf, val_size, val_size1); - } else if (ret != ERROR_SUCCESS) { + } + else if (ret != ERROR_SUCCESS) + { more_data = FALSE; - if (ret != ERROR_NO_MORE_ITEMS) { + if (ret != ERROR_NO_MORE_ITEMS) + { REGPROC_print_error(); } - } else { + } + else + { DWORD line_len; i++; - if ((*val_name_buf)[0]) { + if ((*val_name_buf)[0]) + { const WCHAR val_start[] = {'"','%','s','"','=',0}; line_len = 0; - REGPROC_export_string(line_buf, line_buf_size, &line_len, *val_name_buf, lstrlenW(*val_name_buf)); - REGPROC_resize_char_buffer(val_name_buf, val_name_size, lstrlenW(*line_buf) + 1); + REGPROC_export_string(line_buf, line_buf_size, &line_len, + *val_name_buf, lstrlenW(*val_name_buf)); + REGPROC_resize_char_buffer(val_name_buf, val_name_size, + lstrlenW(*line_buf) + 1); lstrcpyW(*val_name_buf, *line_buf); line_len = 3 + lstrlenW(*val_name_buf); REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len); wsprintfW(*line_buf, val_start, *val_name_buf); - } else { + } + else + { const WCHAR std_val[] = {'@','=',0}; line_len = 2; REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len); lstrcpyW(*line_buf, std_val); } - switch (value_type) { + switch (value_type) + { case REG_SZ: { WCHAR* wstr = (WCHAR*)*val_buf; if (val_size1 < sizeof(WCHAR) || val_size1 % sizeof(WCHAR) || - wstr[val_size1 / sizeof(WCHAR) - 1]) { - REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode); - } else { + wstr[val_size1 / sizeof(WCHAR) - 1]) + { + REGPROC_export_binary(line_buf, line_buf_size, &line_len, + value_type, *val_buf, val_size1, unicode); + } + else + { const WCHAR start[] = {'"',0}; const WCHAR end[] = {'"','\n',0}; DWORD len; @@ -1156,9 +1253,11 @@ /* At this point we know wstr is '\0'-terminated * so we can substract 1 from the size */ - REGPROC_export_string(line_buf, line_buf_size, &line_len, wstr, val_size1 / sizeof(WCHAR) - 1); + REGPROC_export_string(line_buf, line_buf_size, &line_len, + wstr, val_size1 / sizeof(WCHAR) - 1); - REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len + lstrlenW(end)); + REGPROC_resize_char_buffer(line_buf, line_buf_size, + line_len + lstrlenW(end)); lstrcpyW(*line_buf + line_len, end); } break; @@ -1178,19 +1277,20 @@ char* key_nameA = GetMultiByteString(*reg_key_name_buf); char* value_nameA = GetMultiByteString(*val_name_buf); fprintf(stderr,"%s: warning - unsupported registry format '%ld', " - "treat as binary\n", - getAppName(), value_type); + "treat as binary\n", + getAppName(), value_type); fprintf(stderr,"key name: \"%s\"\n", key_nameA); fprintf(stderr,"value name:\"%s\"\n\n", value_nameA); HeapFree(GetProcessHeap(), 0, key_nameA); HeapFree(GetProcessHeap(), 0, value_nameA); } - /* falls through */ + /* falls through */ case REG_EXPAND_SZ: case REG_MULTI_SZ: /* falls through */ case REG_BINARY: - REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode); + REGPROC_export_binary(line_buf, line_buf_size, &line_len, + value_type, *val_buf, val_size1, unicode); } REGPROC_write_line(file, *line_buf, unicode); } @@ -1199,30 +1299,41 @@ i = 0; more_data = TRUE; (*reg_key_name_buf)[curr_len] = '\\'; - while(more_data) { + while(more_data) + { DWORD buf_size = *reg_key_name_size - curr_len - 1; ret = RegEnumKeyExW(key, i, *reg_key_name_buf + curr_len + 1, &buf_size, - NULL, NULL, NULL, NULL); - if (ret == ERROR_MORE_DATA) { + NULL, NULL, NULL, NULL); + if (ret == ERROR_MORE_DATA) + { /* Increase the size of the buffer and retry */ - REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size, curr_len + 1 + buf_size); - } else if (ret != ERROR_SUCCESS) { + REGPROC_resize_char_buffer(reg_key_name_buf, reg_key_name_size, + curr_len + 1 + buf_size); + } + else if (ret != ERROR_SUCCESS) + { more_data = FALSE; - if (ret != ERROR_NO_MORE_ITEMS) { + if (ret != ERROR_NO_MORE_ITEMS) + { REGPROC_print_error(); } - } else { + } + else + { HKEY subkey; i++; if (RegOpenKeyW(key, *reg_key_name_buf + curr_len + 1, - &subkey) == ERROR_SUCCESS) { + &subkey) == ERROR_SUCCESS) + { export_hkey(file, subkey, reg_key_name_buf, reg_key_name_size, - val_name_buf, val_name_size, val_buf, val_size, - line_buf, line_buf_size, unicode); + val_name_buf, val_name_size, val_buf, val_size, + line_buf, line_buf_size, unicode); RegCloseKey(subkey); - } else { + } + else + { REGPROC_print_error(); } } @@ -1246,7 +1357,8 @@ file = _wfopen(file_name, L"wb"); else file = _wfopen(file_name, L"w"); - if (!file) { + if (!file) + { CHAR* file_nameA = GetMultiByteString(file_name); perror(""); fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), file_nameA); @@ -1291,75 +1403,87 @@ BOOL unicode = (format == REG_FORMAT_5); reg_key_name_buf = HeapAlloc(GetProcessHeap(), 0, - reg_key_name_size * sizeof(*reg_key_name_buf)); + reg_key_name_size * sizeof(*reg_key_name_buf)); val_name_buf = HeapAlloc(GetProcessHeap(), 0, - val_name_size * sizeof(*val_name_buf)); + val_name_size * sizeof(*val_name_buf)); val_buf = HeapAlloc(GetProcessHeap(), 0, val_size); line_buf = HeapAlloc(GetProcessHeap(), 0, line_buf_size * sizeof(*line_buf)); CHECK_ENOUGH_MEMORY(reg_key_name_buf && val_name_buf && val_buf && line_buf); - if (reg_key_name && reg_key_name[0]) { + if (reg_key_name && reg_key_name[0]) + { HKEY reg_key_class; WCHAR *branch_name = NULL; HKEY key; REGPROC_resize_char_buffer(®_key_name_buf, ®_key_name_size, - lstrlenW(reg_key_name)); + lstrlenW(reg_key_name)); lstrcpyW(reg_key_name_buf, reg_key_name); /* open the specified key */ - if (!parseKeyName(reg_key_name, ®_key_class, &branch_name)) { + if (!parseKeyName(reg_key_name, ®_key_class, &branch_name)) + { CHAR* key_nameA = GetMultiByteString(reg_key_name); fprintf(stderr,"%s: Incorrect registry class specification in '%s'\n", - getAppName(), key_nameA); + getAppName(), key_nameA); HeapFree(GetProcessHeap(), 0, key_nameA); exit(1); } - if (!branch_name[0]) { + if (!branch_name[0]) + { /* no branch - registry class is specified */ file = REGPROC_open_export_file(file_name, unicode); export_hkey(file, reg_key_class, - ®_key_name_buf, ®_key_name_size, - &val_name_buf, &val_name_size, - &val_buf, &val_size, &line_buf, - &line_buf_size, unicode); - } else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS) { + ®_key_name_buf, ®_key_name_size, + &val_name_buf, &val_name_size, + &val_buf, &val_size, &line_buf, + &line_buf_size, unicode); + } + else if (RegOpenKeyW(reg_key_class, branch_name, &key) == ERROR_SUCCESS) + { file = REGPROC_open_export_file(file_name, unicode); export_hkey(file, key, - ®_key_name_buf, ®_key_name_size, - &val_name_buf, &val_name_size, - &val_buf, &val_size, &line_buf, - &line_buf_size, unicode); + ®_key_name_buf, ®_key_name_size, + &val_name_buf, &val_name_size, + &val_buf, &val_size, &line_buf, + &line_buf_size, unicode); RegCloseKey(key); - } else { + } + else + { CHAR* key_nameA = GetMultiByteString(reg_key_name); fprintf(stderr,"%s: Can't export. Registry key '%s' does not exist!\n", - getAppName(), key_nameA); + getAppName(), key_nameA); HeapFree(GetProcessHeap(), 0, key_nameA); REGPROC_print_error(); } - } else { + } + else + { unsigned int i; /* export all registry classes */ file = REGPROC_open_export_file(file_name, unicode); - for (i = 0; i < REG_CLASS_NUMBER; i++) { + for (i = 0; i < REG_CLASS_NUMBER; i++) + { /* do not export HKEY_CLASSES_ROOT */ if (reg_class_keys[i] != HKEY_CLASSES_ROOT && - reg_class_keys[i] != HKEY_CURRENT_USER && - reg_class_keys[i] != HKEY_CURRENT_CONFIG && - reg_class_keys[i] != HKEY_DYN_DATA) { + reg_class_keys[i] != HKEY_CURRENT_USER && + reg_class_keys[i] != HKEY_CURRENT_CONFIG && + reg_class_keys[i] != HKEY_DYN_DATA) + { lstrcpyW(reg_key_name_buf, reg_class_namesW[i]); export_hkey(file, reg_class_keys[i], - ®_key_name_buf, ®_key_name_size, - &val_name_buf, &val_name_size, - &val_buf, &val_size, &line_buf, - &line_buf_size, unicode); + ®_key_name_buf, ®_key_name_size, + &val_name_buf, &val_name_size, + &val_buf, &val_size, &line_buf, + &line_buf_size, unicode); } } } - if (file) { + if (file) + { fclose(file); } HeapFree(GetProcessHeap(), 0, reg_key_name); @@ -1382,7 +1506,8 @@ if (s[0] == 0xff && s[1] == 0xfe) { processRegLinesW(reg_file); - } else + } + else { fseek(reg_file, 0, SEEK_SET); processRegLinesA(reg_file); @@ -1408,17 +1533,19 @@ if (!reg_key_name || !reg_key_name[0]) return; - if (!parseKeyName(reg_key_name, &key_class, &key_name)) { + if (!parseKeyName(reg_key_name, &key_class, &key_name)) + { char* reg_key_nameA = GetMultiByteString(reg_key_name); fprintf(stderr,"%s: Incorrect registry class specification in '%s'\n", - getAppName(), reg_key_nameA); + getAppName(), reg_key_nameA); HeapFree(GetProcessHeap(), 0, reg_key_nameA); exit(1); } - if (!*key_name) { + if (!*key_name) + { char* reg_key_nameA = GetMultiByteString(reg_key_name); fprintf(stderr,"%s: Can't delete registry class '%s'\n", - getAppName(), reg_key_nameA); + getAppName(), reg_key_nameA); HeapFree(GetProcessHeap(), 0, reg_key_nameA); exit(1); } Index: base/applications/regedit/framewnd.c =================================================================== --- base/applications/regedit/framewnd.c (revision 49426) +++ base/applications/regedit/framewnd.c (working copy) @@ -38,14 +38,15 @@ { RECT rt; /* - if (IsWindowVisible(hToolBar)) { - SendMessage(hToolBar, WM_SIZE, 0, 0); - GetClientRect(hToolBar, &rt); - prect->top = rt.bottom+3; - prect->bottom -= rt.bottom+3; - } + if (IsWindowVisible(hToolBar)) { + SendMessage(hToolBar, WM_SIZE, 0, 0); + GetClientRect(hToolBar, &rt); + prect->top = rt.bottom+3; + prect->bottom -= rt.bottom+3; + } */ - if (IsWindowVisible(hStatusBar)) { + if (IsWindowVisible(hStatusBar)) + { SetupStatusBar(hWnd, TRUE); GetClientRect(hStatusBar, &rt); prect->bottom -= rt.bottom; @@ -97,7 +98,8 @@ { cbValueName = COUNT_OF(szValueName); cbValueData = sizeof(abValueData); - lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, abValueData, &cbValueData); + lResult = RegEnumValue(hKey, dwIndex, szValueName, &cbValueName, NULL, &dwType, + abValueData, &cbValueData); if ((lResult == ERROR_SUCCESS) && (dwType == REG_SZ)) { if (!bDisplayedAny) @@ -141,12 +143,15 @@ TCHAR str[100]; _tcscpy(str, _T("")); - if (nFlags & MF_POPUP) { - if (hSysMenu != GetMenu(hWnd)) { + if (nFlags & MF_POPUP) + { + if (hSysMenu != GetMenu(hWnd)) + { if (nItemID == 2) nItemID = 5; } } - if (LoadString(hInst, nItemID, str, 100)) { + if (LoadString(hInst, nItemID, str, 100)) + { /* load appropriate string*/ LPTSTR lpsz = str; /* first newline terminates actual string*/ @@ -171,8 +176,8 @@ void UpdateStatusBar(void) { - NMHDR nmhdr; - ZeroMemory(&nmhdr, sizeof(NMHDR)); + NMHDR nmhdr; + ZeroMemory(&nmhdr, sizeof(NMHDR)); nmhdr.code = TVN_SELCHANGED; SendMessage(g_pChildWnd->hWnd, WM_NOTIFY, (WPARAM)TREE_WINDOW, (LPARAM)&nmhdr); } @@ -191,7 +196,8 @@ { DWORD dwErrorCode = CommDlgExtendedError(); UNREFERENCED_PARAMETER(hWnd); - switch (dwErrorCode) { + switch (dwErrorCode) + { case CDERR_DIALOGFAILURE: break; case CDERR_FINDRESFAILURE: @@ -233,24 +239,24 @@ typedef struct { - UINT DisplayID; - UINT FilterID; + UINT DisplayID; + UINT FilterID; } FILTERPAIR, *PFILTERPAIR; void BuildFilterStrings(TCHAR *Filter, PFILTERPAIR Pairs, int PairCount) { - int i, c; + int i, c; - c = 0; - for(i = 0; i < PairCount; i++) - { - c += LoadString(hInst, Pairs[i].DisplayID, &Filter[c], 255 * sizeof(TCHAR)); + c = 0; + for(i = 0; i < PairCount; i++) + { + c += LoadString(hInst, Pairs[i].DisplayID, &Filter[c], 255 * sizeof(TCHAR)); + Filter[++c] = '\0'; + c += LoadString(hInst, Pairs[i].FilterID, &Filter[c], 255 * sizeof(TCHAR)); + Filter[++c] = '\0'; + } Filter[++c] = '\0'; - c += LoadString(hInst, Pairs[i].FilterID, &Filter[c], 255 * sizeof(TCHAR)); - Filter[++c] = '\0'; - } - Filter[++c] = '\0'; } static BOOL InitOpenFileName(HWND hWnd, OPENFILENAME* pofn) @@ -282,6 +288,108 @@ return TRUE; } +static INT_PTR CALLBACK LoadHive_KeyNameInHookProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static LPTSTR sKey = NULL; + static INT sLength = 0; + switch(uMsg) + { + case WM_INITDIALOG: + sKey = (LPTSTR)lParam; + sLength = 128; /* FIXME: Ugly hack! */ + case WM_COMMAND: + switch(LOWORD(wParam)) + { + case IDOK: + if(GetDlgItemText(hWndDlg, IDC_EDIT_KEY, sKey, sLength)) + return EndDialog(hWndDlg, -1); + else + return EndDialog(hWndDlg, 0); + case IDCANCEL: + return EndDialog(hWndDlg, 0); + } + break; + } + return FALSE; +} + +static BOOL LoadHive(HWND hWnd) +{ + OPENFILENAME ofn; + TCHAR Caption[128]; + LPCTSTR pszKeyPath; + TCHAR xPath[128]; + HKEY hRootKey; + TCHAR Filter[1024]; + FILTERPAIR filter; + /* get the item key to load the hive in */ + pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); + /* initialize the "open file" dialog */ + InitOpenFileName(hWnd, &ofn); + /* build the "All Files" filter up */ + filter.DisplayID = IDS_FLT_ALLFILES; + filter.FilterID = IDS_FLT_ALLFILES_FLT; + BuildFilterStrings(Filter, &filter, sizeof(filter)); + ofn.lpstrFilter = Filter; + /* load and set the caption and flags for dialog */ + LoadString(hInst, IDS_LOAD_HIVE, Caption, COUNT_OF(Caption)); + ofn.lpstrTitle = Caption; + ofn.Flags |= OFN_ENABLESIZING; + /* ofn.lCustData = ;*/ + /* now load the hive */ + if (GetOpenFileName(&ofn)) + { + if(DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOADHIVE), hWnd, + &LoadHive_KeyNameInHookProc, (LPARAM)xPath)) + { + LONG regLoadResult = RegLoadKey(hRootKey, xPath, ofn.lpstrFile); + if(regLoadResult == ERROR_SUCCESS) + { + /* refresh tree and list views */ + RefreshTreeView(g_pChildWnd->hTreeWnd); + pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); + RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath); + } + else + { + ErrorMessageBox(hWnd, Caption, regLoadResult); + return FALSE; + } + } + } + else + { + CheckCommDlgError(hWnd); + } + return TRUE; +} + +static BOOL UnloadHive(HWND hWnd) +{ + TCHAR Caption[128]; + LPCTSTR pszKeyPath; + HKEY hRootKey; + /* get the item key to unload */ + pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); + /* load and set the caption and flags for dialog */ + LoadString(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption)); + /* now unload the hive */ + LONG regUnloadResult = RegUnLoadKey(hRootKey, pszKeyPath); + if(regUnloadResult == ERROR_SUCCESS) + { + /* refresh tree and list views */ + RefreshTreeView(g_pChildWnd->hTreeWnd); + pszKeyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hRootKey); + RefreshListView(g_pChildWnd->hListWnd, hRootKey, pszKeyPath); + } + else + { + ErrorMessageBox(hWnd, Caption, regUnloadResult); + return FALSE; + } + return TRUE; +} + static BOOL ImportRegistryFile(HWND hWnd) { OPENFILENAME ofn; @@ -294,9 +402,11 @@ ofn.lpstrTitle = Caption; ofn.Flags |= OFN_ENABLESIZING; /* ofn.lCustData = ;*/ - if (GetOpenFileName(&ofn)) { + if (GetOpenFileName(&ofn)) + { FILE *fp = _wfopen(ofn.lpstrFile, L"r"); - if (fp == NULL || !import_registry_file(fp)) { + if (fp == NULL || !import_registry_file(fp)) + { LPSTR p = GetMultiByteString(ofn.lpstrFile); fprintf(stderr, "Can't open file \"%s\"\n", p); HeapFree(GetProcessHeap(), 0, p); @@ -305,7 +415,9 @@ return FALSE; } fclose(fp); - } else { + } + else + { CheckCommDlgError(hWnd); } @@ -316,8 +428,8 @@ return TRUE; } - -static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) +static UINT_PTR CALLBACK ExportRegistryFile_OFNHookProc(HWND hdlg, UINT uiMsg, + WPARAM wParam, LPARAM lParam) { HWND hwndExportAll; HWND hwndExportBranch; @@ -329,8 +441,9 @@ UNREFERENCED_PARAMETER(wParam); - switch(uiMsg) { - case WM_INITDIALOG: + switch(uiMsg) + { + case WM_INITDIALOG: pOfn = (OPENFILENAME *) lParam; pszSelectedKey = (LPTSTR) pOfn->lCustData; @@ -347,7 +460,7 @@ SetWindowText(hwndExportBranchText, pszSelectedKey); break; - case WM_NOTIFY: + case WM_NOTIFY: if (((NMHDR *) lParam)->code == CDN_FILEOK) { pOfnNotify = (OFNOTIFY *) lParam; @@ -356,15 +469,15 @@ hwndExportBranch = GetDlgItem(hdlg, IDC_EXPORT_BRANCH); hwndExportBranchText = GetDlgItem(hdlg, IDC_EXPORT_BRANCH_TEXT); if (hwndExportBranch && hwndExportBranchText - && (SendMessage(hwndExportBranch, BM_GETCHECK, 0, 0) == BST_CHECKED)) - { - GetWindowText(hwndExportBranchText, pszSelectedKey, _MAX_PATH); - } - else - { - pszSelectedKey[0] = '\0'; - } - } + && (SendMessage(hwndExportBranch, BM_GETCHECK, 0, 0) == BST_CHECKED)) + { + GetWindowText(hwndExportBranchText, pszSelectedKey, _MAX_PATH); + } + else + { + pszSelectedKey[0] = '\0'; + } + } break; } return iResult; @@ -394,22 +507,26 @@ ofn.Flags = OFN_ENABLETEMPLATE | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_OVERWRITEPROMPT; ofn.lpfnHook = ExportRegistryFile_OFNHookProc; ofn.lpTemplateName = MAKEINTRESOURCE(IDD_EXPORTRANGE); - if (GetSaveFileName(&ofn)) { + if (GetSaveFileName(&ofn)) + { BOOL result; DWORD format; - + if (ofn.nFilterIndex == 1) format = REG_FORMAT_5; else format = REG_FORMAT_4; result = export_registry_key(ofn.lpstrFile, ExportKeyPath, format); - if (!result) { + if (!result) + { LPSTR p = GetMultiByteString(ofn.lpstrFile); fprintf(stderr, "Can't open file \"%s\"\n", p); HeapFree(GetProcessHeap(), 0, p); return FALSE; } - } else { + } + else + { CheckCommDlgError(hWnd); } return TRUE; @@ -432,7 +549,8 @@ pd.nToPage = 0xFFFF; pd.nMinPage = 1; pd.nMaxPage = 0xFFFF; - if (PrintDlg(&pd)) { + if (PrintDlg(&pd)) + { /* GDI calls to render output. */ DeleteDC(pd.hDC); /* Delete DC when done.*/ } @@ -441,8 +559,10 @@ PRINTDLGEX pd; hResult = PrintDlgEx(&pd); - if (hResult == S_OK) { - switch (pd.dwResultAction) { + if (hResult == S_OK) + { + switch (pd.dwResultAction) + { case PD_RESULT_APPLY: /*The user clicked the Apply button and later clicked the Cancel button. This indicates that the user wants to apply the changes made in the property sheet, but does not yet want to print. The PRINTDLGEX structure contains the information specified by the user at the time the Apply button was clicked. */ break; @@ -455,8 +575,11 @@ default: break; } - } else { - switch (hResult) { + } + else + { + switch (hResult) + { case E_OUTOFMEMORY: /*Insufficient memory. */ break; @@ -564,9 +687,11 @@ wsprintf(szNewValue, szNewValueFormat, iIndex++); cbData = sizeof(data); lResult = RegQueryValueEx(hKey, szNewValue, NULL, &dwExistingType, data, &cbData); - } while(lResult == ERROR_SUCCESS); + } + while(lResult == ERROR_SUCCESS); - switch(dwType) { + switch(dwType) + { case REG_DWORD: cbData = sizeof(DWORD); break; @@ -625,9 +750,9 @@ { sizeof(DSOP_SCOPE_INIT_INFO), DSOP_SCOPE_TYPE_USER_ENTERED_UPLEVEL_SCOPE | DSOP_SCOPE_TYPE_USER_ENTERED_DOWNLEVEL_SCOPE | - DSOP_SCOPE_TYPE_GLOBAL_CATALOG | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN | - DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN | DSOP_SCOPE_TYPE_WORKGROUP | - DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN, + DSOP_SCOPE_TYPE_GLOBAL_CATALOG | DSOP_SCOPE_TYPE_EXTERNAL_UPLEVEL_DOMAIN | + DSOP_SCOPE_TYPE_EXTERNAL_DOWNLEVEL_DOMAIN | DSOP_SCOPE_TYPE_WORKGROUP | + DSOP_SCOPE_TYPE_UPLEVEL_JOINED_DOMAIN | DSOP_SCOPE_TYPE_DOWNLEVEL_JOINED_DOMAIN, 0, { { @@ -652,7 +777,7 @@ InitInfo.apwzAttributeNames = NULL; hRet = (*pDsObjectPicker)->lpVtbl->Initialize(*pDsObjectPicker, - &InitInfo); + &InitInfo); if (FAILED(hRet)) { @@ -674,8 +799,8 @@ HRESULT hRet; hRet = pDsObjectPicker->lpVtbl->InvokeDialog(pDsObjectPicker, - hwndParent, - &pdo); + hwndParent, + &pdo); if (hRet == S_OK) { STGMEDIUM stm; @@ -757,7 +882,14 @@ UNREFERENCED_PARAMETER(lParam); UNREFERENCED_PARAMETER(message); - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)) + { + case ID_REGISTRY_LOADHIVE: + LoadHive(hWnd); + return TRUE; + case ID_REGISTRY_UNLOADHIVE: + UnloadHive(hWnd); + return TRUE; case ID_REGISTRY_IMPORTREGISTRYFILE: ImportRegistryFile(hWnd); return TRUE; @@ -820,9 +952,9 @@ pts = pt; if(ClientToScreen(g_pChildWnd->hWnd, &pts)) { - SetCursorPos(pts.x, pts.y); - SetCursor(LoadCursor(0, IDC_SIZEWE)); - SendMessage(g_pChildWnd->hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y)); + SetCursorPos(pts.x, pts.y); + SetCursor(LoadCursor(0, IDC_SIZEWE)); + SendMessage(g_pChildWnd->hWnd, WM_LBUTTONDOWN, 0, MAKELPARAM(pt.x, pt.y)); } return TRUE; } @@ -836,12 +968,14 @@ keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); valueName = GetValueName(g_pChildWnd->hListWnd, -1); - if (keyPath) { + if (keyPath) + { lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, regsam, &hKey); if (lRet != ERROR_SUCCESS) hKey = 0; } - switch (LOWORD(wParam)) { + switch (LOWORD(wParam)) + { case ID_EDIT_MODIFY: if (valueName && ModifyValue(hWnd, hKey, valueName, FALSE)) RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); @@ -874,49 +1008,50 @@ { if (GetFocus() == g_pChildWnd->hListWnd) { - UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd); - if(nSelected >= 1) - { - TCHAR msg[128], caption[128]; - LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); - LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), msg, sizeof(msg)/sizeof(TCHAR)); - if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES) + UINT nSelected = ListView_GetSelectedCount(g_pChildWnd->hListWnd); + if(nSelected >= 1) { - int ni, errs; + TCHAR msg[128], caption[128]; + LoadString(hInst, IDS_QUERY_DELETE_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); + LoadString(hInst, (nSelected == 1 ? IDS_QUERY_DELETE_ONE : IDS_QUERY_DELETE_MORE), + msg, sizeof(msg)/sizeof(TCHAR)); + if(MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) == IDYES) + { + int ni, errs; - item = -1; - errs = 0; - while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1) - { - valueName = GetValueName(g_pChildWnd->hListWnd, item); - if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS) - { - errs++; + item = -1; + errs = 0; + while((ni = ListView_GetNextItem(g_pChildWnd->hListWnd, item, LVNI_SELECTED)) > -1) + { + valueName = GetValueName(g_pChildWnd->hListWnd, item); + if(RegDeleteValue(hKey, valueName) != ERROR_SUCCESS) + { + errs++; + } + item = ni; + } + + RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); + if(errs > 0) + { + LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); + LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR)); + MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP); + } } - item = ni; - } - - RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath); - if(errs > 0) - { - LoadString(hInst, IDS_ERR_DELVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); - LoadString(hInst, IDS_ERR_DELETEVALUE, msg, sizeof(msg)/sizeof(TCHAR)); - MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONSTOP); - } } - } } else if (GetFocus() == g_pChildWnd->hTreeWnd) { - if (keyPath == 0 || *keyPath == 0) - { - MessageBeep(MB_ICONHAND); - } else - if (DeleteKey(hWnd, hKeyRoot, keyPath)) - { - DeleteNode(g_pChildWnd->hTreeWnd, 0); - RefreshTreeView(g_pChildWnd->hTreeWnd); - } + if (keyPath == 0 || *keyPath == 0) + { + MessageBeep(MB_ICONHAND); + } + else if (DeleteKey(hWnd, hKeyRoot, keyPath)) + { + DeleteNode(g_pChildWnd->hTreeWnd, 0); + RefreshTreeView(g_pChildWnd->hTreeWnd); + } } break; } @@ -960,9 +1095,9 @@ RefreshTreeView(g_pChildWnd->hTreeWnd); /*RefreshListView(g_pChildWnd->hListWnd, hKeyRoot, keyPath, NULL); */ break; - /*case ID_OPTIONS_TOOLBAR:*/ - /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/ - /* break;*/ + /*case ID_OPTIONS_TOOLBAR:*/ + /* toggle_child(hWnd, LOWORD(wParam), hToolBar);*/ + /* break;*/ case ID_EDIT_NEW_KEY: CreateNewKey(g_pChildWnd->hTreeWnd, TreeView_GetSelection(g_pChildWnd->hTreeWnd)); break; @@ -995,7 +1130,7 @@ } if(hKey) - RegCloseKey(hKey); + RegCloseKey(hKey); return result; } @@ -1012,7 +1147,8 @@ LRESULT CALLBACK FrameWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch (message) { + switch (message) + { case WM_CREATE: CreateWindowEx(0, szChildClass, NULL, WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, Index: base/applications/regedit/listview.c =================================================================== --- base/applications/regedit/listview.c (revision 49426) +++ base/applications/regedit/listview.c (working copy) @@ -96,23 +96,23 @@ i = ListView_FindItem(hwndLV, -1, &fi); } ListView_SetItemState(hwndLV, i, LVIS_FOCUSED | LVIS_SELECTED, - LVIS_FOCUSED | LVIS_SELECTED); + LVIS_FOCUSED | LVIS_SELECTED); iListViewSelect = i; } BOOL IsDefaultValue(HWND hwndLV, int i) { - PLINE_INFO lineinfo; - LVITEM Item; + PLINE_INFO lineinfo; + LVITEM Item; - Item.mask = LVIF_PARAM; - Item.iItem = i; - if(ListView_GetItem(hwndLV, &Item)) - { - lineinfo = (PLINE_INFO)Item.lParam; - return lineinfo && (!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))); - } - return FALSE; + Item.mask = LVIF_PARAM; + Item.iItem = i; + if(ListView_GetItem(hwndLV, &Item)) + { + lineinfo = (PLINE_INFO)Item.lParam; + return lineinfo && (!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))); + } + return FALSE; } /******************************************************************************* @@ -129,7 +129,7 @@ linfo->val_len = dwCount; if(dwCount > 0) { - memcpy(&linfo[1], ValBuf, dwCount); + memcpy(&linfo[1], ValBuf, dwCount); } linfo->name = _tcsdup(Name); @@ -146,12 +146,12 @@ item.lParam = (LPARAM)linfo; switch(dwValType) { - case REG_SZ: - case REG_EXPAND_SZ: - case REG_MULTI_SZ: + case REG_SZ: + case REG_EXPAND_SZ: + case REG_MULTI_SZ: item.iImage = Image_String; break; - default: + default: item.iImage = Image_Bin; break; } @@ -162,88 +162,91 @@ #endif index = ListView_InsertItem(hwndLV, &item); - if (index != -1) { - switch (dwValType) { + if (index != -1) + { + switch (dwValType) + { case REG_SZ: case REG_EXPAND_SZ: if(dwCount > 0) { - ListView_SetItemText(hwndLV, index, 2, ValBuf); + ListView_SetItemText(hwndLV, index, 2, ValBuf); } else if(!ValExists) { - TCHAR buffer[255]; - /* load (value not set) string */ - LoadString(hInst, IDS_VALUE_NOT_SET, buffer, sizeof(buffer)/sizeof(TCHAR)); - ListView_SetItemText(hwndLV, index, 2, buffer); + TCHAR buffer[255]; + /* load (value not set) string */ + LoadString(hInst, IDS_VALUE_NOT_SET, buffer, sizeof(buffer)/sizeof(TCHAR)); + ListView_SetItemText(hwndLV, index, 2, buffer); } break; case REG_MULTI_SZ: + { + LPTSTR src, str; + if(dwCount >= 2) { - LPTSTR src, str; - if(dwCount >= 2) - { - src = (LPTSTR)ValBuf; - str = HeapAlloc(GetProcessHeap(), 0, dwCount); - if(str != NULL) - { - *str = _T('\0'); - /* concatenate all srings */ - while(*src != _T('\0')) - { - _tcscat(str, src); - _tcscat(str, _T(" ")); - src += _tcslen(src) + 1; - } - ListView_SetItemText(hwndLV, index, 2, str); - HeapFree(GetProcessHeap(), 0, str); - } - else - ListView_SetItemText(hwndLV, index, 2, _T("")); - } - else - ListView_SetItemText(hwndLV, index, 2, _T("")); - } - break; - case REG_DWORD: { - TCHAR buf[200]; - if(dwCount == sizeof(DWORD)) + src = (LPTSTR)ValBuf; + str = HeapAlloc(GetProcessHeap(), 0, dwCount); + if(str != NULL) { - wsprintf(buf, _T("0x%08x (%u)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf); + *str = _T('\0'); + /* concatenate all srings */ + while(*src != _T('\0')) + { + _tcscat(str, src); + _tcscat(str, _T(" ")); + src += _tcslen(src) + 1; + } + ListView_SetItemText(hwndLV, index, 2, str); + HeapFree(GetProcessHeap(), 0, str); } else - { - LoadString(hInst, IDS_INVALID_DWORD, buf, sizeof(buf)/sizeof(TCHAR)); - } - ListView_SetItemText(hwndLV, index, 2, buf); + ListView_SetItemText(hwndLV, index, 2, _T("")); } - /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */ - break; + else + ListView_SetItemText(hwndLV, index, 2, _T("")); + } + break; + case REG_DWORD: + { + TCHAR buf[200]; + if(dwCount == sizeof(DWORD)) + { + wsprintf(buf, _T("0x%08x (%u)"), *(DWORD*)ValBuf, *(DWORD*)ValBuf); + } + else + { + LoadString(hInst, IDS_INVALID_DWORD, buf, sizeof(buf)/sizeof(TCHAR)); + } + ListView_SetItemText(hwndLV, index, 2, buf); + } + /* lpsRes = convertHexToDWORDStr(lpbData, dwLen); */ + break; default: - { - unsigned int i; - LPBYTE pData = (LPBYTE)ValBuf; - LPTSTR strBinary; - if(dwCount > 0) + { + unsigned int i; + LPBYTE pData = (LPBYTE)ValBuf; + LPTSTR strBinary; + if(dwCount > 0) + { + strBinary = HeapAlloc(GetProcessHeap(), 0, (dwCount * sizeof(TCHAR) * 3) + sizeof(TCHAR)); + for (i = 0; i < dwCount; i++) { - strBinary = HeapAlloc(GetProcessHeap(), 0, (dwCount * sizeof(TCHAR) * 3) + sizeof(TCHAR)); - for (i = 0; i < dwCount; i++) - { - wsprintf( strBinary + i*3, _T("%02X "), pData[i] ); - } - strBinary[dwCount * 3] = 0; - ListView_SetItemText(hwndLV, index, 2, strBinary); - HeapFree(GetProcessHeap(), 0, strBinary); + wsprintf( strBinary + i*3, _T("%02X "), pData[i] ); } - else - { - TCHAR szText[128]; - LoadString(hInst, IDS_BINARY_EMPTY, szText, sizeof(szText)/sizeof(TCHAR)); - ListView_SetItemText(hwndLV, index, 2, szText); - } + strBinary[dwCount * 3] = 0; + ListView_SetItemText(hwndLV, index, 2, strBinary); + HeapFree(GetProcessHeap(), 0, strBinary); } - break; + else + { + TCHAR szText[128]; + LoadString(hInst, IDS_BINARY_EMPTY, szText, sizeof(szText)/sizeof(TCHAR)); + ListView_SetItemText(hwndLV, index, 2, szText); + } } + break; + } } } @@ -258,7 +261,8 @@ lvC.pszText = szText; /* Load the column labels from the resource file. */ - for (index = 0; index < MAX_LIST_COLUMNS; index++) { + for (index = 0; index < MAX_LIST_COLUMNS; index++) + { lvC.iSubItem = index; lvC.cx = default_column_widths[index]; lvC.fmt = column_alignment[index]; @@ -288,7 +292,7 @@ /* Fail if not all of the images were added. */ if (ImageList_GetImageCount(himl) < NUM_ICONS) { - return FALSE; + return FALSE; } /* Associate the image list with the tree view control. */ @@ -306,13 +310,15 @@ plvdi->item.pszText = NULL; plvdi->item.cchTextMax = 0; - switch (plvdi->item.iSubItem) { + switch (plvdi->item.iSubItem) + { case 0: LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); - plvdi->item.pszText = buffer; + plvdi->item.pszText = buffer; break; case 1: - switch (((LINE_INFO*)plvdi->item.lParam)->dwValType) { + switch (((LINE_INFO*)plvdi->item.lParam)->dwValType) + { case REG_NONE: plvdi->item.pszText = _T("REG_NONE"); break; @@ -349,14 +355,15 @@ case REG_QWORD: /* REG_QWORD_LITTLE_ENDIAN */ plvdi->item.pszText = _T("REG_QWORD"); break; - default: { + default: + { TCHAR buf2[200]; - LoadString(hInst, IDS_UNKNOWN_TYPE, buf2, sizeof(buf2)/sizeof(TCHAR)); - wsprintf(buffer, buf2, ((LINE_INFO*)plvdi->item.lParam)->dwValType); + LoadString(hInst, IDS_UNKNOWN_TYPE, buf2, sizeof(buf2)/sizeof(TCHAR)); + wsprintf(buffer, buf2, ((LINE_INFO*)plvdi->item.lParam)->dwValType); plvdi->item.pszText = buffer; break; - } } + } break; case 3: plvdi->item.pszText = _T(""); @@ -377,7 +384,8 @@ if (g_columnToSort == 1 && l->dwValType != r->dwValType) return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType; - if (g_columnToSort == 2) { + if (g_columnToSort == 2) + { /* FIXME: Sort on value */ } return g_invertSort ? _tcsicmp(r->name, l->name) : _tcsicmp(l->name, r->name); @@ -388,87 +396,89 @@ NMLVDISPINFO* Info; UNREFERENCED_PARAMETER(wParam); *Result = TRUE; - switch (((LPNMHDR)lParam)->code) { - case LVN_GETDISPINFO: - OnGetDispInfo((NMLVDISPINFO*)lParam); - return TRUE; - case LVN_COLUMNCLICK: - if (g_columnToSort == (DWORD)((LPNMLISTVIEW)lParam)->iSubItem) - g_invertSort = !g_invertSort; - else { - g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem; - g_invertSort = FALSE; - } + switch (((LPNMHDR)lParam)->code) + { + case LVN_GETDISPINFO: + OnGetDispInfo((NMLVDISPINFO*)lParam); + return TRUE; + case LVN_COLUMNCLICK: + if (g_columnToSort == (DWORD)((LPNMLISTVIEW)lParam)->iSubItem) + g_invertSort = !g_invertSort; + else + { + g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem; + g_invertSort = FALSE; + } - (void)ListView_SortItems(hWnd, CompareFunc, (WPARAM)hWnd); - return TRUE; - case NM_DBLCLK: - case NM_RETURN: + (void)ListView_SortItems(hWnd, CompareFunc, (WPARAM)hWnd); + return TRUE; + case NM_DBLCLK: + case NM_RETURN: + { + SendMessage(hFrameWnd, WM_COMMAND, MAKEWPARAM(ID_EDIT_MODIFY, 0), 0); + } + return TRUE; + case NM_SETFOCUS: + g_pChildWnd->nFocusPanel = 0; + break; + case LVN_BEGINLABELEDIT: + Info = (NMLVDISPINFO*)lParam; + if(Info) + { + PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam; + if(!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))) { - SendMessage(hFrameWnd, WM_COMMAND, MAKEWPARAM(ID_EDIT_MODIFY, 0), 0); + *Result = TRUE; } - return TRUE; - case NM_SETFOCUS: - g_pChildWnd->nFocusPanel = 0; - break; - case LVN_BEGINLABELEDIT: - Info = (NMLVDISPINFO*)lParam; - if(Info) + else { - PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam; - if(!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))) - { - *Result = TRUE; - } - else - { - *Result = FALSE; - } + *Result = FALSE; } + } + else + *Result = TRUE; + return TRUE; + case LVN_ENDLABELEDIT: + Info = (NMLVDISPINFO*)lParam; + if(Info && Info->item.pszText) + { + PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam; + if(!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))) + { + *Result = FALSE; + } else - *Result = TRUE; - return TRUE; - case LVN_ENDLABELEDIT: - Info = (NMLVDISPINFO*)lParam; - if(Info && Info->item.pszText) { - PLINE_INFO lineinfo = (PLINE_INFO)Info->item.lParam; - if(!lineinfo->name || !_tcscmp(lineinfo->name, _T(""))) + if(_tcslen(Info->item.pszText) == 0) { - *Result = FALSE; + TCHAR msg[128], caption[128]; + + LoadString(hInst, IDS_ERR_RENVAL_TOEMPTY, msg, sizeof(msg)/sizeof(TCHAR)); + LoadString(hInst, IDS_ERR_RENVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); + MessageBox(0, msg, caption, 0); + *Result = TRUE; } else { - if(_tcslen(Info->item.pszText) == 0) - { - TCHAR msg[128], caption[128]; + HKEY hKeyRoot; + LPCTSTR keyPath; + LONG lResult; - LoadString(hInst, IDS_ERR_RENVAL_TOEMPTY, msg, sizeof(msg)/sizeof(TCHAR)); - LoadString(hInst, IDS_ERR_RENVAL_CAPTION, caption, sizeof(caption)/sizeof(TCHAR)); - MessageBox(0, msg, caption, 0); - *Result = TRUE; - } - else - { - HKEY hKeyRoot; - LPCTSTR keyPath; - LONG lResult; + keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); + lResult = RenameValue(hKeyRoot, keyPath, Info->item.pszText, lineinfo->name); + lineinfo->name = realloc(lineinfo->name, (_tcslen(Info->item.pszText)+1)*sizeof(TCHAR)); + if (lineinfo->name != NULL) + _tcscpy(lineinfo->name, Info->item.pszText); - keyPath = GetItemPath(g_pChildWnd->hTreeWnd, 0, &hKeyRoot); - lResult = RenameValue(hKeyRoot, keyPath, Info->item.pszText, lineinfo->name); - lineinfo->name = realloc(lineinfo->name, (_tcslen(Info->item.pszText)+1)*sizeof(TCHAR)); - if (lineinfo->name != NULL) - _tcscpy(lineinfo->name, Info->item.pszText); - - *Result = TRUE; - return (lResult == ERROR_SUCCESS); - } + *Result = TRUE; + return (lResult == ERROR_SUCCESS); } } - else - *Result = TRUE; + } + else + *Result = TRUE; - return TRUE; + return TRUE; } return FALSE; } @@ -500,10 +510,11 @@ void DestroyListView(HWND hwndLV) { INT count, i; - LVITEM item; + LVITEM item; count = ListView_GetItemCount(hwndLV); - for (i = 0; i < count; i++) { + for (i = 0; i < count; i++) + { item.mask = LVIF_PARAM; item.iItem = i; (void)ListView_GetItem(hwndLV, &item); @@ -555,7 +566,9 @@ /* AddEntryToList(hwndLV, _T("(Default)"), dwValType, ValBuf, dwValSize); */ /* } */ /* dwValSize = max_val_size; */ - while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) { + while (RegEnumValue(hNewKey, dwIndex, ValName, &dwValNameLen, + NULL, &dwValType, ValBuf, &dwValSize) == ERROR_SUCCESS) + { /* Add a terminating 0 character. Usually this is only necessary for strings. */ ValBuf[dwValSize] = 0; #ifdef UNICODE @@ -568,7 +581,7 @@ ++dwIndex; if(!_tcscmp(ValName, _T(""))) { - AddedDefault = TRUE; + AddedDefault = TRUE; } } HeapFree(GetProcessHeap(), 0, ValBuf); @@ -576,7 +589,7 @@ } if(!AddedDefault) { - AddEntryToList(hwndLV, _T(""), REG_SZ, NULL, 0, 0, FALSE); + AddEntryToList(hwndLV, _T(""), REG_SZ, NULL, 0, 0, FALSE); } ListView_SortItems(hwndLV, CompareFunc, (WPARAM)hwndLV); c = ListView_GetItemCount(hwndLV); @@ -585,8 +598,8 @@ ListView_SetItemState(hwndLV, i, 0, LVIS_FOCUSED | LVIS_SELECTED); } ListView_SetItemState(hwndLV, iListViewSelect, - LVIS_FOCUSED | LVIS_SELECTED, - LVIS_FOCUSED | LVIS_SELECTED); + LVIS_FOCUSED | LVIS_SELECTED, + LVIS_FOCUSED | LVIS_SELECTED); RegCloseKey(hNewKey); SendMessage(hwndLV, WM_SETREDRAW, TRUE, 0); Index: base/applications/regedit/security.c =================================================================== --- base/applications/regedit/security.c (revision 49426) +++ base/applications/regedit/security.c (working copy) @@ -47,7 +47,7 @@ impl_from_ISecurityInformation(struct ISecurityInformation *iface) { return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity, - lpISecurityInformationVtbl)); + lpISecurityInformationVtbl)); } #if REGEDIT_IMPLEMENT_ISECURITYINFORMATION2 @@ -55,7 +55,7 @@ impl_from_ISecurityInformation2(struct ISecurityInformation2 *iface) { return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity, - lpISecurityInformation2Vtbl)); + lpISecurityInformation2Vtbl)); } #endif @@ -63,14 +63,14 @@ impl_from_ISecurityObjectTypeInfo(struct ISecurityObjectTypeInfo *iface) { return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity, - lpISecurityObjectTypeInfoVtbl)); + lpISecurityObjectTypeInfoVtbl)); } static __inline PCRegKeySecurity impl_from_IEffectivePermission(struct IEffectivePermission *iface) { return (PCRegKeySecurity)((ULONG_PTR)iface - FIELD_OFFSET(CRegKeySecurity, - lpIEffectivePermissionVtbl)); + lpIEffectivePermissionVtbl)); } #define impl_to_interface(impl,iface) (struct iface *)(&(impl)->lp##iface##Vtbl) @@ -162,7 +162,7 @@ /* ISecurityInformation */ static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this, - PSI_OBJECT_INFO pObjectInfo); + PSI_OBJECT_INFO pObjectInfo); static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetSecurity(struct ISecurityInformation *this, @@ -178,26 +178,26 @@ static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetAccessRights(struct ISecurityInformation *this, const GUID* pguidObjectType, - DWORD dwFlags, - PSI_ACCESS* ppAccess, - ULONG* pcAccesses, - ULONG* piDefaultAccess); + DWORD dwFlags, + PSI_ACCESS* ppAccess, + ULONG* pcAccesses, + ULONG* piDefaultAccess); static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnMapGeneric(struct ISecurityInformation *this, - const GUID* pguidObjectType, - UCHAR* pAceFlags, - ACCESS_MASK* pMask); + const GUID* pguidObjectType, + UCHAR* pAceFlags, + ACCESS_MASK* pMask); static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetInheritTypes(struct ISecurityInformation *this, - PSI_INHERIT_TYPE* ppInheritTypes, - ULONG* pcInheritTypes); + PSI_INHERIT_TYPE* ppInheritTypes, + ULONG* pcInheritTypes); static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this, - HWND hwnd, - UINT uMsg, - SI_PAGE_TYPE uPage); + HWND hwnd, + UINT uMsg, + SI_PAGE_TYPE uPage); static const struct ifaceISecurityInformationVbtl vtblISecurityInformation = { @@ -276,14 +276,14 @@ /* IEffectivePermission */ static HRESULT STDMETHODCALLTYPE IEffectivePermission_fnGetEffectivePermission(struct IEffectivePermission *this, - const GUID* pguidObjectType, - PSID pUserSid, - LPCWSTR pszServerName, - PSECURITY_DESCRIPTOR pSD, - POBJECT_TYPE_LIST* ppObjectTypeList, - ULONG* pcObjectTypeListLength, - PACCESS_MASK* ppGrantedAccessList, - ULONG* pcGrantedAccessListLength); + const GUID* pguidObjectType, + PSID pUserSid, + LPCWSTR pszServerName, + PSECURITY_DESCRIPTOR pSD, + POBJECT_TYPE_LIST* ppObjectTypeList, + ULONG* pcObjectTypeListLength, + PACCESS_MASK* ppGrantedAccessList, + ULONG* pcGrantedAccessListLength); static const struct ifaceIEffectivePermissionVbtl vtblIEffectivePermission = { @@ -303,8 +303,8 @@ /* IUnknown */ static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this, - REFIID iid, - PVOID *pvObject); + REFIID iid, + PVOID *pvObject); static ULONG STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnAddRef(struct ISecurityObjectTypeInfo *this); @@ -315,9 +315,9 @@ /* ISecurityObjectTypeInfo */ static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this, - SECURITY_INFORMATION si, - PACL pACL, - PINHERITED_FROM* ppInheritArray); + SECURITY_INFORMATION si, + PACL pACL, + PINHERITED_FROM* ppInheritArray); static const struct ifaceISecurityObjectTypeInfoVbtl vtblISecurityObjectTypeInfo = { @@ -335,7 +335,8 @@ Implementation of the ISecurityInformation interface ******************************************************************************/ -static SI_ACCESS RegAccess[] = { +static SI_ACCESS RegAccess[] = +{ {&GUID_NULL, KEY_ALL_ACCESS, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_FULLCONTROL), SI_ACCESS_GENERAL | SI_ACCESS_SPECIFIC}, {&GUID_NULL, KEY_READ, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_READ), SI_ACCESS_GENERAL}, {&GUID_NULL, KEY_QUERY_VALUE, (LPWSTR)MAKEINTRESOURCE(IDS_ACCESS_QUERYVALUE), SI_ACCESS_SPECIFIC}, @@ -352,14 +353,16 @@ static const DWORD RegDefaultAccess = 1; /* KEY_READ */ -static GENERIC_MAPPING RegAccessMasks = { +static GENERIC_MAPPING RegAccessMasks = +{ KEY_READ, KEY_WRITE, KEY_EXECUTE, KEY_ALL_ACCESS }; -static SI_INHERIT_TYPE RegInheritTypes[] = { +static SI_INHERIT_TYPE RegInheritTypes[] = +{ {&GUID_NULL, 0, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_THISKEYONLY)}, {&GUID_NULL, CONTAINER_INHERIT_ACE, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_THISKEYANDSUBKEYS)}, {&GUID_NULL, INHERIT_ONLY_ACE | CONTAINER_INHERIT_ACE, (LPWSTR)MAKEINTRESOURCE(IDS_INHERIT_SUBKEYSONLY)}, @@ -397,7 +400,7 @@ static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnGetObjectInformation(struct ISecurityInformation *this, - PSI_OBJECT_INFO pObjectInfo) + PSI_OBJECT_INFO pObjectInfo) { PCRegKeySecurity obj = impl_from_ISecurityInformation(this); @@ -484,9 +487,9 @@ static HRESULT STDMETHODCALLTYPE ISecurityInformation_fnPropertySheetPageCallback(struct ISecurityInformation *this, - HWND hwnd, - UINT uMsg, - SI_PAGE_TYPE uPage) + HWND hwnd, + UINT uMsg, + SI_PAGE_TYPE uPage) { return S_OK; } @@ -581,14 +584,14 @@ static HRESULT STDMETHODCALLTYPE IEffectivePermission_fnGetEffectivePermission(struct IEffectivePermission *this, - const GUID* pguidObjectType, - PSID pUserSid, - LPCWSTR pszServerName, - PSECURITY_DESCRIPTOR pSD, - POBJECT_TYPE_LIST* ppObjectTypeList, - ULONG* pcObjectTypeListLength, - PACCESS_MASK* ppGrantedAccessList, - ULONG* pcGrantedAccessListLength) + const GUID* pguidObjectType, + PSID pUserSid, + LPCWSTR pszServerName, + PSECURITY_DESCRIPTOR pSD, + POBJECT_TYPE_LIST* ppObjectTypeList, + ULONG* pcObjectTypeListLength, + PACCESS_MASK* ppGrantedAccessList, + ULONG* pcGrantedAccessListLength) { PACL Dacl = NULL; BOOL DaclPresent, DaclDefaulted; @@ -609,7 +612,7 @@ &DaclDefaulted) && DaclPresent) { GrantedAccessList = (PACCESS_MASK)LocalAlloc(LMEM_FIXED, - sizeof(ACCESS_MASK)); + sizeof(ACCESS_MASK)); if (GrantedAccessList == NULL) { goto Fail; @@ -639,8 +642,8 @@ static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnQueryInterface(struct ISecurityObjectTypeInfo *this, - REFIID iid, - PVOID *pvObject) + REFIID iid, + PVOID *pvObject) { if (IsEqualGUID(iid, &IID_IUnknown)) @@ -669,9 +672,9 @@ static HRESULT STDMETHODCALLTYPE ISecurityObjectTypeInfo_fnGetInheritSource(struct ISecurityObjectTypeInfo *this, - SECURITY_INFORMATION si, - PACL pACL, - PINHERITED_FROM* ppInheritArray) + SECURITY_INFORMATION si, + PACL pACL, + PINHERITED_FROM* ppInheritArray) { PCRegKeySecurity obj = impl_from_ISecurityObjectTypeInfo(this); PINHERITED_FROM pif, pif2; @@ -703,8 +706,8 @@ { /* Calculate the size of the buffer to return */ for (i = 0; - i < pACL->AceCount; - i++) + i < pACL->AceCount; + i++) { if (pif[i].AncestorName != NULL) { @@ -724,8 +727,8 @@ /* copy the array and strings to the buffer */ lpBuf = (LPTSTR)((ULONG_PTR)pif2 + (pACL->AceCount * sizeof(INHERITED_FROM))); for (i = 0; - i < pACL->AceCount; - i++) + i < pACL->AceCount; + i++) { pif2[i].GenerationGap = pif[i].GenerationGap; if (pif[i].AncestorName != NULL) @@ -769,7 +772,7 @@ obj = (PCRegKeySecurity)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(CRegKeySecurity, - szRegKey[_tcslen(lpRegKey) + 1])); + szRegKey[_tcslen(lpRegKey) + 1])); if (obj != NULL) { obj->ref = 1; @@ -797,8 +800,8 @@ typedef struct _CHANGE_CONTEXT { - HKEY hKey; - LPTSTR KeyString; + HKEY hKey; + LPTSTR KeyString; } CHANGE_CONTEXT, *PCHANGE_CONTEXT; typedef BOOL (WINAPI *PEDITSECURITY)(HWND hwndOwner, @@ -816,7 +819,7 @@ } if (!(pfnEditSecurity = (PEDITSECURITY)GetProcAddress(hAclUiDll, - "EditSecurity"))) + "EditSecurity"))) { FreeLibrary(hAclUiDll); hAclUiDll = NULL; @@ -919,8 +922,8 @@ /* build registry path */ if (lpMachine != NULL && - (lpMachine[0] == _T('\0') || - (lpMachine[0] == _T('.') && lpMachine[1] == _T('.')))) + (lpMachine[0] == _T('\0') || + (lpMachine[0] == _T('.') && lpMachine[1] == _T('.')))) { lnMachine = 0; } @@ -936,7 +939,7 @@ else if (hKey == HKEY_CURRENT_CONFIG) lphKey = TEXT("CONFIG"); else - goto Cleanup; + goto Cleanup; lpKeyPath = HeapAlloc(GetProcessHeap(), 0, @@ -973,16 +976,16 @@ } ObjectInfo.dwFlags = SI_EDIT_ALL | SI_ADVANCED | SI_CONTAINER | SI_EDIT_EFFECTIVE | SI_EDIT_PERMS | - SI_OWNER_RECURSE | SI_RESET_DACL_TREE | SI_RESET_SACL_TREE; + SI_OWNER_RECURSE | SI_RESET_DACL_TREE | SI_RESET_SACL_TREE; ObjectInfo.hInstance = hInst; ObjectInfo.pszServerName = Machine; ObjectInfo.pszObjectName = KeyName; /* FIXME */ ObjectInfo.pszPageTitle = KeyName; /* FIXME */ if (!(RegKeySecurity = CRegKeySecurity_fnConstructor(lpKeyPath, - hKey, - &ObjectInfo, - &Result))) + hKey, + &ObjectInfo, + &Result))) { goto Cleanup; } Index: base/applications/regedit/find.c =================================================================== --- base/applications/regedit/find.c (revision 49426) +++ base/applications/regedit/find.c (working copy) @@ -20,7 +20,7 @@ #include #define RSF_WHOLESTRING 0x00000001 -#define RSF_LOOKATKEYS 0x00000002 +#define RSF_LOOKATKEYS 0x00000002 #define RSF_LOOKATVALUES 0x00000004 #define RSF_LOOKATDATA 0x00000008 #define RSF_MATCHCASE 0x00010000 @@ -103,7 +103,7 @@ return 2 == CompareString(LOCALE_SYSTEM_DEFAULT, 0, psz1, cch1, psz2, cch2); else - return 2 == CompareString(LOCALE_SYSTEM_DEFAULT, + return 2 == CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, psz1, cch1, psz2, cch2); } @@ -134,7 +134,7 @@ } BOOL RegFindRecurse( - HKEY hKey, + HKEY hKey, LPCTSTR pszSubKey, LPCTSTR pszValueName, LPTSTR *ppszFoundSubKey, @@ -176,7 +176,7 @@ goto err; s_cbName = MAX_PATH * sizeof(TCHAR); - lResult = RegEnumValue(hSubKey, i, s_szName, &s_cbName, NULL, NULL, + lResult = RegEnumValue(hSubKey, i, s_szName, &s_cbName, NULL, NULL, NULL, &cb); if (lResult == ERROR_NO_MORE_ITEMS) { @@ -206,7 +206,7 @@ if (!fPast) continue; - if ((s_dwFlags & RSF_LOOKATVALUES) && + if ((s_dwFlags & RSF_LOOKATVALUES) && CompareName(ppszNames[i], s_szFindWhat)) { *ppszFoundSubKey = _tcsdup(szSubKey); @@ -229,7 +229,7 @@ if (lResult != ERROR_SUCCESS) goto err; - if ((s_dwFlags & RSF_LOOKATDATA) && + if ((s_dwFlags & RSF_LOOKATDATA) && CompareData(type, (LPTSTR) pb, s_szFindWhat)) { *ppszFoundSubKey = _tcsdup(szSubKey); @@ -266,7 +266,7 @@ goto err; s_cbName = MAX_PATH * sizeof(TCHAR); - lResult = RegEnumKeyEx(hSubKey, i, s_szName, &s_cbName, NULL, NULL, + lResult = RegEnumKeyEx(hSubKey, i, s_szName, &s_cbName, NULL, NULL, NULL, NULL); if (lResult == ERROR_NO_MORE_ITEMS) { @@ -292,7 +292,7 @@ CompareName(ppszNames[i], s_szFindWhat)) { *ppszFoundSubKey = malloc( - (lstrlen(szSubKey) + lstrlen(ppszNames[i]) + 2) * + (lstrlen(szSubKey) + lstrlen(ppszNames[i]) + 2) * sizeof(TCHAR)); if (*ppszFoundSubKey == NULL) goto err; @@ -352,7 +352,7 @@ } BOOL RegFindWalk( - HKEY * phKey, + HKEY * phKey, LPCTSTR pszSubKey, LPCTSTR pszValueName, LPTSTR *ppszFoundSubKey, @@ -462,12 +462,12 @@ goto success; } - if (RegFindRecurse(hSubKey, ppszNames[i], NULL, + if (RegFindRecurse(hSubKey, ppszNames[i], NULL, ppszFoundSubKey, ppszFoundValueName)) { LPTSTR psz = *ppszFoundSubKey; *ppszFoundSubKey = malloc( - (lstrlen(szSubKey) + lstrlen(psz) + 2) * + (lstrlen(szSubKey) + lstrlen(psz) + 2) * sizeof(TCHAR)); if (*ppszFoundSubKey == NULL) goto err; @@ -667,7 +667,7 @@ EnableWindow(g_pChildWnd->hListWnd, FALSE); EnableWindow(g_pChildWnd->hAddressBarWnd, FALSE); - fSuccess = RegFindWalk(&hKeyRoot, pszKeyPath, pszValueName, + fSuccess = RegFindWalk(&hKeyRoot, pszKeyPath, pszValueName, &pszFoundSubKey, &pszFoundValueName); EnableWindow(hFrameWnd, TRUE); Index: base/applications/regedit/regedit.rbuild =================================================================== --- base/applications/regedit/regedit.rbuild (revision 49426) +++ base/applications/regedit/regedit.rbuild (working copy) @@ -23,6 +23,7 @@ hexedit.c listview.c main.c + error.c regedit.c regproc.c security.c Index: base/applications/regedit/regedit.c =================================================================== --- base/applications/regedit/regedit.c (revision 49426) +++ base/applications/regedit/regedit.c (working copy) @@ -52,7 +52,8 @@ "This program is command-line compatible with Microsoft Windows\n" "regedit.\n"; -typedef enum { +typedef enum +{ ACTION_UNDEF, ACTION_ADD, ACTION_EXPORT, ACTION_DELETE } REGEDIT_ACTION; @@ -79,40 +80,52 @@ int pos = 0; /* position of pointer "s" in *command_line */ file_name[0] = 0; - if (!s[0]) { + if (!s[0]) + { return; } - if (s[0] == L'"') { + if (s[0] == L'"') + { s++; (*command_line)++; - while(s[0] != L'"') { - if (!s[0]) { + while(s[0] != L'"') + { + if (!s[0]) + { fprintf(stderr, "%s: Unexpected end of file name!\n", getAppName()); exit(1); } s++; pos++; } - } else { - while(s[0] && !iswspace(s[0])) { + } + else + { + while(s[0] && !iswspace(s[0])) + { s++; pos++; } } memcpy(file_name, *command_line, pos * sizeof((*command_line)[0])); /* remove the last backslash */ - if (file_name[pos - 1] == L'\\') { + if (file_name[pos - 1] == L'\\') + { file_name[pos - 1] = L'\0'; - } else { + } + else + { file_name[pos] = L'\0'; } - if (s[0]) { + if (s[0]) + { s++; pos++; } - while(s[0] && iswspace(s[0])) { + while(s[0] && iswspace(s[0])) + { s++; pos++; } @@ -121,64 +134,75 @@ BOOL PerformRegAction(REGEDIT_ACTION action, LPWSTR s) { - switch (action) { - case ACTION_ADD: { - WCHAR filename[MAX_PATH]; - FILE *fp; + switch (action) + { + case ACTION_ADD: + { + WCHAR filename[MAX_PATH]; + FILE *fp; - get_file_name(&s, filename); - if (!filename[0]) { - fprintf(stderr, "%s: No file name is specified\n", getAppName()); - fprintf(stderr, usage); - exit(4); - } + get_file_name(&s, filename); + if (!filename[0]) + { + fprintf(stderr, "%s: No file name is specified\n", getAppName()); + fprintf(stderr, usage); + exit(4); + } - while(filename[0]) { - fp = _wfopen(filename, L"r"); - if (fp == NULL) - { - LPSTR p = GetMultiByteString(filename); - perror(""); - fprintf(stderr, "%s: Can't open file \"%s\"\n", getAppName(), p); - HeapFree(GetProcessHeap(), 0, p); - exit(5); - } - import_registry_file(fp); - get_file_name(&s, filename); + while(filename[0]) + { + fp = _wfopen(filename, L"r"); + if (fp == NULL) + { + LPSTR p = GetMultiByteString(filename); + perror(""); + fprintf(stderr, "%s: Can't open file \"%s\"\n", getAppName(), p); + HeapFree(GetProcessHeap(), 0, p); + exit(5); } - break; + import_registry_file(fp); + get_file_name(&s, filename); } - case ACTION_DELETE: { - WCHAR reg_key_name[KEY_MAX_LEN]; - get_file_name(&s, reg_key_name); - if (!reg_key_name[0]) { - fprintf(stderr, "%s: No registry key is specified for removal\n", getAppName()); - fprintf(stderr, usage); - exit(6); - } - delete_registry_key(reg_key_name); - break; + break; + } + case ACTION_DELETE: + { + WCHAR reg_key_name[KEY_MAX_LEN]; + get_file_name(&s, reg_key_name); + if (!reg_key_name[0]) + { + fprintf(stderr, "%s: No registry key is specified for removal\n", getAppName()); + fprintf(stderr, usage); + exit(6); } - case ACTION_EXPORT: { - WCHAR filename[MAX_PATH]; + delete_registry_key(reg_key_name); + break; + } + case ACTION_EXPORT: + { + WCHAR filename[MAX_PATH]; - filename[0] = _T('\0'); - get_file_name(&s, filename); - if (!filename[0]) { - fprintf(stderr, "%s: No file name is specified\n", getAppName()); - fprintf(stderr, usage); - exit(7); - } + filename[0] = _T('\0'); + get_file_name(&s, filename); + if (!filename[0]) + { + fprintf(stderr, "%s: No file name is specified\n", getAppName()); + fprintf(stderr, usage); + exit(7); + } - if (s[0]) { - WCHAR reg_key_name[KEY_MAX_LEN]; - get_file_name(&s, reg_key_name); - export_registry_key(filename, reg_key_name, REG_FORMAT_4); - } else { - export_registry_key(filename, NULL, REG_FORMAT_4); - } - break; + if (s[0]) + { + WCHAR reg_key_name[KEY_MAX_LEN]; + get_file_name(&s, reg_key_name); + export_registry_key(filename, reg_key_name, REG_FORMAT_4); } + else + { + export_registry_key(filename, NULL, REG_FORMAT_4); + } + break; + } default: fprintf(stderr, "%s: Unhandled action!\n", getAppName()); exit(8); @@ -196,9 +220,12 @@ */ static void error_unknown_switch(WCHAR chu, LPWSTR s) { - if (iswalpha(chu)) { + if (iswalpha(chu)) + { fprintf(stderr, "%s: Undefined switch /%c!\n", getAppName(), chu); - } else { + } + else + { fprintf(stderr, "%s: Alphabetic character is expected after '%c' " "in swit ch specification\n", getAppName(), *(s - 1)); } @@ -220,12 +247,16 @@ ch = *s; ch2 = *(s + 1); chu = (WCHAR)towupper(ch); - if (!ch2 || iswspace(ch2)) { + if (!ch2 || iswspace(ch2)) + { if (chu == L'S' || chu == L'V') { /* ignore these switches */ - } else { - switch (chu) { + } + else + { + switch (chu) + { case L'D': action = ACTION_DELETE; break; @@ -242,14 +273,19 @@ } } s++; - } else { - if (ch2 == L':') { - switch (chu) { + } + else + { + if (ch2 == L':') + { + switch (chu) + { case L'L': /* fall through */ case L'R': s += 2; - while (*s && !iswspace(*s)) { + while (*s && !iswspace(*s)) + { s++; } break; @@ -257,7 +293,9 @@ error_unknown_switch(chu, s); break; } - } else { + } + else + { /* this is a file name, starting from '/' */ s--; break; @@ -265,7 +303,8 @@ } /* skip spaces to the next parameter */ ch = *s; - while (ch && iswspace(ch)) { + while (ch && iswspace(ch)) + { s++; ch = *s; } Index: base/applications/regedit/main.c =================================================================== --- base/applications/regedit/main.c (revision 49426) +++ base/applications/regedit/main.c (working copy) @@ -88,9 +88,9 @@ wcChild.hInstance = hInstance; wcChild.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)); wcChild.hCursor = LoadCursor(0, IDC_ARROW), - wcChild.lpszClassName = szChildClass, - wcChild.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, - GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); + wcChild.lpszClassName = szChildClass, + wcChild.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); RegisterClassEx(&wcChild); /* register child windows class */ @@ -107,13 +107,13 @@ AclUiAvailable = InitializeAclUiDll(); if(!AclUiAvailable) { - /* hide the Edit/Permissions... menu entry */ - if(hEditMenu != NULL) - { - RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND); - /* remove the separator after the menu item */ - RemoveMenu(hEditMenu, 4, MF_BYPOSITION); - } + /* hide the Edit/Permissions... menu entry */ + if(hEditMenu != NULL) + { + RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND); + /* remove the separator after the menu item */ + RemoveMenu(hEditMenu, 4, MF_BYPOSITION); + } } if(hEditMenu != NULL) @@ -129,14 +129,16 @@ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenuFrame, hInstance, NULL/*lpParam*/); - if (!hFrameWnd) { + if (!hFrameWnd) + { return FALSE; } /* Create the status bar */ hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, _T(""), hFrameWnd, STATUS_WINDOW); - if (hStatusBar) { + if (hStatusBar) + { /* Create the status bar panes */ SetupStatusBar(hFrameWnd, FALSE); CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); @@ -144,7 +146,7 @@ /* Restore position */ if (QueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey, _T("LastKey"), - szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) + szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) { SelectNode(g_pChildWnd->hTreeWnd, szBuffer); } @@ -159,8 +161,9 @@ /* we need to destroy the main menu before destroying the main window to avoid a memory leak */ -void DestroyMainMenu() { - DestroyMenu(hMenuFrame); +void DestroyMainMenu() +{ + DestroyMenu(hMenuFrame); } /******************************************************************************/ @@ -175,11 +178,11 @@ BOOL TranslateChildTabMessage(MSG *msg) { - if (msg->message != WM_KEYDOWN) return FALSE; - if (msg->wParam != VK_TAB) return FALSE; - if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE; - PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0); - return TRUE; + if (msg->message != WM_KEYDOWN) return FALSE; + if (msg->wParam != VK_TAB) return FALSE; + if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE; + PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0); + return TRUE; } int APIENTRY wWinMain(HINSTANCE hInstance, @@ -192,7 +195,8 @@ UNREFERENCED_PARAMETER(hPrevInstance); - if (ProcessCmdLine(lpCmdLine)) { + if (ProcessCmdLine(lpCmdLine)) + { return 0; } @@ -205,15 +209,18 @@ hInst = hInstance; /* Perform application initialization */ - if (!InitInstance(hInstance, nCmdShow)) { + if (!InitInstance(hInstance, nCmdShow)) + { return FALSE; } hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL)); /* Main message loop */ - while (GetMessage(&msg, (HWND)NULL, 0, 0)) { + while (GetMessage(&msg, (HWND)NULL, 0, 0)) + { if (!TranslateAccelerator(hFrameWnd, hAccel, &msg) - && !TranslateChildTabMessage(&msg)) { + && !TranslateChildTabMessage(&msg)) + { TranslateMessage(&msg); DispatchMessage(&msg); } Index: base/applications/regedit/edit.c =================================================================== --- base/applications/regedit/edit.c (revision 49426) +++ base/applications/regedit/edit.c (working copy) @@ -22,8 +22,8 @@ typedef enum _EDIT_MODE { - EDIT_MODE_DEC, - EDIT_MODE_HEX + EDIT_MODE_DEC, + EDIT_MODE_HEX } EDIT_MODE; @@ -59,19 +59,10 @@ static void error_code_messagebox(HWND hwnd, DWORD error_code) { - LPTSTR lpMsgBuf; - DWORD status; TCHAR title[256]; - static const TCHAR fallback[] = TEXT("Error displaying error message.\n"); if (!LoadString(hInst, IDS_ERROR, title, COUNT_OF(title))) lstrcpy(title, TEXT("Error")); - status = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, error_code, 0, (LPTSTR)&lpMsgBuf, 0, NULL); - if (!status) - lpMsgBuf = (LPTSTR)fallback; - MessageBox(hwnd, lpMsgBuf, title, MB_OK | MB_ICONERROR); - if (lpMsgBuf != fallback) - LocalFree(lpMsgBuf); + ErrorMessageBox(hwnd, title, error_code); } void warning(HWND hwnd, INT resId, ...) @@ -105,17 +96,18 @@ UNREFERENCED_PARAMETER(lParam); - switch(uMsg) { + switch(uMsg) + { case WM_INITDIALOG: if(editValueName && _tcscmp(editValueName, _T(""))) { - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); } else { - TCHAR buffer[255]; - LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); + TCHAR buffer[255]; + LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); } SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); @@ -149,8 +141,8 @@ } else { - if (stringValueData) - *stringValueData = 0; + if (stringValueData) + *stringValueData = 0; } } EndDialog(hwndDlg, IDOK); @@ -172,17 +164,18 @@ UNREFERENCED_PARAMETER(lParam); - switch(uMsg) { + switch(uMsg) + { case WM_INITDIALOG: if(editValueName && _tcscmp(editValueName, _T(""))) { - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); } else { - TCHAR buffer[255]; - LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); + TCHAR buffer[255]; + LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); } SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); @@ -216,8 +209,8 @@ } else { - if (stringValueData) - *stringValueData = 0; + if (stringValueData) + *stringValueData = 0; } } EndDialog(hwndDlg, IDOK); @@ -283,7 +276,8 @@ UNREFERENCED_PARAMETER(lParam); - switch(uMsg) { + switch(uMsg) + { case WM_INITDIALOG: dwordEditMode = EDIT_MODE_HEX; @@ -299,9 +293,9 @@ } else { - TCHAR buffer[255]; - LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); + TCHAR buffer[255]; + LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); } CheckRadioButton (hwndDlg, IDC_FORMAT_HEX, IDC_FORMAT_DEC, IDC_FORMAT_HEX); _stprintf (ValueString, _T("%lx"), dwordValueData); @@ -368,8 +362,8 @@ } else { - EndDialog(hwndDlg, IDCANCEL); - return TRUE; + EndDialog(hwndDlg, IDCANCEL); + return TRUE; } } EndDialog(hwndDlg, IDOK); @@ -391,17 +385,18 @@ UNREFERENCED_PARAMETER(lParam); - switch(uMsg) { + switch(uMsg) + { case WM_INITDIALOG: if(editValueName && _tcscmp(editValueName, _T(""))) { - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); } else { - TCHAR buffer[255]; - LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); - SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); + TCHAR buffer[255]; + LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); + SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); } hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA); HexEdit_LoadBuffer(hwndValue, binValueData, valueDataLen); @@ -417,9 +412,9 @@ { len = (UINT) HexEdit_GetBufferSize(hwndValue); if (len > 0 && binValueData) - binValueData = HeapReAlloc(GetProcessHeap(), 0, binValueData, len); + binValueData = HeapReAlloc(GetProcessHeap(), 0, binValueData, len); else - binValueData = HeapAlloc(GetProcessHeap(), 0, len + 1); + binValueData = HeapAlloc(GetProcessHeap(), 0, len + 1); HexEdit_CopyBuffer(hwndValue, binValueData, len); valueDataLen = len; } @@ -448,11 +443,11 @@ lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen); if (lRet != ERROR_SUCCESS && (!_tcscmp(valueName, _T("")) || valueName == NULL)) { - lRet = ERROR_SUCCESS; /* Allow editing of (Default) values which don't exist */ - type = REG_SZ; - valueDataLen = 0; - stringValueData = NULL; - binValueData = NULL; + lRet = ERROR_SUCCESS; /* Allow editing of (Default) values which don't exist */ + type = REG_SZ; + valueDataLen = 0; + stringValueData = NULL; + binValueData = NULL; } if (lRet != ERROR_SUCCESS) @@ -503,7 +498,7 @@ size_t llen, listlen, nl_len; LPTSTR src, lines = NULL; - if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) + if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) { error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); goto done; @@ -515,7 +510,7 @@ goto done; } - /* convert \0 to \r\n */ + /* convert \0 to \r\n */ src = stringValueData; nl_len = _tcslen(_T("\r\n")) * sizeof(TCHAR); listlen = sizeof(TCHAR); @@ -524,12 +519,12 @@ { llen = _tcslen(src); if(llen == 0) - break; + break; listlen += (llen * sizeof(TCHAR)) + nl_len; - lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, listlen); - _tcscat(lines, src); - _tcscat(lines, _T("\r\n")); - src += llen + 1; + lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, listlen); + _tcscat(lines, src); + _tcscat(lines, _T("\r\n")); + src += llen + 1; } HeapFree(GetProcessHeap(), 0, stringValueData); stringValueData = lines; @@ -539,7 +534,8 @@ stringValueData = NULL; } - if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_MULTI_STRING), hwnd, modify_multi_string_dlgproc) == IDOK) + if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_MULTI_STRING), hwnd, + modify_multi_string_dlgproc) == IDOK) { if (stringValueData) { @@ -561,7 +557,7 @@ if(nl == src) { EmptyLines = TRUE; - src = nl + c_nl; + src = nl + c_nl; continue; } } @@ -571,7 +567,7 @@ } if(linechars > 0) { - buflen += ((linechars + 1) * sizeof(TCHAR)); + buflen += ((linechars + 1) * sizeof(TCHAR)); lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, buflen); memcpy((lines + dest), src, linechars * sizeof(TCHAR)); dest += linechars; @@ -590,8 +586,8 @@ warning(hwnd, IDS_MULTI_SZ_EMPTY_STRING); } - lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)lines, (DWORD) buflen); - HeapFree(GetProcessHeap(), 0, lines); + lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)lines, (DWORD) buflen); + HeapFree(GetProcessHeap(), 0, lines); } else { @@ -623,44 +619,44 @@ LPWSTR u_valuename; int len_vname = lstrlen(valueName); - if(len_vname > 0) + if(len_vname > 0) { - if(!(u_valuename = HeapAlloc(GetProcessHeap(), 0, (len_vname + 1) * sizeof(WCHAR)))) - { - error(hwnd, IDS_TOO_BIG_VALUE, len_vname); - goto done; - } - /* convert the ansi value name to an unicode string */ - MultiByteToWideChar(CP_ACP, 0, valueName, -1, u_valuename, len_vname + 1); - valueDataLen *= sizeof(WCHAR); + if(!(u_valuename = HeapAlloc(GetProcessHeap(), 0, (len_vname + 1) * sizeof(WCHAR)))) + { + error(hwnd, IDS_TOO_BIG_VALUE, len_vname); + goto done; + } + /* convert the ansi value name to an unicode string */ + MultiByteToWideChar(CP_ACP, 0, valueName, -1, u_valuename, len_vname + 1); + valueDataLen *= sizeof(WCHAR); } else - u_valuename = L""; + u_valuename = L""; #endif - if(valueDataLen > 0) + if(valueDataLen > 0) { - if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen + 1))) + if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen + 1))) { - error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); - goto done; + error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); + goto done; } - /* force to use the unicode version, so editing strings in binary mode is correct */ - lRet = RegQueryValueExW(hKey, + /* force to use the unicode version, so editing strings in binary mode is correct */ + lRet = RegQueryValueExW(hKey, #ifndef UNICODE - u_valuename, + u_valuename, #else - valueName, + valueName, #endif - 0, 0, (LPBYTE)binValueData, &valueDataLen); + 0, 0, (LPBYTE)binValueData, &valueDataLen); if (lRet != ERROR_SUCCESS) { HeapFree(GetProcessHeap(), 0, binValueData); #ifndef UNICODE if(len_vname > 0) - HeapFree(GetProcessHeap(), 0, u_valuename); + HeapFree(GetProcessHeap(), 0, u_valuename); #endif - error(hwnd, IDS_BAD_VALUE, valueName); + error(hwnd, IDS_BAD_VALUE, valueName); goto done; } } @@ -671,22 +667,22 @@ if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_BIN_DATA), hwnd, modify_binary_dlgproc) == IDOK) { - /* force to use the unicode version, so editing strings in binary mode is correct */ - lRet = RegSetValueExW(hKey, + /* force to use the unicode version, so editing strings in binary mode is correct */ + lRet = RegSetValueExW(hKey, #ifndef UNICODE - u_valuename, + u_valuename, #else - valueName, + valueName, #endif - 0, type, (LPBYTE)binValueData, valueDataLen); + 0, type, (LPBYTE)binValueData, valueDataLen); if (lRet == ERROR_SUCCESS) result = TRUE; } if(binValueData != NULL) - HeapFree(GetProcessHeap(), 0, binValueData); + HeapFree(GetProcessHeap(), 0, binValueData); #ifndef UNICODE if(len_vname > 0) - HeapFree(GetProcessHeap(), 0, u_valuename); + HeapFree(GetProcessHeap(), 0, u_valuename); #endif } else @@ -726,7 +722,7 @@ /* create the destination subkey */ lResult = RegCreateKeyEx(hDestKey, lpDestSubKey, 0, NULL, 0, KEY_WRITE, NULL, - &hDestSubKey, &dwDisposition); + &hDestSubKey, &dwDisposition); if (lResult) goto done; @@ -795,9 +791,10 @@ HKEY hKey; lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey); - if (lRet != ERROR_SUCCESS) { - error_code_messagebox(hwnd, lRet); - return FALSE; + if (lRet != ERROR_SUCCESS) + { + error_code_messagebox(hwnd, lRet); + return FALSE; } LoadString(hInst, IDS_QUERY_DELETE_KEY_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); @@ -807,9 +804,10 @@ goto done; lRet = SHDeleteKey(hKeyRoot, keyPath); - if (lRet != ERROR_SUCCESS) { - error(hwnd, IDS_BAD_KEY, keyPath); - goto done; + if (lRet != ERROR_SUCCESS) + { + error(hwnd, IDS_BAD_KEY, keyPath); + goto done; } result = TRUE; @@ -831,7 +829,8 @@ if (s) { s++; - lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR)); + lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, + (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR)); if (lpNewSubKey != NULL) { memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR)); @@ -883,7 +882,8 @@ return lResult; } -LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen) +LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, + LPTSTR pszBuffer, DWORD dwBufferLen) { LONG lResult; HKEY hSubKey = NULL; @@ -898,7 +898,8 @@ } cbData = (dwBufferLen - 1) * sizeof(*pszBuffer); - lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData); + lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, + (LPBYTE) pszBuffer, &cbData); if (lResult != ERROR_SUCCESS) goto done; if (dwType != REG_SZ) @@ -917,7 +918,8 @@ return lResult; } -BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey) +BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, + HKEY hRootKey, LPCTSTR lpSubKey) { LPCTSTR pszRootKey; Index: base/applications/regedit/main.h =================================================================== --- base/applications/regedit/main.h (revision 49426) +++ base/applications/regedit/main.h (working copy) @@ -27,8 +27,8 @@ #define TREE_WINDOW 2002 #define LIST_WINDOW 2003 -#define SPLIT_WIDTH 5 -#define SPLIT_MIN 30 +#define SPLIT_WIDTH 5 +#define SPLIT_MIN 30 #define COUNT_OF(a) (sizeof(a)/sizeof(a[0])) @@ -43,23 +43,26 @@ /******************************************************************************/ -enum OPTION_FLAGS { - OPTIONS_AUTO_REFRESH = 0x01, - OPTIONS_READ_ONLY_MODE = 0x02, - OPTIONS_CONFIRM_ON_DELETE = 0x04, - OPTIONS_SAVE_ON_EXIT = 0x08, - OPTIONS_DISPLAY_BINARY_DATA = 0x10, - OPTIONS_VIEW_TREE_ONLY = 0x20, - OPTIONS_VIEW_DATA_ONLY = 0x40, +enum OPTION_FLAGS +{ + OPTIONS_AUTO_REFRESH = 0x01, + OPTIONS_READ_ONLY_MODE = 0x02, + OPTIONS_CONFIRM_ON_DELETE = 0x04, + OPTIONS_SAVE_ON_EXIT = 0x08, + OPTIONS_DISPLAY_BINARY_DATA = 0x10, + OPTIONS_VIEW_TREE_ONLY = 0x20, + OPTIONS_VIEW_DATA_ONLY = 0x40, }; -typedef struct { +typedef struct +{ HWND hWnd; HWND hTreeWnd; HWND hListWnd; - HWND hAddressBarWnd; + HWND hAddressBarWnd; + HWND hAddressBtnWnd; int nFocusPanel; /* 0: left 1: right */ - int nSplitPos; + int nSplitPos; WINDOWPLACEMENT pos; TCHAR szPath[MAX_PATH]; } ChildWnd; @@ -88,6 +91,9 @@ /* childwnd.c */ extern LRESULT CALLBACK ChildWndProc(HWND, UINT, WPARAM, LPARAM); +/* error.c */ +extern void ErrorMessageBox(HWND hWnd, LPCTSTR title, DWORD code); + /* find.c */ extern void FindDialog(HWND hWnd); extern BOOL FindNext(HWND hWnd); Index: base/applications/regedit/hexedit.c =================================================================== --- base/applications/regedit/hexedit.c (revision 49426) +++ base/applications/regedit/hexedit.c (working copy) @@ -21,45 +21,45 @@ #include typedef struct { - HWND hWndSelf; - HWND hWndParent; - HLOCAL hBuffer; - DWORD style; - DWORD MaxBuffer; - INT ColumnsPerLine; - INT nLines; - INT nVisibleLinesComplete; - INT nVisibleLines; - INT Index; - INT LineHeight; - INT CharWidth; - HFONT hFont; - BOOL SbVisible; + HWND hWndSelf; + HWND hWndParent; + HLOCAL hBuffer; + DWORD style; + DWORD MaxBuffer; + INT ColumnsPerLine; + INT nLines; + INT nVisibleLinesComplete; + INT nVisibleLines; + INT Index; + INT LineHeight; + INT CharWidth; + HFONT hFont; + BOOL SbVisible; - INT LeftMargin; - INT AddressSpacing; - INT SplitSpacing; + INT LeftMargin; + INT AddressSpacing; + INT SplitSpacing; - BOOL EditingField; - INT CaretCol; - INT CaretLine; - BOOL InMid; + BOOL EditingField; + INT CaretCol; + INT CaretLine; + BOOL InMid; - INT SelStart; - INT SelEnd; + INT SelStart; + INT SelEnd; } HEXEDIT_DATA, *PHEXEDIT_DATA; static const TCHAR ClipboardFormatName[] = TEXT("RegEdit_HexData"); static UINT ClipboardFormatID = 0; /* hit test codes */ -#define HEHT_LEFTMARGIN (0x1) -#define HEHT_ADDRESS (0x2) -#define HEHT_ADDRESSSPACING (0x3) -#define HEHT_HEXDUMP (0x4) -#define HEHT_HEXDUMPSPACING (0x5) -#define HEHT_ASCIIDUMP (0x6) -#define HEHT_RIGHTMARGIN (0x7) +#define HEHT_LEFTMARGIN (0x1) +#define HEHT_ADDRESS (0x2) +#define HEHT_ADDRESSSPACING (0x3) +#define HEHT_HEXDUMP (0x4) +#define HEHT_HEXDUMPSPACING (0x5) +#define HEHT_ASCIIDUMP (0x6) +#define HEHT_RIGHTMARGIN (0x7) INT_PTR CALLBACK HexEditWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -67,28 +67,28 @@ WINAPI RegisterHexEditorClass(HINSTANCE hInstance) { - WNDCLASSEX WndClass; + WNDCLASSEX WndClass; - ClipboardFormatID = RegisterClipboardFormat(ClipboardFormatName); + ClipboardFormatID = RegisterClipboardFormat(ClipboardFormatName); - ZeroMemory(&WndClass, sizeof(WNDCLASSEX)); - WndClass.cbSize = sizeof(WNDCLASSEX); - WndClass.style = CS_DBLCLKS; - WndClass.lpfnWndProc = (WNDPROC)HexEditWndProc; - WndClass.cbWndExtra = sizeof(PHEXEDIT_DATA); - WndClass.hInstance = hInstance; - WndClass.hCursor = LoadCursor(0, IDC_IBEAM); - WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - WndClass.lpszClassName = HEX_EDIT_CLASS_NAME; + ZeroMemory(&WndClass, sizeof(WNDCLASSEX)); + WndClass.cbSize = sizeof(WNDCLASSEX); + WndClass.style = CS_DBLCLKS; + WndClass.lpfnWndProc = (WNDPROC)HexEditWndProc; + WndClass.cbWndExtra = sizeof(PHEXEDIT_DATA); + WndClass.hInstance = hInstance; + WndClass.hCursor = LoadCursor(0, IDC_IBEAM); + WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + WndClass.lpszClassName = HEX_EDIT_CLASS_NAME; - return RegisterClassEx(&WndClass); + return RegisterClassEx(&WndClass); } BOOL WINAPI UnregisterHexEditorClass(HINSTANCE hInstance) { - return UnregisterClass(HEX_EDIT_CLASS_NAME, hInstance); + return UnregisterClass(HEX_EDIT_CLASS_NAME, hInstance); } /*** Helper functions *********************************************************/ @@ -96,470 +96,472 @@ static VOID HEXEDIT_MoveCaret(PHEXEDIT_DATA hed, BOOL Scroll) { - SCROLLINFO si; + SCROLLINFO si; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_POS; - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS; + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - if(Scroll) - { - if(si.nPos > hed->CaretLine) + if(Scroll) { - si.nPos = hed->CaretLine; - SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - InvalidateRect(hed->hWndSelf, NULL, TRUE); + if(si.nPos > hed->CaretLine) + { + si.nPos = hed->CaretLine; + SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + InvalidateRect(hed->hWndSelf, NULL, TRUE); + } + else if(hed->CaretLine >= (hed->nVisibleLinesComplete + si.nPos)) + { + si.nPos = hed->CaretLine - hed->nVisibleLinesComplete + 1; + SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + InvalidateRect(hed->hWndSelf, NULL, TRUE); + } } - else if(hed->CaretLine >= (hed->nVisibleLinesComplete + si.nPos)) - { - si.nPos = hed->CaretLine - hed->nVisibleLinesComplete + 1; - SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - InvalidateRect(hed->hWndSelf, NULL, TRUE); - } - } - if(hed->EditingField) - SetCaretPos(hed->LeftMargin + ((4 + hed->AddressSpacing + (3 * hed->CaretCol) + hed->InMid * 2) * hed->CharWidth) - 1, (hed->CaretLine - si.nPos) * hed->LineHeight); - else - SetCaretPos(hed->LeftMargin + ((4 + hed->AddressSpacing + hed->SplitSpacing + (3 * hed->ColumnsPerLine) + hed->CaretCol) * hed->CharWidth) - 2, (hed->CaretLine - si.nPos) * hed->LineHeight); + if(hed->EditingField) + SetCaretPos(hed->LeftMargin + ((4 + hed->AddressSpacing + (3 * hed->CaretCol) + hed->InMid * 2) * hed->CharWidth) - 1, + (hed->CaretLine - si.nPos) * hed->LineHeight); + else + SetCaretPos(hed->LeftMargin + ((4 + hed->AddressSpacing + hed->SplitSpacing + (3 * hed->ColumnsPerLine) + hed->CaretCol) * hed->CharWidth) - 2, + (hed->CaretLine - si.nPos) * hed->LineHeight); } static VOID HEXEDIT_Update(PHEXEDIT_DATA hed) { - SCROLLINFO si; - RECT rcClient; - BOOL SbVisible; - INT bufsize, cvislines; + SCROLLINFO si; + RECT rcClient; + BOOL SbVisible; + INT bufsize, cvislines; - GetClientRect(hed->hWndSelf, &rcClient); - hed->style = GetWindowLongPtr(hed->hWndSelf, GWL_STYLE); + GetClientRect(hed->hWndSelf, &rcClient); + hed->style = GetWindowLongPtr(hed->hWndSelf, GWL_STYLE); - bufsize = (hed->hBuffer ? (INT) LocalSize(hed->hBuffer) : 0); - hed->nLines = max(bufsize / hed->ColumnsPerLine, 1); - if(bufsize > hed->ColumnsPerLine && (bufsize % hed->ColumnsPerLine) > 0) - { - hed->nLines++; - } + bufsize = (hed->hBuffer ? (INT) LocalSize(hed->hBuffer) : 0); + hed->nLines = max(bufsize / hed->ColumnsPerLine, 1); + if(bufsize > hed->ColumnsPerLine && (bufsize % hed->ColumnsPerLine) > 0) + { + hed->nLines++; + } - if(hed->LineHeight > 0) - { - hed->nVisibleLinesComplete = cvislines = rcClient.bottom / hed->LineHeight; - hed->nVisibleLines = hed->nVisibleLinesComplete; - if(rcClient.bottom % hed->LineHeight) + if(hed->LineHeight > 0) { - hed->nVisibleLines++; + hed->nVisibleLinesComplete = cvislines = rcClient.bottom / hed->LineHeight; + hed->nVisibleLines = hed->nVisibleLinesComplete; + if(rcClient.bottom % hed->LineHeight) + { + hed->nVisibleLines++; + } } - } - else - { - hed->nVisibleLines = cvislines = 0; - } + else + { + hed->nVisibleLines = cvislines = 0; + } - SbVisible = bufsize > 0 && cvislines < hed->nLines; - ShowScrollBar(hed->hWndSelf, SB_VERT, SbVisible); + SbVisible = bufsize > 0 && cvislines < hed->nLines; + ShowScrollBar(hed->hWndSelf, SB_VERT, SbVisible); - /* update scrollbar */ - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_RANGE | SIF_PAGE; - si.nMin = 0; - si.nMax = ((bufsize > 0) ? hed->nLines - 1 : 0); - si.nPage = ((hed->LineHeight > 0) ? rcClient.bottom / hed->LineHeight : 0); - SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); + /* update scrollbar */ + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_RANGE | SIF_PAGE; + si.nMin = 0; + si.nMax = ((bufsize > 0) ? hed->nLines - 1 : 0); + si.nPage = ((hed->LineHeight > 0) ? rcClient.bottom / hed->LineHeight : 0); + SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); - if(IsWindowVisible(hed->hWndSelf) && SbVisible != hed->SbVisible) - { - InvalidateRect(hed->hWndSelf, NULL, TRUE); - } + if(IsWindowVisible(hed->hWndSelf) && SbVisible != hed->SbVisible) + { + InvalidateRect(hed->hWndSelf, NULL, TRUE); + } - hed->SbVisible = SbVisible; + hed->SbVisible = SbVisible; } static HFONT HEXEDIT_GetFixedFont(VOID) { - LOGFONT lf; - GetObject(GetStockObject(ANSI_FIXED_FONT), sizeof(LOGFONT), &lf); - return CreateFontIndirect(&lf); + LOGFONT lf; + GetObject(GetStockObject(ANSI_FIXED_FONT), sizeof(LOGFONT), &lf); + return CreateFontIndirect(&lf); } static VOID HEXEDIT_PaintLines(PHEXEDIT_DATA hed, HDC hDC, DWORD ScrollPos, DWORD First, DWORD Last, RECT *rc) { - DWORD dx, dy, linestart; - INT i, isave, i0, i1, x; - PBYTE buf, current, end, line; - size_t bufsize; - TCHAR hex[3], addr[17]; - RECT rct, rct2; + DWORD dx, dy, linestart; + INT i, isave, i0, i1, x; + PBYTE buf, current, end, line; + size_t bufsize; + TCHAR hex[3], addr[17]; + RECT rct, rct2; - FillRect(hDC, rc, (HBRUSH)(COLOR_WINDOW + 1)); - SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); + FillRect(hDC, rc, (HBRUSH)(COLOR_WINDOW + 1)); + SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); - if (hed->SelStart < hed->SelEnd) - { - i0 = hed->SelStart; - i1 = hed->SelEnd; - } - else - { - i0 = hed->SelEnd; - i1 = hed->SelStart; - } + if (hed->SelStart < hed->SelEnd) + { + i0 = hed->SelStart; + i1 = hed->SelEnd; + } + else + { + i0 = hed->SelEnd; + i1 = hed->SelStart; + } - if(hed->hBuffer) - { - bufsize = LocalSize(hed->hBuffer); - buf = LocalLock(hed->hBuffer); - } - else - { - buf = NULL; - bufsize = 0; - - if(ScrollPos + First == 0) + if(hed->hBuffer) { - /* draw address */ - wsprintf(addr, TEXT("%04X"), 0); - TextOut(hDC, hed->LeftMargin, First * hed->LineHeight, addr, 4); + bufsize = LocalSize(hed->hBuffer); + buf = LocalLock(hed->hBuffer); } - } + else + { + buf = NULL; + bufsize = 0; - if(buf) - { - end = buf + bufsize; - dy = First * hed->LineHeight; - linestart = (ScrollPos + First) * hed->ColumnsPerLine; - i = linestart; - current = buf + linestart; - Last = min(hed->nLines - ScrollPos, Last); + if(ScrollPos + First == 0) + { + /* draw address */ + wsprintf(addr, TEXT("%04X"), 0); + TextOut(hDC, hed->LeftMargin, First * hed->LineHeight, addr, 4); + } + } - SetBkMode(hDC, TRANSPARENT); - while(First <= Last && current < end) + if(buf) { - DWORD dh; + end = buf + bufsize; + dy = First * hed->LineHeight; + linestart = (ScrollPos + First) * hed->ColumnsPerLine; + i = linestart; + current = buf + linestart; + Last = min(hed->nLines - ScrollPos, Last); - dx = hed->LeftMargin; + SetBkMode(hDC, TRANSPARENT); + while(First <= Last && current < end) + { + DWORD dh; - /* draw address */ - wsprintf(addr, TEXT("%04lX"), linestart); - TextOut(hDC, dx, dy, addr, 4); + dx = hed->LeftMargin; - dx += ((4 + hed->AddressSpacing) * hed->CharWidth); - dh = (3 * hed->CharWidth); + /* draw address */ + wsprintf(addr, TEXT("%04lX"), linestart); + TextOut(hDC, dx, dy, addr, 4); - rct.left = dx; - rct.top = dy; - rct.right = rct.left + dh; - rct.bottom = dy + hed->LineHeight; + dx += ((4 + hed->AddressSpacing) * hed->CharWidth); + dh = (3 * hed->CharWidth); - /* draw hex map */ - dx += (hed->CharWidth / 2); - line = current; - isave = i; - for(x = 0; x < hed->ColumnsPerLine && current < end; x++) - { - rct.left += dh; - rct.right += dh; + rct.left = dx; + rct.top = dy; + rct.right = rct.left + dh; + rct.bottom = dy + hed->LineHeight; - wsprintf(hex, TEXT("%02X"), *(current++)); - if (i0 <= i && i < i1) - { - rct2.left = dx; - rct2.top = dy; - rct2.right = dx + hed->CharWidth * 2 + 1; - rct2.bottom = dy + hed->LineHeight; - InflateRect(&rct2, hed->CharWidth / 2, 0); - FillRect(hDC, &rct2, (HBRUSH)(COLOR_HIGHLIGHT + 1)); - SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); - ExtTextOut(hDC, dx, dy, 0, &rct, hex, 2, NULL); - SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); - } - else - ExtTextOut(hDC, dx, dy, ETO_OPAQUE, &rct, hex, 2, NULL); - dx += dh; - i++; - } + /* draw hex map */ + dx += (hed->CharWidth / 2); + line = current; + isave = i; + for(x = 0; x < hed->ColumnsPerLine && current < end; x++) + { + rct.left += dh; + rct.right += dh; - /* draw ascii map */ - dx = ((4 + hed->AddressSpacing + hed->SplitSpacing + (hed->ColumnsPerLine * 3)) * hed->CharWidth); - current = line; - i = isave; - for(x = 0; x < hed->ColumnsPerLine && current < end; x++) - { - wsprintf(hex, _T("%C"), *(current++)); - hex[0] = ((hex[0] & _T('\x007f')) >= _T(' ') ? hex[0] : _T('.')); - if (i0 <= i && i < i1) - { - rct2.left = dx; - rct2.top = dy; - rct2.right = dx + hed->CharWidth; - rct2.bottom = dy + hed->LineHeight; - FillRect(hDC, &rct2, (HBRUSH)(COLOR_HIGHLIGHT + 1)); - SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); - TextOut(hDC, dx, dy, hex, 1); - SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); + wsprintf(hex, TEXT("%02X"), *(current++)); + if (i0 <= i && i < i1) + { + rct2.left = dx; + rct2.top = dy; + rct2.right = dx + hed->CharWidth * 2 + 1; + rct2.bottom = dy + hed->LineHeight; + InflateRect(&rct2, hed->CharWidth / 2, 0); + FillRect(hDC, &rct2, (HBRUSH)(COLOR_HIGHLIGHT + 1)); + SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); + ExtTextOut(hDC, dx, dy, 0, &rct, hex, 2, NULL); + SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); + } + else + ExtTextOut(hDC, dx, dy, ETO_OPAQUE, &rct, hex, 2, NULL); + dx += dh; + i++; + } + + /* draw ascii map */ + dx = ((4 + hed->AddressSpacing + hed->SplitSpacing + (hed->ColumnsPerLine * 3)) * hed->CharWidth); + current = line; + i = isave; + for(x = 0; x < hed->ColumnsPerLine && current < end; x++) + { + wsprintf(hex, _T("%C"), *(current++)); + hex[0] = ((hex[0] & _T('\x007f')) >= _T(' ') ? hex[0] : _T('.')); + if (i0 <= i && i < i1) + { + rct2.left = dx; + rct2.top = dy; + rct2.right = dx + hed->CharWidth; + rct2.bottom = dy + hed->LineHeight; + FillRect(hDC, &rct2, (HBRUSH)(COLOR_HIGHLIGHT + 1)); + SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); + TextOut(hDC, dx, dy, hex, 1); + SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT)); + } + else + TextOut(hDC, dx, dy, hex, 1); + dx += hed->CharWidth; + i++; + } + + dy += hed->LineHeight; + linestart += hed->ColumnsPerLine; + First++; } - else - TextOut(hDC, dx, dy, hex, 1); - dx += hed->CharWidth; - i++; - } - - dy += hed->LineHeight; - linestart += hed->ColumnsPerLine; - First++; } - } - LocalUnlock(hed->hBuffer); + LocalUnlock(hed->hBuffer); } static DWORD HEXEDIT_HitRegionTest(PHEXEDIT_DATA hed, POINTS pt) { - int d; + int d; - if(pt.x <= hed->LeftMargin) - { - return HEHT_LEFTMARGIN; - } + if(pt.x <= hed->LeftMargin) + { + return HEHT_LEFTMARGIN; + } - pt.x -= hed->LeftMargin; - d = (4 * hed->CharWidth); - if(pt.x <= d) - { - return HEHT_ADDRESS; - } + pt.x -= hed->LeftMargin; + d = (4 * hed->CharWidth); + if(pt.x <= d) + { + return HEHT_ADDRESS; + } - pt.x -= d; - d = (hed->AddressSpacing * hed->CharWidth); - if(pt.x <= d) - { - return HEHT_ADDRESSSPACING; - } + pt.x -= d; + d = (hed->AddressSpacing * hed->CharWidth); + if(pt.x <= d) + { + return HEHT_ADDRESSSPACING; + } - pt.x -= d; - d = ((3 * hed->ColumnsPerLine + 1) * hed->CharWidth); - if(pt.x <= d) - { - return HEHT_HEXDUMP; - } + pt.x -= d; + d = ((3 * hed->ColumnsPerLine + 1) * hed->CharWidth); + if(pt.x <= d) + { + return HEHT_HEXDUMP; + } - pt.x -= d; - d = ((hed->SplitSpacing - 1) * hed->CharWidth); - if(pt.x <= d) - { - return HEHT_HEXDUMPSPACING; - } + pt.x -= d; + d = ((hed->SplitSpacing - 1) * hed->CharWidth); + if(pt.x <= d) + { + return HEHT_HEXDUMPSPACING; + } - pt.x -= d; - d = (hed->ColumnsPerLine * hed->CharWidth); - if(pt.x <= d) - { - return HEHT_ASCIIDUMP; - } + pt.x -= d; + d = (hed->ColumnsPerLine * hed->CharWidth); + if(pt.x <= d) + { + return HEHT_ASCIIDUMP; + } - return HEHT_RIGHTMARGIN; + return HEHT_RIGHTMARGIN; } static DWORD HEXEDIT_IndexFromPoint(PHEXEDIT_DATA hed, POINTS pt, DWORD Hit, POINT *EditPos, BOOL *EditField) { - SCROLLINFO si; - DWORD Index, bufsize; + SCROLLINFO si; + DWORD Index, bufsize; - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_POS; - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS; + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - EditPos->x = 0; + EditPos->x = 0; - if(hed->LineHeight > 0) - { - EditPos->y = min(si.nPos + (pt.y / hed->LineHeight), hed->nLines - 1); - } - else - { - EditPos->y = si.nPos; - } + if(hed->LineHeight > 0) + { + EditPos->y = min(si.nPos + (pt.y / hed->LineHeight), hed->nLines - 1); + } + else + { + EditPos->y = si.nPos; + } - switch(Hit) - { + switch(Hit) + { case HEHT_LEFTMARGIN: case HEHT_ADDRESS: case HEHT_ADDRESSSPACING: case HEHT_HEXDUMP: - pt.x -= (SHORT) hed->LeftMargin + ((4 + hed->AddressSpacing) * hed->CharWidth); - *EditField = TRUE; - break; + pt.x -= (SHORT) hed->LeftMargin + ((4 + hed->AddressSpacing) * hed->CharWidth); + *EditField = TRUE; + break; default: - pt.x -= hed->LeftMargin + ((4 + hed->AddressSpacing + hed->SplitSpacing + (3 * hed->ColumnsPerLine)) * hed->CharWidth); - *EditField = FALSE; - break; - } + pt.x -= hed->LeftMargin + ((4 + hed->AddressSpacing + hed->SplitSpacing + (3 * hed->ColumnsPerLine)) * hed->CharWidth); + *EditField = FALSE; + break; + } - if(pt.x > 0) - { - INT BlockWidth = (*EditField ? hed->CharWidth * 3 : hed->CharWidth); - EditPos->x = min(hed->ColumnsPerLine, (pt.x + BlockWidth / 2) / BlockWidth); - } + if(pt.x > 0) + { + INT BlockWidth = (*EditField ? hed->CharWidth * 3 : hed->CharWidth); + EditPos->x = min(hed->ColumnsPerLine, (pt.x + BlockWidth / 2) / BlockWidth); + } - bufsize = (hed->hBuffer ? (DWORD) LocalSize(hed->hBuffer) : 0); - Index = (EditPos->y * hed->ColumnsPerLine) + EditPos->x; - if(Index > bufsize) - { - INT tmp = bufsize % hed->ColumnsPerLine; - Index = bufsize; - EditPos->x = (tmp == 0 ? hed->ColumnsPerLine : tmp); - } - return Index; + bufsize = (hed->hBuffer ? (DWORD) LocalSize(hed->hBuffer) : 0); + Index = (EditPos->y * hed->ColumnsPerLine) + EditPos->x; + if(Index > bufsize) + { + INT tmp = bufsize % hed->ColumnsPerLine; + Index = bufsize; + EditPos->x = (tmp == 0 ? hed->ColumnsPerLine : tmp); + } + return Index; } static VOID HEXEDIT_Copy(PHEXEDIT_DATA hed) { - PBYTE pb, buf; - UINT cb; - INT i0, i1; - HGLOBAL hGlobal; + PBYTE pb, buf; + UINT cb; + INT i0, i1; + HGLOBAL hGlobal; - if (hed->SelStart < hed->SelEnd) - { - i0 = hed->SelStart; - i1 = hed->SelEnd; - } - else - { - i0 = hed->SelEnd; - i1 = hed->SelStart; - } + if (hed->SelStart < hed->SelEnd) + { + i0 = hed->SelStart; + i1 = hed->SelEnd; + } + else + { + i0 = hed->SelEnd; + i1 = hed->SelStart; + } - cb = i1 - i0; - if (cb == 0) - return; + cb = i1 - i0; + if (cb == 0) + return; - hGlobal = GlobalAlloc(GHND | GMEM_SHARE, cb + sizeof(DWORD)); - if (hGlobal == NULL) - return; + hGlobal = GlobalAlloc(GHND | GMEM_SHARE, cb + sizeof(DWORD)); + if (hGlobal == NULL) + return; - pb = GlobalLock(hGlobal); - if (pb) - { - *(PDWORD)pb = cb; - pb += sizeof(DWORD); - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + pb = GlobalLock(hGlobal); + if (pb) { - CopyMemory(pb, buf + i0, cb); - LocalUnlock(hed->hBuffer); - } - GlobalUnlock(hGlobal); + *(PDWORD)pb = cb; + pb += sizeof(DWORD); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + CopyMemory(pb, buf + i0, cb); + LocalUnlock(hed->hBuffer); + } + GlobalUnlock(hGlobal); - if (OpenClipboard(hed->hWndSelf)) - { - EmptyClipboard(); - SetClipboardData(ClipboardFormatID, hGlobal); - CloseClipboard(); + if (OpenClipboard(hed->hWndSelf)) + { + EmptyClipboard(); + SetClipboardData(ClipboardFormatID, hGlobal); + CloseClipboard(); + } } - } - else - GlobalFree(hGlobal); + else + GlobalFree(hGlobal); } static VOID HEXEDIT_Delete(PHEXEDIT_DATA hed) { - PBYTE buf; - INT i0, i1; - UINT bufsize; + PBYTE buf; + INT i0, i1; + UINT bufsize; - if (hed->SelStart < hed->SelEnd) - { - i0 = hed->SelStart; - i1 = hed->SelEnd; - } - else - { - i0 = hed->SelEnd; - i1 = hed->SelStart; - } + if (hed->SelStart < hed->SelEnd) + { + i0 = hed->SelStart; + i1 = hed->SelEnd; + } + else + { + i0 = hed->SelEnd; + i1 = hed->SelStart; + } - if (i0 != i1) - { - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + if (i0 != i1) { - MoveMemory(buf + i0, buf + i1, bufsize - i1); - LocalUnlock(hed->hBuffer); + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + i0, buf + i1, bufsize - i1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); + hed->InMid = FALSE; + hed->Index = hed->SelStart = hed->SelEnd = i0; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); - hed->InMid = FALSE; - hed->Index = hed->SelStart = hed->SelEnd = i0; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - } } static VOID HEXEDIT_Paste(PHEXEDIT_DATA hed) { - HGLOBAL hGlobal; - UINT bufsize; - PBYTE pb, buf; - DWORD cb; + HGLOBAL hGlobal; + UINT bufsize; + PBYTE pb, buf; + DWORD cb; - HEXEDIT_Delete(hed); - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + HEXEDIT_Delete(hed); + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - if (OpenClipboard(hed->hWndSelf)) - { - hGlobal = GetClipboardData(ClipboardFormatID); - if (hGlobal != NULL) + if (OpenClipboard(hed->hWndSelf)) { - pb = (PBYTE) GlobalLock(hGlobal); - cb = *(PDWORD) pb; - pb += sizeof(DWORD); - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + cb); - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index + cb, buf + hed->Index, - bufsize - hed->Index); - CopyMemory(buf + hed->Index, pb, cb); - LocalUnlock(hed->hBuffer); - } - GlobalUnlock(hGlobal); + hGlobal = GetClipboardData(ClipboardFormatID); + if (hGlobal != NULL) + { + pb = (PBYTE) GlobalLock(hGlobal); + cb = *(PDWORD) pb; + pb += sizeof(DWORD); + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + cb); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index + cb, buf + hed->Index, + bufsize - hed->Index); + CopyMemory(buf + hed->Index, pb, cb); + LocalUnlock(hed->hBuffer); + } + GlobalUnlock(hGlobal); + } + CloseClipboard(); } - CloseClipboard(); - } - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } static VOID HEXEDIT_Cut(PHEXEDIT_DATA hed) { - HEXEDIT_Copy(hed); - HEXEDIT_Delete(hed); + HEXEDIT_Copy(hed); + HEXEDIT_Delete(hed); } static VOID HEXEDIT_SelectAll(PHEXEDIT_DATA hed) { - INT bufsize; + INT bufsize; - bufsize = (hed->hBuffer ? (INT) LocalSize(hed->hBuffer) : 0); - hed->Index = hed->SelStart = 0; - hed->SelEnd = bufsize; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); + bufsize = (hed->hBuffer ? (INT) LocalSize(hed->hBuffer) : 0); + hed->Index = hed->SelStart = 0; + hed->SelEnd = bufsize; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } /*** Control specific messages ************************************************/ @@ -567,111 +569,111 @@ static LRESULT HEXEDIT_HEM_LOADBUFFER(PHEXEDIT_DATA hed, PVOID Buffer, DWORD Size) { - if(Buffer != NULL && Size > 0) - { - LPVOID buf; - - if(hed->MaxBuffer > 0 && Size > hed->MaxBuffer) + if(Buffer != NULL && Size > 0) { - Size = hed->MaxBuffer; - } + LPVOID buf; - if(hed->hBuffer) - { - if(Size > 0) - { - if(LocalSize(hed->hBuffer) != Size) + if(hed->MaxBuffer > 0 && Size > hed->MaxBuffer) { - hed->hBuffer = LocalReAlloc(hed->hBuffer, Size, LMEM_MOVEABLE | LMEM_ZEROINIT); + Size = hed->MaxBuffer; } - } - else - { - hed->hBuffer = LocalFree(hed->hBuffer); + + if(hed->hBuffer) + { + if(Size > 0) + { + if(LocalSize(hed->hBuffer) != Size) + { + hed->hBuffer = LocalReAlloc(hed->hBuffer, Size, LMEM_MOVEABLE | LMEM_ZEROINIT); + } + } + else + { + hed->hBuffer = LocalFree(hed->hBuffer); + hed->Index = 0; + HEXEDIT_Update(hed); + + return 0; + } + } + else if(Size > 0) + { + hed->hBuffer = LocalAlloc(LHND, Size); + } + + if(Size > 0) + { + buf = LocalLock(hed->hBuffer); + if(buf) + { + memcpy(buf, Buffer, Size); + } + else + Size = 0; + LocalUnlock(hed->hBuffer); + } + hed->Index = 0; HEXEDIT_Update(hed); - - return 0; - } + return Size; } - else if(Size > 0) + else if(hed->hBuffer) { - hed->hBuffer = LocalAlloc(LHND, Size); + hed->Index = 0; + hed->hBuffer = LocalFree(hed->hBuffer); + HEXEDIT_Update(hed); } - if(Size > 0) - { - buf = LocalLock(hed->hBuffer); - if(buf) - { - memcpy(buf, Buffer, Size); - } - else - Size = 0; - LocalUnlock(hed->hBuffer); - } - - hed->Index = 0; - HEXEDIT_Update(hed); - return Size; - } - else if(hed->hBuffer) - { - hed->Index = 0; - hed->hBuffer = LocalFree(hed->hBuffer); - HEXEDIT_Update(hed); - } - - return 0; + return 0; } static LRESULT HEXEDIT_HEM_COPYBUFFER(PHEXEDIT_DATA hed, PVOID Buffer, DWORD Size) { - size_t nCpy; + size_t nCpy; - if(!hed->hBuffer) - { - return 0; - } + if(!hed->hBuffer) + { + return 0; + } - if(Buffer != NULL && Size > 0) - { - nCpy = min(Size, LocalSize(hed->hBuffer)); - if(nCpy > 0) + if(Buffer != NULL && Size > 0) { - PVOID buf; + nCpy = min(Size, LocalSize(hed->hBuffer)); + if(nCpy > 0) + { + PVOID buf; - buf = LocalLock(hed->hBuffer); - if(buf) - { - memcpy(Buffer, buf, nCpy); - } - else - nCpy = 0; - LocalUnlock(hed->hBuffer); + buf = LocalLock(hed->hBuffer); + if(buf) + { + memcpy(Buffer, buf, nCpy); + } + else + nCpy = 0; + LocalUnlock(hed->hBuffer); + } + return nCpy; } - return nCpy; - } - return (LRESULT)LocalSize(hed->hBuffer); + return (LRESULT)LocalSize(hed->hBuffer); } static LRESULT HEXEDIT_HEM_SETMAXBUFFERSIZE(PHEXEDIT_DATA hed, DWORD nMaxSize) { - hed->MaxBuffer = nMaxSize; - if (hed->MaxBuffer == 0) - { - hed->hBuffer = LocalFree(hed->hBuffer); + hed->MaxBuffer = nMaxSize; + if (hed->MaxBuffer == 0) + { + hed->hBuffer = LocalFree(hed->hBuffer); + return 0; + } + if (hed->hBuffer) + hed->hBuffer = LocalReAlloc(hed->hBuffer, hed->MaxBuffer, LMEM_MOVEABLE); + else + hed->hBuffer = LocalAlloc(LMEM_MOVEABLE, hed->MaxBuffer); + HEXEDIT_Update(hed); return 0; - } - if (hed->hBuffer) - hed->hBuffer = LocalReAlloc(hed->hBuffer, hed->MaxBuffer, LMEM_MOVEABLE); - else - hed->hBuffer = LocalAlloc(LMEM_MOVEABLE, hed->MaxBuffer); - HEXEDIT_Update(hed); - return 0; } /*** Message Proc *************************************************************/ @@ -679,875 +681,876 @@ static LRESULT HEXEDIT_WM_NCCREATE(HWND hWnd, CREATESTRUCT *cs) { - PHEXEDIT_DATA hed; + PHEXEDIT_DATA hed; - if(!(hed = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEXEDIT_DATA)))) - { - return FALSE; - } + if(!(hed = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HEXEDIT_DATA)))) + { + return FALSE; + } - hed->hWndSelf = hWnd; - hed->hWndParent = cs->hwndParent; - hed->style = cs->style; + hed->hWndSelf = hWnd; + hed->hWndParent = cs->hwndParent; + hed->style = cs->style; - hed->ColumnsPerLine = 8; - hed->LeftMargin = 2; - hed->AddressSpacing = 2; - hed->SplitSpacing = 2; - hed->EditingField = TRUE; /* in hexdump field */ + hed->ColumnsPerLine = 8; + hed->LeftMargin = 2; + hed->AddressSpacing = 2; + hed->SplitSpacing = 2; + hed->EditingField = TRUE; /* in hexdump field */ - SetWindowLongPtr(hWnd, 0, (DWORD_PTR)hed); - HEXEDIT_Update(hed); + SetWindowLongPtr(hWnd, 0, (DWORD_PTR)hed); + HEXEDIT_Update(hed); - return TRUE; + return TRUE; } static LRESULT HEXEDIT_WM_NCDESTROY(PHEXEDIT_DATA hed) { - if(hed->hBuffer) - { - //while(LocalUnlock(hed->hBuffer)); - LocalFree(hed->hBuffer); - } + if(hed->hBuffer) + { + //while(LocalUnlock(hed->hBuffer)); + LocalFree(hed->hBuffer); + } - if(hed->hFont) - { - DeleteObject(hed->hFont); - } + if(hed->hFont) + { + DeleteObject(hed->hFont); + } - SetWindowLongPtr(hed->hWndSelf, 0, (DWORD_PTR)0); - HeapFree(GetProcessHeap(), 0, hed); + SetWindowLongPtr(hed->hWndSelf, 0, (DWORD_PTR)0); + HeapFree(GetProcessHeap(), 0, hed); - return 0; + return 0; } static LRESULT HEXEDIT_WM_CREATE(PHEXEDIT_DATA hed) { - UNREFERENCED_PARAMETER(hed); - return 1; + UNREFERENCED_PARAMETER(hed); + return 1; } static LRESULT HEXEDIT_WM_SETFOCUS(PHEXEDIT_DATA hed) { - CreateCaret(hed->hWndSelf, 0, 1, hed->LineHeight); - HEXEDIT_MoveCaret(hed, FALSE); - ShowCaret(hed->hWndSelf); - return 0; + CreateCaret(hed->hWndSelf, 0, 1, hed->LineHeight); + HEXEDIT_MoveCaret(hed, FALSE); + ShowCaret(hed->hWndSelf); + return 0; } static LRESULT HEXEDIT_WM_KILLFOCUS(PHEXEDIT_DATA hed) { - UNREFERENCED_PARAMETER(hed); - DestroyCaret(); - return 0; + UNREFERENCED_PARAMETER(hed); + DestroyCaret(); + return 0; } static LRESULT HEXEDIT_WM_VSCROLL(PHEXEDIT_DATA hed, WORD ThumbPosition, WORD SbCmd) { - int ScrollY; - SCROLLINFO si; + int ScrollY; + SCROLLINFO si; - UNREFERENCED_PARAMETER(ThumbPosition); + UNREFERENCED_PARAMETER(ThumbPosition); - ZeroMemory(&si, sizeof(SCROLLINFO)); - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_ALL; - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + ZeroMemory(&si, sizeof(SCROLLINFO)); + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_ALL; + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - ScrollY = si.nPos; - switch(SbCmd) - { + ScrollY = si.nPos; + switch(SbCmd) + { case SB_TOP: - si.nPos = si.nMin; - break; + si.nPos = si.nMin; + break; case SB_BOTTOM: - si.nPos = si.nMax; - break; + si.nPos = si.nMax; + break; case SB_LINEUP: - si.nPos--; - break; + si.nPos--; + break; case SB_LINEDOWN: - si.nPos++; - break; + si.nPos++; + break; case SB_PAGEUP: - si.nPos -= si.nPage; - break; + si.nPos -= si.nPage; + break; case SB_PAGEDOWN: - si.nPos += si.nPage; - break; + si.nPos += si.nPage; + break; case SB_THUMBTRACK: - si.nPos = si.nTrackPos; - break; - } + si.nPos = si.nTrackPos; + break; + } - si.fMask = SIF_POS; - SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + si.fMask = SIF_POS; + SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - if(si.nPos != ScrollY) - { - ScrollWindow(hed->hWndSelf, 0, (ScrollY - si.nPos) * hed->LineHeight, NULL, NULL); - UpdateWindow(hed->hWndSelf); - } + if(si.nPos != ScrollY) + { + ScrollWindow(hed->hWndSelf, 0, (ScrollY - si.nPos) * hed->LineHeight, NULL, NULL); + UpdateWindow(hed->hWndSelf); + } - return 0; + return 0; } static LRESULT HEXEDIT_WM_SETFONT(PHEXEDIT_DATA hed, HFONT hFont, BOOL bRedraw) { - HDC hDC; - TEXTMETRIC tm; - HFONT hOldFont = 0; + HDC hDC; + TEXTMETRIC tm; + HFONT hOldFont = 0; - if(hFont == 0) - { - hFont = HEXEDIT_GetFixedFont(); - } + if(hFont == 0) + { + hFont = HEXEDIT_GetFixedFont(); + } - hed->hFont = hFont; - hDC = GetDC(hed->hWndSelf); - if(hFont) - { - hOldFont = SelectObject(hDC, hFont); - } - GetTextMetrics(hDC, &tm); - hed->LineHeight = tm.tmHeight; - hed->CharWidth = tm.tmAveCharWidth; - if(hOldFont) - { - SelectObject(hDC, hOldFont); - } - ReleaseDC(hed->hWndSelf, hDC); + hed->hFont = hFont; + hDC = GetDC(hed->hWndSelf); + if(hFont) + { + hOldFont = SelectObject(hDC, hFont); + } + GetTextMetrics(hDC, &tm); + hed->LineHeight = tm.tmHeight; + hed->CharWidth = tm.tmAveCharWidth; + if(hOldFont) + { + SelectObject(hDC, hOldFont); + } + ReleaseDC(hed->hWndSelf, hDC); - if(bRedraw) - { - InvalidateRect(hed->hWndSelf, NULL, TRUE); - } + if(bRedraw) + { + InvalidateRect(hed->hWndSelf, NULL, TRUE); + } - return 0; + return 0; } static LRESULT HEXEDIT_WM_GETFONT(PHEXEDIT_DATA hed) { - return (LRESULT)hed->hFont; + return (LRESULT)hed->hFont; } static LRESULT HEXEDIT_WM_PAINT(PHEXEDIT_DATA hed) { - PAINTSTRUCT ps; - SCROLLINFO si; - RECT rc; - HBITMAP hbmp, hbmpold; - INT nLines, nFirst; - HFONT hOldFont; - HDC hTempDC; - DWORD height; + PAINTSTRUCT ps; + SCROLLINFO si; + RECT rc; + HBITMAP hbmp, hbmpold; + INT nLines, nFirst; + HFONT hOldFont; + HDC hTempDC; + DWORD height; - if(GetUpdateRect(hed->hWndSelf, &rc, FALSE) && (hed->LineHeight > 0)) - { - ZeroMemory(&si, sizeof(SCROLLINFO)); - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_POS; - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - - height = (rc.bottom - rc.top); - nLines = height / hed->LineHeight; - if((height % hed->LineHeight) > 0) + if(GetUpdateRect(hed->hWndSelf, &rc, FALSE) && (hed->LineHeight > 0)) { - nLines++; - } - if(nLines > hed->nLines - si.nPos) - { - nLines = hed->nLines - si.nPos; - } - nFirst = rc.top / hed->LineHeight; + ZeroMemory(&si, sizeof(SCROLLINFO)); + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_POS; + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - BeginPaint(hed->hWndSelf, &ps); - if(!(hTempDC = CreateCompatibleDC(ps.hdc))) - { - FillRect(ps.hdc, &rc, (HBRUSH)(COLOR_WINDOW + 1)); - goto epaint; - } - if(!(hbmp = CreateCompatibleBitmap(ps.hdc, ps.rcPaint.right, ps.rcPaint.bottom))) - { - FillRect(ps.hdc, &rc, (HBRUSH)(COLOR_WINDOW + 1)); - DeleteDC(hTempDC); - goto epaint; - } - hbmpold = SelectObject(hTempDC, hbmp); - hOldFont = SelectObject(hTempDC, hed->hFont); - HEXEDIT_PaintLines(hed, hTempDC, si.nPos, nFirst, nFirst + nLines, &ps.rcPaint); - BitBlt(ps.hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hTempDC, rc.left, rc.top, SRCCOPY); - SelectObject(hTempDC, hOldFont); - SelectObject(hTempDC, hbmpold); + height = (rc.bottom - rc.top); + nLines = height / hed->LineHeight; + if((height % hed->LineHeight) > 0) + { + nLines++; + } + if(nLines > hed->nLines - si.nPos) + { + nLines = hed->nLines - si.nPos; + } + nFirst = rc.top / hed->LineHeight; - DeleteObject(hbmp); - DeleteDC(hTempDC); + BeginPaint(hed->hWndSelf, &ps); + if(!(hTempDC = CreateCompatibleDC(ps.hdc))) + { + FillRect(ps.hdc, &rc, (HBRUSH)(COLOR_WINDOW + 1)); + goto epaint; + } + if(!(hbmp = CreateCompatibleBitmap(ps.hdc, ps.rcPaint.right, ps.rcPaint.bottom))) + { + FillRect(ps.hdc, &rc, (HBRUSH)(COLOR_WINDOW + 1)); + DeleteDC(hTempDC); + goto epaint; + } + hbmpold = SelectObject(hTempDC, hbmp); + hOldFont = SelectObject(hTempDC, hed->hFont); + HEXEDIT_PaintLines(hed, hTempDC, si.nPos, nFirst, nFirst + nLines, &ps.rcPaint); + BitBlt(ps.hdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, + hTempDC, rc.left, rc.top, SRCCOPY); + SelectObject(hTempDC, hOldFont); + SelectObject(hTempDC, hbmpold); + DeleteObject(hbmp); + DeleteDC(hTempDC); + epaint: - EndPaint(hed->hWndSelf, &ps); - } + EndPaint(hed->hWndSelf, &ps); + } - return 0; + return 0; } static LRESULT HEXEDIT_WM_MOUSEWHEEL(PHEXEDIT_DATA hed, int cyMoveLines, WORD ButtonsDown, LPPOINTS MousePos) { - SCROLLINFO si; - int ScrollY; + SCROLLINFO si; + int ScrollY; - UNREFERENCED_PARAMETER(ButtonsDown); - UNREFERENCED_PARAMETER(MousePos); + UNREFERENCED_PARAMETER(ButtonsDown); + UNREFERENCED_PARAMETER(MousePos); - SetFocus(hed->hWndSelf); + SetFocus(hed->hWndSelf); - si.cbSize = sizeof(SCROLLINFO); - si.fMask = SIF_ALL; - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + si.cbSize = sizeof(SCROLLINFO); + si.fMask = SIF_ALL; + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - ScrollY = si.nPos; + ScrollY = si.nPos; - si.fMask = SIF_POS; - si.nPos += cyMoveLines; - SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); + si.fMask = SIF_POS; + si.nPos += cyMoveLines; + SetScrollInfo(hed->hWndSelf, SB_VERT, &si, TRUE); - GetScrollInfo(hed->hWndSelf, SB_VERT, &si); - if(si.nPos != ScrollY) - { - ScrollWindow(hed->hWndSelf, 0, (ScrollY - si.nPos) * hed->LineHeight, NULL, NULL); - UpdateWindow(hed->hWndSelf); - } + GetScrollInfo(hed->hWndSelf, SB_VERT, &si); + if(si.nPos != ScrollY) + { + ScrollWindow(hed->hWndSelf, 0, (ScrollY - si.nPos) * hed->LineHeight, NULL, NULL); + UpdateWindow(hed->hWndSelf); + } - return 0; + return 0; } static LRESULT HEXEDIT_WM_GETDLGCODE(LPMSG Msg) { - UNREFERENCED_PARAMETER(Msg); - return DLGC_WANTARROWS | DLGC_WANTCHARS; + UNREFERENCED_PARAMETER(Msg); + return DLGC_WANTARROWS | DLGC_WANTCHARS; } static LRESULT HEXEDIT_WM_LBUTTONDOWN(PHEXEDIT_DATA hed, INT Buttons, POINTS Pt) { - BOOL NewField; - POINT EditPos; - DWORD Hit; + BOOL NewField; + POINT EditPos; + DWORD Hit; - UNREFERENCED_PARAMETER(Buttons); - SetFocus(hed->hWndSelf); + UNREFERENCED_PARAMETER(Buttons); + SetFocus(hed->hWndSelf); - if (GetAsyncKeyState(VK_SHIFT) < 0) - { - if (hed->EditingField) - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); + if (GetAsyncKeyState(VK_SHIFT) < 0) + { + if (hed->EditingField) + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); + else + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); + hed->SelEnd = hed->Index; + } else - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); - hed->SelEnd = hed->Index; - } - else - { - Hit = HEXEDIT_HitRegionTest(hed, Pt); - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, Hit, &EditPos, &NewField); - hed->SelStart = hed->SelEnd = hed->Index; - hed->EditingField = NewField; - SetCapture(hed->hWndSelf); - } - hed->CaretCol = EditPos.x; - hed->CaretLine = EditPos.y; - hed->InMid = FALSE; - InvalidateRect(hed->hWndSelf, NULL, FALSE); - HEXEDIT_MoveCaret(hed, TRUE); + { + Hit = HEXEDIT_HitRegionTest(hed, Pt); + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, Hit, &EditPos, &NewField); + hed->SelStart = hed->SelEnd = hed->Index; + hed->EditingField = NewField; + SetCapture(hed->hWndSelf); + } + hed->CaretCol = EditPos.x; + hed->CaretLine = EditPos.y; + hed->InMid = FALSE; + InvalidateRect(hed->hWndSelf, NULL, FALSE); + HEXEDIT_MoveCaret(hed, TRUE); - return 0; + return 0; } static LRESULT HEXEDIT_WM_LBUTTONUP(PHEXEDIT_DATA hed, INT Buttons, POINTS Pt) { - BOOL NewField; - POINT EditPos; - if (GetCapture() == hed->hWndSelf) - { - if (hed->EditingField) - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); - else - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); - hed->CaretCol = EditPos.x; - hed->CaretLine = EditPos.y; - hed->SelEnd = hed->Index; - ReleaseCapture(); - InvalidateRect(hed->hWndSelf, NULL, FALSE); - HEXEDIT_MoveCaret(hed, TRUE); - } - return 0; + BOOL NewField; + POINT EditPos; + if (GetCapture() == hed->hWndSelf) + { + if (hed->EditingField) + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); + else + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); + hed->CaretCol = EditPos.x; + hed->CaretLine = EditPos.y; + hed->SelEnd = hed->Index; + ReleaseCapture(); + InvalidateRect(hed->hWndSelf, NULL, FALSE); + HEXEDIT_MoveCaret(hed, TRUE); + } + return 0; } static LRESULT HEXEDIT_WM_MOUSEMOVE(PHEXEDIT_DATA hed, INT Buttons, POINTS Pt) { - BOOL NewField; - POINT EditPos; - if (GetCapture() == hed->hWndSelf) - { - if (hed->EditingField) - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); - else - hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); - hed->CaretCol = EditPos.x; - hed->CaretLine = EditPos.y; - hed->SelEnd = hed->Index; - InvalidateRect(hed->hWndSelf, NULL, FALSE); - HEXEDIT_MoveCaret(hed, TRUE); - } - return 0; + BOOL NewField; + POINT EditPos; + if (GetCapture() == hed->hWndSelf) + { + if (hed->EditingField) + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_HEXDUMP, &EditPos, &NewField); + else + hed->Index = HEXEDIT_IndexFromPoint(hed, Pt, HEHT_ASCIIDUMP, &EditPos, &NewField); + hed->CaretCol = EditPos.x; + hed->CaretLine = EditPos.y; + hed->SelEnd = hed->Index; + InvalidateRect(hed->hWndSelf, NULL, FALSE); + HEXEDIT_MoveCaret(hed, TRUE); + } + return 0; } static BOOL HEXEDIT_WM_KEYDOWN(PHEXEDIT_DATA hed, INT VkCode) { - size_t bufsize; - PBYTE buf; - INT i0, i1; + size_t bufsize; + PBYTE buf; + INT i0, i1; - if(GetKeyState(VK_MENU) & 0x8000) - { - return FALSE; - } + if(GetKeyState(VK_MENU) & 0x8000) + { + return FALSE; + } - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - if (hed->SelStart < hed->SelEnd) - { - i0 = hed->SelStart; - i1 = hed->SelEnd; - } - else - { - i0 = hed->SelEnd; - i1 = hed->SelStart; - } + if (hed->SelStart < hed->SelEnd) + { + i0 = hed->SelStart; + i1 = hed->SelEnd; + } + else + { + i0 = hed->SelEnd; + i1 = hed->SelStart; + } - switch(VkCode) - { + switch(VkCode) + { case 'X': - if (GetAsyncKeyState(VK_SHIFT) >= 0 && - GetAsyncKeyState(VK_CONTROL) < 0 && hed->SelStart != hed->SelEnd) - HEXEDIT_Cut(hed); - else - return TRUE; - break; + if (GetAsyncKeyState(VK_SHIFT) >= 0 && + GetAsyncKeyState(VK_CONTROL) < 0 && hed->SelStart != hed->SelEnd) + HEXEDIT_Cut(hed); + else + return TRUE; + break; case 'C': - if (GetAsyncKeyState(VK_SHIFT) >= 0 && - GetAsyncKeyState(VK_CONTROL) < 0 && hed->SelStart != hed->SelEnd) - HEXEDIT_Copy(hed); - else - return TRUE; - break; + if (GetAsyncKeyState(VK_SHIFT) >= 0 && + GetAsyncKeyState(VK_CONTROL) < 0 && hed->SelStart != hed->SelEnd) + HEXEDIT_Copy(hed); + else + return TRUE; + break; case 'V': - if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) - HEXEDIT_Paste(hed); - else - return TRUE; - break; + if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) + HEXEDIT_Paste(hed); + else + return TRUE; + break; case 'A': - if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) - HEXEDIT_SelectAll(hed); - else - return TRUE; - break; + if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) + HEXEDIT_SelectAll(hed); + else + return TRUE; + break; case VK_INSERT: - if (hed->SelStart != hed->SelEnd) - { - if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) - HEXEDIT_Copy(hed); - } - if (GetAsyncKeyState(VK_SHIFT) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0) - HEXEDIT_Paste(hed); - break; + if (hed->SelStart != hed->SelEnd) + { + if (GetAsyncKeyState(VK_SHIFT) >= 0 && GetAsyncKeyState(VK_CONTROL) < 0) + HEXEDIT_Copy(hed); + } + if (GetAsyncKeyState(VK_SHIFT) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0) + HEXEDIT_Paste(hed); + break; case VK_DELETE: - if (GetAsyncKeyState(VK_SHIFT) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0 && - hed->SelStart != hed->SelEnd) - HEXEDIT_Copy(hed); - if (i0 != i1) - { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + if (GetAsyncKeyState(VK_SHIFT) < 0 && GetAsyncKeyState(VK_CONTROL) >= 0 && + hed->SelStart != hed->SelEnd) + HEXEDIT_Copy(hed); + if (i0 != i1) { - MoveMemory(buf + i0, buf + i1, bufsize - i1); - LocalUnlock(hed->hBuffer); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + i0, buf + i1, bufsize - i1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); + hed->InMid = FALSE; + hed->Index = hed->SelStart = hed->SelEnd = i0; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); - hed->InMid = FALSE; - hed->Index = hed->SelStart = hed->SelEnd = i0; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - } - else - { - if (hed->InMid && hed->EditingField) + else { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index, buf + hed->Index + 1, - bufsize - hed->Index - 1); - LocalUnlock(hed->hBuffer); - } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); - hed->InMid = FALSE; + if (hed->InMid && hed->EditingField) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index, buf + hed->Index + 1, + bufsize - hed->Index - 1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); + hed->InMid = FALSE; + } + else if (hed->Index < bufsize) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index, buf + hed->Index + 1, + bufsize - hed->Index - 1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); + } } - else if (hed->Index < bufsize) + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); + break; + + case VK_BACK: + if (i0 != i1) { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index, buf + hed->Index + 1, - bufsize - hed->Index - 1); - LocalUnlock(hed->hBuffer); - } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + i0, buf + i1, bufsize - i1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); + hed->InMid = FALSE; + hed->Index = hed->SelStart = hed->SelEnd = i0; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; } - } - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - break; + else + { + if (hed->InMid && hed->EditingField) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index, buf + hed->Index + 1, + bufsize - hed->Index - 1); + LocalUnlock(hed->hBuffer); + } + } + else if (hed->Index > 0) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index - 1, buf + hed->Index, + bufsize - hed->Index); + LocalUnlock(hed->hBuffer); + } + hed->Index--; + hed->SelStart = hed->SelEnd = hed->Index; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + } + else + return TRUE; + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); + hed->InMid = FALSE; + } + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); + break; - case VK_BACK: - if (i0 != i1) - { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + case VK_LEFT: + if (hed->Index > 0) { - MoveMemory(buf + i0, buf + i1, bufsize - i1); - LocalUnlock(hed->hBuffer); + hed->Index--; + if (GetAsyncKeyState(VK_SHIFT) < 0) + hed->SelEnd = hed->Index; + else + hed->SelStart = hed->SelEnd = hed->Index; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + hed->InMid = FALSE; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); - hed->InMid = FALSE; - hed->Index = hed->SelStart = hed->SelEnd = i0; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - } - else - { - if (hed->InMid && hed->EditingField) + break; + + case VK_RIGHT: + if (hed->Index < (INT)bufsize) { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index, buf + hed->Index + 1, - bufsize - hed->Index - 1); - LocalUnlock(hed->hBuffer); - } + hed->Index++; + if (GetAsyncKeyState(VK_SHIFT) < 0) + hed->SelEnd = hed->Index; + else + hed->SelStart = hed->SelEnd = hed->Index; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + hed->InMid = FALSE; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } - else if (hed->Index > 0) + break; + + case VK_UP: + if (hed->Index >= hed->ColumnsPerLine) { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index - 1, buf + hed->Index, - bufsize - hed->Index); - LocalUnlock(hed->hBuffer); - } - hed->Index--; - hed->SelStart = hed->SelEnd = hed->Index; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; + hed->Index -= hed->ColumnsPerLine; + if (GetAsyncKeyState(VK_SHIFT) < 0) + hed->SelEnd = hed->Index; + else + hed->SelStart = hed->SelEnd = hed->Index; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + hed->InMid = FALSE; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); } - else - return TRUE; - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - 1); - hed->InMid = FALSE; - } - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - break; + break; - case VK_LEFT: - if (hed->Index > 0) - { - hed->Index--; - if (GetAsyncKeyState(VK_SHIFT) < 0) - hed->SelEnd = hed->Index; + case VK_DOWN: + if (hed->Index + hed->ColumnsPerLine <= (INT) bufsize) + hed->Index += hed->ColumnsPerLine; else - hed->SelStart = hed->SelEnd = hed->Index; + hed->Index = bufsize; hed->CaretCol = hed->Index % hed->ColumnsPerLine; hed->CaretLine = hed->Index / hed->ColumnsPerLine; - hed->InMid = FALSE; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - } - break; - - case VK_RIGHT: - if (hed->Index < (INT)bufsize) - { - hed->Index++; if (GetAsyncKeyState(VK_SHIFT) < 0) - hed->SelEnd = hed->Index; + hed->SelEnd = hed->Index; else - hed->SelStart = hed->SelEnd = hed->Index; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; + hed->SelStart = hed->SelEnd = hed->Index; hed->InMid = FALSE; InvalidateRect(hed->hWndSelf, NULL, TRUE); HEXEDIT_MoveCaret(hed, TRUE); - } - break; + break; - case VK_UP: - if (hed->Index >= hed->ColumnsPerLine) - { - hed->Index -= hed->ColumnsPerLine; - if (GetAsyncKeyState(VK_SHIFT) < 0) - hed->SelEnd = hed->Index; - else - hed->SelStart = hed->SelEnd = hed->Index; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - hed->InMid = FALSE; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - } - break; - - case VK_DOWN: - if (hed->Index + hed->ColumnsPerLine <= (INT) bufsize) - hed->Index += hed->ColumnsPerLine; - else - hed->Index = bufsize; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - if (GetAsyncKeyState(VK_SHIFT) < 0) - hed->SelEnd = hed->Index; - else - hed->SelStart = hed->SelEnd = hed->Index; - hed->InMid = FALSE; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - break; - default: - return TRUE; - } + return TRUE; + } - return FALSE; + return FALSE; } static BOOL HEXEDIT_WM_CHAR(PHEXEDIT_DATA hed, WCHAR ch) { - size_t bufsize; - PBYTE buf; - INT i0, i1; + size_t bufsize; + PBYTE buf; + INT i0, i1; - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - if (hed->SelStart < hed->SelEnd) - { - i0 = hed->SelStart; - i1 = hed->SelEnd; - } - else - { - i0 = hed->SelEnd; - i1 = hed->SelStart; - } - if (!hed->EditingField) - { - if (0x20 <= ch && ch <= 0xFF) + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + if (hed->SelStart < hed->SelEnd) { - if (hed->SelStart != hed->SelEnd) - { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + i0 = hed->SelStart; + i1 = hed->SelEnd; + } + else + { + i0 = hed->SelEnd; + i1 = hed->SelStart; + } + if (!hed->EditingField) + { + if (0x20 <= ch && ch <= 0xFF) { - MoveMemory(buf + i0, buf + i1, bufsize - i1); - LocalUnlock(hed->hBuffer); + if (hed->SelStart != hed->SelEnd) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + i0, buf + i1, bufsize - i1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); + hed->InMid = FALSE; + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + hed->Index = hed->SelStart = hed->SelEnd = i0; + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + 1); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index + 1, buf + hed->Index, + bufsize - hed->Index); + buf[hed->Index] = ch; + LocalUnlock(hed->hBuffer); + } + hed->Index++; + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); + return FALSE; } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); - hed->InMid = FALSE; - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - hed->Index = hed->SelStart = hed->SelEnd = i0; - } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + 1); - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index + 1, buf + hed->Index, - bufsize - hed->Index); - buf[hed->Index] = ch; - LocalUnlock(hed->hBuffer); - } - hed->Index++; - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - return FALSE; } - } - else - { - if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || - ('a' <= ch && ch <= 'f')) + else { - if (hed->SelStart != hed->SelEnd) - { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) + if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || + ('a' <= ch && ch <= 'f')) { - MoveMemory(buf + i0, buf + i1, bufsize - i1); - LocalUnlock(hed->hBuffer); + if (hed->SelStart != hed->SelEnd) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + i0, buf + i1, bufsize - i1); + LocalUnlock(hed->hBuffer); + } + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); + hed->InMid = FALSE; + bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); + hed->Index = hed->SelStart = hed->SelEnd = i0; + } + if (hed->InMid) + { + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + if ('0' <= ch && ch <= '9') + buf[hed->Index] |= ch - '0'; + else if ('A' <= ch && ch <= 'F') + buf[hed->Index] |= ch + 10 - 'A'; + else if ('a' <= ch && ch <= 'f') + buf[hed->Index] |= ch + 10 - 'a'; + LocalUnlock(hed->hBuffer); + } + hed->InMid = FALSE; + hed->Index++; + } + else + { + HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + 1); + buf = (PBYTE) LocalLock(hed->hBuffer); + if (buf) + { + MoveMemory(buf + hed->Index + 1, buf + hed->Index, + bufsize - hed->Index); + if ('0' <= ch && ch <= '9') + buf[hed->Index] = (ch - '0') << 4; + else if ('A' <= ch && ch <= 'F') + buf[hed->Index] = (ch + 10 - 'A') << 4; + else if ('a' <= ch && ch <= 'f') + buf[hed->Index] = (ch + 10 - 'a') << 4; + LocalUnlock(hed->hBuffer); + } + hed->InMid = TRUE; + } + hed->CaretCol = hed->Index % hed->ColumnsPerLine; + hed->CaretLine = hed->Index / hed->ColumnsPerLine; + InvalidateRect(hed->hWndSelf, NULL, TRUE); + HEXEDIT_MoveCaret(hed, TRUE); + return FALSE; } - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize - (i1 - i0)); - hed->InMid = FALSE; - bufsize = (hed->hBuffer ? LocalSize(hed->hBuffer) : 0); - hed->Index = hed->SelStart = hed->SelEnd = i0; - } - if (hed->InMid) - { - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - if ('0' <= ch && ch <= '9') - buf[hed->Index] |= ch - '0'; - else if ('A' <= ch && ch <= 'F') - buf[hed->Index] |= ch + 10 - 'A'; - else if ('a' <= ch && ch <= 'f') - buf[hed->Index] |= ch + 10 - 'a'; - LocalUnlock(hed->hBuffer); - } - hed->InMid = FALSE; - hed->Index++; - } - else - { - HexEdit_SetMaxBufferSize(hed->hWndSelf, bufsize + 1); - buf = (PBYTE) LocalLock(hed->hBuffer); - if (buf) - { - MoveMemory(buf + hed->Index + 1, buf + hed->Index, - bufsize - hed->Index); - if ('0' <= ch && ch <= '9') - buf[hed->Index] = (ch - '0') << 4; - else if ('A' <= ch && ch <= 'F') - buf[hed->Index] = (ch + 10 - 'A') << 4; - else if ('a' <= ch && ch <= 'f') - buf[hed->Index] = (ch + 10 - 'a') << 4; - LocalUnlock(hed->hBuffer); - } - hed->InMid = TRUE; - } - hed->CaretCol = hed->Index % hed->ColumnsPerLine; - hed->CaretLine = hed->Index / hed->ColumnsPerLine; - InvalidateRect(hed->hWndSelf, NULL, TRUE); - HEXEDIT_MoveCaret(hed, TRUE); - return FALSE; } - } - return TRUE; + return TRUE; } static LRESULT HEXEDIT_WM_SIZE(PHEXEDIT_DATA hed, DWORD sType, WORD NewWidth, WORD NewHeight) { - UNREFERENCED_PARAMETER(sType); - UNREFERENCED_PARAMETER(NewHeight); - UNREFERENCED_PARAMETER(NewWidth); - HEXEDIT_Update(hed); - return 0; + UNREFERENCED_PARAMETER(sType); + UNREFERENCED_PARAMETER(NewHeight); + UNREFERENCED_PARAMETER(NewWidth); + HEXEDIT_Update(hed); + return 0; } static VOID HEXEDIT_WM_CONTEXTMENU(PHEXEDIT_DATA hed, INT x, INT y) { - HMENU hMenu; - RECT rc; + HMENU hMenu; + RECT rc; - if (x == -1 && y == -1) - { - GetWindowRect(hed->hWndSelf, &rc); - x = rc.left; - y = rc.top; - } + if (x == -1 && y == -1) + { + GetWindowRect(hed->hWndSelf, &rc); + x = rc.left; + y = rc.top; + } - hMenu = GetSubMenu(hPopupMenus, PM_HEXEDIT); - if (hed->SelStart == hed->SelEnd) - { - EnableMenuItem(hMenu, ID_HEXEDIT_CUT, MF_GRAYED); - EnableMenuItem(hMenu, ID_HEXEDIT_COPY, MF_GRAYED); - EnableMenuItem(hMenu, ID_HEXEDIT_PASTE, MF_GRAYED); - EnableMenuItem(hMenu, ID_HEXEDIT_DELETE, MF_GRAYED); - } - else - { - EnableMenuItem(hMenu, ID_HEXEDIT_CUT, MF_ENABLED); - EnableMenuItem(hMenu, ID_HEXEDIT_COPY, MF_ENABLED); - EnableMenuItem(hMenu, ID_HEXEDIT_PASTE, MF_ENABLED); - EnableMenuItem(hMenu, ID_HEXEDIT_DELETE, MF_ENABLED); - } + hMenu = GetSubMenu(hPopupMenus, PM_HEXEDIT); + if (hed->SelStart == hed->SelEnd) + { + EnableMenuItem(hMenu, ID_HEXEDIT_CUT, MF_GRAYED); + EnableMenuItem(hMenu, ID_HEXEDIT_COPY, MF_GRAYED); + EnableMenuItem(hMenu, ID_HEXEDIT_PASTE, MF_GRAYED); + EnableMenuItem(hMenu, ID_HEXEDIT_DELETE, MF_GRAYED); + } + else + { + EnableMenuItem(hMenu, ID_HEXEDIT_CUT, MF_ENABLED); + EnableMenuItem(hMenu, ID_HEXEDIT_COPY, MF_ENABLED); + EnableMenuItem(hMenu, ID_HEXEDIT_PASTE, MF_ENABLED); + EnableMenuItem(hMenu, ID_HEXEDIT_DELETE, MF_ENABLED); + } - SetForegroundWindow(hed->hWndSelf); - TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, x, y, 0, hed->hWndSelf, NULL); - PostMessage(hed->hWndSelf, WM_NULL, 0, 0); + SetForegroundWindow(hed->hWndSelf); + TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, x, y, 0, hed->hWndSelf, NULL); + PostMessage(hed->hWndSelf, WM_NULL, 0, 0); } INT_PTR CALLBACK HexEditWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { - PHEXEDIT_DATA hed; - POINTS p; + PHEXEDIT_DATA hed; + POINTS p; - hed = (PHEXEDIT_DATA)(LONG_PTR)GetWindowLongPtr(hWnd, (DWORD_PTR)0); - switch(uMsg) - { + hed = (PHEXEDIT_DATA)(LONG_PTR)GetWindowLongPtr(hWnd, (DWORD_PTR)0); + switch(uMsg) + { case WM_ERASEBKGND: - return TRUE; + return TRUE; case WM_PAINT: - return HEXEDIT_WM_PAINT(hed); + return HEXEDIT_WM_PAINT(hed); case WM_KEYDOWN: - return HEXEDIT_WM_KEYDOWN(hed, (INT)wParam); + return HEXEDIT_WM_KEYDOWN(hed, (INT)wParam); case WM_CHAR: - return HEXEDIT_WM_CHAR(hed, (WCHAR)wParam); + return HEXEDIT_WM_CHAR(hed, (WCHAR)wParam); case WM_VSCROLL: - return HEXEDIT_WM_VSCROLL(hed, HIWORD(wParam), LOWORD(wParam)); + return HEXEDIT_WM_VSCROLL(hed, HIWORD(wParam), LOWORD(wParam)); case WM_SIZE: - return HEXEDIT_WM_SIZE(hed, (DWORD)wParam, LOWORD(lParam), HIWORD(lParam)); + return HEXEDIT_WM_SIZE(hed, (DWORD)wParam, LOWORD(lParam), HIWORD(lParam)); case WM_LBUTTONDOWN: { - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - return HEXEDIT_WM_LBUTTONDOWN(hed, (INT)wParam, p); + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + return HEXEDIT_WM_LBUTTONDOWN(hed, (INT)wParam, p); } case WM_LBUTTONUP: { - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - return HEXEDIT_WM_LBUTTONUP(hed, (INT)wParam, p); + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + return HEXEDIT_WM_LBUTTONUP(hed, (INT)wParam, p); } case WM_MOUSEMOVE: { - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - return HEXEDIT_WM_MOUSEMOVE(hed, (INT)wParam, p); + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + return HEXEDIT_WM_MOUSEMOVE(hed, (INT)wParam, p); } case WM_MOUSEWHEEL: { - UINT nScrollLines = 3; - int delta = 0; + UINT nScrollLines = 3; + int delta = 0; - SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &nScrollLines, 0); - delta -= (SHORT)HIWORD(wParam); - if(abs(delta) >= WHEEL_DELTA && nScrollLines != 0) - { - p.x = LOWORD(lParam); - p.y = HIWORD(lParam); - return HEXEDIT_WM_MOUSEWHEEL(hed, nScrollLines * (delta / WHEEL_DELTA), LOWORD(wParam), &p); - } - break; + SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &nScrollLines, 0); + delta -= (SHORT)HIWORD(wParam); + if(abs(delta) >= WHEEL_DELTA && nScrollLines != 0) + { + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + return HEXEDIT_WM_MOUSEWHEEL(hed, nScrollLines * (delta / WHEEL_DELTA), LOWORD(wParam), &p); + } + break; } case HEM_LOADBUFFER: - return HEXEDIT_HEM_LOADBUFFER(hed, (PVOID)wParam, (DWORD)lParam); + return HEXEDIT_HEM_LOADBUFFER(hed, (PVOID)wParam, (DWORD)lParam); case HEM_COPYBUFFER: - return HEXEDIT_HEM_COPYBUFFER(hed, (PVOID)wParam, (DWORD)lParam); + return HEXEDIT_HEM_COPYBUFFER(hed, (PVOID)wParam, (DWORD)lParam); case HEM_SETMAXBUFFERSIZE: - return HEXEDIT_HEM_SETMAXBUFFERSIZE(hed, (DWORD)lParam); + return HEXEDIT_HEM_SETMAXBUFFERSIZE(hed, (DWORD)lParam); case WM_SETFOCUS: - return HEXEDIT_WM_SETFOCUS(hed); + return HEXEDIT_WM_SETFOCUS(hed); case WM_KILLFOCUS: - return HEXEDIT_WM_KILLFOCUS(hed); + return HEXEDIT_WM_KILLFOCUS(hed); case WM_GETDLGCODE: - return HEXEDIT_WM_GETDLGCODE((LPMSG)lParam); + return HEXEDIT_WM_GETDLGCODE((LPMSG)lParam); case WM_SETFONT: - return HEXEDIT_WM_SETFONT(hed, (HFONT)wParam, (BOOL)LOWORD(lParam)); + return HEXEDIT_WM_SETFONT(hed, (HFONT)wParam, (BOOL)LOWORD(lParam)); case WM_GETFONT: - return HEXEDIT_WM_GETFONT(hed); + return HEXEDIT_WM_GETFONT(hed); case WM_CREATE: - return HEXEDIT_WM_CREATE(hed); + return HEXEDIT_WM_CREATE(hed); case WM_NCCREATE: - if(!hed) - { - return HEXEDIT_WM_NCCREATE(hWnd, (CREATESTRUCT*)lParam); - } - break; + if(!hed) + { + return HEXEDIT_WM_NCCREATE(hWnd, (CREATESTRUCT*)lParam); + } + break; case WM_NCDESTROY: - if(hed) - { - return HEXEDIT_WM_NCDESTROY(hed); - } - break; + if(hed) + { + return HEXEDIT_WM_NCDESTROY(hed); + } + break; case WM_CONTEXTMENU: - HEXEDIT_WM_CONTEXTMENU(hed, (short)LOWORD(lParam), (short)HIWORD(lParam)); - break; + HEXEDIT_WM_CONTEXTMENU(hed, (short)LOWORD(lParam), (short)HIWORD(lParam)); + break; case WM_COMMAND: - switch(LOWORD(wParam)) - { + switch(LOWORD(wParam)) + { case ID_HEXEDIT_CUT: - HEXEDIT_Cut(hed); - break; + HEXEDIT_Cut(hed); + break; case ID_HEXEDIT_COPY: - HEXEDIT_Copy(hed); - break; + HEXEDIT_Copy(hed); + break; case ID_HEXEDIT_PASTE: - HEXEDIT_Paste(hed); - break; + HEXEDIT_Paste(hed); + break; case ID_HEXEDIT_DELETE: - HEXEDIT_Delete(hed); - break; + HEXEDIT_Delete(hed); + break; case ID_HEXEDIT_SELECT_ALL: - HEXEDIT_SelectAll(hed); - break; - } - break; - } + HEXEDIT_SelectAll(hed); + break; + } + break; + } - return DefWindowProc(hWnd, uMsg, wParam, lParam); + return DefWindowProc(hWnd, uMsg, wParam, lParam); } Index: base/applications/regedit/treeview.c =================================================================== --- base/applications/regedit/treeview.c (revision 49426) +++ base/applications/regedit/treeview.c (working copy) @@ -32,7 +32,8 @@ #define NUM_ICONS 3 -static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, LPTSTR* pKeyPath, int* pPathLen, int* pMaxLen) +static BOOL get_item_path(HWND hwndTV, HTREEITEM hItem, HKEY* phKey, + LPTSTR* pKeyPath, int* pPathLen, int* pMaxLen) { TVITEM item; size_t maxLen, len; @@ -42,19 +43,24 @@ item.hItem = hItem; if (!TreeView_GetItem(hwndTV, &item)) return FALSE; - if (item.lParam) { - /* found root key with valid key value */ - *phKey = (HKEY)item.lParam; - return TRUE; + if (item.lParam) + { + /* found root key with valid key value */ + *phKey = (HKEY)item.lParam; + return TRUE; } - if(!get_item_path(hwndTV, TreeView_GetParent(hwndTV, hItem), phKey, pKeyPath, pPathLen, pMaxLen)) return FALSE; - if (*pPathLen) { + if(!get_item_path(hwndTV, TreeView_GetParent(hwndTV, hItem), + phKey, pKeyPath, pPathLen, pMaxLen)) + return FALSE; + if (*pPathLen) + { (*pKeyPath)[*pPathLen] = _T('\\'); ++(*pPathLen); } - do { + do + { item.mask = TVIF_TEXT; item.hItem = hItem; item.pszText = *pKeyPath + *pPathLen; @@ -62,15 +68,17 @@ item.cchTextMax = (int) maxLen; if (!TreeView_GetItem(hwndTV, &item)) return FALSE; len = _tcslen(item.pszText); - if (len < maxLen - 1) { + if (len < maxLen - 1) + { *pPathLen += (int) len; break; - } - newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxLen * 2); - if (!newStr) return FALSE; - *pKeyPath = newStr; - *pMaxLen *= 2; - } while(TRUE); + } + newStr = HeapReAlloc(GetProcessHeap(), 0, *pKeyPath, *pMaxLen * 2); + if (!newStr) return FALSE; + *pKeyPath = newStr; + *pMaxLen *= 2; + } + while(TRUE); return TRUE; } @@ -87,9 +95,10 @@ if (maxLen == -1) return NULL; if (!hItem) hItem = TreeView_GetSelection(hwndTV); if (!hItem) return NULL; - if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) { - return NULL; - } + if (!get_item_path(hwndTV, hItem, phRootKey, &pathBuffer, &pathLen, &maxLen)) + { + return NULL; + } return pathBuffer; } @@ -101,13 +110,17 @@ } /* Add an entry to the tree. Only give hKey for root nodes (HKEY_ constants) */ -static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, LPTSTR label, HKEY hKey, DWORD dwChildren) +static HTREEITEM AddEntryToTree(HWND hwndTV, HTREEITEM hParent, + LPTSTR label, HKEY hKey, DWORD dwChildren) { TVITEM tvi; TVINSERTSTRUCT tvins; - if (hKey) { - if (RegQueryInfoKey(hKey, 0, 0, 0, &dwChildren, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { + if (hKey) + { + if (RegQueryInfoKey(hKey, 0, 0, 0, &dwChildren, + 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) + { dwChildren = 0; } } @@ -140,15 +153,21 @@ KeyPath = GetItemPath(hwndTV, hItem, &hRoot); - if (*KeyPath) { - if (RegOpenKeyEx(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) { + if (*KeyPath) + { + if (RegOpenKeyEx(hRoot, KeyPath, 0, KEY_READ, &hKey) != ERROR_SUCCESS) + { goto done; } - } else { + } + else + { hKey = hRoot; } - if (RegQueryInfoKey(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { + if (RegQueryInfoKey(hKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, + 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) + { goto done; } @@ -156,19 +175,22 @@ tvItem.mask = TVIF_CHILDREN; tvItem.hItem = hItem; tvItem.cChildren = dwCount; - if (!TreeView_SetItem(hwndTV, &tvItem)) { + if (!TreeView_SetItem(hwndTV, &tvItem)) + { goto done; } /* We don't have to bother with the rest if it's not expanded. */ - if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDED) == 0) { + if (TreeView_GetItemState(hwndTV, hItem, TVIS_EXPANDED) == 0) + { RegCloseKey(hKey); bSuccess = TRUE; goto done; } dwMaxSubKeyLen++; /* account for the \0 terminator */ - if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(TCHAR)))) { + if (!(Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(TCHAR)))) + { goto done; } tvItem.cchTextMax = dwMaxSubKeyLen; @@ -185,14 +207,16 @@ DWORD dwStep = 10000; for (childItem = TreeView_GetChild(hwndTV, hItem); childItem; - childItem = TreeView_GetNextSibling(hwndTV, childItem)) { + childItem = TreeView_GetNextSibling(hwndTV, childItem)) + { if (dwActualSize + dwMaxSubKeyLen + 1 > dwPhysicalSize) { dwNewPhysicalSize = dwActualSize + dwMaxSubKeyLen + 1 + dwStep; if (pszNodes) - pszNewNodes = (LPTSTR) HeapReAlloc(GetProcessHeap(), 0, pszNodes, dwNewPhysicalSize * sizeof(TCHAR)); + pszNewNodes = (LPTSTR) HeapReAlloc(GetProcessHeap(), 0, pszNodes, + dwNewPhysicalSize * sizeof(TCHAR)); else pszNewNodes = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, dwNewPhysicalSize * sizeof(TCHAR)); if (!pszNewNodes) @@ -218,40 +242,51 @@ /* Now go through all the children in the tree, and check if any have to be removed. */ childItem = TreeView_GetChild(hwndTV, hItem); - while (childItem) { + while (childItem) + { HTREEITEM nextItem = TreeView_GetNextSibling(hwndTV, childItem); - if (RefreshTreeItem(hwndTV, childItem) == FALSE) { + if (RefreshTreeItem(hwndTV, childItem) == FALSE) + { (void)TreeView_DeleteItem(hwndTV, childItem); } childItem = nextItem; } - /* Now go through all the children in the registry, and check if any have to be added. */ + /* Now go through all the children in the registry, and check if any have to be added. */ bAddedAny = FALSE; - for (dwIndex = 0; dwIndex < dwCount; dwIndex++) { + for (dwIndex = 0; dwIndex < dwCount; dwIndex++) + { DWORD cName = dwMaxSubKeyLen, dwSubCount; BOOL found; found = FALSE; - if (RegEnumKeyEx(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) { + if (RegEnumKeyEx(hKey, dwIndex, Name, &cName, 0, 0, 0, NULL) != ERROR_SUCCESS) + { continue; } /* Check if the node is already in there. */ - if (pszNodes) { - for (s = pszNodes; *s; s += _tcslen(s) + 1) { - if (!_tcscmp(s, Name)) { + if (pszNodes) + { + for (s = pszNodes; *s; s += _tcslen(s) + 1) + { + if (!_tcscmp(s, Name)) + { found = TRUE; break; } } } - if (found == FALSE) { + if (found == FALSE) + { /* Find the number of children of the node. */ dwSubCount = 0; - if (RegOpenKeyEx(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) { - if (RegQueryInfoKey(hSubKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) { + if (RegOpenKeyEx(hKey, Name, 0, KEY_QUERY_VALUE, &hSubKey) == ERROR_SUCCESS) + { + if (RegQueryInfoKey(hSubKey, 0, 0, 0, &dwSubCount, + 0, 0, 0, 0, 0, 0, 0) != ERROR_SUCCESS) + { dwSubCount = 0; } RegCloseKey(hSubKey); @@ -287,7 +322,8 @@ SendMessage(hwndTV, WM_SETREDRAW, FALSE, 0); hItem = TreeView_GetChild(hwndTV, TreeView_GetRoot(hwndTV)); - while (hItem) { + while (hItem) + { RefreshTreeItem(hwndTV, hItem); hItem = TreeView_GetNextSibling(hwndTV, hItem); } @@ -325,7 +361,7 @@ hNewItem = AddEntryToTree(hwndTV, hItem, name, 0, 0); SendMessage(hwndTV, TVM_SORTCHILDREN, 0, (LPARAM) hItem); } - else + else { item.mask = TVIF_CHILDREN | TVIF_HANDLE; item.hItem = hItem; @@ -337,7 +373,8 @@ (void)TreeView_Expand(hwndTV, hItem, TVE_EXPAND); if (!hNewItem) { - for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem)) + for(hNewItem = TreeView_GetChild(hwndTV, hItem); hNewItem; + hNewItem = TreeView_GetNextSibling(hwndTV, hNewItem)) { item.mask = TVIF_HANDLE | TVIF_TEXT; item.hItem = hNewItem; @@ -388,11 +425,11 @@ if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_USERS"), HKEY_USERS, 1)) return FALSE; if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_CURRENT_CONFIG"), HKEY_CURRENT_CONFIG, 1)) return FALSE; - if (GetVersion() & 0x80000000) + if (GetVersion() & 0x80000000) { /* Win9x specific key */ if (!AddEntryToTree(hwndTV, hRoot, _T("HKEY_DYN_DATA"), HKEY_DYN_DATA, 1)) return FALSE; - } + } /* expand and select host name */ (void)TreeView_Expand(hwndTV, hRoot, TVE_EXPAND); @@ -431,8 +468,8 @@ 0); if (hico) { - Image_Open = ImageList_AddIcon(himl, hico); - DestroyIcon(hico); + Image_Open = ImageList_AddIcon(himl, hico); + DestroyIcon(hico); } hico = LoadImage(hInst, @@ -443,8 +480,8 @@ 0); if (hico) { - Image_Closed = ImageList_AddIcon(himl, hico); - DestroyIcon(hico); + Image_Closed = ImageList_AddIcon(himl, hico); + DestroyIcon(hico); } hico = LoadImage(hInst, @@ -455,8 +492,8 @@ 0); if (hico) { - Image_Root = ImageList_AddIcon(himl, hico); - DestroyIcon(hico); + Image_Root = ImageList_AddIcon(himl, hico); + DestroyIcon(hico); } /* Fail if not all of the images were added. */ @@ -483,7 +520,8 @@ static int expanding; if (expanding) return FALSE; - if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE ) { + if (pnmtv->itemNew.state & TVIS_EXPANDEDONCE ) + { return TRUE; } expanding = TRUE; @@ -493,12 +531,15 @@ keyPath = GetItemPath(hwndTV, pnmtv->itemNew.hItem, &hRoot); if (!keyPath) goto done; - if (*keyPath) { + if (*keyPath) + { errCode = RegOpenKeyEx(hRoot, keyPath, 0, KEY_READ, &hNewKey); if (errCode != ERROR_SUCCESS) goto done; - } else { - hNewKey = hRoot; } + else + { + hNewKey = hRoot; + } errCode = RegQueryInfoKey(hNewKey, 0, 0, 0, &dwCount, &dwMaxSubKeyLen, 0, 0, 0, 0, 0, 0); if (errCode != ERROR_SUCCESS) goto done; @@ -506,13 +547,15 @@ Name = HeapAlloc(GetProcessHeap(), 0, dwMaxSubKeyLen * sizeof(TCHAR)); if (!Name) goto done; - for (dwIndex = 0; dwIndex < dwCount; dwIndex++) { + for (dwIndex = 0; dwIndex < dwCount; dwIndex++) + { DWORD cName = dwMaxSubKeyLen, dwSubCount; errCode = RegEnumKeyEx(hNewKey, dwIndex, Name, &cName, 0, 0, 0, 0); if (errCode != ERROR_SUCCESS) continue; errCode = RegOpenKeyEx(hNewKey, Name, 0, KEY_QUERY_VALUE, &hKey); - if (errCode == ERROR_SUCCESS) { + if (errCode == ERROR_SUCCESS) + { errCode = RegQueryInfoKey(hKey, 0, 0, 0, &dwSubCount, 0, 0, 0, 0, 0, 0, 0); RegCloseKey(hKey); } @@ -552,14 +595,16 @@ else if (RegOpenKey(hRootKey, pszKeyPath, &hKey) != ERROR_SUCCESS) goto done; - if (LoadString(hInst, IDS_NEW_KEY, szNewKeyFormat, sizeof(szNewKeyFormat) / sizeof(szNewKeyFormat[0])) <= 0) + if (LoadString(hInst, IDS_NEW_KEY, szNewKeyFormat, + sizeof(szNewKeyFormat) / sizeof(szNewKeyFormat[0])) <= 0) goto done; /* Need to create a new key with a unique name */ do { wsprintf(szNewKey, szNewKeyFormat, iIndex++); - nResult = RegCreateKeyEx(hKey, szNewKey, 0, NULL, 0, KEY_WRITE, NULL, &hNewKey, &dwDisposition); + nResult = RegCreateKeyEx(hKey, szNewKey, 0,NULL, 0, KEY_WRITE, NULL, + &hNewKey, &dwDisposition); if (hNewKey && dwDisposition == REG_OPENED_EXISTING_KEY) { RegCloseKey(hNewKey); @@ -611,88 +656,90 @@ 0, 0, rcClient.right, rcClient.bottom, hwndParent, id, hInst, NULL); /* Initialize the image list, and add items to the control. */ - if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) { + if (!InitTreeViewImageLists(hwndTV) || !InitTreeViewItems(hwndTV, pHostName)) + { DestroyWindow(hwndTV); return NULL; } return hwndTV; } -void DestroyTreeView() { - if (pathBuffer) - HeapFree(GetProcessHeap(), 0, pathBuffer); +void DestroyTreeView() +{ + if (pathBuffer) + HeapFree(GetProcessHeap(), 0, pathBuffer); } BOOL SelectNode(HWND hwndTV, LPCTSTR keyPath) { - HTREEITEM hRoot, hItem; - HTREEITEM hChildItem; - TCHAR szPathPart[128]; - TCHAR szBuffer[128]; - LPCTSTR s; - TVITEM tvi; + HTREEITEM hRoot, hItem; + HTREEITEM hChildItem; + TCHAR szPathPart[128]; + TCHAR szBuffer[128]; + LPCTSTR s; + TVITEM tvi; /* Total no-good hack */ - if (!_tcsncmp(keyPath, _T("My Computer\\"), 12)) + if (!_tcsnicmp(keyPath, _T("My Computer\\"), 12)) keyPath += 12; - hRoot = TreeView_GetRoot(hwndTV); - hItem = hRoot; + hRoot = TreeView_GetRoot(hwndTV); + hItem = hRoot; - while(keyPath[0]) - { - s = _tcschr(keyPath, TEXT('\\')); - lstrcpyn(szPathPart, keyPath, s ? s - keyPath + 1 : _tcslen(keyPath) + 1); + while(keyPath[0]) + { + s = _tcschr(keyPath, TEXT('\\')); + lstrcpyn(szPathPart, keyPath, s ? s - keyPath + 1 : _tcslen(keyPath) + 1); - /* Special case for root to expand root key abbreviations */ - if (hItem == hRoot) - { - if (!_tcscmp(szPathPart, TEXT("HKCR"))) - _tcscpy(szPathPart, TEXT("HKEY_CLASSES_ROOT")); - else if (!_tcscmp(szPathPart, TEXT("HKCU"))) - _tcscpy(szPathPart, TEXT("HKEY_CURRENT_USER")); - else if (!_tcscmp(szPathPart, TEXT("HKLM"))) - _tcscpy(szPathPart, TEXT("HKEY_LOCAL_MACHINE")); - else if (!_tcscmp(szPathPart, TEXT("HKU"))) - _tcscpy(szPathPart, TEXT("HKEY_USERS")); - else if (!_tcscmp(szPathPart, TEXT("HKCC"))) - _tcscpy(szPathPart, TEXT("HKEY_CURRENT_CONFIG")); - else if (!_tcscmp(szPathPart, TEXT("HKDD"))) - _tcscpy(szPathPart, TEXT("HKEY_DYN_DATA")); - } + /* Special case for root to expand root key abbreviations */ + if (hItem == hRoot) + { + if (!_tcsicmp(szPathPart, TEXT("HKCR"))) + _tcscpy(szPathPart, TEXT("HKEY_CLASSES_ROOT")); + else if (!_tcsicmp(szPathPart, TEXT("HKCU"))) + _tcscpy(szPathPart, TEXT("HKEY_CURRENT_USER")); + else if (!_tcsicmp(szPathPart, TEXT("HKLM"))) + _tcscpy(szPathPart, TEXT("HKEY_LOCAL_MACHINE")); + else if (!_tcsicmp(szPathPart, TEXT("HKU"))) + _tcscpy(szPathPart, TEXT("HKEY_USERS")); + else if (!_tcsicmp(szPathPart, TEXT("HKCC"))) + _tcscpy(szPathPart, TEXT("HKEY_CURRENT_CONFIG")); + else if (!_tcsicmp(szPathPart, TEXT("HKDD"))) + _tcscpy(szPathPart, TEXT("HKEY_DYN_DATA")); + } - for (hChildItem = TreeView_GetChild(hwndTV, hItem); hChildItem; - hChildItem = TreeView_GetNextSibling(hwndTV, hChildItem)) - { - memset(&tvi, 0, sizeof(tvi)); - tvi.hItem = hChildItem; - tvi.mask = TVIF_TEXT | TVIF_CHILDREN; - tvi.pszText = szBuffer; - tvi.cchTextMax = sizeof(szBuffer) / sizeof(szBuffer[0]); + for (hChildItem = TreeView_GetChild(hwndTV, hItem); hChildItem; + hChildItem = TreeView_GetNextSibling(hwndTV, hChildItem)) + { + memset(&tvi, 0, sizeof(tvi)); + tvi.hItem = hChildItem; + tvi.mask = TVIF_TEXT | TVIF_CHILDREN; + tvi.pszText = szBuffer; + tvi.cchTextMax = sizeof(szBuffer) / sizeof(szBuffer[0]); - (void)TreeView_GetItem(hwndTV, &tvi); + (void)TreeView_GetItem(hwndTV, &tvi); - if (!_tcscmp(szBuffer, szPathPart)) - break; - } + if (!_tcsicmp(szBuffer, szPathPart)) + break; + } - if (!hChildItem) - return FALSE; + if (!hChildItem) + return FALSE; - if (tvi.cChildren > 0) - { - if (!TreeView_Expand(hwndTV, hChildItem, TVE_EXPAND)) - return FALSE; - } + if (tvi.cChildren > 0) + { + if (!TreeView_Expand(hwndTV, hChildItem, TVE_EXPAND)) + return FALSE; + } - keyPath = s ? s + 1 : _T(""); - hItem = hChildItem; - } + keyPath = s ? s + 1 : _T(""); + hItem = hChildItem; + } - (void)TreeView_SelectItem(hwndTV, hItem); - (void)TreeView_EnsureVisible(hwndTV, hItem); + (void)TreeView_SelectItem(hwndTV, hItem); + (void)TreeView_EnsureVisible(hwndTV, hItem); - return TRUE; + return TRUE; } Index: base/applications/regedit/childwnd.c =================================================================== --- base/applications/regedit/childwnd.c (revision 49426) +++ base/applications/regedit/childwnd.c (working copy) @@ -49,12 +49,12 @@ if(!SizingPattern) { - const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA}; - SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern); + const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA}; + SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern); } if(!SizingBrush) { - SizingBrush = CreatePatternBrush(SizingPattern); + SizingBrush = CreatePatternBrush(SizingPattern); } GetClientRect(hWnd, &rt); rt.left = x - SPLIT_WIDTH/2; @@ -67,19 +67,32 @@ static void ResizeWnd(ChildWnd* pChildWnd, int cx, int cy) { - HDWP hdwp = BeginDeferWindowPos(2); - RECT rt, rs; - + HDWP hdwp = BeginDeferWindowPos(3); + RECT rt, rs, rb; + const int tHeight = 18; SetRect(&rt, 0, 0, cx, cy); cy = 0; - if (hStatusBar != NULL) { + if (hStatusBar != NULL) + { GetWindowRect(hStatusBar, &rs); - cy = rs.bottom - rs.top + 8; + cy = rs.bottom - rs.top; } + GetWindowRect(pChildWnd->hAddressBtnWnd, &rb); cx = pChildWnd->nSplitPos + SPLIT_WIDTH/2; - DeferWindowPos(hdwp, pChildWnd->hAddressBarWnd, 0, rt.left, rt.top, rt.right-rt.left, 23, SWP_NOZORDER|SWP_NOACTIVATE); - DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, rt.left, rt.top + 25, pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); - DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, rt.left+cx , rt.top + 25, rt.right-cx, rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, pChildWnd->hAddressBarWnd, 0, + rt.left, rt.top, rt.right-rt.left - tHeight-2, tHeight, + SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, pChildWnd->hAddressBtnWnd, 0, + rt.right - tHeight, rt.top, tHeight, tHeight, + SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, pChildWnd->hTreeWnd, 0, + rt.left, rt.top + tHeight+2, + pChildWnd->nSplitPos-SPLIT_WIDTH/2-rt.left, + rt.bottom-rt.top-cy, SWP_NOZORDER|SWP_NOACTIVATE); + DeferWindowPos(hdwp, pChildWnd->hListWnd, 0, + rt.left+cx, rt.top + tHeight+2, + rt.right-cx, rt.bottom-rt.top-cy, + SWP_NOZORDER|SWP_NOACTIVATE); EndDeferWindowPos(hdwp); } @@ -130,7 +143,8 @@ UNREFERENCED_PARAMETER(message); - switch (wID) { + switch (wID) + { /* Parse the menu selections: */ case ID_REGISTRY_EXIT: DestroyWindow(hWnd); @@ -139,14 +153,19 @@ /* TODO */ break; case ID_TREE_EXPANDBRANCH: - (void)TreeView_Expand(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd), TVE_EXPAND); + (void)TreeView_Expand(pChildWnd->hTreeWnd, + TreeView_GetSelection(pChildWnd->hTreeWnd), + TVE_EXPAND); break; case ID_TREE_COLLAPSEBRANCH: - (void)TreeView_Expand(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd), TVE_COLLAPSE); + (void)TreeView_Expand(pChildWnd->hTreeWnd, + TreeView_GetSelection(pChildWnd->hTreeWnd), + TVE_COLLAPSE); break; case ID_TREE_RENAME: SetFocus(pChildWnd->hTreeWnd); - (void)TreeView_EditLabel(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd)); + (void)TreeView_EditLabel(pChildWnd->hTreeWnd, + TreeView_GetSelection(pChildWnd->hTreeWnd)); break; case ID_TREE_DELETE: hSelection = TreeView_GetSelection(pChildWnd->hTreeWnd); @@ -154,15 +173,15 @@ if (keyPath == 0 || *keyPath == 0) { - MessageBeep(MB_ICONHAND); - } else - if (DeleteKey(hWnd, hRootKey, keyPath)) - DeleteNode(g_pChildWnd->hTreeWnd, 0); + MessageBeep(MB_ICONHAND); + } + else if (DeleteKey(hWnd, hRootKey, keyPath)) + DeleteNode(g_pChildWnd->hTreeWnd, 0); break; - case ID_TREE_EXPORT: + case ID_TREE_EXPORT: ExportRegistryFile(pChildWnd->hTreeWnd); break; - case ID_EDIT_FIND: + case ID_EDIT_FIND: FindDialog(hWnd); break; case ID_EDIT_COPYKEYNAME: @@ -171,7 +190,8 @@ CopyKeyName(hWnd, hRootKey, keyPath); break; case ID_EDIT_NEW_KEY: - CreateNewKey(pChildWnd->hTreeWnd, TreeView_GetSelection(pChildWnd->hTreeWnd)); + CreateNewKey(pChildWnd->hTreeWnd, + TreeView_GetSelection(pChildWnd->hTreeWnd)); break; case ID_EDIT_NEW_STRINGVALUE: case ID_EDIT_NEW_BINARYVALUE: @@ -184,13 +204,13 @@ break; default: if ((wID >= ID_TREE_SUGGESTION_MIN) && (wID <= ID_TREE_SUGGESTION_MAX)) - { + { s = Suggestions; while(wID > ID_TREE_SUGGESTION_MIN) { if (*s) s += _tcslen(s) + 1; - wID--; + wID--; } SelectNode(pChildWnd->hTreeWnd, s); break; @@ -205,98 +225,98 @@ * Key suggestion */ -#define MIN(a,b) ((a < b) ? (a) : (b)) +#define MIN(a,b) ((a < b) ? (a) : (b)) static void SuggestKeys(HKEY hRootKey, LPCTSTR pszKeyPath, LPTSTR pszSuggestions, - size_t iSuggestionsLength) + size_t iSuggestionsLength) { - TCHAR szBuffer[256]; - TCHAR szLastFound[256]; - size_t i; - HKEY hOtherKey, hSubKey; - BOOL bFound; + TCHAR szBuffer[256]; + TCHAR szLastFound[256]; + size_t i; + HKEY hOtherKey, hSubKey; + BOOL bFound; - memset(pszSuggestions, 0, iSuggestionsLength * sizeof(*pszSuggestions)); - iSuggestionsLength--; + memset(pszSuggestions, 0, iSuggestionsLength * sizeof(*pszSuggestions)); + iSuggestionsLength--; - /* Are we a root key in HKEY_CLASSES_ROOT? */ - if ((hRootKey == HKEY_CLASSES_ROOT) && pszKeyPath[0] && !_tcschr(pszKeyPath, TEXT('\\'))) - { - do - { - bFound = FALSE; + /* Are we a root key in HKEY_CLASSES_ROOT? */ + if ((hRootKey == HKEY_CLASSES_ROOT) && pszKeyPath[0] && !_tcschr(pszKeyPath, TEXT('\\'))) + { + do + { + bFound = FALSE; - /* Check default key */ - if (QueryStringValue(hRootKey, pszKeyPath, NULL, - szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) - { - /* Sanity check this key; it cannot be empty, nor can it be a - * loop back */ - if ((szBuffer[0] != '\0') && _tcsicmp(szBuffer, pszKeyPath)) - { - if (RegOpenKey(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS) - { - lstrcpyn(pszSuggestions, TEXT("HKCR\\"), (int) iSuggestionsLength); - i = _tcslen(pszSuggestions); - pszSuggestions += i; - iSuggestionsLength -= i; + /* Check default key */ + if (QueryStringValue(hRootKey, pszKeyPath, NULL, + szBuffer, COUNT_OF(szBuffer)) == ERROR_SUCCESS) + { + /* Sanity check this key; it cannot be empty, nor can it be a + * loop back */ + if ((szBuffer[0] != '\0') && _tcsicmp(szBuffer, pszKeyPath)) + { + if (RegOpenKey(hRootKey, szBuffer, &hOtherKey) == ERROR_SUCCESS) + { + lstrcpyn(pszSuggestions, TEXT("HKCR\\"), (int) iSuggestionsLength); + i = _tcslen(pszSuggestions); + pszSuggestions += i; + iSuggestionsLength -= i; - lstrcpyn(pszSuggestions, szBuffer, (int) iSuggestionsLength); - i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength); - pszSuggestions += i; - iSuggestionsLength -= i; - RegCloseKey(hOtherKey); + lstrcpyn(pszSuggestions, szBuffer, (int) iSuggestionsLength); + i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength); + pszSuggestions += i; + iSuggestionsLength -= i; + RegCloseKey(hOtherKey); - bFound = TRUE; - _tcscpy(szLastFound, szBuffer); - pszKeyPath = szLastFound; - } - } - } - } - while(bFound && (iSuggestionsLength > 0)); + bFound = TRUE; + _tcscpy(szLastFound, szBuffer); + pszKeyPath = szLastFound; + } + } + } + } + while(bFound && (iSuggestionsLength > 0)); - /* Check CLSID key */ - if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS) - { - if (QueryStringValue(hSubKey, TEXT("CLSID"), NULL, szBuffer, - COUNT_OF(szBuffer)) == ERROR_SUCCESS) - { - lstrcpyn(pszSuggestions, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength); - i = _tcslen(pszSuggestions); - pszSuggestions += i; - iSuggestionsLength -= i; + /* Check CLSID key */ + if (RegOpenKey(hRootKey, pszKeyPath, &hSubKey) == ERROR_SUCCESS) + { + if (QueryStringValue(hSubKey, TEXT("CLSID"), NULL, szBuffer, + COUNT_OF(szBuffer)) == ERROR_SUCCESS) + { + lstrcpyn(pszSuggestions, TEXT("HKCR\\CLSID\\"), (int) iSuggestionsLength); + i = _tcslen(pszSuggestions); + pszSuggestions += i; + iSuggestionsLength -= i; - lstrcpyn(pszSuggestions, szBuffer, (int) iSuggestionsLength); - i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength); - pszSuggestions += i; - iSuggestionsLength -= i; - } - RegCloseKey(hSubKey); - } - } + lstrcpyn(pszSuggestions, szBuffer, (int) iSuggestionsLength); + i = MIN(_tcslen(pszSuggestions) + 1, iSuggestionsLength); + pszSuggestions += i; + iSuggestionsLength -= i; + } + RegCloseKey(hSubKey); + } + } } LRESULT CALLBACK AddressBarProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WNDPROC oldwndproc; - static TCHAR s_szNode[256]; + static TCHAR s_szNode[256]; oldwndproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(hwnd, GWL_USERDATA); - switch (uMsg) + switch (uMsg) { - case WM_KEYUP: - if (wParam == VK_RETURN) - { - GetWindowText(hwnd, s_szNode, sizeof(s_szNode) / sizeof(s_szNode[0])); - SelectNode(g_pChildWnd->hTreeWnd, s_szNode); - } - break; - default: - break; - } - return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam); + case WM_KEYUP: + if (wParam == VK_RETURN) + { + GetWindowText(hwnd, s_szNode, sizeof(s_szNode) / sizeof(s_szNode[0])); + SelectNode(g_pChildWnd->hTreeWnd, s_szNode); + } + break; + default: + break; + } + return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam); } /******************************************************************************* @@ -315,76 +335,94 @@ BOOL Result; ChildWnd* pChildWnd = g_pChildWnd; - switch (message) { - case WM_CREATE: + switch (message) { - WNDPROC oldproc; - HFONT hFont; - TCHAR buffer[MAX_PATH]; - /* load "My Computer" string */ - LoadString(hInst, IDS_MY_COMPUTER, buffer, sizeof(buffer)/sizeof(TCHAR)); + case WM_CREATE: + { + WNDPROC oldproc; + HFONT hFont; + TCHAR buffer[MAX_PATH]; + /* load "My Computer" string */ + LoadString(hInst, IDS_MY_COMPUTER, buffer, sizeof(buffer)/sizeof(TCHAR)); - g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ChildWnd)); + g_pChildWnd = pChildWnd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ChildWnd)); - if (!pChildWnd) return 0; - _tcsncpy(pChildWnd->szPath, buffer, MAX_PATH); - pChildWnd->nSplitPos = 250; - pChildWnd->hWnd = hWnd; - pChildWnd->hAddressBarWnd = CreateWindowEx(WS_EX_CLIENTEDGE, _T("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP, - CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, - hWnd, (HMENU)0, hInst, 0); - pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, (HMENU) TREE_WINDOW); - pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW/*, pChildWnd->szPath*/); - SetFocus(pChildWnd->hTreeWnd); + if (!pChildWnd) return 0; + _tcsncpy(pChildWnd->szPath, buffer, MAX_PATH); + pChildWnd->nSplitPos = 250; + pChildWnd->hWnd = hWnd; + pChildWnd->hAddressBarWnd = CreateWindowEx(WS_EX_CLIENTEDGE, _T("Edit"), NULL, + WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + hWnd, (HMENU)0, hInst, 0); + pChildWnd->hAddressBtnWnd = CreateWindowEx(WS_EX_CLIENTEDGE, _T("Button"), _T("ยป"), + WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP | BS_DEFPUSHBUTTON, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + hWnd, (HMENU)0, hInst, 0); + pChildWnd->hTreeWnd = CreateTreeView(hWnd, pChildWnd->szPath, (HMENU) TREE_WINDOW); + pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW/*, pChildWnd->szPath*/); + SetFocus(pChildWnd->hTreeWnd); - /* set the address bar font */ - if (pChildWnd->hAddressBarWnd) - { - hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); - SendMessage(pChildWnd->hAddressBarWnd, - WM_SETFONT, - (WPARAM)hFont, - 0); + /* set the address bar and button font */ + if ((pChildWnd->hAddressBarWnd) && (pChildWnd->hAddressBtnWnd)) + { + hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + SendMessage(pChildWnd->hAddressBarWnd, + WM_SETFONT, + (WPARAM)hFont, + 0); + SendMessage(pChildWnd->hAddressBtnWnd, + WM_SETFONT, + (WPARAM)hFont, + 0); + } + /* Subclass the AddressBar */ + oldproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_WNDPROC); + SetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_USERDATA, (DWORD_PTR)oldproc); + SetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_WNDPROC, (DWORD_PTR)AddressBarProc); + break; } - - /* Subclass the AddressBar */ - oldproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_WNDPROC); - SetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_USERDATA, (DWORD_PTR)oldproc); - SetWindowLongPtr(pChildWnd->hAddressBarWnd, GWL_WNDPROC, (DWORD_PTR)AddressBarProc); - break; - } - case WM_COMMAND: - if (!_CmdWndProc(hWnd, message, wParam, lParam)) { + case WM_COMMAND: + if(HIWORD(wParam) == BN_CLICKED) + { + PostMessage(pChildWnd->hAddressBarWnd, WM_KEYUP, VK_RETURN, 0); + } + else if (!_CmdWndProc(hWnd, message, wParam, lParam)) + { + goto def; + } + break; + case WM_PAINT: + OnPaint(hWnd); + return 0; + case WM_SETCURSOR: + if (LOWORD(lParam) == HTCLIENT) + { + POINT pt; + GetCursorPos(&pt); + ScreenToClient(hWnd, &pt); + if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.xnSplitPos+SPLIT_WIDTH/2+1) + { + SetCursor(LoadCursor(0, IDC_SIZEWE)); + return TRUE; + } + } goto def; - } - break; - case WM_PAINT: - OnPaint(hWnd); - return 0; - case WM_SETCURSOR: - if (LOWORD(lParam) == HTCLIENT) { - POINT pt; - GetCursorPos(&pt); - ScreenToClient(hWnd, &pt); - if (pt.x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && pt.xnSplitPos+SPLIT_WIDTH/2+1) { - SetCursor(LoadCursor(0, IDC_SIZEWE)); - return TRUE; - } - } - goto def; - case WM_DESTROY: - DestroyTreeView(); - DestroyListView(pChildWnd->hListWnd); - DestroyMainMenu(); - HeapFree(GetProcessHeap(), 0, pChildWnd); - pChildWnd = NULL; - PostQuitMessage(0); - break; - case WM_LBUTTONDOWN: { + case WM_DESTROY: + DestroyTreeView(); + DestroyListView(pChildWnd->hListWnd); + DestroyMainMenu(); + HeapFree(GetProcessHeap(), 0, pChildWnd); + pChildWnd = NULL; + PostQuitMessage(0); + break; + case WM_LBUTTONDOWN: + { RECT rt; int x = (short)LOWORD(lParam); GetClientRect(hWnd, &rt); - if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && xnSplitPos+SPLIT_WIDTH/2+1) { + if (x>=pChildWnd->nSplitPos-SPLIT_WIDTH/2 && xnSplitPos+SPLIT_WIDTH/2+1) + { last_split = pChildWnd->nSplitPos; draw_splitbar(hWnd, last_split); SetCapture(hWnd); @@ -392,336 +430,367 @@ break; } - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - if (GetCapture() == hWnd) { - finish_splitbar(hWnd, LOWORD(lParam)); - } - break; + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + if (GetCapture() == hWnd) + { + finish_splitbar(hWnd, LOWORD(lParam)); + } + break; - case WM_CAPTURECHANGED: - if (GetCapture()==hWnd && last_split>=0) - draw_splitbar(hWnd, last_split); - break; + case WM_CAPTURECHANGED: + if (GetCapture()==hWnd && last_split>=0) + draw_splitbar(hWnd, last_split); + break; - case WM_KEYDOWN: - if (wParam == VK_ESCAPE) - if (GetCapture() == hWnd) { + case WM_KEYDOWN: + if (wParam == VK_ESCAPE) + if (GetCapture() == hWnd) + { + RECT rt; + draw_splitbar(hWnd, last_split); + GetClientRect(hWnd, &rt); + ResizeWnd(pChildWnd, rt.right, rt.bottom); + last_split = -1; + ReleaseCapture(); + SetCursor(LoadCursor(0, IDC_ARROW)); + } + break; + + case WM_MOUSEMOVE: + if (GetCapture() == hWnd) + { + HDC hdc; RECT rt; - draw_splitbar(hWnd, last_split); + HGDIOBJ OldObj; + int x = LOWORD(lParam); + if(!SizingPattern) + { + const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA}; + SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern); + } + if(!SizingBrush) + { + SizingBrush = CreatePatternBrush(SizingPattern); + } + GetClientRect(hWnd, &rt); - ResizeWnd(pChildWnd, rt.right, rt.bottom); - last_split = -1; - ReleaseCapture(); - SetCursor(LoadCursor(0, IDC_ARROW)); + x = (SHORT) min(max(x, SPLIT_MIN), rt.right - SPLIT_MIN); + if(last_split != x) + { + rt.left = last_split-SPLIT_WIDTH/2; + rt.right = last_split+SPLIT_WIDTH/2+1; + hdc = GetDC(hWnd); + OldObj = SelectObject(hdc, SizingBrush); + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT); + last_split = x; + rt.left = x-SPLIT_WIDTH/2; + rt.right = x+SPLIT_WIDTH/2+1; + PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT); + SelectObject(hdc, OldObj); + ReleaseDC(hWnd, hdc); + } } - break; + break; - case WM_MOUSEMOVE: - if (GetCapture() == hWnd) { - HDC hdc; - RECT rt; - HGDIOBJ OldObj; - int x = LOWORD(lParam); - if(!SizingPattern) + case WM_SETFOCUS: + if (pChildWnd != NULL) { - const DWORD Pattern[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA}; - SizingPattern = CreateBitmap(8, 8, 1, 1, Pattern); + SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd); } - if(!SizingBrush) - { - SizingBrush = CreatePatternBrush(SizingPattern); - } + break; - GetClientRect(hWnd, &rt); - x = (SHORT) min(max(x, SPLIT_MIN), rt.right - SPLIT_MIN); - if(last_split != x) + case WM_TIMER: + break; + + case WM_NOTIFY: + if ((int)wParam == TREE_WINDOW) { - rt.left = last_split-SPLIT_WIDTH/2; - rt.right = last_split+SPLIT_WIDTH/2+1; - hdc = GetDC(hWnd); - OldObj = SelectObject(hdc, SizingBrush); - PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT); - last_split = x; - rt.left = x-SPLIT_WIDTH/2; - rt.right = x+SPLIT_WIDTH/2+1; - PatBlt(hdc, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, PATINVERT); - SelectObject(hdc, OldObj); - ReleaseDC(hWnd, hdc); - } - } - break; - - case WM_SETFOCUS: - if (pChildWnd != NULL) { - SetFocus(pChildWnd->nFocusPanel? pChildWnd->hListWnd: pChildWnd->hTreeWnd); - } - break; - - case WM_TIMER: - break; - - case WM_NOTIFY: - if ((int)wParam == TREE_WINDOW) { - switch (((LPNMHDR)lParam)->code) { - case TVN_ITEMEXPANDING: - return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam); - case TVN_SELCHANGED: { + switch (((LPNMHDR)lParam)->code) + { + case TVN_ITEMEXPANDING: + return !OnTreeExpanding(pChildWnd->hTreeWnd, (NMTREEVIEW*)lParam); + case TVN_SELCHANGED: + { LPCTSTR keyPath, rootName; - LPTSTR fullPath; + LPTSTR fullPath; HKEY hRootKey; - keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey); - if (keyPath) { - RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath); - rootName = get_root_key_name(hRootKey); - fullPath = HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName) + 1 + _tcslen(keyPath) + 1) * sizeof(TCHAR)); - if (fullPath) { - _stprintf(fullPath, _T("%s\\%s"), rootName, keyPath); - SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath); - SendMessage(pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath); - HeapFree(GetProcessHeap(), 0, fullPath); + keyPath = GetItemPath(pChildWnd->hTreeWnd, ((NMTREEVIEW*)lParam)->itemNew.hItem, &hRootKey); + if (keyPath) + { + RefreshListView(pChildWnd->hListWnd, hRootKey, keyPath); + rootName = get_root_key_name(hRootKey); + fullPath = HeapAlloc(GetProcessHeap(), 0, (_tcslen(rootName) + 1 + _tcslen(keyPath) + 1) * sizeof(TCHAR)); + if (fullPath) + { + /* set (correct) the address bar text */ + if(keyPath[0] != '\0') + _stprintf(fullPath, _T("%s\\%s"), rootName, keyPath); + else + fullPath = _tcscpy(fullPath, rootName); + SendMessage(hStatusBar, SB_SETTEXT, 0, (LPARAM)fullPath); + SendMessage(pChildWnd->hAddressBarWnd, WM_SETTEXT, 0, (LPARAM)fullPath); + HeapFree(GetProcessHeap(), 0, fullPath); + /* disable hive manipulation items temporarily (enable only if necessary) */ + EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_GRAYED); + EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_GRAYED); + /* compare the strings to see if we should enable/disable the "Load Hive" menus accordingly */ + if (!(_tcsicmp(rootName, TEXT("HKEY_LOCAL_MACHINE")) && + _tcsicmp(rootName, TEXT("HKEY_USERS")))) + { + // enable the unload menu item if at the root + // otherwise enable the load menu item if there is no slash in keyPath (ie. immediate child selected) + if(keyPath[0] == '\0') + EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_LOADHIVE, MF_BYCOMMAND | MF_ENABLED); + else if(!_tcschr(keyPath, _T('\\'))) + EnableMenuItem(GetSubMenu(hMenuFrame,0), ID_REGISTRY_UNLOADHIVE, MF_BYCOMMAND | MF_ENABLED); + } - { - HKEY hKey; - TCHAR szBuffer[MAX_PATH]; - _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("My Computer\\%s\\%s"), rootName, keyPath); + { + HKEY hKey; + TCHAR szBuffer[MAX_PATH]; + _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("My Computer\\%s\\%s"), rootName, keyPath); - if (RegCreateKey(HKEY_CURRENT_USER, - g_szGeneralRegKey, - &hKey) == ERROR_SUCCESS) - { - RegSetValueEx(hKey, _T("LastKey"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) _tcslen(szBuffer) * sizeof(szBuffer[0])); - RegCloseKey(hKey); - } - } - } - } + if (RegCreateKey(HKEY_CURRENT_USER, + g_szGeneralRegKey, + &hKey) == ERROR_SUCCESS) + { + RegSetValueEx(hKey, _T("LastKey"), 0, REG_SZ, (LPBYTE) szBuffer, (DWORD) _tcslen(szBuffer) * sizeof(szBuffer[0])); + RegCloseKey(hKey); + } + } + } + } } break; - case NM_SETFOCUS: - pChildWnd->nFocusPanel = 0; - break; - case TVN_BEGINLABELEDIT: - { - LPNMTVDISPINFO ptvdi; - /* cancel label edit for rootkeys */ - ptvdi = (LPNMTVDISPINFO) lParam; - if (!TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem) || - !TreeView_GetParent(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem))) - return TRUE; - break; - } - case TVN_ENDLABELEDIT: + case NM_SETFOCUS: + pChildWnd->nFocusPanel = 0; + break; + case TVN_BEGINLABELEDIT: { - LPCTSTR keyPath; - HKEY hRootKey; - HKEY hKey = NULL; - LPNMTVDISPINFO ptvdi; - LONG lResult = TRUE; - TCHAR szBuffer[MAX_PATH]; + LPNMTVDISPINFO ptvdi; + /* cancel label edit for rootkeys */ + ptvdi = (LPNMTVDISPINFO) lParam; + if (!TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem) || + !TreeView_GetParent(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem))) + return TRUE; + break; + } + case TVN_ENDLABELEDIT: + { + LPCTSTR keyPath; + HKEY hRootKey; + HKEY hKey = NULL; + LPNMTVDISPINFO ptvdi; + LONG lResult = TRUE; + TCHAR szBuffer[MAX_PATH]; - ptvdi = (LPNMTVDISPINFO) lParam; - if (ptvdi->item.pszText) - { - keyPath = GetItemPath(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey); - _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("%s\\%s"), keyPath, ptvdi->item.pszText); - keyPath = GetItemPath(pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey); - if (RegOpenKeyEx(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + ptvdi = (LPNMTVDISPINFO) lParam; + if (ptvdi->item.pszText) { - lResult = FALSE; - RegCloseKey(hKey); - (void)TreeView_EditLabel(pChildWnd->hTreeWnd, ptvdi->item.hItem); + keyPath = GetItemPath(pChildWnd->hTreeWnd, TreeView_GetParent(pChildWnd->hTreeWnd, ptvdi->item.hItem), &hRootKey); + _sntprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), _T("%s\\%s"), keyPath, ptvdi->item.pszText); + keyPath = GetItemPath(pChildWnd->hTreeWnd, ptvdi->item.hItem, &hRootKey); + if (RegOpenKeyEx(hRootKey, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + lResult = FALSE; + RegCloseKey(hKey); + (void)TreeView_EditLabel(pChildWnd->hTreeWnd, ptvdi->item.hItem); + } + else + { + if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS) + lResult = FALSE; + } + return lResult; } - else + } + default: + return 0; + } + } + else + { + if ((int)wParam == LIST_WINDOW) + { + switch (((LPNMHDR)lParam)->code) { - if (RenameKey(hRootKey, keyPath, ptvdi->item.pszText) != ERROR_SUCCESS) - lResult = FALSE; + case NM_SETFOCUS: + pChildWnd->nFocusPanel = 1; + break; + default: + if(!ListWndNotifyProc(pChildWnd->hListWnd, wParam, lParam, &Result)) + { + goto def; + } + return Result; + break; } - return lResult; - } } - default: - return 0; } - } else + break; + + case WM_CONTEXTMENU: { - if ((int)wParam == LIST_WINDOW) + POINT pt; + if((HWND)wParam == pChildWnd->hListWnd) { - switch (((LPNMHDR)lParam)->code) { - case NM_SETFOCUS: - pChildWnd->nFocusPanel = 1; - break; - default: - if(!ListWndNotifyProc(pChildWnd->hListWnd, wParam, lParam, &Result)) - { - goto def; - } - return Result; - break; - } + int i, cnt; + BOOL IsDefault; + pt.x = (short) LOWORD(lParam); + pt.y = (short) HIWORD(lParam); + cnt = ListView_GetSelectedCount(pChildWnd->hListWnd); + i = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED | LVNI_SELECTED); + if (pt.x == -1 && pt.y == -1) + { + RECT rc; + if (i != -1) + { + rc.left = LVIR_BOUNDS; + SendMessage(pChildWnd->hListWnd, LVM_GETITEMRECT, i, (LPARAM) &rc); + pt.x = rc.left + 8; + pt.y = rc.top + 8; + } + else + pt.x = pt.y = 0; + ClientToScreen(pChildWnd->hListWnd, &pt); + } + if(i == -1) + { + TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW), TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL); + } + else + { + HMENU mnu = GetSubMenu(hPopupMenus, PM_MODIFYVALUE); + SetMenuDefaultItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND); + IsDefault = IsDefaultValue(pChildWnd->hListWnd, i); + if(cnt == 1) + EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | (IsDefault ? MF_DISABLED | MF_GRAYED : MF_ENABLED)); + else + EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); + EnableMenuItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED)); + EnableMenuItem(mnu, ID_EDIT_MODIFY_BIN, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED)); + + TrackPopupMenu(mnu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL); + } } - } - break; - - case WM_CONTEXTMENU: - { - POINT pt; - if((HWND)wParam == pChildWnd->hListWnd) - { - int i, cnt; - BOOL IsDefault; - pt.x = (short) LOWORD(lParam); - pt.y = (short) HIWORD(lParam); - cnt = ListView_GetSelectedCount(pChildWnd->hListWnd); - i = ListView_GetNextItem(pChildWnd->hListWnd, -1, LVNI_FOCUSED | LVNI_SELECTED); - if (pt.x == -1 && pt.y == -1) - { - RECT rc; - if (i != -1) + else if ((HWND)wParam == pChildWnd->hTreeWnd) { - rc.left = LVIR_BOUNDS; - SendMessage(pChildWnd->hListWnd, LVM_GETITEMRECT, i, (LPARAM) &rc); - pt.x = rc.left + 8; - pt.y = rc.top + 8; - } - else - pt.x = pt.y = 0; - ClientToScreen(pChildWnd->hListWnd, &pt); - } - if(i == -1) - { - TrackPopupMenu(GetSubMenu(hPopupMenus, PM_NEW), TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL); - } - else - { - HMENU mnu = GetSubMenu(hPopupMenus, PM_MODIFYVALUE); - SetMenuDefaultItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND); - IsDefault = IsDefaultValue(pChildWnd->hListWnd, i); - if(cnt == 1) - EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | (IsDefault ? MF_DISABLED | MF_GRAYED : MF_ENABLED)); - else - EnableMenuItem(mnu, ID_EDIT_RENAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - EnableMenuItem(mnu, ID_EDIT_MODIFY, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED)); - EnableMenuItem(mnu, ID_EDIT_MODIFY_BIN, MF_BYCOMMAND | (cnt == 1 ? MF_ENABLED : MF_DISABLED | MF_GRAYED)); + TVHITTESTINFO hti; + HMENU hContextMenu; + TVITEM item; + MENUITEMINFO mii; + TCHAR resource[256]; + TCHAR buffer[256]; + LPTSTR s; + LPCTSTR keyPath; + HKEY hRootKey; + int iLastPos; + WORD wID; - TrackPopupMenu(mnu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hFrameWnd, NULL); - } - } - else if ((HWND)wParam == pChildWnd->hTreeWnd) - { - TVHITTESTINFO hti; - HMENU hContextMenu; - TVITEM item; - MENUITEMINFO mii; - TCHAR resource[256]; - TCHAR buffer[256]; - LPTSTR s; - LPCTSTR keyPath; - HKEY hRootKey; - int iLastPos; - WORD wID; + pt.x = (short) LOWORD(lParam); + pt.y = (short) HIWORD(lParam); - pt.x = (short) LOWORD(lParam); - pt.y = (short) HIWORD(lParam); + if (pt.x == -1 && pt.y == -1) + { + RECT rc; + hti.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd); + if (hti.hItem != NULL) + { + TreeView_GetItemRect(pChildWnd->hTreeWnd, hti.hItem, &rc, TRUE); + pt.x = rc.left + 8; + pt.y = rc.top + 8; + ClientToScreen(pChildWnd->hTreeWnd, &pt); + hti.flags = TVHT_ONITEM; + } + else + hti.flags = 0; + } + else + { + hti.pt.x = pt.x; + hti.pt.y = pt.y; + ScreenToClient(pChildWnd->hTreeWnd, &hti.pt); + (void)TreeView_HitTest(pChildWnd->hTreeWnd, &hti); + } - if (pt.x == -1 && pt.y == -1) - { - RECT rc; - hti.hItem = TreeView_GetSelection(pChildWnd->hTreeWnd); - if (hti.hItem != NULL) - { - TreeView_GetItemRect(pChildWnd->hTreeWnd, hti.hItem, &rc, TRUE); - pt.x = rc.left + 8; - pt.y = rc.top + 8; - ClientToScreen(pChildWnd->hTreeWnd, &pt); - hti.flags = TVHT_ONITEM; - } - else - hti.flags = 0; - } - else - { - hti.pt.x = pt.x; - hti.pt.y = pt.y; - ScreenToClient(pChildWnd->hTreeWnd, &hti.pt); - (void)TreeView_HitTest(pChildWnd->hTreeWnd, &hti); - } + if (hti.flags & TVHT_ONITEM) + { + hContextMenu = GetSubMenu(hPopupMenus, PM_TREECONTEXT); + (void)TreeView_SelectItem(pChildWnd->hTreeWnd, hti.hItem); - if (hti.flags & TVHT_ONITEM) - { - hContextMenu = GetSubMenu(hPopupMenus, PM_TREECONTEXT); - (void)TreeView_SelectItem(pChildWnd->hTreeWnd, hti.hItem); + memset(&item, 0, sizeof(item)); + item.mask = TVIF_STATE | TVIF_CHILDREN; + item.hItem = hti.hItem; + (void)TreeView_GetItem(pChildWnd->hTreeWnd, &item); - memset(&item, 0, sizeof(item)); - item.mask = TVIF_STATE | TVIF_CHILDREN; - item.hItem = hti.hItem; - (void)TreeView_GetItem(pChildWnd->hTreeWnd, &item); + /* Set the Expand/Collapse menu item appropriately */ + LoadString(hInst, (item.state & TVIS_EXPANDED) ? IDS_COLLAPSE : IDS_EXPAND, buffer, sizeof(buffer) / sizeof(buffer[0])); + memset(&mii, 0, sizeof(mii)); + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_ID; + mii.fState = (item.cChildren > 0) ? MFS_DEFAULT : MFS_GRAYED; + mii.wID = (item.state & TVIS_EXPANDED) ? ID_TREE_COLLAPSEBRANCH : ID_TREE_EXPANDBRANCH; + mii.dwTypeData = (LPTSTR) buffer; + SetMenuItemInfo(hContextMenu, 0, TRUE, &mii); - /* Set the Expand/Collapse menu item appropriately */ - LoadString(hInst, (item.state & TVIS_EXPANDED) ? IDS_COLLAPSE : IDS_EXPAND, buffer, sizeof(buffer) / sizeof(buffer[0])); - memset(&mii, 0, sizeof(mii)); - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STRING | MIIM_STATE | MIIM_ID; - mii.fState = (item.cChildren > 0) ? MFS_DEFAULT : MFS_GRAYED; - mii.wID = (item.state & TVIS_EXPANDED) ? ID_TREE_COLLAPSEBRANCH : ID_TREE_EXPANDBRANCH; - mii.dwTypeData = (LPTSTR) buffer; - SetMenuItemInfo(hContextMenu, 0, TRUE, &mii); + /* Remove any existing suggestions */ + memset(&mii, 0, sizeof(mii)); + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_ID; + GetMenuItemInfo(hContextMenu, GetMenuItemCount(hContextMenu) - 1, TRUE, &mii); + if ((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX)) + { + do + { + iLastPos = GetMenuItemCount(hContextMenu) - 1; + GetMenuItemInfo(hContextMenu, iLastPos, TRUE, &mii); + RemoveMenu(hContextMenu, iLastPos, MF_BYPOSITION); + } + while((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX)); + } - /* Remove any existing suggestions */ - memset(&mii, 0, sizeof(mii)); - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_ID; - GetMenuItemInfo(hContextMenu, GetMenuItemCount(hContextMenu) - 1, TRUE, &mii); - if ((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX)) - { - do - { - iLastPos = GetMenuItemCount(hContextMenu) - 1; - GetMenuItemInfo(hContextMenu, iLastPos, TRUE, &mii); - RemoveMenu(hContextMenu, iLastPos, MF_BYPOSITION); - } - while((mii.wID >= ID_TREE_SUGGESTION_MIN) && (mii.wID <= ID_TREE_SUGGESTION_MAX)); - } + /* Come up with suggestions */ + keyPath = GetItemPath(pChildWnd->hTreeWnd, NULL, &hRootKey); + SuggestKeys(hRootKey, keyPath, Suggestions, sizeof(Suggestions) / sizeof(Suggestions[0])); + if (Suggestions[0]) + { + AppendMenu(hContextMenu, MF_SEPARATOR, 0, NULL); - /* Come up with suggestions */ - keyPath = GetItemPath(pChildWnd->hTreeWnd, NULL, &hRootKey); - SuggestKeys(hRootKey, keyPath, Suggestions, sizeof(Suggestions) / sizeof(Suggestions[0])); - if (Suggestions[0]) - { - AppendMenu(hContextMenu, MF_SEPARATOR, 0, NULL); + LoadString(hInst, IDS_GOTO_SUGGESTED_KEY, resource, sizeof(resource) / sizeof(resource[0])); - LoadString(hInst, IDS_GOTO_SUGGESTED_KEY, resource, sizeof(resource) / sizeof(resource[0])); + s = Suggestions; + wID = ID_TREE_SUGGESTION_MIN; + while(*s && (wID <= ID_TREE_SUGGESTION_MAX)) + { + _sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), resource, s); - s = Suggestions; - wID = ID_TREE_SUGGESTION_MIN; - while(*s && (wID <= ID_TREE_SUGGESTION_MAX)) - { - _sntprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), resource, s); + memset(&mii, 0, sizeof(mii)); + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STRING | MIIM_ID; + mii.wID = wID++; + mii.dwTypeData = buffer; + InsertMenuItem(hContextMenu, GetMenuItemCount(hContextMenu), TRUE, &mii); - memset(&mii, 0, sizeof(mii)); - mii.cbSize = sizeof(mii); - mii.fMask = MIIM_STRING | MIIM_ID; - mii.wID = wID++; - mii.dwTypeData = buffer; - InsertMenuItem(hContextMenu, GetMenuItemCount(hContextMenu), TRUE, &mii); - - s += _tcslen(s) + 1; - } - } - TrackPopupMenu(hContextMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, pChildWnd->hWnd, NULL); + s += _tcslen(s) + 1; + } + } + TrackPopupMenu(hContextMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, pChildWnd->hWnd, NULL); + } + } + break; } - } - break; - } - case WM_SIZE: - if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) { - ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam)); - } - /* fall through */ -default: def: - return DefWindowProc(hWnd, message, wParam, lParam); + case WM_SIZE: + if (wParam != SIZE_MINIMIZED && pChildWnd != NULL) + { + ResizeWnd(pChildWnd, LOWORD(lParam), HIWORD(lParam)); + } + /* fall through */ + default: + def: + return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } Index: base/applications/regedit/resource.h =================================================================== --- base/applications/regedit/resource.h (revision 49426) +++ base/applications/regedit/resource.h (working copy) @@ -115,34 +115,36 @@ #define ID_HEXEDIT_SELECT_ALL 32839 #define IDS_LICENSE 32835 #define IDS_ERROR 32836 -#define IDS_BAD_VALUE 32837 -#define IDS_UNSUPPORTED_TYPE 32838 -#define IDS_TOO_BIG_VALUE 32839 -#define ID_EDIT_MODIFY_BIN 32840 -#define IDS_WARNING 32841 -#define IDS_MULTI_SZ_EMPTY_STRING 32842 -#define IDS_BINARY_EMPTY 32843 -#define IDS_DEFAULT_VALUE_NAME 32844 -#define IDS_VALUE_NOT_SET 32845 -#define IDS_UNKNOWN_TYPE 32846 -#define IDS_MY_COMPUTER 32847 -#define IDS_IMPORT_REG_FILE 32848 -#define IDS_EXPORT_REG_FILE 32849 -#define IDS_INVALID_DWORD 32850 -#define IDS_QUERY_DELETE_ONE 32851 -#define IDS_QUERY_DELETE_MORE 32852 -#define IDS_QUERY_DELETE_CONFIRM 32853 -#define IDS_ERR_DELVAL_CAPTION 32854 -#define IDS_ERR_DELETEVALUE 32855 -#define IDS_ERR_RENVAL_CAPTION 32856 -#define IDS_ERR_RENVAL_TOEMPTY 32857 +#define IDS_BAD_VALUE 32837 +#define IDS_UNSUPPORTED_TYPE 32838 +#define IDS_TOO_BIG_VALUE 32839 +#define ID_EDIT_MODIFY_BIN 32840 +#define IDS_WARNING 32841 +#define IDS_MULTI_SZ_EMPTY_STRING 32842 +#define IDS_BINARY_EMPTY 32843 +#define IDS_DEFAULT_VALUE_NAME 32844 +#define IDS_VALUE_NOT_SET 32845 +#define IDS_UNKNOWN_TYPE 32846 +#define IDS_MY_COMPUTER 32847 +#define IDS_IMPORT_REG_FILE 32848 +#define IDS_EXPORT_REG_FILE 32849 +#define IDS_INVALID_DWORD 32850 +#define IDS_QUERY_DELETE_ONE 32851 +#define IDS_QUERY_DELETE_MORE 32852 +#define IDS_QUERY_DELETE_CONFIRM 32853 +#define IDS_ERR_DELVAL_CAPTION 32854 +#define IDS_ERR_DELETEVALUE 32855 +#define IDS_ERR_RENVAL_CAPTION 32856 +#define IDS_ERR_RENVAL_TOEMPTY 32857 #define IDS_BAD_KEY 32858 +#define IDS_LOAD_HIVE 32859 +#define IDS_UNLOAD_HIVE 32860 -#define ID_EDIT_NEW_MULTISTRINGVALUE 32860 -#define ID_EDIT_NEW_EXPANDABLESTRINGVALUE 32861 +#define ID_EDIT_NEW_MULTISTRINGVALUE 32861 +#define ID_EDIT_NEW_EXPANDABLESTRINGVALUE 32862 #define ID_SWITCH_PANELS 32871 -#define ID_EDIT_PERMISSIONS 32872 +#define ID_EDIT_PERMISSIONS 32872 #define ID_TREE_DELETE 32873 #define ID_TREE_RENAME 32874 #define IDS_QUERY_DELETE_KEY_ONE 32875 @@ -154,29 +156,29 @@ #define ID_TREE_PERMISSIONS 32889 #define IDS_FLT_REGFILE 31000 -#define IDS_FLT_REGFILES 31001 -#define IDS_FLT_REGFILES_FLT 31002 -#define IDS_FLT_REGEDIT4 31003 -#define IDS_FLT_REGEDIT4_FLT 31004 -#define IDS_FLT_ALLFILES 31005 -#define IDS_FLT_ALLFILES_FLT 31006 +#define IDS_FLT_REGFILES 31001 +#define IDS_FLT_REGFILES_FLT 31002 +#define IDS_FLT_REGEDIT4 31003 +#define IDS_FLT_REGEDIT4_FLT 31004 +#define IDS_FLT_ALLFILES 31005 +#define IDS_FLT_ALLFILES_FLT 31006 -#define IDS_ACCESS_FULLCONTROL 31101 -#define IDS_ACCESS_READ 31102 -#define IDS_ACCESS_QUERYVALUE 31103 -#define IDS_ACCESS_SETVALUE 31104 -#define IDS_ACCESS_CREATESUBKEY 31105 -#define IDS_ACCESS_ENUMERATESUBKEYS 31106 -#define IDS_ACCESS_NOTIFY 31107 -#define IDS_ACCESS_CREATELINK 31108 -#define IDS_ACCESS_DELETE 31109 -#define IDS_ACCESS_WRITEDAC 31110 -#define IDS_ACCESS_WRITEOWNER 31111 -#define IDS_ACCESS_READCONTROL 31112 +#define IDS_ACCESS_FULLCONTROL 31101 +#define IDS_ACCESS_READ 31102 +#define IDS_ACCESS_QUERYVALUE 31103 +#define IDS_ACCESS_SETVALUE 31104 +#define IDS_ACCESS_CREATESUBKEY 31105 +#define IDS_ACCESS_ENUMERATESUBKEYS 31106 +#define IDS_ACCESS_NOTIFY 31107 +#define IDS_ACCESS_CREATELINK 31108 +#define IDS_ACCESS_DELETE 31109 +#define IDS_ACCESS_WRITEDAC 31110 +#define IDS_ACCESS_WRITEOWNER 31111 +#define IDS_ACCESS_READCONTROL 31112 -#define IDS_INHERIT_THISKEYONLY 31121 -#define IDS_INHERIT_THISKEYANDSUBKEYS 31122 -#define IDS_INHERIT_SUBKEYSONLY 31123 +#define IDS_INHERIT_THISKEYONLY 31121 +#define IDS_INHERIT_THISKEYANDSUBKEYS 31122 +#define IDS_INHERIT_SUBKEYSONLY 31123 #define IDS_EXPAND 31124 #define IDS_COLLAPSE 31125 #define IDS_NEW_KEY 31126 @@ -184,21 +186,23 @@ #define IDS_GOTO_SUGGESTED_KEY 31128 -#define IDD_EDIT_STRING 2000 -#define IDC_VALUE_NAME 2001 -#define IDC_VALUE_DATA 2002 +#define IDD_EDIT_STRING 2000 +#define IDC_VALUE_NAME 2001 +#define IDC_VALUE_DATA 2002 -#define IDD_EDIT_DWORD 2003 -#define IDC_FORMAT_HEX 2004 -#define IDC_FORMAT_DEC 2005 +#define IDD_EDIT_DWORD 2003 +#define IDC_FORMAT_HEX 2004 +#define IDC_FORMAT_DEC 2005 -#define IDD_EDIT_MULTI_STRING 2006 -#define IDD_EDIT_BIN_DATA 2007 +#define IDD_EDIT_MULTI_STRING 2006 +#define IDD_EDIT_BIN_DATA 2007 #define IDC_EXPORT_ALL 2008 #define IDC_EXPORT_BRANCH 2009 #define IDC_EXPORT_BRANCH_TEXT 2010 +#define IDD_LOADHIVE 2500 +#define IDC_EDIT_KEY 2501 #define IDC_FAVORITENAME 2011 #define IDC_FAVORITESLIST 2012