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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
| /* ----- Defines pour que ça compile sous mon Visual 2005 ----- */
/* Parce qu'il me manque le reste de ton projet */
#undef _UNICODE
#undef UNICODE
#include <windows.h>
#define ID_MONBUTTON 1000
#define IDM_OPEN 1001
#define IDM_SAVE 1002
#define IDM_ABOUT 1003
#define IDM_FONT 1004
/* ----- Fin des Defines ----- */
struct st_MainWndMemory
{
HFONT hFont;
LOGFONT lf;
BOOL EditNotChg;
HBRUSH EditBrush;
COLORREF BkEditcolor;
COLORREF TextColor;
HWND hEdit;
HWND hbtn1;
HWND hbtn2;
HWND hbtn3;
HWND hbtn4;
HWND hbtn5;
HWND hbtn6;
HWND hbtn7;
HWND hbtn8;
HWND hbtn9;
HWND hbtn10;
HWND hbtn11;
HWND hbtn12;
HWND hbtn13;
};
LRESULT ProcessWmCommand(HWND hWnd, struct st_MainWndMemory *pt_mem, WORD commandId, WORD notification, HWND hControl)
{
LRESULT ret = 0;
switch(commandId)
{
case IDM_OPEN:
{
OPENFILENAME ofn;
CHAR szFile[MAX_PATH]={0};
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "Fichier texte\0*.txt\0Fichier Word 2003\0*.doc\0Fichier Word 2007\0*.docx\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(pt_mem->hEdit, WM_SETTEXT, 0, (LPARAM)buffer);
LocalFree(buffer);
CloseHandle(hf);
}
}
break;
case IDM_SAVE:
{
OPENFILENAME ofn;
CHAR szFile[260]={0};
ZeroMemory(&ofn, sizeof(OPENFILENAME));
#ifdef OPENFILENAME_SIZE_VERSION_400
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
ofn.lStructSize = sizeof(OPENFILENAME);
#endif
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "Fichier texte\0*.txt\0Fichier Word 2003\0*.doc\0Fichier Word 2007\0*.docx\0";
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if (GetSaveFileName(&ofn)==TRUE)
{
HANDLE hf;
DWORD FileSize,nbcharRead ;
char *buffer;
FileSize = GetWindowTextLength(pt_mem->hEdit);
buffer = (char*)LocalAlloc(LMEM_FIXED, FileSize+1);
GetWindowText(pt_mem->hEdit, buffer, FileSize+1);
hf = CreateFile(szFile, GENERIC_WRITE, 0,NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hf, buffer, FileSize, &nbcharRead, NULL) ;
CloseHandle(hf);
LocalFree(buffer);
}
}
break;
/////// IDM_ABOUT ////////
case IDM_ABOUT :
MessageBox(hWnd, "Supernet... C'est La solution de votre société!!", "C'est Notre Societé!!", MB_OK);
break;
/////// Police Change ////////
case IDM_FONT:
{
CHOOSEFONT cf;
ZeroMemory(&cf, sizeof(CHOOSEFONT));
cf.lStructSize = sizeof (CHOOSEFONT);
cf.hwndOwner = hWnd;
cf.lpLogFont = &pt_mem->lf;
cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
if (ChooseFont(&cf))
{
DeleteObject(pt_mem->hFont);
pt_mem->hFont = CreateFontIndirect(&pt_mem->lf);
SendMessage(pt_mem->hEdit,WM_SETFONT,(WPARAM)pt_mem->hFont,TRUE);
}
}
break;
default:
if(hControl == pt_mem->hEdit && notification==EN_CHANGE)
{
pt_mem->EditNotChg = FALSE;
}
break;
}
return ret;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static struct st_MainWndMemory my_mem = {
NULL,
{0L, 0L, 0L, 0L, 0L, 0, 0, 0, 0, 0, 0, 0, 0, ""},
TRUE,
NULL,
0xFFFFFF,
0x000000,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
LRESULT ret = 0;
switch (uMsg)
{
case WM_CREATE:
{
HFONT hFont;
my_mem.hEdit = CreateWindow("edit", "Texte",
WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
40,40, 0, 0, hwnd, NULL, NULL, NULL
);
/*permet de récupérer des objets initialisés au démarrage de Windows, tel des pinceaux, crayons..*/
hFont = (HFONT)GetStockObject(ANSI_FIXED_FONT);/*changer le police de caractère*/
SendMessage(my_mem.hEdit, WM_SETFONT, (WPARAM)hFont, TRUE);/*mêmes paramètres que PostMessage et dans le même ordre//envoie le message directement à la procédure de fenêtre sans passer par la file d'attente*/
ZeroMemory(&my_mem.lf, sizeof(LOGFONT));
lstrcpy(my_mem.lf.lfFaceName,"Courier");
my_mem.lf.lfHeight = 10;
hFont = CreateFontIndirect(&my_mem.lf);
SendMessage(my_mem.hEdit,WM_SETFONT, (WPARAM)hFont,TRUE);
SendMessage(my_mem.hEdit, EM_SETMARGINS,
EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5)
);
}
SendMessage(my_mem.hEdit, EM_SETMARGINS,
EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(5, 5)
);/*pour mettre ses marges interieures droite et gauche à 5 pixels*/
//EXEC SQL CONNECT TO spernet [AS nom_connexion] [USER utilisateur];
my_mem.hbtn1 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE|ES_WANTRETURN | ES_MULTILINE,
3,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn2 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
103,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn3 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
203,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn4 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
303,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn5 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
403,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn6 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
503,285, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn7 = CreateWindow("button", "Login", WS_CHILD | WS_VISIBLE,
3,3, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn8 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,52, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn9 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,87, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn10 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,122, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn11 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,157, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn12 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,192, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
my_mem.hbtn13 = CreateWindow("button", "-----", WS_CHILD | WS_VISIBLE,
3,227, 100, 35, hwnd, (HMENU)ID_MONBUTTON, NULL, NULL);
break;
case WM_COMMAND:
ret = ProcessWmCommand(hwnd, &my_mem, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
ret = DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return ret;
} |
Partager