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
|
// Form11.cpp
// cl Form11.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib gdi32.lib
// cl Form11.cpp /O1 /Os kernel32.lib user32.lib gdi32.lib
// Size: 56,320 Bytes; LIBC, LIBCMT Linkage; VC15 (VStudio 2008)
// Size: 6,144 Bytes; TCLib Linkage; VC15 (VStudio 2008)
//#define TCLib
//#define Debug
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
#ifdef TCLib
#include "stdio.h"
#include "Form11.h"
extern "C" int _fltused = 1;
#else
#include <cstdio>
#include "Form11.h"
#endif
#ifdef Debug
FILE* fp=NULL;
#endif
void SetMyProcessDpiAware()
{
BOOL (__stdcall* pFn)(void);
HINSTANCE hInstance=LoadLibrary(L"user32.dll");
if(hInstance)
{
pFn=(BOOL (__stdcall*)(void))GetProcAddress(hInstance,"SetProcessDPIAware");
if(pFn)
pFn();
FreeLibrary(hInstance);
}
}
#ifdef Debug
BOOL IsMyProcessDpiAware()
{
BOOL (__stdcall* pFn)(void);
BOOL blnReturn=FALSE;
HINSTANCE hInstance=LoadLibrary(L"user32.dll");
if(hInstance)
{
pFn=(BOOL (__stdcall*)(void))GetProcAddress(hInstance,"IsProcessDPIAware");
if(pFn)
blnReturn=pFn();
FreeLibrary(hInstance);
}
return blnReturn;
}
#endif
LRESULT CALLBACK fnWndProc_OnCreate(WndEventArgs& Wea)
{
HWND hCtl = NULL;
HDC hDC = NULL;
HFONT hFont = NULL;
BOOL blnDpiAware = FALSE;
double dblFont = 14.0;
double dpiX = 0.0;
double dpiY = 0.0;
int nHeight = 0;
#ifdef Debug
fp=fopen("Output.txt","w");
fprintf(fp,"Entering fnWndProc_OnCreate()\n");
#endif
Wea.hIns = ((LPCREATESTRUCT)Wea.lParam)->hInstance;
hDC = GetDC(NULL);
dpiX = (double)GetDeviceCaps(hDC, LOGPIXELSX);
dpiY = (double)GetDeviceCaps(hDC, LOGPIXELSY);
nHeight = -MulDiv(dblFont, dpiY, 72);
blnDpiAware = IsProcessDPIAware();
#ifdef Debug
fprintf(fp," blnDpiAware = %d\n",blnDpiAware);
fprintf(fp," nHeight = %d\n",nHeight);
fprintf(fp," dpiX = %6.3f\n",dpiX);
fprintf(fp," dpiY = %6.3f\n",dpiY);
#endif
MoveWindow(Wea.hWnd,SizX(200),SizY(200),SizX(400),SizY(400),FALSE);
ReleaseDC(Wea.hWnd,hDC);
hCtl = CreateWindow(L"button",L"Default Button",WS_CHILD|WS_VISIBLE,SizX(40),SizY(40),SizX(150),SizX(40),Wea.hWnd,(HMENU)IDC_DEFAULT_BUTTON,Wea.hIns,0);
hCtl = CreateWindow(L"button",L"User Button",WS_CHILD|WS_VISIBLE,SizX(40),SizX(200),SizX(150),SizX(40),Wea.hWnd,(HMENU)IDC_CUSTOM_FONT_BUTTON,Wea.hIns,0);
hFont = CreateFont(nHeight,0,0,0,FW_BOLD,0,0,0,0,0,0,2,0,L"DEFAULT_GUI_FONT");
SendMessage(hCtl,WM_SETFONT,(WPARAM)hFont,0);
SetProp(Wea.hWnd,L"Font",hFont);
#ifdef Debug
fprintf(fp,"Leaving fnWndProc_OnCreate()\n\n");
#endif
return 0;
}
LRESULT CALLBACK fnWndProc_OnDestroy(WndEventArgs& Wea)
{
HFONT hFnt = NULL;
#ifdef Debug
fprintf(fp,"Entering fnWndProc_OnDestroy()\n");
fprintf(fp," Wea.hWnd = %u\n",Wea.hWnd);
#endif
hFnt=(HFONT)GetProp(Wea.hWnd,L"Font");
DeleteObject(hFnt);
RemoveProp(Wea.hWnd,L"Font");
PostQuitMessage(0);
#ifdef Debug
fprintf(fp,"Leaving fnWndProc_OnDestroy()\n");
fclose(fp);
#endif
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
WndEventArgs Wea;
for(unsigned int i=0; i<dim(EventHandler); i++)
{
if(EventHandler[i].iMsg==msg)
{
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (*EventHandler[i].fnPtr)(Wea);
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
wchar_t szClassName[]=L"Form10";
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
SetMyProcessDpiAware();
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX); wc.style=0;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hIns;
wc.hIconSm=NULL; wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW; wc.cbWndExtra=0;
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,0,0,0,0,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return (int)messages.wParam;
}
| |