Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

TEXTE SUR IMAGE (WIN32, NON MFC)


Information sur la source

Catégorie :API Niveau : Initié Date de création : 10/03/2003 Date de mise à jour : 10/03/2003 12:17:09 Vu / téléchargé: 3 277 / 369

Note :
7,5 / 10 - par 4 personnes
7,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note


Description

On met le texte dans un EDIT.
Un bouton pour l'inserer sur l'image.
Ceci simple grace a un STATIC invisible.
Il faut juste coordonner refresh de l'image.
Couleur du texte modifiable.
 

Source

  • #include <windows.h>
  • #include "resource.h"
  • HINSTANCE hinst;
  • char sztxt[400];
  • HWND hstbmp, hsttxt;
  • BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
  • {
  • switch(mssg) {
  • case WM_INITDIALOG:
  • RECT rc;
  • int cx, cy;
  • SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
  • hstbmp = GetDlgItem(hdlg, IDST_BMP);
  • GetWindowRect(hstbmp, &rc);
  • cx = rc.right - rc.left;
  • cy = rc.bottom - rc.top;
  • ScreenToClient(hdlg, (POINT*) &rc);
  • hsttxt = GetDlgItem(hdlg, IDST_TXT);
  • SetWindowPos(hsttxt, HWND_TOP, rc.left, rc.top, cx, cy, SWP_SHOWWINDOW);
  • SendDlgItemMessage(hdlg, IDED_TXT, EM_SETLIMITTEXT, 399, 0);
  • return TRUE;
  • case WM_CTLCOLORSTATIC:
  • if(GetWindowLong((HWND)lParam, GWL_ID) == IDST_TXT) {
  • SetBkMode((HDC) wParam, TRANSPARENT);
  • SetTextColor((HDC) wParam, 0xFF); // tu peux enlever ou changer couleur
  • return (BOOL) GetStockObject(NULL_BRUSH);
  • }
  • return 0;
  • case WM_COMMAND:
  • switch(wParam) {
  • case IDBT_TXT:
  • InvalidateRect(hstbmp, 0, 1);
  • SetWindowText(hsttxt, 0);
  • InvalidateRect(hsttxt, 0, 1);
  • GetDlgItemText(hdlg, IDED_TXT, sztxt, 400);
  • SetWindowText(hsttxt, sztxt);
  • return 0;
  • case IDCANCEL:
  • EndDialog(hdlg, 0);
  • }
  • }
  • return 0;
  • }
  • int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
  • {
  • hinst = hInstance;
  • DialogBox(hinst, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
  • return 0;
  • }
#include <windows.h>
#include "resource.h"

HINSTANCE hinst;
char sztxt[400];
HWND hstbmp, hsttxt;

BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
  switch(mssg) {
    case WM_INITDIALOG:
      RECT rc;
      int cx, cy;
      SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(0, IDI_APPLICATION));
      hstbmp = GetDlgItem(hdlg, IDST_BMP);
      GetWindowRect(hstbmp, &rc);
      cx = rc.right - rc.left;
      cy = rc.bottom - rc.top;
      ScreenToClient(hdlg, (POINT*) &rc);
      hsttxt = GetDlgItem(hdlg, IDST_TXT);
      SetWindowPos(hsttxt, HWND_TOP, rc.left, rc.top, cx, cy, SWP_SHOWWINDOW);
      SendDlgItemMessage(hdlg, IDED_TXT, EM_SETLIMITTEXT, 399, 0);
      return TRUE;
    case WM_CTLCOLORSTATIC:
      if(GetWindowLong((HWND)lParam, GWL_ID) == IDST_TXT) {
        SetBkMode((HDC) wParam, TRANSPARENT);
        SetTextColor((HDC) wParam, 0xFF); // tu peux enlever ou changer couleur
        return (BOOL) GetStockObject(NULL_BRUSH);
      }
      return 0;
    case WM_COMMAND:
      switch(wParam) {
        case IDBT_TXT:
          InvalidateRect(hstbmp, 0, 1);
          SetWindowText(hsttxt, 0);
          InvalidateRect(hsttxt, 0, 1);
          GetDlgItemText(hdlg, IDED_TXT, sztxt, 400);
          SetWindowText(hsttxt, sztxt);
          return 0;
        case IDCANCEL:
          EndDialog(hdlg, 0);
      }
  }
  return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
  hinst = hInstance;
  DialogBox(hinst, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
  return 0;
}

Conclusion

Tout dans le zip pour recompiler + exe.
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de levetot le 06/11/2004 16:15:50

j'utilise dev-cpp 4.9.9.0 et je n'arrive pas a compiler
mais le résultat est sympa :)

signaler à un administrateur
Commentaire de NeoUmbrella le 25/12/2004 22:58:29

Nikel, ce que je cherchaiiiiiiis,
bien la foto =)

NeoUmbrella Corp.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Décembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,296 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.