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
| #include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM, LPARAM)
{
if(uMsg == WM_CLOSE) EndDialog(hDlg, 0);
return 0;
}
LPWORD CreateControl(LPWORD lpw, DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle,
int x, int y, int cx, int cy, int ctlID)
{
if((LPARAM)lpw & 3) lpw++; // Aligner sur un DWORD
LPDLGITEMTEMPLATE lpit = (LPDLGITEMTEMPLATE)lpw;
lpit->x = x;
lpit->y = y;
lpit->cx = cx;
lpit->cy = cy;
lpit->style = dwStyle;
lpit->dwExtendedStyle = dwExStyle;
lpit->id = ctlID;
lpw = (LPWORD) (lpit + 1);
lpw += MultiByteToWideChar(CP_ACP, 0, lpClassName, -1, (LPWSTR)lpw, 128);
if(lpWindowName) lpw += MultiByteToWideChar(CP_ACP, 0, lpWindowName, -1, (LPWSTR)lpw, 128);
else *lpw++ = 0;
*lpw++ = 0; // Pas de data
return lpw;
}
LPWORD CreateDlg(LPWORD lpw, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int cx, int cy,
int fontSize, LPCTSTR lpFontName, int ctrlNum)
{
LPDLGTEMPLATE lpdt = (LPDLGTEMPLATE)lpw;
if(!lpFontName)
{
lpFontName = "Ms Shell Dlg 2";
fontSize = 8;
}
lpdt->style = dwStyle;
lpdt->x = x;
lpdt->y = y;
lpdt->cx = cx;
lpdt->cy = cy;
lpdt->cdit = ctrlNum; // Nombre de contrôles
lpw = (LPWORD)(lpdt + 1);
*lpw++ = 0; // Pas de menu
*lpw++ = 0; // Classe par défaut
if(lpWindowName) lpw += MultiByteToWideChar(CP_ACP, 0, lpWindowName, -1, (LPWSTR)lpw, 128);
else *lpw++ = 0;
*lpw++ = fontSize;
return lpw + MultiByteToWideChar(CP_ACP, 0, lpFontName, -1, (LPWSTR)lpw, 128);
}
#ifdef _DEBUG
int main()
#else
#pragma comment(linker, "/entry:myWinMain")
int __stdcall myWinMain()
#endif
{
InitCommonControls();
HGLOBAL mem = GlobalAlloc(GPTR, 1024);
LPWORD lpw = (LPWORD)mem;
lpw = CreateDlg(lpw, "Test", DS_SETFONT | DS_CENTER | WS_POPUP | WS_BORDER | WS_MINIMIZEBOX | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION,
0, 0, 249, 89, 0, 0, 3);
// Création de quelques controles
lpw = CreateControl(lpw, 0, "Button", "Cancel", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 192, 68, 50, 14, 1000);
lpw = CreateControl(lpw, 0, "msctls_progress32", 0, WS_VISIBLE | WS_CHILD | PBS_SMOOTH, 7, 40, 235, 9, 1001);
lpw = CreateControl(lpw, WS_EX_CLIENTEDGE, "edit", 0, WS_VISIBLE | WS_CHILD, 7, 7, 100, 13, 1002);
DialogBoxIndirect(0, (LPDLGTEMPLATE)mem, NULL, DialogProc);
GlobalFree(mem);
#ifdef _DEBUG
return 0;
#else
ExitProcess(0);
#endif
} |
Partager