FORMPROC.C
资源名称:cbuilder.zip [点击查看]
上传用户:needlamp
上传日期:2007-01-07
资源大小:78k
文件大小:11k
源码类别:
Delphi控件源码
开发平台:
Visual C++
- #include <windows.h>
- #include "appmain.h"
- #include "formproc.h"
- long CALLBACK __export FormWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- static BOOL isMouseDown =FALSE,isChildMouseDown =FALSE,isRecSizing =FALSE;
- static POINT pt0,pt1;
- POINT pt;
- static POINT ptFrame;
- HDC hDC;
- HWND hwnd;
- RECT rc,rcForm;
- int i,j;
- HWND hWndCurSel;
- char tmp[150];
- int CtlNo;
- switch(message)
- {
- case WM_CREATE:
- GetWindowRect(hWnd,&rc);
- ptFrame.x =ptFrame.y =0;
- ClientToScreen(hWnd,&ptFrame);
- ptFrame.x -=rc.left;
- ptFrame.y -=rc.top;
- SetWindowWord(hWnd,CTLNO,0);
- return 0L;
- case WM_SETFOCUS:
- if(GetParent(hWndRecSize[0])!=hWnd)
- {
- for(i=0;i<8;i++){
- SetParent(hWndRecSize[i],hWnd);
- ShowWindow(hWndRecSize[i],SW_HIDE);
- }
- hWndCurSel =(HWND)GetWindowWord(hWnd,CUR_SELWND);
- //if(hWndCurSel)
- //SetRecPos()
- }
- break;
- case WM_SETCURSOR:
- if(IsChild(hWnd,(HWND)wParam))
- {
- SetCursor(LoadCursor(NULL,IDC_SIZE));
- return TRUE;
- }
- break;
- case WM_ACTIVATEAPP:
- if(wParam) SetActiveWindow(hWnd);
- break;
- case WM_SYSCOMMAND:
- if(wParam ==SC_KEYMENU)
- {
- hWndPrev =hWnd;
- SetFocus(hWndMain);
- SendMessage(hWndMain,WM_SYSCOMMAND,wParam,lParam);
- return 0L;
- }
- break;
- case WM_RECSIZING:
- isRecSizing =TRUE;
- switch(wParam)
- {
- case 0:
- break;
- case 1:
- break;
- }
- break;
- case WM_PARENTNOTIFY:
- if(wParam ==WM_LBUTTONDOWN)
- {
- pt =pt0 =MAKEPOINT(lParam);
- CtlNo =GetWindowWord(hWnd,CTLNO);
- for(i=0;i<CtlNo;i++)
- {
- hwnd =GetDlgItem(hWnd,100+i);
- if(hwnd)
- {
- GetWindowRect(hwnd,&rc);
- pt1.x =rc.left;
- pt1.y =rc.top;
- ScreenToClient(hWnd,&pt1);
- rc.right =rc.right-rc.left+pt1.x;
- rc.bottom =rc.bottom-rc.top+pt1.y;
- rc.left =pt1.x;
- rc.top =pt1.y;
- if(PtInRect(&rc,pt0))
- {
- hWndCurSel =hwnd;
- SetWindowWord(hWnd, CUR_SELWND,hWndCurSel);
- pt0.x -=pt1.x;
- pt0.y -=pt1.y;
- pt1 =pt;
- hDC =GetWindowDC(hWnd);
- GetClientRect(hwnd,&rc);
- SelectObject(hDC, GetStockObject(NULL_BRUSH));
- SelectObject(hDC, GetStockObject(WHITE_PEN));
- SetROP2(hDC, R2_NOT);
- Rectangle(hDC,pt1.x-pt0.x+ptFrame.x,pt1.y-pt0.y+ptFrame.y,
- pt1.x-pt0.x+rc.right+ptFrame.x,pt1.y-pt0.y+rc.bottom+ptFrame.y);
- ReleaseDC(hWnd,hDC);
- if(GetParent(hWndRecSize[0])!=hWnd)
- for(j=0;j<8;j++) SetParent(hWndRecSize[j],hWnd);
- for(j=0;j<8;j++)
- {
- switch(j)
- {
- case 0:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 1:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 2:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 3:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 4:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 5:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 6:
- //SetWindowPos(hWndRecSize[j],
- break;
- case 7:
- //SetWindowPos(hWndRecSize[j],
- break;
- }
- ShowWindow(hWndRecSize[j],SW_SHOW);
- }
- SetFocus(hWnd);
- break;
- }
- }
- }
- }
- break;
- case WM_MOUSEACTIVATE:
- if(HIWORD(lParam) ==WM_LBUTTONDOWN && LOWORD(lParam)==HTCLIENT && GetFocus()==hWnd)
- {
- SetCapture(hWnd);
- if(isRecSizing)
- {
- isChildMouseDown =FALSE;
- isRecSizing =FALSE;
- }
- else
- isChildMouseDown =TRUE;
- return MA_NOACTIVATEANDEAT;
- }
- break;
- case WM_LBUTTONDOWN:
- isMouseDown =TRUE;
- pt1 =pt0 =MAKEPOINT(lParam);
- SetCapture(hWnd);
- return 0L;
- case WM_MOUSEMOVE:
- if(!isMouseDown && !isChildMouseDown) break;
- hDC =GetWindowDC(hWnd);
- hWndCurSel =(HWND)GetWindowWord(hWnd,CUR_SELWND);
- SelectObject(hDC, GetStockObject(NULL_BRUSH));
- SelectObject(hDC, GetStockObject(WHITE_PEN));
- SetROP2(hDC, R2_NOT);
- if(isMouseDown)
- Rectangle(hDC, pt0.x+ptFrame.x,pt0.y+ptFrame.y,pt1.x+ptFrame.x,pt1.y+ptFrame.y);
- else
- {
- if(hWndCurSel)
- {
- GetClientRect(hWndCurSel,&rc);
- Rectangle(hDC,pt1.x-pt0.x+ptFrame.x,pt1.y-pt0.y+ptFrame.y,
- pt1.x-pt0.x+rc.right+ptFrame.x,pt1.y-pt0.y+rc.bottom+ptFrame.y);
- }
- }
- pt1 =MAKEPOINT(lParam);
- if(isMouseDown)
- Rectangle(hDC, pt0.x+ptFrame.x,pt0.y+ptFrame.y,pt1.x+ptFrame.x,pt1.y+ptFrame.y);
- else if(hWndCurSel)
- Rectangle(hDC,pt1.x-pt0.x+ptFrame.x,pt1.y-pt0.y+ptFrame.y,
- pt1.x-pt0.x+rc.right+ptFrame.x,pt1.y-pt0.y+rc.bottom+ptFrame.y);
- ReleaseDC(hWnd,hDC);
- return 0L;
- case WM_LBUTTONUP:
- ReleaseCapture();
- if(!isMouseDown && !isChildMouseDown) return 0L;
- pt1 =MAKEPOINT(lParam);
- hWndCurSel =GetWindowWord(hWnd,CUR_SELWND);
- hDC =GetWindowDC(hWnd);
- SetROP2(hDC, R2_NOT);
- SelectObject(hDC, GetStockObject(NULL_BRUSH));
- SelectObject(hDC, GetStockObject(WHITE_PEN));
- if(isChildMouseDown && hWndCurSel)
- {
- GetClientRect(hWndCurSel,&rc);
- Rectangle(hDC,pt1.x-pt0.x+ptFrame.x,pt1.y-pt0.y+ptFrame.y,
- pt1.x-pt0.x+rc.right+ptFrame.x,pt1.y-pt0.y+rc.bottom+ptFrame.y);
- GetClientRect(hWndCurSel,&rc);
- if(pt0.x-pt1.x>rc.right) pt1.x =pt0.x;
- if(pt0.y-pt1.y>rc.bottom) pt1.y =pt0.y;
- GetClientRect(hWnd,&rcForm);
- if(pt1.x-pt0.x>rcForm.right) pt1.x =pt0.x+rcForm.right-rc.right;
- if(pt1.y-pt0.y>rcForm.bottom) pt1.y =pt0.y+rcForm.bottom-rc.bottom;
- SetWindowPos(hWndCurSel,0,pt1.x-pt0.x,pt1.y-pt0.y,0,0,SWP_NOSIZE |SWP_NOZORDER);
- InvalidateRect(hWndCurSel,NULL,FALSE);
- isChildMouseDown =FALSE;
- ReleaseDC(hWnd,hDC);
- pt0.x =pt1.x-pt0.x;
- pt0.y =pt1.y-pt0.y;
- pt1.x =pt0.x+rc.right;
- pt1.y =pt0.y+rc.bottom;
- //return TRUE;
- }
- else
- if(isMouseDown)
- {
- isMouseDown =FALSE;
- CtlNo =GetWindowWord(hWnd,CTLNO);
- Rectangle(hDC, pt0.x+ptFrame.x,pt0.y+ptFrame.y,pt1.x+ptFrame.x,pt1.y+ptFrame.y);
- if(lpCurCtlInfo)
- {
- wsprintf((LPSTR)tmp,"%s%d",(LPSTR)lpCurCtlInfo->ClassName,lpCurCtlInfo->WndCount+1);
- if(pt1.x<pt0.x)
- {
- pt.x =pt1.x;
- pt1.x =pt0.x;
- pt0.x =pt.x;
- }
- if(pt1.y<pt0.y)
- {
- pt.y =pt1.y;
- pt1.y =pt0.y;
- pt0.y =pt.y;
- }
- hwnd =CreateWindow(lpCurCtlInfo->ClassName,tmp,WS_CHILD | WS_VISIBLE | lpCurCtlInfo->WndStyle,
- pt0.x, pt0.y, pt1.x-pt0.x, pt1.y-pt0.y,
- hWnd, 100+CtlNo,hInst,NULL);
- if(hwnd)
- {
- SetWindowWord(hWnd,CTLNO,CtlNo+1);
- lpCurCtlInfo->WndCount++;
- }
- hWndCurSel=hwnd;
- }
- ReleaseDC(hWnd,hDC);
- }
- if(GetParent(hWndRecSize[0])!=hWnd)
- for(i=0;i<8;i++) SetParent(hWndRecSize[i],hWnd);
- if(hWndCurSel)
- for(i=0;i<8;i++)
- {
- ShowWindow(hWndRecSize[i],SW_SHOW);
- switch(i)
- {
- case 0:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt0.x-3,pt0.y-3,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 1:
- SetWindowPos(hWndRecSize[i],HWND_TOP,(pt1.x+pt0.x)/2,pt0.y-3,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 2:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt1.x-2,pt0.y-3,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 3:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt1.x-2,(pt0.y+pt1.y)/2,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 4:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt1.x-2,pt1.y-2,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 5:
- SetWindowPos(hWndRecSize[i],HWND_TOP,(pt1.x+pt0.x)/2,pt1.y-2,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 6:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt0.x-3,pt1.y-2,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- case 7:
- SetWindowPos(hWndRecSize[i],HWND_TOP,pt0.x-3,(pt0.y+pt1.y)/2,0,0,SWP_NOSIZE|SWP_NOACTIVATE);
- break;
- }
- //InvalidateRect(hWndRecSize[i],NULL,TRUE);
- }
- return 0L;
- case WM_CLOSE:
- break;
- default:
- break;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- long CALLBACK __export RecSizeWndProc(HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- HCURSOR hCursor;
- switch(message)
- {
- case WM_SETCURSOR:
- switch(GetWindowWord(hWnd,0))
- {
- case 0:
- case 4:
- hCursor=LoadCursor(NULL,IDC_SIZENWSE);
- break;
- case 1:
- case 5:
- hCursor=LoadCursor(NULL,IDC_SIZENS);
- break;
- case 2:
- case 6:
- hCursor=LoadCursor(NULL,IDC_SIZENESW);
- break;
- case 3:
- case 7:
- hCursor=LoadCursor(NULL,IDC_SIZEWE);
- break;
- default: return FALSE;
- }
- SetCursor(hCursor);
- return TRUE;
- case WM_MOUSEMOVE:
- return 0L;
- case WM_LBUTTONDOWN:
- SendMessage(GetParent(hWnd),WM_RECSIZING,hWnd,0L);
- return 0L;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }