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
| #define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x501
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
void writeCon(LPCTSTR scz)
{
DWORD cchEcrits = 0;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), scz, lstrlen(scz), &cchEcrits, NULL);
}
int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmd, int nShow)
{
DWORD err;
HWND hWnd;
TCHAR szBuf[80];
(void)hInst;
(void)hPrev;
(void)szCmd;
(void)nShow;
//Création console et récupération fenêtre
AllocConsole();
writeCon(TEXT("Test\n"));
hWnd = GetConsoleWindow();
_sntprintf_s(szBuf, 80, _TRUNCATE, TEXT("Fenêtre : hWnd = %p\n"), hWnd);
writeCon(szBuf);
//Tests de style
{
DWORD style;
DWORD style2;
DWORD style3;
//Lecture du style
style = GetWindowLong(hWnd, GWL_STYLE);
_sntprintf_s(szBuf, 80, _TRUNCATE, TEXT("style = %08lX\n"), style);
writeCon(szBuf);
//Ecriture du style
SetLastError(0);
style2 = SetWindowLong(hWnd, GWL_STYLE, style);
err = GetLastError();
style3 = GetWindowLong(hWnd, GWL_STYLE);
_sntprintf_s(szBuf, 80, _TRUNCATE,
TEXT("style2 = %08lX - style3 = %08lX - err = %lu\n"), style2, style3, err
);
writeCon(szBuf);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, szBuf, 80, NULL);
szBuf[80-1] = TEXT('\0');
writeCon(szBuf);
}
MessageBox(NULL, TEXT("Test"), TEXT("Test"), MB_OK);
FreeConsole();
return 0;
} |
Partager