Visionneuse API Windows
Le
Timothée Arnauld

Bonjour à tous,
Voila, je cherche à programmer une visionneuse de fichier .bmp à
partir d'un logiciel que j'ai deja creé (un editeur de texte) :)
Quelqu'un pourrait t'il m'aider a modifier mon code afin de pouvoir
realiser mon projet? :)
#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;
}
et pour mes fonctions:
#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]==' ')
{
buf[i] = '';
if (buf[i+1]==' ')
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 *.*";
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);
}
}
Voila, je cherche à programmer une visionneuse de fichier .bmp à
partir d'un logiciel que j'ai deja creé (un editeur de texte) :)
Quelqu'un pourrait t'il m'aider a modifier mon code afin de pouvoir
realiser mon projet? :)
#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;
}
et pour mes fonctions:
#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]==' ')
{
buf[i] = '';
if (buf[i+1]==' ')
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 *.*";
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);
}
}
Il y a de nombreuses façons d'afficher des bmp et autres formats
Un classique est avec l'interface IPicture
Voir l'exemple Loadpic de la KB218972
Ben, l'exemple "Loadpic" de la KB218972 comme cité...
Tout étant commenté, je ne vois pas trop ce qui pose problème dans ce
code...
Je suis desole parce que je me suis mal exprimé, ce que je comprend
pas c'est ou trouver ce "Loadpic" parce que j'ai cherché mais j'ai pas
trouvé :)
http://lmgtfy.com/?q=KB218972
Merci beaucoup :)