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
|
#include <windows.h>
#include <stdio.h>//for some reason, #include <cstdio> didn't work, even though it's always worked before
char filename[MAX_PATH+1];
bool image::load(char* fname){
if(fname=NULL){
return false;}
//SHOWERR(fname);
//^^^ shows a messagebox with no text (???)
HANDLE file=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(file==INVALID_HANDLE_VALUE){
//apparently, fname is an empty string, so CreateFile can't load it
SHOWERR("ERROR: Couldn't load image file");
return false;}
char* ext=NULL;
get_ext(fname,ext);
bool loaded=false;
if(!memcmp(ext,"bmp",3)){
loaded=load_bmp(file,*this);}
else{
SHOWERR("ERROR: File format not supported.\n\nSupported file formats:\n\t.BMP");
return false;}
delete[] ext;
CloseHandle(file);
return loaded;}
char* open_file(HWND hwnd,HINSTANCE hinst,char* filter,char* title){
OPENFILENAME ofn;
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.hwndOwner=hwnd;
ofn.lpstrFile=filename;
filename[0]=0;
ofn.nMaxFile=sizeof(filename);
ofn.lpstrFilter=filter;
ofn.nFilterIndex=1;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
ofn.lpstrInitialDir=NULL;
ofn.lpstrTitle=title;
ofn.Flags=OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
ofn.nFileOffset=0;
ofn.nFileExtension=0;
ofn.lpstrDefExt="bmp";
if(GetOpenFileName(&ofn)){
return filename;}
return NULL;}
image img;
HDC hdc;
PAINTSTRUCT ps;
LRESULT CALLBACK piproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
switch(msg){
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_COMMAND:
switch(LOWORD(wparam)){
case IDM_LOAD:
//SHOWERR(open_file(hwnd,GetModuleHandle(0),"All Files (*.*)\0*.*\0Bitmap (*.bmp)\0*.bmp\0","PiPaint - Load"));
//^^^ shows a perfectly valid filename
img.load(open_file(hwnd,GetModuleHandle(0),"All Files (*.*)\0*.*\0Bitmap (*.bmp)\0*.bmp\0","PiPaint - Load"));
break;
case IDM_EXIT:
DestroyWindow(hwnd);
break;
case IDM_MANUAL:
MessageBox(hwnd,"There is no manual. Sorry for the inconvience.","PiPaint - Manual",MB_OK);
break;}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
img.draw(0,0,hdc);
EndPaint(hwnd,&ps);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);}
return 0;}
|