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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
| /*
http://www.developpez.net/forums/d1596301/general-developpement/programmation-systeme/windows/changer-font-d-fenetre-enfant-enfant/
*/
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <ole2.h>
#pragma warning(push)
#pragma warning(disable: 4201)
#include <commctrl.h>
#include <shlwapi.h>
#pragma warning(pop)
#include <tchar.h>
#pragma comment(lib, "comctl32.lib")
HINSTANCE g_hinst; /* This application's HINSTANCE */
HWND g_hwndChild; /* Optional child window */
/*
* OnSize
* If we have an inner child, resize it to fit.
*/
static void
OnSize(HWND hwnd, UINT state, int cx, int cy)
{
(void)hwnd, (void)state;
if(g_hwndChild) {
MoveWindow(g_hwndChild, 0, 0, cx, cy, TRUE);
}
}
/*
* OnCreate
* Applications will typically override this and maybe even
* create a child window.
*/
static BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
(void)hwnd, (void)lpcs;
return TRUE;
}
/*
* OnDestroy
* Post a quit message because our application is over when the
* user closes this window.
*/
static void
OnDestroy(HWND hwnd)
{
(void)hwnd;
PostQuitMessage(0);
}
/*
* PaintContent
* Interesting things will be painted here eventually.
*/
static void
PaintContent(HWND hwnd, PAINTSTRUCT *pps)
{
(void)hwnd, (void)pps;
}
/*
* OnPaint
* Paint the content as part of the paint cycle.
*/
static void
OnPaint(HWND hwnd)
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
PaintContent(hwnd, &ps);
EndPaint(hwnd, &ps);
}
/*
* OnPrintClient
* Paint the content as requested by USER.
*/
static void
OnPrintClient(HWND hwnd, HDC hdc)
{
PAINTSTRUCT ps = {0}; /*Init ajoutée par Fred*/
ps.hdc = hdc;
GetClientRect(hwnd, &ps.rcPaint);
PaintContent(hwnd, &ps);
}
/*
* Window procedure
*/
static LRESULT CALLBACK
WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch(uiMsg) {
HANDLE_MSG(hwnd, WM_CREATE, OnCreate);
HANDLE_MSG(hwnd, WM_SIZE, OnSize);
HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
HANDLE_MSG(hwnd, WM_PAINT, OnPaint);
case WM_PRINTCLIENT: OnPrintClient(hwnd, (HDC)wParam); return 0;
}
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}
static BOOL
InitApp(void)
{
WNDCLASS wc = {0}; /*Init ajoutée par Fred*/
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = g_hinst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = CreateSolidBrush(0x800080); //(HBRUSH)(INT_PTR)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("Scratch"); /*Modif Fred:TCHAR*/
if(!RegisterClass(&wc)) return FALSE;
InitCommonControls(); /* In case we use a common control */
return TRUE;
}
#pragma region Window title functions
BOOL IsAdmin(void)
{
/*CheckTokenMembership:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376389%28v=vs.85%29.aspx */
BOOL bOK=FALSE;
BOOL bIsAdmin = FALSE;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup = NULL;
bOK = AllocateAndInitializeSid(
&NtAuthority,
2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&AdministratorsGroup);
if(bOK)
{
if (!CheckTokenMembership(NULL, AdministratorsGroup, &bIsAdmin))
{
bIsAdmin = FALSE;
}
FreeSid(AdministratorsGroup);
}
return bIsAdmin;
}
LPTSTR MakeWindowName()
{
TCHAR fileNameBuffer[32767+1]; /*Accept extra-long file paths.*/
DWORD nameLength = GetModuleFileName(NULL, fileNameBuffer, ARRAYSIZE(fileNameBuffer));
if(nameLength == 0 || nameLength==ARRAYSIZE(fileNameBuffer))
return NULL;
{
LPTSTR pLastBackslash = _tcsrchr(fileNameBuffer, _T('\\'));
LPTSTR pFileName = (pLastBackslash!=NULL) ? pLastBackslash+1 : fileNameBuffer;
LPTSTR pLastDot = _tcsrchr(pFileName, _T('.'));
if(pLastDot == NULL)
pLastDot = pFileName + _tcslen(pFileName);
*pLastDot = '\0'; /*Truncate.*/
{
LPCTSTR isAdminStr = IsAdmin() ? _T(" (Admin)") : _T("");
BOOL isScratch = CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, pFileName, -1, _T("Scratch"), -1) == CSTR_EQUAL;
LPCTSTR fmt = isScratch ? _T("Raymond's %s program, upgraded%s") : _T("Scratch: %s%s");
size_t length = _sctprintf(fmt, pFileName, isAdminStr);
LPTSTR ret = (LPTSTR)calloc(length+1, sizeof(TCHAR)); /*Cast allows compiling in both C and C++*/
if(ret == NULL)
return NULL;
#ifdef _stprintf_s
_stprintf_s(ret, length+1, fmt, pFileName, isAdminStr);
#else
_sntprintf(ret, length+1, fmt, pFileName, isAdminStr);
ret[length] = _T('\0');
#endif
return ret;
}
}
}
#pragma endregion
WNDPROC g_oldWndProc;
LRESULT CALLBACK CustomGroupBox4_2Proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CTLCOLORSTATIC:
{
HDC hdc = (HDC)wParam;
LRESULT res;
_tprintf(_T("WM_CTLCOLORSTATIC(hdc=0x%p, hWnd=0x%p) [text=0x%08lX, bk=0x%08lX:%d, hFont=%p]"), wParam, lParam, GetTextColor(hdc), GetBkColor(hdc), GetBkMode(hdc), GetCurrentObject(hdc, OBJ_FONT));
res = CallWindowProc(g_oldWndProc, hWnd, msg, wParam, lParam);
_tprintf(_T("-->%08lX [text=0x%08lX, bk=0x%08lX:%d, hFont=%p]\n"), res, GetTextColor(hdc), GetBkColor(hdc), GetBkMode(hdc), GetCurrentObject(hdc, OBJ_FONT));
}
break;
case WM_CTLCOLORBTN:
{
HDC hdc = (HDC)wParam;
LRESULT res;
_tprintf(_T("WM_CTLCOLORBTN(hdc=0x%p, hWnd=0x%p) [text=0x%08lX, bk=0x%08lX:%d, hFont=%p]"), wParam, lParam, GetTextColor(hdc), GetBkColor(hdc), GetBkMode(hdc), GetCurrentObject(hdc, OBJ_FONT));
res = CallWindowProc(g_oldWndProc, hWnd, msg, wParam, lParam);
_tprintf(_T("-->%08lX [text=0x%08lX, bk=0x%08lX:%d, hFont=%p]\n"), res, GetTextColor(hdc), GetBkColor(hdc), GetBkMode(hdc), GetCurrentObject(hdc, OBJ_FONT));
}
break;
}
return CallWindowProc(g_oldWndProc, hWnd, msg, wParam, lParam);
}
EXTERN_C int WINAPI groupBoxes_WinMain(
HINSTANCE hinst, HINSTANCE hinstPrev,
LPSTR lpCmdLine, int nShowCmd
)
{
MSG msg;
HWND hwnd;
LPTSTR windowName = MakeWindowName();
(void)hinstPrev, (void)lpCmdLine;
g_hinst = hinst;
if(!InitApp()) return 0;
if(SUCCEEDED(CoInitialize(NULL))) {/* In case we use COM */
hwnd = CreateWindow(
TEXT("Scratch"), /* Class Name (Modif Fred:TCHAR)*/
windowName, /* Title */
WS_OVERLAPPEDWINDOW, /* Style */
CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
CW_USEDEFAULT, CW_USEDEFAULT, /* Size */
NULL, /* Parent */
NULL, /* No menu */
hinst, /* Instance */
0); /* No special parameters */
free(windowName), windowName=NULL;
ShowWindow(hwnd, nShowCmd);
{
//creating the fonts objects
HFONT hFont = CreateFont(16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
HFONT hFontBold = CreateFont(14, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
/////////////////////
/////////////////////
HWND GroupBox4_2 = CreateWindow(TEXT("BUTTON"), TEXT("RS"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 285, 45, 626, 442, hwnd, 0, 0, 0);
WNDPROC wpOldGroupBox4_2Proc = g_oldWndProc = (WNDPROC)SetWindowLongPtr(GroupBox4_2, GWLP_WNDPROC, (LONG_PTR)CustomGroupBox4_2Proc);
LRESULT res1 = SendMessage(GroupBox4_2, WM_SETFONT, (WPARAM)hFontBold, TRUE);
HWND GroupBox5 = CreateWindow(TEXT("BUTTON"), TEXT("SS"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 560, 35, 260, 120, GroupBox4_2, 0, 0, 0);
LRESULT res2 = SendMessage(GroupBox5, WM_SETFONT, (WPARAM)hFontBold, TRUE);
_tprintf(_T("GroupBox4_2=%p, GroupBox5=%p, hFontBold=%p\n"), GroupBox4_2, GroupBox5, hFontBold);
(void)res2, (void)hFont, (void)res1;
(void)wpOldGroupBox4_2Proc;
}
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
}
return 0;
} |
Partager