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
|
// cl ScrollControls.cpp /O1 /Os kernel32.lib user32.lib gdi32.lib
// cl ScrollControls.cpp /O1 /Os /GR- /GS- TCLib.lib kernel32.lib user32.lib gdi32.lib
// 8,192 Bytes TCLib x64
// 79,872 Bytes LIBCMT x86
// 95,232 Bytes LIBCMT x64
#include <windows.h>
//#define TCLib
#ifdef TCLib
#include "string.h"
#include "tchar.h"
#else
#include <string>
#include <tchar.h>
#endif
#include "ScrollControls.h"
LRESULT CALLBACK fnPaneProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
if(msg==WM_COMMAND && LOWORD(wParam)==IDC_SUBMIT)
MessageBox(NULL,_T("You Apparently Want To Submit The Information!"),_T("Here Is What You Want..."),MB_OK);
return (DefWindowProc(hwnd,msg,wParam,lParam));
}
LRESULT fnWndProc_OnCreate(lpWndEventArgs Wea)
{
HWND hCtrl,hPane;
TCHAR szPane[8];
SCROLLINFO vsi;
WNDCLASSEX wc;
RECT rc;
Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
_tcscpy(szPane,_T("Pane")); //Set up 'Pane' class
wc.cbSize=sizeof(WNDCLASSEX), wc.style=CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc=fnPaneProc, wc.cbClsExtra=0;
wc.cbWndExtra=0, wc.hInstance=Wea->hIns;
wc.hIcon=0, wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW, wc.lpszMenuName=NULL;
wc.lpszClassName=szPane, wc.hIconSm=0;
RegisterClassEx(&wc);
hPane=CreateWindowEx(0,szPane,_T(""),WS_CHILD|WS_VISIBLE,0,0,325,490,Wea->hWnd,(HMENU)ID__PANE,Wea->hIns,0);
SetWindowLongPtr(Wea->hWnd,0,(LONG_PTR)hPane);
//Create all the child window controls on the 'Pane'
hCtrl=CreateWindowEx(0,_T("static"),_T("First Name"),WS_CHILD|WS_VISIBLE,10,10,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,10,150,25,hPane,(HMENU)IDC_FIRST_NAME,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Middle Name"),WS_CHILD|WS_VISIBLE,10,40,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,40,150,25,hPane,(HMENU)IDC_MIDDLE_NAME,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Last Name"),WS_CHILD|WS_VISIBLE,10,70,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,70,150,25,hPane,(HMENU)IDC_LAST_NAME,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Address1"),WS_CHILD|WS_VISIBLE,10,100,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,100,150,25,hPane,(HMENU)IDC_ADDRESS1,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Address2"),WS_CHILD|WS_VISIBLE,10,130,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,130,150,25,hPane,(HMENU)IDC_ADDRESS2,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("City"),WS_CHILD|WS_VISIBLE,10,160,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,160,150,25,hPane,(HMENU)IDC_CITY,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("State"),WS_CHILD|WS_VISIBLE,10,190,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,190,150,25,hPane,(HMENU)IDC_STATE,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Country"),WS_CHILD|WS_VISIBLE,10,220,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,220,150,25,hPane,(HMENU)IDC_COUNTRY,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Zip Code"),WS_CHILD|WS_VISIBLE,10,250,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,250,150,25,hPane,(HMENU)IDC_ZIP,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Email"),WS_CHILD|WS_VISIBLE,10,280,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,280,150,25,hPane,(HMENU)IDC_EMAIL,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Telephone"),WS_CHILD|WS_VISIBLE,10,310,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER,140,310,150,25,hPane,(HMENU)IDC_TELEPHONE,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("static"),_T("Interests"),WS_CHILD|WS_VISIBLE,10,340,100,25,hPane,(HMENU)-1,Wea->hIns,0);
hCtrl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE,140,340,150,100,hPane,(HMENU)IDC_TELEPHONE,Wea->hIns,0);
hCtrl=CreateWindowEx(0,_T("button"),_T("Submit"),WS_CHILD|WS_VISIBLE,100,455,100,25,hPane,(HMENU)IDC_SUBMIT,Wea->hIns,0);
//Initialize Window's internal scrolling apparatus (vsi think verticle scroll info)
GetClientRect(Wea->hWnd,&rc); //Need size of main window's client area to determine .nMax
vsi.cbSize=sizeof(SCROLLINFO); //Api docs say to do this
vsi.nMin=0;
vsi.nMax=489;
vsi.nPage=rc.bottom;
vsi.fMask=SIF_PAGE|SIF_RANGE;
SetScrollInfo(Wea->hWnd,SB_VERT,&vsi,TRUE);
return 0;
}
LRESULT fnWndProc_OnVScroll(lpWndEventArgs Wea)
{
int iVScrollPos;
SCROLLINFO vsi;
HWND hPane;
ZeroMemory(&vsi, sizeof(SCROLLINFO));
hPane=(HWND)GetWindowLongPtr(Wea->hWnd,0);
vsi.cbSize=sizeof(SCROLLINFO);
vsi.fMask=SIF_ALL; //vsi.fMask=SIF_POS|SIF_RANGE;
GetScrollInfo(Wea->hWnd,SB_VERT,&vsi);
iVScrollPos=vsi.nPos;
switch(LOWORD(Wea->wParam))
{
case SB_LINEUP:
if(vsi.nPos>vsi.nMin)
vsi.nPos=vsi.nPos-10;
break;
case SB_PAGEUP:
vsi.nPos = vsi.nPos - vsi.nPage;
break;
case SB_LINEDOWN:
if(vsi.nPos<vsi.nMax)
vsi.nPos=vsi.nPos+10;
break;
case SB_PAGEDOWN:
vsi.nPos = vsi.nPos + vsi.nPage;
break;
case SB_THUMBTRACK:
vsi.nPos=vsi.nTrackPos;
break;
}
vsi.fMask=SIF_POS;
SetScrollInfo(Wea->hWnd,SB_VERT,&vsi,TRUE);
GetScrollInfo(Wea->hWnd, SB_VERT, &vsi);
if(vsi.nPos != iVScrollPos)
MoveWindow(hPane,0,-1*vsi.nPos,325,500,TRUE);
return 0;
}
LRESULT fnWndProc_OnDestroy(lpWndEventArgs Wea)
{
PostQuitMessage(0);
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)
{
char szClassName[]=_T("ScrollControls");
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX); wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hIns;
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.cbWndExtra=sizeof(void*);
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW^WS_MAXIMIZEBOX,100,100,350,300,0,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|