From: André Hentschel Subject: [3/3] winedbg: Add the ability to save the backtrace to a file (try 3) Message-Id: <4EF360A0.5080108@dawncrow.de> Date: Thu, 22 Dec 2011 17:53:52 +0100 --- programs/winedbg/Makefile.in | 2 +- programs/winedbg/crashdlg.c | 47 ++++++++++++++++++++++++++++++++++++++++++ programs/winedbg/resource.h | 6 +++++ programs/winedbg/winedbg.rc | 10 +++++++++ 4 files changed, 64 insertions(+), 1 deletions(-) diff --git a/programs/winedbg/Makefile.in b/programs/winedbg/Makefile.in index 92105c8..26b40a3 100644 --- a/programs/winedbg/Makefile.in +++ b/programs/winedbg/Makefile.in @@ -1,7 +1,7 @@ MODULE = winedbg.exe APPMODE = -mconsole IMPORTS = psapi dbghelp advapi32 -DELAYIMPORTS = shell32 comctl32 user32 gdi32 +DELAYIMPORTS = shell32 comctl32 user32 gdi32 comdlg32 EXTRALIBS = @LIBPOLL@ EXTRADEFS = -DWINE_NO_UNICODE_MACROS diff --git a/programs/winedbg/crashdlg.c b/programs/winedbg/crashdlg.c index ede5d2c..f9b97d0 100644 --- a/programs/winedbg/crashdlg.c +++ b/programs/winedbg/crashdlg.c @@ -173,6 +173,38 @@ static void report_output(HWND hDlg, enum output_targets target) HeapFree(GetProcessHeap(), 0, pTemp); } +static void report_to_file(HWND hDlg) +{ + OPENFILENAMEW ofn; + static const WCHAR txt_files[] = { '*', '.', 't', 'x', 't', 0 }; + static const WCHAR all_files[] = { '*', '.', '*', 0 }; + static WCHAR file[MAX_PATH] = {'b', 'a', 'c', 'k', 't', 'r', 'a', 'c', 'e', '.', 't', 'x', 't', 0}; + static WCHAR filter[MAXIMUM_FILENAME_LENGTH]; + LPWSTR p = filter; + + LoadStringW(hInstance, IDS_TEXT_FILES, p, sizeof(filter)/sizeof(WCHAR)); + p += lstrlenW(p) + 1; + lstrcpyW(p, txt_files); + p += lstrlenW(p) + 1; + LoadStringW(hInstance, IDS_ALL_FILES, p, sizeof(filter)/sizeof(WCHAR)); + p += lstrlenW(p) + 1; + lstrcpyW(p, all_files); + p += lstrlenW(p) + 1; + *p = '\0'; + + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; + ofn.hInstance = hInstance; + ofn.hwndOwner = hDlg; + ofn.lpstrFile = file; + ofn.lpstrFilter = filter; + ofn.nMaxFile = MAX_PATH; + + if (!GetSaveFileNameW(&ofn)) return; + CopyFileW( filename, file, FALSE ); +} + static LRESULT WINAPI report_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) @@ -191,6 +223,20 @@ static LRESULT WINAPI report_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM break; } + case WM_COMMAND: + switch (wParam) + { + case ID_SAVEREPORT: + report_to_file(hwnd); + break; + case ID_EXITREPORT: + DestroyWindow(hwnd); + break; + default: + break; + } + break; + case WM_SIZE: SetWindowPos(hEdit, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam), SWP_NOOWNERZORDER | SWP_NOZORDER); @@ -231,6 +277,7 @@ static INT_PTR WINAPI DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) class.lpfnWndProc = report_WndProc; class.hInstance = hInstance; class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + class.lpszMenuName = MAKEINTRESOURCEW(MAIN_MENU); class.lpszClassName = className; if (!RegisterClassExW(&class)) return FALSE; diff --git a/programs/winedbg/resource.h b/programs/winedbg/resource.h index 6563a53..07a3ae3 100644 --- a/programs/winedbg/resource.h +++ b/programs/winedbg/resource.h @@ -28,8 +28,14 @@ #define IDC_STATIC_TXT2 102 #define IDC_CRASHLOG 103 +#define MAIN_MENU 100 + #define ID_SHOWDETAILS 200 +#define ID_SAVEREPORT 201 +#define ID_EXITREPORT 202 #define IDS_AUTO_CAPTION 16 #define IDS_INVALID_PARAMS 17 #define IDS_UNIDENTIFIED 18 +#define IDS_ALL_FILES 19 +#define IDS_TEXT_FILES 20 diff --git a/programs/winedbg/winedbg.rc b/programs/winedbg/winedbg.rc index fbd1410..9bcc744 100644 --- a/programs/winedbg/winedbg.rc +++ b/programs/winedbg/winedbg.rc @@ -22,11 +22,21 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT +MAIN_MENU MENU +{ + POPUP "&Report" { + MENUITEM "Save &as...", ID_SAVEREPORT + MENUITEM "E&xit", ID_EXITREPORT + } +} + STRINGTABLE BEGIN IDS_AUTO_CAPTION "Wine program crash" IDS_INVALID_PARAMS "Internal errors - invalid parameters received" IDS_UNIDENTIFIED "(unidentified)" + IDS_TEXT_FILES "Text files (*.txt)" + IDS_ALL_FILES "All files (*.*)" END IDD_CRASH_DLG DIALOGEX 100, 100, 273, 175 -- Best Regards, André Hentschel