Bonjour,
J'ai �crit un programme utilisant la SDL2(SDL2.lib, SDL2main.lib, SDL2_image.lib et SDL2_ttf.lib) pour simuler un editBox. �a fonctionnait tr�s bien jusqu'au rajout d'une fonction pour ouvrir un fichier dans l'explorer.
C'est pr�cis�ment apr�s avoir cliqu� sur Ouvrir que ma police LucidaSansRegular.ttf n'est plus reconnue: TTF_GetError() renvoi "couldn't open xxx.ttf".
J'ai cherch� � r�soudre le probl�me par diverses mani�res : cr�er une nouvelle thread ex�cutant l'ouverture/s�lection du fichier, avec des events win32 et Sdl mais je n'ai pas r�ussi � r�soudre le probl�me.
Voici la fonction qui me permet de r�cup�r� le nom du fichier ouvert et celle qui r�cup�re du texte � afficher :
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 void CMain::changeDirectoryPath() { OPENFILENAME ofn; TCHAR szFile[MAX_PATH]; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.hwndOwner = NULL; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = TEXT("Text Files\0*.txt\0Any File\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrTitle = TEXT("Select dictionary"); ofn.lpstrInitialDir = L"data\\dictionary"; ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) { OutputDebugString(ofn.lpstrFile); int cSize = WideCharToMultiByte (CP_ACP, 0, ofn.lpstrFile, wcslen(ofn.lpstrFile), NULL, 0, NULL, NULL); string output(static_cast<size_t>(cSize), '\0'); WideCharToMultiByte (CP_ACP, 0, ofn.lpstrFile, wcslen(ofn.lpstrFile), reinterpret_cast<char*>(&output[0]), cSize, NULL, NULL); cout<<output<<endl; } cdpOn = false; }Est-ce que vous sauriez pourquoi je ne peux plus r�-ouvrir ma police apr�s avoir s�lectionn� un fichier et comment r�soudre le probl�me?
Code : S�lectionner tout - Visualiser dans une fen�tre � part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 bool CDictionary::loadFromRenderedText(std::string textureText) { if(Message!=NULL) { SDL_DestroyTexture(Message); Message = NULL; TTF_CloseFont(font); } font = TTF_OpenFont(filePath.c_str(), policeSize); if(!font) { cout<<"TTF_OpenFont: "<<TTF_GetError()<<endl; return 0; } textSurface = TTF_RenderText_Solid(font, textureText.c_str(), textColor); if(textSurface != NULL) { Message = SDL_CreateTextureFromSurface(renderer, textSurface); if(Message==NULL) { printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); } else { position.x=50; position.y=50; position.w=textSurface->w; position.h=textSurface->h; } SDL_FreeSurface(textSurface); } else { printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() ); } return Message != NULL; }
Merci d'avance
Partager