Bonjour à tous,
Voila, je vous expose mon problème: je cherche a programmer une visionneuse à partir d'un editeur de texte que j'avais deja creer

Voici mon code:

Pour mon main.c:

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
38
39
40
41
42
43
#include <windows.h>
#include <stdio.h>
 
#include "constantes.h"
#include "fonctions.h"
 
int WINAPI WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance,
                    LPSTR lignesDeCommande, int modeDAffichage)
{
    HWND hwnd;
    MSG message;
    WNDCLASS classeFenetre;
 
    instance = cetteInstance;
 
    classeFenetre.style = 0;
    classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
    classeFenetre.cbClsExtra = 0;
    classeFenetre.cbWndExtra = 0;
    classeFenetre.hInstance = NULL;
    classeFenetre.hIcon = LoadIcon(instance, MAKEINTRESOURCE (2));
    classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
    classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
    classeFenetre.lpszMenuName = "ID_MENU";
    classeFenetre.lpszClassName = "classeF";
 
    if(!RegisterClass(&classeFenetre)) return FALSE;
 
    hwnd = CreateWindow("classeF", "Aviator",WS_OVERLAPPEDWINDOW,
                                  CW_USEDEFAULT,CW_USEDEFAULT, 800, 600,
                                         NULL, NULL,cetteInstance, NULL);
 
    if (!hwnd)   return FALSE;
 
    ShowWindow(hwnd, modeDAffichage);
 
    while (GetMessage(&message, NULL, 0, 0))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
    return message.wParam;
}
Pour les fonctions.c:

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <windows.h>
#include <stdio.h>
 
#include "constantes.h"
#include "fonctions.h"
 
LRESULT CALLBACK procedureFenetrePrincipale(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static BOOL EditNotChg = FALSE;
       switch (message)
    {
 
        case WM_TIMER:
        {
            switch (wParam)
               case ID_B_TIMER:
               DestroyWindow(hstatic);
               return 0;
        }
 
        case WM_CREATE:
         SetTimer(hwnd, ID_B_TIMER, 3000, (TIMERPROC)NULL);
 
         hstatic = CreateWindowEx(WS_EX_TOPMOST ,"STATIC", "MyPicture",
                                    WS_POPUP | WS_VISIBLE | SS_BITMAP,
                                         300, 250, 450, 300, hwnd, NULL,
                                          instance, NULL);
 
             hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "Texte",
               WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
                                            0, 0, 0, 0, hwnd, NULL, instance, NULL);
             hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
             SendMessage(hEdit,WM_SETFONT,(UINT)hFont,TRUE);
             SendMessage(hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN,
                                                                MAKELONG(5, 5));
             return 0;
 
        case WM_CLOSE:
            if(EditNotChg ||
               MessageBox(hwnd,"Voulez-vous vraiment quitter?"
                            ,"Quitter",MB_YESNO | MB_ICONQUESTION ) == IDYES)
                                                            DestroyWindow(hwnd);
            return 0;
 
         case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_B_APROPOS:
                DialogBox(instance, "APROPOS", hwnd, (DLGPROC)aPropos_procedure);
                break;
                case ID_B_QUITTER:
                if(EditNotChg ||
               MessageBox(hwnd,"Voulez-vous vraiment quitter?"
                            ,"Quitter",MB_YESNO | MB_ICONQUESTION ) == IDYES)
                                                            DestroyWindow(hwnd);                SendMessage(hwnd, WM_DESTROY, 0, 0);
                break;
                case EN_CHANGE:
                EditNotChg = FALSE;
                break;
                case ID_B_OUVRIR:
                charger();
                break;
            }
            return 0;
 
       case WM_SIZE:
             MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
             return 0;
 
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
 
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }
}
 
BOOL APIENTRY aPropos_procedure(HWND boiteDeDialogue,UINT message,WPARAM wParam,LPARAM lParam)
{
    switch (message)
    {
      case WM_INITDIALOG:
 
         return TRUE;
 
      case WM_COMMAND:
         if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
         {
           EndDialog(boiteDeDialogue,0);
           return TRUE;
         }
         return 0;
 
      default:
         return FALSE;
    }
}
 
void convert_multiple(char* buf)
{
    int i;
    for(i=0;;i++)
    {
        if (buf[i]=='\0')
        {
            buf[i] = '\n';
            if (buf[i+1]=='\0')
                break;
        }
    }
}
 
void charger()
{
   OPENFILENAME ofn;
               CHAR szFile[MAX_PATH]={0};
               ZeroMemory(&ofn, sizeof(OPENFILENAME));
               ofn.lStructSize = sizeof(OPENFILENAME);
               ofn.lpstrFile = szFile;
               ofn.nMaxFile = MAX_PATH;
               ofn.lpstrFilter =
                           "Tout les fichiers\0*.*";
               ofn.nFilterIndex = 1;
               ofn.Flags =
                       OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    if (GetOpenFileName(&ofn)==TRUE)
    {
        HANDLE hf;
        DWORD FileSize,nbcharRead ;
        CHAR *buffer;
 
        hf = CreateFile(szFile, GENERIC_READ, 0,NULL,
                            OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        FileSize = GetFileSize(hf, NULL);
        buffer = (PCHAR)LocalAlloc(LMEM_FIXED, FileSize+1);
        ReadFile(hf, buffer, FileSize, &nbcharRead, NULL) ;
        buffer[FileSize] = 0;
        SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM)buffer);
        LocalFree(buffer);
        CloseHandle(hf);
    }
}
Avez vous une idee? Je sais qu'il faut que je modifie le hEdit mais pour le reste je ne reussis pas

Merci d'avance

Ps: J'ai lu et appris le tutoriel de l'api windows