ReactOS  0.4.13-dev-961-g238ea69
psmtest.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Tests
3  * FILE: rostests/win32/user32/psmtest/psmtest.c
4  * PURPOSE: Side by side comparison of the undocumented
5  * LpkPSMTextOut and UserLpkPSMTextOut functions
6  *
7  * PROGRAMMER: Program skeleton: https://github.com/TransmissionZero/MinGW-Win32-Application
8  * Test code by Baruch Rutman
9  */
10 
11 #include <windows.h>
12 #include <commctrl.h>
13 #include <strsafe.h>
14 
15 #define IDI_APPICON 101
16 #define IDR_ACCELERATOR 103
18 
19 /* Prototypes */
20 INT WINAPI LpkPSMTextOut(HDC hdc, int x, int y, LPCWSTR lpString, int cString, DWORD dwFlags);
21 INT WINAPI UserLpkPSMTextOut(HDC hdc, int x, int y, LPCWSTR lpString, int cString, DWORD dwFlags);
22 
23 /* Main window class and title */
24 static LPCWSTR MainWndClass = L"PSM Test";
25 
26 #define LPK 1
27 #define USERLPK 2
28 static void DrawTest(HDC hdc, int ypos, LPCWSTR str, DWORD dwFlags, int testtype)
29 {
30  WCHAR Result[100];
31  INT ret = 0;
32 
33  if (testtype == LPK)
34  {
35  ret = LpkPSMTextOut(hdc, 0, ypos, str, (!str) ? 10 : wcslen(str), dwFlags);
36  StringCchPrintfW(Result, 100, L"Return Value = %d", ret);
37  TextOutW(hdc, 200, ypos, Result, wcslen(Result));
38  }
39  else if (testtype == USERLPK)
40  {
41  ret = UserLpkPSMTextOut(hdc, 400, ypos, str, wcslen(str), dwFlags);
42  StringCchPrintfW(Result, 100, L"Return Value = %d", ret);
43  TextOutW(hdc, 600, ypos, Result, wcslen(Result));
44  }
45 
46 }
47 
48 /* Our application entry point */
49 int WINAPI
51  HINSTANCE hPrevInstance,
52  LPTSTR lpszCmdLine,
53  int nCmdShow)
54 {
56  HWND hWnd;
57  HACCEL hAccelerators;
58  MSG msg;
59  WNDCLASSEXW wc;
60 
61  /* Class for our main window */
62  wc.cbSize = sizeof(wc);
63  wc.style = 0;
65  wc.cbClsExtra = 0;
66  wc.cbWndExtra = 0;
67  wc.hInstance = hInstance;
71  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
74 
75  /* Initialise common controls */
76  icc.dwSize = sizeof(icc);
79 
80  /* Register our main window class, or error */
81  if (!RegisterClassExW(&wc))
82  {
83  MessageBoxW(NULL, L"Error registering main window class.", L"Error", MB_ICONERROR | MB_OK);
84  return 0;
85  }
86 
88  NULL, NULL, hInstance, NULL);
89 
90  /* Create our main window, or error */
91  if (!hWnd)
92  {
93  MessageBoxW(NULL, L"Error creating main window.", L"Error", MB_ICONERROR | MB_OK);
94  return 0;
95  }
96 
97  /* Load accelerators */
99 
100  /* Show main window and force a paint */
101  ShowWindow(hWnd, nCmdShow | SW_MAXIMIZE);
103 
104  /* Main message loop */
105  while (GetMessageW(&msg, NULL, 0, 0) > 0)
106  {
107  if (!TranslateAcceleratorW(hWnd, hAccelerators, &msg))
108  {
111  }
112  }
113 
114  return (int)msg.wParam;
115 }
116 
117 /* Window procedure for our main window */
119 {
120  switch (msg)
121  {
122 
123  case WM_GETMINMAXINFO:
124  {
125  /* Prevent our window from being sized too small */
126  MINMAXINFO *minMax = (MINMAXINFO*)lParam;
127  minMax->ptMinTrackSize.x = 220;
128  minMax->ptMinTrackSize.y = 110;
129 
130  return 0;
131  }
132 
133  case WM_PAINT:
134  {
135  PAINTSTRUCT ps;
136  HDC hdc = BeginPaint(hWnd, &ps);
137 
138  enum {
139  ALEF = 0x5D0,
140  BET,
141  GIMEL,
142  DALET,
143  HEY,
144  VAV,
145  ZAYIN,
146  HET,
147  TET,
148  YUD,
149  KAF_SOFIT,
150  KAF,
151  LAMED,
152  MEM_SOFIT,
153  MEM,
154  NUN_SOFIT,
155  NUN,
156  SAMEKH,
157  AYIN,
158  PEY_SOFIT,
159  PEY,
160  TSADI_SOFIT,
161  TSADI,
162  QOF,
163  RESH,
164  SHIN,
165  TAV
166  };
167 
168  LOGFONTW font;
169  HFONT hfont;
170  WCHAR Test[] = L"&Test Text";
171  WCHAR Test2[] = L"&Test\nText";
172  WCHAR Test3[] = L"&Test\tText";
173  WCHAR Test4[] = L"&Test T&ex&t";
174  WCHAR Test5[] = { TET, QOF, SAMEKH, TET, L' ', L'&', BET, DALET, YUD, QOF, HEY, 0 };
175  WCHAR Test6[] = L"Test&&Text";
176  WCHAR Test7[] = { BET, DALET, YUD, QOF, HEY, L'&', 'T','e','s','t', 0};
177  WCHAR Test8[] = L"TestText&";
178  WCHAR Test9[] = L"TestText&&";
179  WCHAR Test10[] = L"TestText";
180 
181  ZeroMemory(&font, sizeof(LOGFONTW));
182  StringCchCopyW(font.lfFaceName, 32, L"Microsoft Sans Serif");
186 
187  DrawTest(hdc, 0, Test, 0, LPK);
188  DrawTest(hdc, 20, Test, DT_NOPREFIX, LPK);
191  DrawTest(hdc, 80, Test2, 0, LPK);
192  DrawTest(hdc, 100, Test2, DT_CALCRECT, LPK);
193  DrawTest(hdc, 120, Test3, 0, LPK);
195  DrawTest(hdc, 160, NULL, 0, LPK);
196  DrawTest(hdc, 180, Test4, 0, LPK);
197  DrawTest(hdc, 200, Test4, DT_NOPREFIX, LPK);
198  DrawTest(hdc, 220, Test4, DT_HIDEPREFIX, LPK);
199  DrawTest(hdc, 240, Test5, 0, LPK);
200  DrawTest(hdc, 260, Test5, DT_NOPREFIX, LPK);
201  DrawTest(hdc, 280, Test5, DT_HIDEPREFIX, LPK);
202  DrawTest(hdc, 300, Test5, DT_PREFIXONLY, LPK);
203  DrawTest(hdc, 320, Test6, 0, LPK);
204  DrawTest(hdc, 340, Test6, DT_NOPREFIX, LPK);
205  DrawTest(hdc, 360, Test6, DT_HIDEPREFIX, LPK);
206  DrawTest(hdc, 380, Test6, DT_PREFIXONLY, LPK);
207  DrawTest(hdc, 400, Test7, 0, LPK);
208  DrawTest(hdc, 420, Test7, DT_NOPREFIX, LPK);
209  DrawTest(hdc, 440, Test7, DT_HIDEPREFIX, LPK);
210  DrawTest(hdc, 460, Test7, DT_PREFIXONLY, LPK);
211  DrawTest(hdc, 480, Test7, DT_RTLREADING, LPK);
213  DrawTest(hdc, 500, Test7, 0, LPK);
215  DrawTest(hdc, 520, Test8, 0, LPK);
216  DrawTest(hdc, 540, Test8, DT_NOPREFIX, LPK);
217  DrawTest(hdc, 560, Test8, DT_HIDEPREFIX, LPK);
218  DrawTest(hdc, 580, Test8, DT_PREFIXONLY, LPK);
219  DrawTest(hdc, 600, Test9, 0, LPK);
220  DrawTest(hdc, 620, Test9, DT_NOPREFIX, LPK);
221  DrawTest(hdc, 640, Test9, DT_HIDEPREFIX, LPK);
222  DrawTest(hdc, 660, Test9, DT_PREFIXONLY, LPK);
223  DrawTest(hdc, 680, Test10, 0, LPK);
224  DrawTest(hdc, 700, Test10, DT_NOPREFIX, LPK);
225  DrawTest(hdc, 720, Test10, DT_HIDEPREFIX, LPK);
226  DrawTest(hdc, 740, Test10, DT_PREFIXONLY, LPK);
227 
228  TextOutW(hdc, 100, 760, L"LpkPSMTextOut", 13);
229 
230  DrawTest(hdc, 0, Test, 0, USERLPK);
234  DrawTest(hdc, 80, Test2, 0, USERLPK);
236  DrawTest(hdc, 120, Test3, 0, USERLPK);
238  /* DrawTest(hdc, 160, NULL, 0, USERLPK); */ /* Crash on windows */
239  DrawTest(hdc, 180, Test4, 0, USERLPK);
240  DrawTest(hdc, 200, Test4, DT_NOPREFIX, USERLPK);
241  DrawTest(hdc, 220, Test4, DT_HIDEPREFIX, USERLPK);
242  DrawTest(hdc, 240, Test5, 0, USERLPK);
243  DrawTest(hdc, 260, Test5, DT_NOPREFIX, USERLPK);
244  DrawTest(hdc, 280, Test5, DT_HIDEPREFIX, USERLPK);
245  DrawTest(hdc, 300, Test5, DT_PREFIXONLY, USERLPK);
246  DrawTest(hdc, 320, Test6, 0, USERLPK);
247  DrawTest(hdc, 340, Test6, DT_NOPREFIX, USERLPK);
248  DrawTest(hdc, 360, Test6, DT_HIDEPREFIX, USERLPK);
249  DrawTest(hdc, 380, Test6, DT_PREFIXONLY, USERLPK);
250  DrawTest(hdc, 400, Test7, 0, USERLPK);
251  DrawTest(hdc, 420, Test7, DT_NOPREFIX, USERLPK);
252  DrawTest(hdc, 440, Test7, DT_HIDEPREFIX, USERLPK);
253  DrawTest(hdc, 460, Test7, DT_PREFIXONLY, USERLPK);
254  DrawTest(hdc, 480, Test7, DT_RTLREADING, USERLPK);
256  DrawTest(hdc, 500, Test7, 0, USERLPK);
258  DrawTest(hdc, 520, Test8, 0, USERLPK);
259  DrawTest(hdc, 540, Test8, DT_NOPREFIX, USERLPK);
260  DrawTest(hdc, 560, Test8, DT_HIDEPREFIX, USERLPK);
261  DrawTest(hdc, 580, Test8, DT_PREFIXONLY, USERLPK);
262  DrawTest(hdc, 600, Test9, 0, USERLPK);
263  DrawTest(hdc, 620, Test9, DT_NOPREFIX, USERLPK);
264  DrawTest(hdc, 640, Test9, DT_HIDEPREFIX, USERLPK);
265  DrawTest(hdc, 660, Test9, DT_PREFIXONLY, USERLPK);
266  DrawTest(hdc, 680, Test10, 0, USERLPK);
267  DrawTest(hdc, 700, Test10, DT_NOPREFIX, USERLPK);
268  DrawTest(hdc, 720, Test10, DT_HIDEPREFIX, USERLPK);
269  DrawTest(hdc, 740, Test10, DT_PREFIXONLY, USERLPK);
270 
271  TextOutW(hdc, 500, 760, L"UserLpkPSMTextOut", 17);
272 
273  EndPaint(hWnd, &ps);
274  break;
275  }
276 
277  case WM_DESTROY:
278  {
279  PostQuitMessage(0);
280  return 0;
281  }
282  }
283  return DefWindowProcW(hWnd, msg, wParam, lParam);
284 }
POINT ptMinTrackSize
Definition: winuser.h:3604
Definition: kbdheb.c:76
#define DT_EXPANDTABS
Definition: winuser.h:532
Definition: kbdheb.c:84
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
Definition: kbdheb.c:88
#define DT_HIDEPREFIX
Definition: winuser.h:547
#define LR_SHARED
Definition: winuser.h:1090
#define IMAGE_ICON
Definition: winuser.h:212
#define DT_RTLREADING
Definition: winuser.h:539
long y
Definition: polytest.cpp:48
int cbWndExtra
Definition: winuser.h:3194
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
long x
Definition: polytest.cpp:48
Definition: kbdheb.c:77
Definition: mk_font.cpp:20
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define IMAGE_CURSOR
Definition: winuser.h:213
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow)
Definition: psmtest.c:50
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
HWND hWnd
Definition: settings.c:17
Definition: kbdheb.c:94
Definition: kbdheb.c:74
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
Definition: kbdheb.c:90
#define ZeroMemory
Definition: winbase.h:1635
HICON hIcon
Definition: winuser.h:3196
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
UINT_PTR WPARAM
Definition: windef.h:207
HICON HCURSOR
Definition: windef.h:284
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
UINT WINAPI SetTextAlign(_In_ HDC, _In_ UINT)
Definition: text.c:853
Definition: kbdheb.c:93
Definition: kbdheb.c:86
#define DT_NOPREFIX
Definition: winuser.h:537
#define IDI_APPICON
Definition: psmtest.c:15
#define DT_PREFIXONLY
Definition: winuser.h:548
int32_t INT
Definition: typedefs.h:56
WPARAM wParam
Definition: combotst.c:138
CHAR * LPTSTR
Definition: xmlstorage.h:192
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
Definition: kbdheb.c:79
Definition: kbdheb.c:81
VOID Test3(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:266
Definition: kbdheb.c:72
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
static LPCWSTR MainWndClass
Definition: psmtest.c:24
UINT WINAPI GetTextAlign(_In_ HDC)
Definition: text.c:808
int WINAPI SetBkMode(_In_ HDC, _In_ int)
Definition: dc.c:1032
HINSTANCE hInstance
Definition: charmap.c:20
#define ICC_WIN95_CLASSES
Definition: commctrl.h:66
#define DT_CALCRECT
Definition: winuser.h:526
LRESULT WINAPI DispatchMessageW(_In_ const MSG *)
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_ UINT, _In_ int, _In_ int, _In_ UINT)
Definition: cursoricon.c:2172
Definition: kbdheb.c:95
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define TRANSPARENT
Definition: wingdi.h:949
#define CW_USEDEFAULT
Definition: winuser.h:225
HACCEL WINAPI LoadAcceleratorsW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
HFONT WINAPI CreateFontIndirectW(_In_ const LOGFONTW *)
Definition: kbdheb.c:82
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
LONG_PTR LPARAM
Definition: windef.h:208
int cbClsExtra
Definition: winuser.h:3193
static HFONT hfont
LPCWSTR lpszClassName
Definition: winuser.h:3200
#define WM_DESTROY
Definition: winuser.h:1591
Definition: kbdheb.c:75
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
#define LR_DEFAULTSIZE
Definition: winuser.h:1084
__wchar_t WCHAR
Definition: xmlstorage.h:180
HBRUSH hbrBackground
Definition: winuser.h:3198
UINT cbSize
Definition: winuser.h:3190
#define IDR_ACCELERATOR
Definition: psmtest.c:16
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
HINSTANCE hInstance
Definition: winuser.h:3195
#define WM_PAINT
Definition: winuser.h:1602
int WINAPI TranslateAcceleratorW(_In_ HWND, _In_ HACCEL, _In_ LPMSG)
int ret
static const WCHAR L[]
Definition: oid.c:1250
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
HDC hdc
Definition: main.c:9
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define COLOR_BTNFACE
Definition: winuser.h:918
#define MB_ICONERROR
Definition: winuser.h:781
HCURSOR hCursor
Definition: winuser.h:3197
#define USERLPK
Definition: psmtest.c:27
UINT style
Definition: winuser.h:3191
BOOL WINAPI TextOutW(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCWSTR lpString, _In_ int c)
WNDPROC lpfnWndProc
Definition: winuser.h:3192
INT WINAPI UserLpkPSMTextOut(HDC hdc, int x, int y, LPCWSTR lpString, int cString, DWORD dwFlags)
Definition: font.c:413
#define DT_SINGLELINE
Definition: winuser.h:540
Definition: kbdheb.c:87
Definition: kbdheb.c:71
Definition: kbdheb.c:70
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
unsigned int UINT
Definition: ndis.h:50
Definition: kbdheb.c:92
#define MB_OK
Definition: winuser.h:784
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
Definition: kbdheb.c:96
HICON hIconSm
Definition: winuser.h:3201
VOID Test2(PTEST Test, HANDLE hEvent)
Definition: tmrqueue.c:192
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static void DrawTest(HDC hdc, int ypos, LPCWSTR str, DWORD dwFlags, int testtype)
Definition: psmtest.c:28
#define LoadImage
Definition: winuser.h:5716
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define LPK
Definition: psmtest.c:26
LONG_PTR LRESULT
Definition: windef.h:209
#define LR_DEFAULTCOLOR
Definition: winuser.h:1077
#define TA_RTLREADING
Definition: wingdi.h:933
#define SW_MAXIMIZE
Definition: winuser.h:766
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: psmtest.c:118
LPARAM lParam
Definition: combotst.c:139
#define WM_GETMINMAXINFO
Definition: winuser.h:1622
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
INT WINAPI LpkPSMTextOut(HDC hdc, int x, int y, LPCWSTR lpString, int cString, DWORD dwFlags)
Definition: lpk.c:389
Definition: kbdheb.c:73
Definition: kbdheb.c:78