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
|
long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
HWND hCtrl,hPane;
TCHAR szPane[8];
SCROLLINFO vsi;
WNDCLASSEX wc;
RECT rc;
Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
//Set up 'Pane' class
_tcscpy(szPane,_T("Pane"));
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);
SetWindowLong(Wea->hWnd,0,(long)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=490-rc.bottom;
vsi.nPos=0;
vsi.fMask=SIF_POS|SIF_RANGE;
SetScrollInfo(Wea->hWnd,SB_VERT,&vsi,TRUE);
return 0;
}
long fnWndProc_OnVScroll(lpWndEventArgs Wea)
{
SCROLLINFO vsi;
HWND hPane;
hPane=(HWND)GetWindowLong(Wea->hWnd,0);
switch(LOWORD(Wea->wParam))
{
case SB_LINEUP:
vsi.cbSize=sizeof(SCROLLINFO);
vsi.fMask=SIF_POS|SIF_RANGE;
GetScrollInfo(Wea->hWnd,SB_VERT,&vsi);
if(vsi.nPos>0)
{
vsi.nPos=vsi.nPos-10;
if(vsi.nPos<0)
vsi.nPos=0;
MoveWindow(hPane,0,-1*vsi.nPos,325,500,TRUE);
vsi.fMask=SIF_POS;
SetScrollInfo(Wea->hWnd,SB_VERT,&vsi,TRUE);
}
break;
case SB_LINEDOWN:
vsi.cbSize=sizeof(SCROLLINFO);
vsi.fMask=SIF_POS|SIF_RANGE;
GetScrollInfo(Wea->hWnd,SB_VERT,&vsi);
if(vsi.nPos<vsi.nMax)
{
vsi.nPos=vsi.nPos+10;
MoveWindow(hPane,0,-1*vsi.nPos,325,500,TRUE);
vsi.fMask=SIF_POS;
SetScrollInfo(Wea->hWnd,SB_VERT,&vsi,TRUE);
}
break;
}
return 0;
}
long fnWndProc_OnDestroy(lpWndEventArgs Wea)
{
PostQuitMessage(0);
return 0;
}
void AttachEventHandlers(void) //This procedure maps windows messages to the
{ //procedure which handles them.
EventHandler[0].Code=WM_CREATE, EventHandler[0].fnPtr=fnWndProc_OnCreate;
EventHandler[1].Code=WM_VSCROLL, EventHandler[1].fnPtr=fnWndProc_OnVScroll;
EventHandler[2].Code=WM_DESTROY, EventHandler[2].fnPtr=fnWndProc_OnDestroy;
}
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
WndEventArgs Wea; //This procedure loops through the EVENTHANDER array
//of structs to try to make a match with the msg parameter
for(unsigned int i=0; i<3; i++) //of the WndProc. If a match is made the event handling
{ //procedure is called through a function pointer -
if(EventHandler[i].Code==msg) //(EventHandler[i].fnPtr). If no match is found the
{ //msg is passed onto DefWindowProc().
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;
AttachEventHandlers();
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=8;
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,100,100,350,300,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|