2007-10-19 23:01:40 +00:00
|
|
|
/*
|
2007-03-06 11:34:03 +00:00
|
|
|
* Copyright 2006 Saveliy Tretiakov
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include "stdio.h"
|
|
|
|
|
|
|
|
WCHAR CaptWndClass[] = L"captwnd_class";
|
|
|
|
|
|
|
|
HINSTANCE hInst;
|
|
|
|
INT testnum = 0;
|
|
|
|
|
|
|
|
//BOOL STDCALL (*DrawCaptionTemp) (
|
|
|
|
// HWND hwnd,
|
|
|
|
// HDC hdc,
|
|
|
|
// const RECT *rect,
|
|
|
|
// HFONT hFont,
|
|
|
|
// HICON hIcon,
|
|
|
|
// LPCWSTR str,
|
|
|
|
// UINT uFlags);
|
|
|
|
|
2007-10-19 23:01:40 +00:00
|
|
|
VOID CapTest(HWND hWnd,
|
|
|
|
HDC hDc,
|
|
|
|
LPRECT pR,
|
|
|
|
WCHAR *Text,
|
2007-03-06 11:34:03 +00:00
|
|
|
DWORD Flags,
|
|
|
|
WCHAR *AddonStr,
|
|
|
|
DWORD Addon)
|
|
|
|
{
|
|
|
|
WCHAR Buf[512];
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
lstrcpy(Buf, AddonStr);
|
|
|
|
if(lstrlen(Buf))lstrcat(Buf, L" | ");
|
|
|
|
lstrcat(Buf, Text);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
DrawText( hDc, Buf, lstrlen(Buf), pR, DT_LEFT );
|
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
pR->top+=20;
|
2007-10-19 23:01:40 +00:00
|
|
|
pR->bottom+=20;
|
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
if(!DrawCaption(hWnd, hDc, pR, Flags | Addon))
|
|
|
|
{
|
|
|
|
printf("PAINT: DrawCaption failed: %d\n", (int)GetLastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
pR->top+=30;
|
2007-10-19 23:01:40 +00:00
|
|
|
pR->bottom+=30;
|
2007-03-06 11:34:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID DrawCaptionTest(HWND hWnd, HDC hDc, WCHAR *AddonStr, DWORD Addon)
|
|
|
|
{
|
|
|
|
RECT Rect;
|
|
|
|
GetClientRect(hWnd, &Rect);
|
|
|
|
Rect.bottom = 30;
|
|
|
|
Rect.left = 10;
|
|
|
|
Rect.right-=10;
|
|
|
|
Rect.top = 10;
|
|
|
|
|
2007-10-19 23:01:40 +00:00
|
|
|
CapTest(hWnd, hDc, &Rect, L"DC_TEXT:", DC_TEXT, AddonStr, Addon);
|
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_ACTIVE:",
|
|
|
|
DC_TEXT | DC_ACTIVE,
|
2007-03-06 11:34:03 +00:00
|
|
|
AddonStr, Addon);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_ICON:" ,
|
|
|
|
DC_TEXT | DC_ICON,
|
|
|
|
AddonStr, Addon);
|
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_ACTIVE | DC_ICON:" ,
|
|
|
|
DC_TEXT | DC_ACTIVE | DC_ICON,
|
2007-03-06 11:34:03 +00:00
|
|
|
AddonStr, Addon);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_INBUTTON:" ,
|
|
|
|
DC_TEXT | DC_INBUTTON,
|
2007-03-06 11:34:03 +00:00
|
|
|
AddonStr, Addon);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_ACTIVE | DC_INBUTTON:" ,
|
|
|
|
DC_TEXT | DC_ACTIVE | DC_INBUTTON,
|
|
|
|
AddonStr, Addon);
|
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
|
|
|
L"DC_TEXT | DC_ICON | DC_INBUTTON:" ,
|
|
|
|
DC_TEXT | DC_ICON | DC_INBUTTON,
|
|
|
|
AddonStr, Addon);
|
|
|
|
|
|
|
|
CapTest(hWnd, hDc, &Rect,
|
2007-03-06 11:34:03 +00:00
|
|
|
L"DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON:" ,
|
2007-10-19 23:01:40 +00:00
|
|
|
DC_TEXT | DC_ACTIVE | DC_ICON | DC_INBUTTON,
|
|
|
|
AddonStr, Addon);
|
2007-03-06 11:34:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-10-19 23:01:40 +00:00
|
|
|
LRESULT CALLBACK CaptWndProc(HWND hWnd,
|
|
|
|
UINT msg,
|
|
|
|
WPARAM wParam,
|
2007-03-06 11:34:03 +00:00
|
|
|
LPARAM lParam)
|
2007-10-19 23:01:40 +00:00
|
|
|
{
|
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
HDC hDc;
|
|
|
|
PAINTSTRUCT Ps;
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
hDc = BeginPaint(hWnd, &Ps);
|
|
|
|
SetBkMode( hDc, TRANSPARENT );
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
switch(testnum)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
DrawCaptionTest(hWnd, hDc, L"", 0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
DrawCaptionTest(hWnd, hDc, L"DC_GRADIENT", DC_GRADIENT);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
DrawCaptionTest(hWnd, hDc, L"DC_SMALLCAP", DC_SMALLCAP);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
DrawCaptionTest(hWnd, hDc, L"DC_BUTTONS", DC_BUTTONS);
|
|
|
|
break;
|
|
|
|
case 5:
|
2007-10-19 23:01:40 +00:00
|
|
|
DrawCaptionTest(hWnd, hDc,
|
|
|
|
L"DC_GRADIENT | DC_SMALLCAP",
|
2007-03-06 11:34:03 +00:00
|
|
|
DC_GRADIENT | DC_SMALLCAP);
|
|
|
|
break;
|
|
|
|
case 6:
|
2007-10-19 23:01:40 +00:00
|
|
|
DrawCaptionTest(hWnd, hDc,
|
|
|
|
L"DC_GRADIENT | DC_BUTTONS",
|
2007-03-06 11:34:03 +00:00
|
|
|
DC_GRADIENT | DC_BUTTONS);
|
|
|
|
break;
|
2007-10-19 23:01:40 +00:00
|
|
|
case 7:
|
|
|
|
DrawCaptionTest(hWnd, hDc,
|
|
|
|
L"DC_BUTTONS | DC_SMALLCAP",
|
2007-03-06 11:34:03 +00:00
|
|
|
DC_BUTTONS | DC_SMALLCAP);
|
|
|
|
break;
|
|
|
|
case 8:
|
2007-10-19 23:01:40 +00:00
|
|
|
DrawCaptionTest(hWnd, hDc,
|
|
|
|
L"DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT",
|
2007-03-06 11:34:03 +00:00
|
|
|
DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT);
|
|
|
|
break;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
EndPaint(hWnd, &Ps);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_DESTROY:
|
|
|
|
{
|
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INT main(INT argc, CHAR **argv)
|
|
|
|
{
|
|
|
|
HWND hWnd;
|
|
|
|
MSG msg;
|
|
|
|
WNDCLASSEX wcx;
|
|
|
|
UINT result;
|
|
|
|
HBRUSH hBr;
|
|
|
|
//HMODULE hLib;
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
if(argc<2)
|
|
|
|
{
|
|
|
|
printf("DrawCaption testcode.\n");
|
|
|
|
printf("USAGE: drawcap.exe <testnumber> [useicon]\n\n");
|
|
|
|
printf("Available tests:\n"
|
|
|
|
"1. DrawCaption test\n"
|
|
|
|
"2. DrawCaption test + DC_GRADIENT\n"
|
|
|
|
"3. DrawCaption test + DC_SMALLCAP\n"
|
|
|
|
"4. DrawCaption test + DC_BUTTONS\n"
|
|
|
|
"5. DrawCaption test + DC_GRADIENT | DC_SMALLCAP\n"
|
|
|
|
"6. DrawCaption test + DC_GRADIENT | DC_BUTTONS\n"
|
|
|
|
"7. DrawCaption test + DC_BUTTONS | DC_SMALLCAP\n"
|
|
|
|
"8. DrawCaption test + DC_BUTTONS | DC_SMALLCAP | DC_GRADIENT\n\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
testnum = atoi(argv[1]);
|
|
|
|
if(testnum < 1 || testnum > 8)
|
|
|
|
{
|
|
|
|
printf("Unknown test %d\n", testnum);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
hInst = GetModuleHandle(NULL);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
//hLib = LoadLibrary(L"user32");
|
|
|
|
//if(!hLib)
|
|
|
|
//{
|
|
|
|
// printf("Shit! Can't load user32.dll\n");
|
|
|
|
// return 1;
|
|
|
|
//}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
//DrawCaptionTemp = GetProcAddress(hLib, "DrawCaptionTempW");
|
|
|
|
//if(!DrawCaptionTemp)
|
|
|
|
//{
|
|
|
|
// printf("Shit! Can't get DrawCaptionTemp address\n");
|
|
|
|
// return 1;
|
|
|
|
//}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
hBr = CreateSolidBrush(RGB(255, 255, 255));
|
|
|
|
if(!hBr)
|
|
|
|
{
|
|
|
|
printf("Shit! Can't create brush.");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
memset(&wcx, 0, sizeof(wcx));
|
|
|
|
wcx.cbSize = sizeof(wcx);
|
|
|
|
wcx.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wcx.lpfnWndProc = (WNDPROC) CaptWndProc;
|
|
|
|
wcx.hInstance = hInst;
|
|
|
|
wcx.hbrBackground = hBr;
|
|
|
|
wcx.lpszClassName = CaptWndClass;
|
|
|
|
if(argc > 2) wcx.hIconSm = LoadIcon(hInst, MAKEINTRESOURCE(ID_ICON1SM));
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
if(!(result = RegisterClassEx(&wcx)))
|
|
|
|
{
|
2007-10-19 23:01:40 +00:00
|
|
|
printf("Shit! RegisterClassEx failed: %d\n",
|
2007-03-06 11:34:03 +00:00
|
|
|
(int)GetLastError());
|
|
|
|
DeleteObject(hBr);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
hWnd = CreateWindowEx(0,
|
|
|
|
CaptWndClass,
|
2007-03-06 11:34:03 +00:00
|
|
|
L"DrawCaption test",
|
|
|
|
WS_OVERLAPPED|WS_THICKFRAME|WS_SYSMENU,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
600,
|
|
|
|
470,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
hInst,
|
|
|
|
NULL);
|
2007-10-19 23:01:40 +00:00
|
|
|
|
2007-03-06 11:34:03 +00:00
|
|
|
if(!hWnd)
|
|
|
|
{
|
|
|
|
printf("Shit! Can't create wnd!\n");
|
|
|
|
UnregisterClass(CaptWndClass, hInst);
|
|
|
|
DeleteObject(hBr);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-10-19 23:01:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
ShowWindow(hWnd, SW_SHOW);
|
|
|
|
UpdateWindow(hWnd);
|
2007-03-06 11:34:03 +00:00
|
|
|
|
|
|
|
while(GetMessage(&msg, NULL, 0, 0 ))
|
|
|
|
{
|
2007-10-19 23:01:40 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2007-03-06 11:34:03 +00:00
|
|
|
|
|
|
|
DeleteObject(hBr);
|
|
|
|
UnregisterClass(CaptWndClass, hInst);
|
|
|
|
return 0;
|
|
|
|
}
|