void openDebugLog() { TCHAR fileName[MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), fileName, MAX_PATH); size_t pos; StringCchLength(fileName, MAX_PATH, &pos); while (pos >= 0 && fileName[pos] != _T('\\')) --pos; StringCchCopy(&fileName[pos+1], MAX_PATH - pos - 1, LOG_DIR); if (!CreateDirectory(fileName, NULL)) { if (GetLastError() != ERROR_ALREADY_EXISTS) { showLastError(NULL, _T("Error creating debug log directory")); return; } } long time = GetTickCount(); StringCchLength(fileName, MAX_PATH, &pos); wsprintf(&fileName[pos], _T("\\taekwindow-debug-%d.%03d.log"), time/1000, time%1000); debugLogFile = CreateFile(fileName, FILE_WRITE_DATA, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (debugLogFile == INVALID_HANDLE_VALUE) { showLastError(NULL, _T("Error opening debug log")); return; } DEBUGLOG("Log file opened"); }
bool GWFFileLoader::load(QString file_name, QObject *output) { SCgScene *scene = qobject_cast<SCgScene*>(output); // read data from file QString errorStr; int errorLine; int errorColumn; QFile file(file_name); QDomDocument document; mFileName = file_name; if (!document.setContent(&file, &errorStr, &errorLine, &errorColumn)) { QMessageBox::information(0, qAppName(), QObject::tr("Error while opening file %1.\nParse error at line %2, column %3:\n%4") .arg(file_name) .arg(errorLine) .arg(errorColumn) .arg(errorStr)); return false; } ///////////////////////////////////////////// // Read document GwfObjectInfoReader reader; if (! reader.read(document)) { mLastError = reader.lastError(); showLastError(); return false; } ///////////////////////////////////////////// ///////////////////////////////////////////// //Place objects to scene DefaultSCgObjectBuilder objectBuilder(scene); objectBuilder.buildObjects(reader.objectsInfo()); if (objectBuilder.hasErrors()) { mLastError = QObject::tr("Building process has finished with following errors:\n").arg(mFileName); foreach(const QString& str, objectBuilder.errorList()) mLastError += str + '\n'; showLastError(); }
TrayIcon::TrayIcon() : d_showing(false) { HINSTANCE instance = GetModuleHandle(NULL); d_enabledIcon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_TRAY_COLOUR), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE); d_disabledIcon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_TRAY_GRAY), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE); // Create the notify icon itself. // We use Version 5.0, that is, Windows 2000/XP semantics. d_data.cbSize = sizeof(d_data); d_data.hWnd = d_window.handle(); d_data.uID = ICON_ID; d_data.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; d_data.uCallbackMessage = TRAYICON_MESSAGE; d_data.hIcon = currentIcon(); StringCchCopy(d_data.szTip, sizeof(d_data.szTip), _T(APPLICATION_TITLE)); d_data.dwState = 0; d_data.dwStateMask = 0; d_data.szInfo[0] = _T('\0'); d_data.uVersion = NOTIFYICON_VERSION; d_data.szInfoTitle[0] = _T('\0'); d_data.dwInfoFlags = 0; if (!Shell_NotifyIcon(NIM_ADD, &d_data)) { showLastError(NULL, _T("Error creating notify icon")); return; } d_window.setWindowProc(WindowProcFwd<TrayIcon>(*this, &TrayIcon::windowProc)); d_showing = true; }
void MessageWindow::setWindowProc(WindowProcFunc const &proc) { if (!d_handle) return; delete d_windowProcFunc; d_windowProcFunc = proc.clone(); SetLastError(0); SetWindowLongPtr(d_handle, GWLP_USERDATA, (LONG_PTR)d_windowProcFunc); if (GetLastError()) { showLastError(NULL, _T("Failed to set window user data")); return; } }
MessageWindow::MessageWindow() : d_handle(NULL), d_windowProcFunc(NULL) { HINSTANCE instance = GetModuleHandle(NULL); // Create the dummy window that receives the icon's messages. d_handle = CreateWindow(d_class.name(), _T(APPLICATION_TITLE), 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_MESSAGE, NULL, instance, 0); if (!d_handle) { showLastError(NULL, _T("Error creating window")); return; } }
void MessageWindowClass::create() { WNDCLASSEX wndClass; wndClass.cbSize = sizeof(wndClass); wndClass.style = 0; wndClass.lpfnWndProc = &windowProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = sizeof(WindowProcFunc); wndClass.hInstance = GetModuleHandle(NULL); wndClass.hIcon = NULL; wndClass.hCursor = NULL; wndClass.hbrBackground = NULL; wndClass.lpszMenuName = NULL; wndClass.lpszClassName = s_name; wndClass.hIconSm = NULL; s_atom = RegisterClassEx(&wndClass); if (!s_atom) { showLastError(NULL, _T("Error registering window class")); return; } }
void GWFFileLoader::showGeneralError() { errorParse(); showLastError(); }