#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[ ] = _T("WindowsApp");
HWND hWndEdit;
HWND hscroll;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
_T("Windows App"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
RECT rect;
if (!GetClientRect(hwnd, &rect))
return NULL;
hscroll = CreateWindowEx(
0,
"SCROLLBAR",
(PTSTR) NULL,
WS_CHILD | WS_VISIBLE
| SBS_HORZ,
rect.left,
rect.bottom - 25,
rect.right,
25,
hwnd,
NULL,
hThisInstance,
NULL
);
SetScrollRange(hscroll,SB_CTL,0,100,TRUE);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int s1Pos=0,s1Min=0,s1Max=100;
switch (message)
{
case WM_HSCROLL:
if((HWND)lParam==hscroll)
{
InvalidateRect(hwnd, 0, TRUE);
UpdateWindow(hwnd);
char str[80];
sprintf (str, "%d",s1Pos);
HDC hdc = GetDC(hwnd);
HFONT font = CreateFont(46, 28,0, 0,
FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_ROMAN,
"Times New Roman");
SelectObject(hdc, font);
TextOut(hdc,0,0,str,strlen(str));
switch(LOWORD(wParam))
{
case SB_PAGERIGHT:
{s1Pos+=1;break;}
case SB_LINERIGHT:
{s1Pos+=1;break;}
case SB_PAGELEFT:
{s1Pos-=1;break;}
case SB_LINELEFT:
{s1Pos-=1;break;}
case SB_TOP:
{s1Pos=s1Min;break;}
case SB_BOTTOM:
{s1Pos=s1Max;break;}
}
SetScrollPos(hscroll,SB_CTL,s1Pos,TRUE);
}
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|