BruNews
Messages postés
21040
Date d'inscription
jeudi 23 janvier 2003
Statut
Modérateur
Dernière intervention
21 août 2019
19 févr. 2004 à 16:32
EN Win32:
fichier RC:
IDD_APP DIALOGEX 0, 0, 186, 135
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_VISIBLE |
WS_CAPTION | WS_SYSMENU
CAPTION "VersInfo"
FONT 10, "Microsoft Sans Serif", 400, 0, 0x0
BEGIN
PUSHBUTTON "Fichier",IDBT_FILE,3,6,31,14
EDITTEXT IDED_RES,1,24,185,91,ES_MULTILINE | ES_AUTOVSCROLL |
ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | WS_HSCROLL
PUSHBUTTON "Quitter",IDCANCEL,145,117,39,16
CTEXT "",IDST_FILE,35,8,151,12,SS_CENTERIMAGE | SS_SUNKEN |
SS_PATHELLIPSIS | NOT WS_GROUP
LTEXT "Mon Nom -- BruNews@online.fr",IDC_STATIC,14,122,
108,8
END
resource.h:
#define IDI_APP 101
#define IDD_APP 102
#define IDBT_FILE 1001
#define IDST_FILE 1002
#define IDED_RES 1003
Le fichier CPP:
#include <windows.h>
#include "resource.h"
#pragma comment(lib, "Version.lib")
HINSTANCE hinst;
HWND hres, hstfl;
char szfile[264], szQuery[200];
char szbuff[1024];
char *szFilter = "EXE\0*.exe\0DLL\0*.dll\0"
"OCX\0*.ocx\0SCR\0*.scr\0FLT\0*.flt\0"
"Tous *.exe;*.dll;*.ocx;*.scr;*.flt\0*.exe;*.dll;*.ocx;*.scr;*.flt\0\0";
char *pszInfos[12] = {"Comments","CompanyName", "FileDescription", "FileVersion",
"InternalName", "LegalCopyright", "OriginalFilename",
"ProductName", "ProductVersion",
"LegalTrademarks", "PrivateBuild", "SpecialBuild"};
int dlgFileOpen(HWND hOwner)
{
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME); ofn.nFilterIndex 1; ofn.lpstrFilter szFilter; ofn.lpstrFile szfile; ofn.nMaxFile MAX_PATH; ofn.hwndOwner = hOwner;
ofn.lpstrTitle = "Recherche INFO";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
szfile[0] = 0;
return GetOpenFileName(&ofn);
}
DWORD HexaToDecimal(const char* pszHexa)
{ DWORD ret 0, t 0, n = 0;
const char *c = pszHexa;
while(*c && (n < 16)) {
if((*c >= '0') && (*c <= '9')) t = (*c - '0');
else if((*c >= 'A') && (*c <= 'F')) t = (*c - 'A' + 10);
else if((*c >= 'a') && (*c <= 'f')) t = (*c - 'a' + 10);
else break;
n++; ret *= 16; ret += t; c++;
if(n >= 8) break;
}
return ret;
}
int ImportInfo()
{
BYTE *pdata, *pbt;
char szlang[16];
DWORD dwhndl, dwsize;
HANDLE hheap;
int bret = 0, i;
void *pAdr;
char *c = szbuff;
UINT uiLen;
hheap = GetProcessHeap();
if(!(dwsize = GetFileVersionInfoSize(szfile, &dwhndl))) return 0;
pdata = (BYTE*)HeapAlloc(hheap, HEAP_ZERO_MEMORY, dwsize + 2);
if(!pdata) return 0;
if(!GetFileVersionInfo(szfile, 0, dwsize + 1, pdata)) goto dataFree;
pbt = pdata + 134;
strcpy(szQuery, "\\StringFileInfo\"); for(int i 0; i < 16; i++) {szlang[i] *pbt; pbt += 2;}
for(i = 0; i < 12; i++) {
strcpy(szQuery+16, szlang); strcat(szQuery, "\");
strcat(szQuery, pszInfos[i]);
strcpy(c, pszInfos[i]);
while(*c) c++; *c++ 32; *c++ '='; *c++ = 32;
if(VerQueryValue(pdata, szQuery, &pAdr, &uiLen)) {
strcpy(c, (char*)pAdr);
while(*c) c++;
} *c++ '\r'; *c++ '\n';
}
szQuery[0] = szlang[2]; szQuery[1] = szlang[3]; szQuery[2] = 0;
strcpy(c, "Langue = ");
GetLocaleInfo(HexaToDecimal(szQuery), LOCALE_SNATIVELANGNAME, c+9, 50);
SetWindowText(hres, szbuff);
bret = 1;
dataFree: HeapFree(hheap, 0, pdata);
return bret;
}
BOOL CALLBACK AppDlgProc(HWND hdlg, UINT mssg, WPARAM wParam, LPARAM lParam)
{
switch(mssg) {
case WM_COMMAND:
switch(wParam) {
case IDBT_FILE:
SetWindowText(hres, 0);
SetWindowText(hstfl, 0);
if(!dlgFileOpen(hdlg)) return 0;;
SetWindowText(hstfl, szfile);
if(!ImportInfo()) SetWindowText(hres, "-- INTROUVABLE --");
PostMessage(hdlg, WM_NEXTDLGCTL, 0, 0);
break;
case IDCANCEL:
EndDialog(hdlg, 0);
}
return 0;
case WM_INITDIALOG:
SetClassLong(hdlg, GCL_HICON, (long)LoadIcon(hinst, MAKEINTRESOURCE(IDI_APP)));
hres = GetDlgItem(hdlg, IDED_RES);
hstfl = GetDlgItem(hdlg, IDST_FILE);
return 1;
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR, int)
{
hinst = hInstance;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_APP), NULL, AppDlgProc);
return 0;
}
ciao...
BruNews, Admin CS, MVP Visual C++