/** * Reads the heightmap and/or size of the heightmap from a PNG file. * If map == NULL only the size of the PNG is read, otherwise a map * with grayscale pixels is allocated and assigned to *map. */ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map) { FILE *fp; png_structp png_ptr = NULL; png_infop info_ptr = NULL; fp = FioFOpenFile(filename, "rb"); if (fp == NULL) { ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR); return false; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_MISC, WL_ERROR); fclose(fp); return false; } info_ptr = png_create_info_struct(png_ptr); if (info_ptr == NULL || setjmp(png_jmpbuf(png_ptr))) { ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_MISC, WL_ERROR); fclose(fp); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return false; } png_init_io(png_ptr, fp); /* Allocate memory and read image, without alpha or 16-bit samples * (result is either 8-bit indexed/grayscale or 24-bit RGB) */ png_set_packing(png_ptr); png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_ALPHA | PNG_TRANSFORM_STRIP_16, NULL); /* Maps of wrong colour-depth are not used. * (this should have been taken care of by stripping alpha and 16-bit samples on load) */ if ((png_get_channels(png_ptr, info_ptr) != 1) && (png_get_channels(png_ptr, info_ptr) != 3) && (png_get_bit_depth(png_ptr, info_ptr) != 8)) { ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_IMAGE_TYPE, WL_ERROR); fclose(fp); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return false; } if (map != NULL) { *map = MallocT<byte>(png_get_image_width(png_ptr, info_ptr) * png_get_image_height(png_ptr, info_ptr)); ReadHeightmapPNGImageData(*map, png_ptr, info_ptr); } *x = png_get_image_width(png_ptr, info_ptr); *y = png_get_image_height(png_ptr, info_ptr); fclose(fp); png_destroy_read_struct(&png_ptr, &info_ptr, NULL); return true; }
/*! * Toplevel network safe docommand function for the current company. Must not be called recursively. * The callback is called when the command succeeded or failed. The parameters * \a tile, \a p1, and \a p2 are from the #CommandProc function. The parameter \a cmd is the command to execute. * The parameter \a my_cmd is used to indicate if the command is from a company or the server. * * @param tile The tile to perform a command on (see #CommandProc) * @param p1 Additional data for the command (see #CommandProc) * @param p2 Additional data for the command (see #CommandProc) * @param cmd The command to execute (a CMD_* value) * @param callback A callback function to call after the command is finished * @param text The text to pass * @param my_cmd indicator if the command is from a company or server (to display error messages for a user) * @return \c true if the command succeeded, else \c false. */ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd) { /* Cost estimation is generally only done when the * local user presses shift while doing somthing. * However, in case of incoming network commands, * map generation or the pause button we do want * to execute. */ bool estimate_only = _shift_pressed && IsLocalCompany() && !_generating_world && !(cmd & CMD_NETWORK_COMMAND) && (cmd & CMD_ID_MASK) != CMD_PAUSE; /* We're only sending the command, so don't do * fancy things for 'success'. */ bool only_sending = _networking && !(cmd & CMD_NETWORK_COMMAND); /* Where to show the message? */ int x = TileX(tile) * TILE_SIZE; int y = TileY(tile) * TILE_SIZE; if (_pause_mode != PM_UNPAUSED && !IsCommandAllowedWhilePaused(cmd)) { ShowErrorMessage(GB(cmd, 16, 16), STR_ERROR_NOT_ALLOWED_WHILE_PAUSED, WL_INFO, x, y); return false; } #ifdef ENABLE_NETWORK /* Only set p2 when the command does not come from the network. */ if (!(cmd & CMD_NETWORK_COMMAND) && GetCommandFlags(cmd) & CMD_CLIENT_ID && p2 == 0) p2 = CLIENT_ID_SERVER; #endif CommandCost res = DoCommandPInternal(tile, p1, p2, cmd, callback, text, my_cmd, estimate_only); if (res.Failed()) { /* Only show the error when it's for us. */ StringID error_part1 = GB(cmd, 16, 16); if (estimate_only || (IsLocalCompany() && error_part1 != 0 && my_cmd)) { ShowErrorMessage(error_part1, res.GetErrorMessage(), WL_INFO, x, y, res.GetTextRefStackSize(), res.GetTextRefStack()); } } else if (estimate_only) { ShowEstimatedCostOrIncome(res.GetCost(), x, y); } else if (!only_sending && res.GetCost() != 0 && tile != 0 && IsLocalCompany() && _game_mode != GM_EDITOR) { /* Only show the cost animation when we did actually * execute the command, i.e. we're not sending it to * the server, when it has cost the local company * something. Furthermore in the editor there is no * concept of cost, so don't show it there either. */ ShowCostOrIncomeAnimation(x, y, GetSlopePixelZ(x, y), res.GetCost()); } if (!estimate_only && !only_sending && callback != NULL) { callback(res, tile, p1, p2); } return res.Succeeded(); }
void CTblInfoView::SaveLocalCache() { //prepare the content firstly CString strContent = ""; //updatetime strContent += m_strUpdateTime; strContent += SEP_RECORD; map<CString, CString>::iterator it; for (it = m_map_req_resp.begin(); it != m_map_req_resp.end(); it++) { strContent += it->first; strContent += SEP_RECORD; strContent += it->second; strContent += SEP_RECORD; } //now write to file HANDLE hFile = ::CreateFile(CACHE_FILE, GENERIC_WRITE, //desired access FILE_SHARE_READ, //share mode NULL, //Security CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hFile) { ShowErrorMessage(); return; } DWORD dwLen = strContent.GetLength(); DWORD dwWriteLen = 0; BOOL bRet = FALSE; bRet = WriteFile(hFile, (LPCVOID)strContent.GetBuffer(0), dwLen, &dwWriteLen, NULL ); if (!bRet) { ShowErrorMessage(); } CloseHandle(hFile); }
/** * Reads the heightmap and/or size of the heightmap from a BMP file. * If map == nullptr only the size of the BMP is read, otherwise a map * with grayscale pixels is allocated and assigned to *map. */ static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, byte **map) { FILE *f; BmpInfo info; BmpData data; BmpBuffer buffer; /* Init BmpData */ memset(&data, 0, sizeof(data)); f = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR); if (f == nullptr) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR); return false; } BmpInitializeBuffer(&buffer, f); if (!BmpReadHeader(&buffer, &info, &data)) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR); fclose(f); BmpDestroyData(&data); return false; } /* Check if image dimensions don't overflow a size_t to avoid memory corruption. */ if ((uint64)info.width * info.height >= (size_t)-1 / (info.bpp == 24 ? 3 : 1)) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_HEIGHTMAP_TOO_LARGE, WL_ERROR); fclose(f); BmpDestroyData(&data); return false; } if (map != nullptr) { if (!BmpReadBitmap(&buffer, &info, &data)) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR); fclose(f); BmpDestroyData(&data); return false; } *map = MallocT<byte>(info.width * info.height); ReadHeightmapBMPImageData(*map, &info, &data); } BmpDestroyData(&data); *x = info.width; *y = info.height; fclose(f); return true; }
virtual void OnClick(Point pt, int widget) { #ifdef ENABLE_NETWORK /* Do not create a network server when you (just) have closed one of the game * creation/load windows for the network server. */ if (IsInsideMM(widget, SGI_GENERATE_GAME, SGI_EDIT_SCENARIO + 1)) _is_network_server = false; #endif /* ENABLE_NETWORK */ switch (widget) { case SGI_GENERATE_GAME: if (_ctrl_pressed) { StartNewGameWithoutGUI(GENERATE_NEW_SEED); } else { ShowGenerateLandscape(); } break; case SGI_LOAD_GAME: ShowSaveLoadDialog(SLD_LOAD_GAME); break; case SGI_PLAY_SCENARIO: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break; case SGI_PLAY_HEIGHTMAP: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break; case SGI_EDIT_SCENARIO: StartScenarioEditor(); break; case SGI_PLAY_NETWORK: if (!_network_available) { ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, 0, 0); } else { ShowNetworkGameWindow(); } break; case SGI_TEMPERATE_LANDSCAPE: case SGI_ARCTIC_LANDSCAPE: case SGI_TROPIC_LANDSCAPE: case SGI_TOYLAND_LANDSCAPE: this->RaiseWidget(_settings_newgame.game_creation.landscape + SGI_TEMPERATE_LANDSCAPE); SetNewLandscapeType(widget - SGI_TEMPERATE_LANDSCAPE); this->SetLandscapeButtons(); break; case SGI_OPTIONS: ShowGameOptions(); break; case SGI_DIFFICULTIES: ShowGameDifficulty(); break; case SGI_SETTINGS_OPTIONS:ShowGameSettings(); break; case SGI_GRF_SETTINGS: ShowNewGRFSettings(true, true, false, &_grfconfig_newgame); break; case SGI_CONTENT_DOWNLOAD: if (!_network_available) { ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, 0, 0); } else { ShowNetworkContentListWindow(); } break; case SGI_AI_SETTINGS: ShowAIConfigWindow(); break; case SGI_EXIT: HandleExitGameRequest(); break; } }
/** * Make an actual screenshot. * @param t the type of screenshot to make. * @param name the name to give to the screenshot. * @return true iff the screenshot was made successfully */ bool MakeScreenshot(ScreenshotType t, const char *name) { if (t == SC_VIEWPORT) { /* First draw the dirty parts of the screen and only then change the name * of the screenshot. This way the screenshot will always show the name * of the previous screenshot in the 'successful' message instead of the * name of the new screenshot (or an empty name). */ UndrawMouseCursor(); DrawDirtyBlocks(); } _screenshot_name[0] = '\0'; if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_name)); bool ret; switch (t) { case SC_VIEWPORT: ret = MakeSmallScreenshot(false); break; case SC_CRASHLOG: ret = MakeSmallScreenshot(true); break; case SC_ZOOMEDIN: case SC_DEFAULTZOOM: case SC_WORLD: ret = MakeLargeWorldScreenshot(t); break; case SC_HEIGHTMAP: { const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format; ret = MakeHeightmapScreenshot(MakeScreenshotName(HEIGHTMAP_NAME, sf->extension)); break; } default: NOT_REACHED(); } if (ret) { SetDParamStr(0, _screenshot_name); ShowErrorMessage(STR_MESSAGE_SCREENSHOT_SUCCESSFULLY, INVALID_STRING_ID, WL_WARNING); } else { ShowErrorMessage(STR_ERROR_SCREENSHOT_FAILED, INVALID_STRING_ID, WL_ERROR); } return ret; }
DEF_CONTENT_RECEIVE_COMMAND(Client, PACKET_CONTENT_SERVER_CONTENT) { if (this->curFile == NULL) { delete this->curInfo; /* When we haven't opened a file this must be our first packet with metadata. */ this->curInfo = new ContentInfo; this->curInfo->type = (ContentType)p->Recv_uint8(); this->curInfo->id = (ContentID)p->Recv_uint32(); this->curInfo->filesize = p->Recv_uint32(); p->Recv_string(this->curInfo->filename, lengthof(this->curInfo->filename)); if (!this->BeforeDownload()) { this->Close(); return false; } } else { /* We have a file opened, thus are downloading internal content */ size_t toRead = (size_t)(p->size - p->pos); if (fwrite(p->buffer + p->pos, 1, toRead, this->curFile) != toRead) { DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, WL_ERROR); this->Close(); fclose(this->curFile); this->curFile = NULL; return false; } this->OnDownloadProgress(this->curInfo, (uint)toRead); if (toRead == 0) this->AfterDownload(); } return true; }
/** * Finish a paste process. * @return Total cost. */ static CommandCost FinalizePasting() { /* Set error string parameters */ CopyInDParam(0, _current_pasting->err_params, lengthof(_current_pasting->err_params)); /* Set error summary message (see COPY_PASTE_ERR_SUMMARY_PARAM for details). */ SetDParam(COPY_PASTE_ERR_SUMMARY_PARAM, _current_pasting->err_summary); /* Store the error tile so the GUI (CcPaste) can highlight it. */ _paste_err_tile = _current_pasting->err_tile; CommandCost ret; if (_current_pasting->had_success) { /* Return overal cost of the operation */ ret = CommandCost(EXPENSES_CONSTRUCTION, _current_pasting->overal_cost); /* Here we are about to return a success. However, there could occured some meaningful * errors (those except "already built", "already leveled" etc.) and we should inform * the user that not everything went right. Show the message now. */ if ((_current_pasting->dc_flags & DC_EXEC) && IsLocalCompany() && GetPasteErrorImportance(_current_pasting->err_message) > GetPasteErrorImportance(STR_ERROR_NOTHING_TO_DO)) { ShowErrorMessage(_current_pasting->err_summary, _current_pasting->err_message, WL_INFO); } else { /* If we are not showing error message then clear the error tile to prevent GUI * (CcPaste) from higlighting it. */ _paste_err_tile = INVALID_TILE; } } else { /* Return an error if we didn't have any success. */ ret = CommandCost(_current_pasting->err_message); } /* cleanup */ delete _current_pasting; _current_pasting = NULL; return ret; }
BOOL OnCreate(HWND hwnd, LPCREATESTRUCT /*lpCreateStruct*/) { DEV_BROADCAST_DEVICEINTERFACE di = { 0 }; di.dbcc_size = sizeof(di); di.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; di.dbcc_classguid = KSCATEGORY_CAPTURE; g_hdevnotify = RegisterDeviceNotification( hwnd, &di, DEVICE_NOTIFY_WINDOW_HANDLE ); if (g_hdevnotify == NULL) { ShowErrorMessage( hwnd, L"RegisterDeviceNotification failed.", HRESULT_FROM_WIN32(GetLastError()) ); return FALSE; } return TRUE; }
virtual void OnTimeout() { /* This test protects against using widgets 11 and 12 which are only available * in those saveload modes. */ if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return; if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked if (!FiosDelete(this->filename_editbox.text.buf)) { ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR); } else { this->InvalidateData(); /* Reset file name to current date on successful delete */ if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName(); } } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { _switch_mode = SM_SAVE_GAME; FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name)); } else { _switch_mode = SM_SAVE_HEIGHTMAP; FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, sizeof(_file_to_saveload.name)); } /* In the editor set up the vehicle engines correctly (date might have changed) */ if (_game_mode == GM_EDITOR) StartupEngines(); } }
void CPreview::OnMediaItemSet(MFP_MEDIAITEM_SET_EVENT * /*pEvent*/) { HRESULT hr = S_OK; SIZE szVideo = { 0 }; RECT rc = { 0 }; // Adjust the preview window to match the native size // of the captured video. hr = m_pPlayer->GetNativeVideoSize(&szVideo, NULL); if (SUCCEEDED(hr)) { SetRect(&rc, 0, 0, szVideo.cx, szVideo.cy); AdjustWindowRect( &rc, GetWindowLong(m_hwnd, GWL_STYLE), TRUE ); SetWindowPos(m_hwnd, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOOWNERZORDER); hr = m_pPlayer->Play(); } if (FAILED(hr)) { ShowErrorMessage(NULL, L"Preview error.", hr); } }
void CPreview::OnMediaItemCreated(MFP_MEDIAITEM_CREATED_EVENT *pEvent) { HRESULT hr = S_OK; if (m_pPlayer) { // Check if there is video. BOOL bHasVideo = FALSE, bIsSelected = FALSE; hr = pEvent->pMediaItem->HasVideo(&bHasVideo, &bIsSelected); if (SUCCEEDED(hr)) { m_bHasVideo = bHasVideo && bIsSelected; // Set this media item on the player. hr = m_pPlayer->SetMediaItem(pEvent->pMediaItem); } } if (FAILED(hr)) { ShowErrorMessage(NULL, L"Preview error.", hr); } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, #ifdef UNDER_CE LPWSTR #else LPSTR #endif /* lpCmdLine */, int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; NT_CHECK try { return WinMain2(); } catch(const CNewException &) { ErrorMessageForHRESULT(E_OUTOFMEMORY); return NExitCode::kMemoryError; } catch(...) { ShowErrorMessage(kUnknownExceptionMessage); return NExitCode::kFatalError; } }
/** * Fatal error handler. Provides support for formatting the system * error message and showing errors with format strings etc blahblah. */ STATIC NORETURN FatalError(DWORD dwError, LPTSTR lpMessage, ...) { DWORD dwExit; va_list lpArgs = NULL; LPTSTR lpDisplayBuf = NULL; // If dwError has not been set, use the value of GetLastError if(dwError == ERROR_SUCCESS) { dwError = GetLastError(); } // Format message against args. va_start(lpArgs, lpMessage); lpDisplayBuf = StringCchVAPrintf(lpMessage, lpArgs); va_end(lpArgs); // If dwError contains an error code, get the system error message for it. if(dwError != ERROR_SUCCESS) { TCHAR *lpErrMsg = NULL, *lpTemp = NULL; dwExit = dwError; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpErrMsg, 0, NULL ); lpTemp = StringCchAPrintf(_T("%s - Windows Error [0x%08X]: %s"), lpDisplayBuf, dwError, lpErrMsg); xfree(lpDisplayBuf); lpDisplayBuf = lpTemp; LocalFree((HLOCAL)lpErrMsg); } else { dwExit = 1; } ShowErrorMessage(lpDisplayBuf); xfree(lpDisplayBuf); ExitProcess(dwExit); }
virtual void OnTimeout() { /* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */ if (this->fop != SLO_SAVE) return; if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked if (!FiosDelete(this->filename_editbox.text.buf)) { ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR); } else { this->InvalidateData(SLIWD_RESCAN_FILES); /* Reset file name to current date on successful delete */ if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName(); } } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) { FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback); } else { _switch_mode = SM_SAVE_GAME; } } else { FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name)); if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) { ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback); } else { _switch_mode = SM_SAVE_HEIGHTMAP; } } /* In the editor set up the vehicle engines correctly (date might have changed) */ if (_game_mode == GM_EDITOR) StartupEngines(); } }
/** * Create an autosave. The default name is "autosave#.sav". However with * the setting 'keep_all_autosave' the name defaults to company-name + date */ static void DoAutosave() { char buf[MAX_PATH]; #if defined(PSP) /* Autosaving in networking is too time expensive for the PSP */ if (_networking) return; #endif /* PSP */ if (_settings_client.gui.keep_all_autosave) { GenerateDefaultSaveName(buf, lastof(buf)); strecat(buf, ".sav", lastof(buf)); } else { static int _autosave_ctr = 0; /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */ snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr); if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0; } DEBUG(sl, 2, "Autosaving to '%s'", buf); if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) { ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR); } }
ULONG CBmpManager::GetScreenBmpGDI(CRect rect,BYTE*& bmpBuf) { ULONG bufSize=0; HBITMAP hOldbitmap,hBitmap; hBitmap=CreateCompatibleBitmap(mv_hScreenDc,rect.Width(),rect.Height()); if(NULL==hBitmap) return 0; hOldbitmap=(HBITMAP)SelectObject(mv_destDC,hBitmap); if(rect.Width()<=0||rect.Height()<=0) return 0; if(0==BitBlt(mv_destDC,0,0,rect.Width(),rect.Height(),mv_hScreenDc, rect.left,rect.top,SRCCOPY)) { DWORD dwError=GetLastError(); ShowErrorMessage(dwError); return 0; } bufSize=rect.Width()*rect.Height()*4; if(bufSize>0) { bmpBuf=new BYTE[bufSize]; ::GetBitmapBits(hBitmap,bufSize,bmpBuf); } ::DeleteObject(hBitmap); ::DeleteObject(hOldbitmap); return bufSize; }
/** * Check the connection's state, i.e. is the connection still up? */ void ClientNetworkGameSocketHandler::CheckConnection() { /* Only once we're authorized we can expect a steady stream of packets. */ if (this->status < STATUS_AUTHORIZED) return; /* It might... sometimes occur that the realtime ticker overflows. */ if (_realtime_tick < this->last_packet) this->last_packet = _realtime_tick; /* Lag is in milliseconds; 5 seconds are roughly twice the * server's "you're slow" threshold (1 game day). */ uint lag = (_realtime_tick - this->last_packet) / 1000; if (lag < 5) return; /* 20 seconds are (way) more than 4 game days after which * the server will forcefully disconnect you. */ if (lag > 20) { this->NetworkGameSocketHandler::CloseConnection(); _switch_mode_errorstr = STR_NETWORK_ERROR_LOSTCONNECTION; return; } /* Prevent showing the lag message every tick; just update it when needed. */ static uint last_lag = 0; if (last_lag == lag) return; last_lag = lag; SetDParam(0, lag); ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO); }
LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam) { CString csNewText = (TCHAR*)wParam; ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText); return TRUE; }
void FeedbackDialog::NetReply(QNetworkReply *reply) { if (reply == genCaptchaRequest) { if (reply->error() != QNetworkReply::NoError) { qDebug() << "Error generating captcha image: " << reply->errorString(); ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); return; } bool okay; QByteArray body = reply->readAll(); captchaID = QString(body).toInt(&okay); if (!okay) { qDebug() << "Failed to get captcha ID: " << body; ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); return; } QString url = "http://hedgewars.org/feedback/?captcha&id="; url += QString::number(captchaID); QNetworkAccessManager *netManager = GetNetManager(); QUrl captchaURL(url); QNetworkRequest req(captchaURL); captchaImageRequest = netManager->get(req); } else if (reply == captchaImageRequest) { if (reply->error() != QNetworkReply::NoError) { qDebug() << "Error loading captcha image: " << reply->errorString(); ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); return; } QByteArray imageData = reply->readAll(); QPixmap pixmap; pixmap.loadFromData(imageData); label_captcha->setPixmap(pixmap); captcha_code->setText(""); } }
bool CreatePotentialField(float t) { // Generate new potential field, make sure it doesn't complain potential_field pf; PotFieldErr err = ComputePotentialField(t, pf); if (err == potSpawn) { ShowErrorMessage(errIsolateSpawnNow); return false; } else if (err == potUnit) { ShowErrorMessage(errIsolateUnitNow); return false; } // Locate current potential field, split it at t auto it = GetPotentialField(t); pf.alive = span(t, it->alive.t1); it->alive.t1 = t; auto newit = g_potential_fields.insert(++it, pf); while (it != g_potential_fields.end()) { err = ComputePotentialField(it->alive.t0, *it); if (err != potOK) { if (err == potSpawn) { ShowErrorMessage(errIsolateSpawnFuture); return false; } else if (err == potUnit) { ShowErrorMessage(errIsolateUnitFuture); return false; } it = newit; --it; it->alive.t1 = newit->alive.t1; g_potential_fields.erase(newit); return false; } ++it; } return true; }
/** * Reads the heightmap and/or size of the heightmap from a BMP file. * If map == NULL only the size of the BMP is read, otherwise a map * with grayscale pixels is allocated and assigned to *map. */ static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map) { FILE *f; BmpInfo info; BmpData data; BmpBuffer buffer; /* Init BmpData */ memset(&data, 0, sizeof(data)); f = FioFOpenFile(filename, "rb"); if (f == NULL) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR); return false; } BmpInitializeBuffer(&buffer, f); if (!BmpReadHeader(&buffer, &info, &data)) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR); fclose(f); BmpDestroyData(&data); return false; } if (map != NULL) { if (!BmpReadBitmap(&buffer, &info, &data)) { ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_BMPMAP_IMAGE_TYPE, WL_ERROR); fclose(f); BmpDestroyData(&data); return false; } *map = MallocT<byte>(info.width * info.height); ReadHeightmapBMPImageData(*map, &info, &data); } BmpDestroyData(&data); *x = info.width; *y = info.height; fclose(f); return true; }
int wmain(int argc, WCHAR* argv[]) { if ((argc == 1) || ((argc == 2) && (lstrcmpi(argv[1], L"/?") == 0))) { ShowUsage(); return E_INVALIDARG; } int i = argc - 1; //File name is always the last option LPCWSTR szFilePath = argv[i]; //Find whether the file is a .exe or a .dll LPCWSTR szExtension = PathFindExtension(szFilePath); bool bExe = false; bool bCurrentUser = false; bool bUnregister = false; if (lstrcmpi(szExtension, TEXT(".exe")) == 0) bExe = true; //else default to dll //Parse the command line to find the other options i--; while(i > 0) { if (lstrcmpi(argv[i], L"/u") == 0) bUnregister = true; else if (lstrcmpi(argv[i], L"/c") == 0) bCurrentUser = true; // else // { // //Ignore the option // } i--; } HRESULT hr; if (bExe) { hr = RegisterExe(szFilePath, bUnregister, bCurrentUser); } else { hr = RegisterDll(szFilePath, bUnregister, bCurrentUser); } if (FAILED(hr)) ShowErrorMessage(hr); return hr; }
void ErrorMessageForHRESULT(HRESULT res) { UString s; if (res == E_OUTOFMEMORY) s = NWindows::MyLoadStringW(IDS_MEM_ERROR); else s = NWindows::NError::MyFormatMessageW(res); ShowErrorMessage(s); }
void CSDKLoginUIMgr::ChangeUIforLoginFailed() { if (m_panel_login_content) { m_panel_login_content->SetVisible(true); } SwitchToWaitingPage(L"",false); ShowErrorMessage(_T("login failed!")); }
virtual void OnConnect(bool success) { if (!success) { ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_CONNECT, INVALID_STRING_ID, WL_ERROR); delete this; return; } this->InvalidateData(); }
void OnFileOpen(HWND hwnd) { HRESULT hr = S_OK; IFileDialog *pDialog = NULL; IShellItem *pItem = NULL; LPWSTR pwszFilePath = NULL; // Create the FileOpenDialog object. hr = CoCreateInstance( __uuidof(FileOpenDialog), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDialog) ); if (FAILED(hr)) { goto done; } hr = pDialog->SetTitle(L"Select a File to Play"); if (FAILED(hr)) { goto done; } // Show the file-open dialog. hr = pDialog->Show(hwnd); if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)) { // User cancelled. hr = S_OK; goto done; } if (FAILED(hr)) { goto done; } hr = pDialog->GetResult(&pItem); if (FAILED(hr)) { goto done; } hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwszFilePath); if (FAILED(hr)) { goto done; } // Open the file and create bitmaps. hr = OpenVideoFile(hwnd, pwszFilePath); done: if (FAILED(hr)) { ShowErrorMessage(L"Cannot open file.", hr); } CoTaskMemFree(pwszFilePath); SafeRelease(&pItem); SafeRelease(&pDialog); }
/** * We found a corrupted sprite. This means that the sprite itself * contains invalid data or is too small for the given dimensions. * @param file_slot the file the errored sprite is in * @param file_pos the location in the file of the errored sprite * @param line the line where the error occurs. * @return always false (to tell loading the sprite failed) */ static bool WarnCorruptSprite(uint8 file_slot, size_t file_pos, int line) { static byte warning_level = 0; if (warning_level == 0) { SetDParamStr(0, FioGetFilename(file_slot)); ShowErrorMessage(STR_NEWGRF_ERROR_CORRUPT_SPRITE, INVALID_STRING_ID, WL_ERROR); } DEBUG(sprite, warning_level, "[%i] Loading corrupted sprite from %s at position %i", line, FioGetFilename(file_slot), (int)file_pos); warning_level = 6; return false; }
/** * Display estimated costs. * @param cost Estimated cost (or income if negative). * @param x X position of the notification window. * @param y Y position of the notification window. */ void ShowEstimatedCostOrIncome(Money cost, int x, int y) { StringID msg = STR_MESSAGE_ESTIMATED_COST; if (cost < 0) { cost = -cost; msg = STR_MESSAGE_ESTIMATED_INCOME; } SetDParam(0, cost); ShowErrorMessage(msg, INVALID_STRING_ID, WL_INFO, x, y); }
/** * Check whether we modified the difficulty level or not. */ void CheckDifficultyLevel() { if (_game_mode == GM_MENU) { if (_settings_newgame.difficulty.diff_level != 3) { _settings_newgame.difficulty.diff_level = 3; ShowErrorMessage(STR_WARNING_DIFFICULTY_TO_CUSTOM, INVALID_STRING_ID, WL_WARNING); } } else if (_settings_game.difficulty.diff_level != 3) { IConsoleSetSetting("difficulty.diff_level", 3); } }