PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/include/error.h

https://bitbucket.org/FI_Mihej/backslash-enter-keys-position-interchanger
C Header | 43 lines | 27 code | 3 blank | 13 comment | 5 complexity | 79791a47b39d4b61fdc156417a8c246e MD5 | raw file
  1. /*
  2. Error message handling
  3. Copyright (C) 2009 Stefan Sundin (recover89@gmail.com)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. */
  9. int showerror = 1;
  10. LRESULT CALLBACK ErrorMsgProc(INT nCode, WPARAM wParam, LPARAM lParam) {
  11. if (nCode == HCBT_ACTIVATE) {
  12. //Edit the caption of the buttons
  13. SetDlgItemText((HWND)wParam, IDYES, L"Copy error");
  14. SetDlgItemText((HWND)wParam, IDNO, L"OK");
  15. }
  16. return 0;
  17. }
  18. void Error(wchar_t *func, wchar_t *info, int errorcode, wchar_t *file, int line) {
  19. if (showerror) {
  20. //Format message
  21. wchar_t errormsg[100];
  22. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorcode, 0, errormsg, sizeof(errormsg)/sizeof(wchar_t), NULL);
  23. errormsg[wcslen(errormsg)-2] = '\0'; //Remove that damn newline at the end of the formatted error message
  24. swprintf(txt, L"%s failed in file %s, line %d.\nError: %s (%d)\n\n%s", func, file, line, errormsg, errorcode, info);
  25. //Display message
  26. HHOOK hhk = SetWindowsHookEx(WH_CBT,&ErrorMsgProc,0,GetCurrentThreadId());
  27. int response = MessageBox(NULL,txt,APP_NAME" Error",MB_ICONERROR|MB_YESNO|MB_DEFBUTTON2);
  28. UnhookWindowsHookEx(hhk);
  29. if (response == IDYES) {
  30. //Copy message to clipboard
  31. OpenClipboard(NULL);
  32. EmptyClipboard();
  33. wchar_t *data = LocalAlloc(LMEM_FIXED,(wcslen(txt)+1)*sizeof(wchar_t));
  34. memcpy(data, txt, (wcslen(txt)+1)*sizeof(wchar_t));
  35. SetClipboardData(CF_UNICODETEXT, data);
  36. CloseClipboard();
  37. }
  38. }
  39. }