APPMAIN.C
资源名称:cbuilder.zip [点击查看]
上传用户:needlamp
上传日期:2007-01-07
资源大小:78k
文件大小:45k
源码类别:
Delphi控件源码
开发平台:
Visual C++
- //8,3,2,20,7,6,4,5,22
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include "lg3d.h"
- #include "appmain.h"
- HINSTANCE hInst;
- HWND hWndMain,hWndPrj,hWndStyle,hWndCtl,hWndInsp,hWndCode;
- HWND hWndPrev =NULL;
- HBRUSH hBrushPat =NULL;
- int slipPos =180;
- typedef struct tag_PrjBtnInfo
- {
- int BmpNO;
- UINT ID;
- int left,top;
- }PrjBtnInfo;
- PrjBtnInfo PrjBtn[PRJ_BTN_COUNT]=
- {
- {0,IDM_OPENPRJ,5,5},
- {1,IDM_SAVEPRJ,5+PRJ_BTN_WIDTH+1,5},
- {2,IDM_ADDFILE,5+(PRJ_BTN_WIDTH+1)*2,5},
- {3,IDM_VIEW_CODE,10+(PRJ_BTN_WIDTH+1)*3,5},
- {4,IDM_VIEW_FORM,10+(PRJ_BTN_WIDTH+1)*4,5},
- {5,IDM_NEWFILE,5,5+PRJ_BTN_HEIGHT+1},
- {6,IDM_SAVEFILE,5+PRJ_BTN_WIDTH+1,5+PRJ_BTN_HEIGHT+1},
- {7,IDM_RMVFILE,5+(PRJ_BTN_WIDTH+1)*2,5+PRJ_BTN_HEIGHT+1},
- {8,IDM_VIEW_TOG,10+(PRJ_BTN_WIDTH+1)*3,5+PRJ_BTN_HEIGHT+1},
- {9,IDM_NEWFRM,10+(PRJ_BTN_WIDTH+1)*4,5+PRJ_BTN_HEIGHT+1}
- };
- typedef struct tag_StyleBtnInfo
- {
- UINT ID;
- char Caption[20];
- int left,right;
- }StyleBtnInfo;
- typedef StyleBtnInfo FAR *LPSTYLEBTN;
- void DrawStyleBtn(HDC,HWND,int, int, BOOL,LPSTYLEBTN);
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- if (!hPrevInstance)
- if (!InitApplication(hInstance))
- return (FALSE);
- if (!InitInstance(hInstance, nCmdShow))
- return (FALSE);
- LgDlg3D(TRUE,NULL); //must using in c, not in cpp
- while (GetMessage(&msg,
- NULL,
- NULL,
- NULL))
- {
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- ExitProg();
- return (msg.wParam);
- }
- void ExitProg(void)
- {
- if(hBrushPat) DeleteObject(hBrushPat);
- hBrushPat = NULL;
- LgDlg3D(FALSE,NULL); //must use in c , not in cpp
- }
- BOOL InitApplication(HINSTANCE hInstance)
- {
- WNDCLASS wc;
- wc.style = CS_DBLCLKS;
- wc.lpfnWndProc = MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(hInstance, "ICON_YW");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
- wc.lpszMenuName = "CBuilder";
- wc.lpszClassName = "CBuilder";
- return (RegisterClass(&wc));
- }
- BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
- {
- HWND hWnd;
- hInst = hInstance;
- hWnd = CreateWindow(
- "CBuilder",
- "CBuilder",
- WS_OVERLAPPEDWINDOW,
- 0,0,638,MAIN_WINDOW_HEIGHT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- if (!hWnd)
- return (FALSE);
- hWndMain = hWnd;
- if(!CreateMainChild(hWnd))
- {
- DestroyWindow(hWnd);
- return FALSE;
- }
- if(!RegLGFORM())
- {
- DestroyWindow(hWnd);
- return FALSE;
- }
- if((hWndInsp =CreateInspWnd()) ==NULL)
- {
- DestroyWindow(hWnd);
- return FALSE;
- }
- if(!CreateRecSizeWnd())
- {
- ErrorMessage("CreateRecSizeWnd failed!");
- DestroyWindow(hWnd);
- return FALSE;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return (TRUE);
- }
- HWND CreateChild(HWND hWndParent,LPSTR ClassName,WNDPROC WndProc,int left,int top,int width,int height,UINT ID,int WndExtra)
- {
- WNDCLASS wc;
- HWND hWnd;
- wc.style = CS_HREDRAW | CS_DBLCLKS;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = WndExtra;
- wc.hInstance = hInst;
- wc.hIcon = LoadIcon(hInst, "ICON_YW");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = ClassName;
- if(!RegisterClass(&wc)) return NULL;
- hWnd = CreateWindow( ClassName,ClassName,WS_CHILD,
- left,top,width,height,
- hWndParent,ID, hInst, NULL
- );
- if (!hWnd)
- return NULL;
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- return hWnd;
- }
- BOOL CreateMainChild(HWND hWnd)
- {
- RECT rc;
- HBITMAP hBmpPat;
- static char tmp[30];
- int i;
- hBmpPat = LoadBitmap(hInst,"BMP_PAT");
- if(hBmpPat)
- hBrushPat = CreatePatternBrush(hBmpPat);
- DeleteObject(hBmpPat);
- GetClientRect(hWnd,&rc);
- if((hWndPrj = CreateChild(hWnd,(LPSTR)"WNDPRJ",(WNDPROC)PrjWndProc,
- 0,0,slipPos,rc.bottom,NULL,0)) == NULL)
- {
- ErrorMessage("CreateMainChild WNDPRJ failed!");
- return FALSE;
- }
- if((hWndCtl = CreateChild(hWnd,(LPSTR)"WNDCTL",(WNDPROC)CtlWndProc,
- slipPos+3,0,rc.right-slipPos-3,rc.bottom-19,NULL,0)) == NULL)
- {
- ErrorMessage("CreateMainChild WNDCTL failed!");
- return FALSE;
- }
- if((hWndStyle = CreateChild(hWnd,(LPSTR)"WNDSTYLE",(WNDPROC)StyleWndProc,
- slipPos+3,rc.bottom-19,rc.right-slipPos-3,19,IDW_STYLE,
- 5*sizeof(WORD))) == NULL)
- {
- ErrorMessage("CreateMainChild WNDSTYLE failed!");
- return FALSE;
- }
- i=0;
- while(LoadString(hInst,IDW_STYLE+i,(LPSTR)tmp,sizeof(tmp)))
- {
- SendMessage(hWndStyle,WM_ADDITEM,IDW_STYLE+i,(LPARAM)(LPSTR)tmp);
- i++;
- }
- return TRUE;
- }
- BOOL RegLGFORM(void)
- {
- WNDCLASS wc;
- wc.style = CS_HREDRAW | CS_DBLCLKS;
- wc.lpfnWndProc = FormWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 2*sizeof(WORD);
- wc.hInstance = hInst;
- wc.hIcon = LoadIcon(hInst, "ICON_YW");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "LGFORM";
- if(!RegisterClass(&wc)) return FALSE;
- wc.style =0;
- wc.lpfnWndProc = RecSizeWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = sizeof(WORD);
- wc.hInstance = hInst;
- wc.hIcon = NULL;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(BLACK_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "RECSIZE";
- return (RegisterClass(&wc));
- }
- HWND hWndRecSize[8];
- BOOL CreateRecSizeWnd(void)
- {
- int i;
- for(i=0;i<8;i++)
- {
- hWndRecSize[i]=CreateWindow("RECSIZE","",WS_CHILD,0,0,5,5,
- hWndMain,0,hInst,NULL);
- if(hWndRecSize[i]==NULL) return FALSE;
- SetWindowWord(hWndRecSize[i],0,i);
- }
- return TRUE;
- }
- HWND CreateInspWnd(void)
- {
- HWND hWnd;
- WNDCLASS wc;
- wc.style = CS_HREDRAW | CS_DBLCLKS;
- wc.lpfnWndProc = InspWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = sizeof(WORD);
- wc.hInstance = hInst;
- wc.hIcon = LoadIcon(hInst, "ICON_YW");
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "LGINSP";
- if(!RegisterClass(&wc)) return NULL;
- hWnd =CreateWindow("LGINSP","对象流览器",
- WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX
- |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_THICKFRAME,
- 0,120,200,280,
- NULL, NULL, hInst, NULL);
- if (!hWnd)
- return NULL;
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- SetWindowPos(hWnd,hWndMain,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
- return hWnd;
- }
- HCURSOR hCurSplit = NULL;
- BOOL isInSlip = FALSE;
- BOOL isMouseDown=FALSE;
- BOOL gSlipped =FALSE;
- int FormNum =0;
- HFONT hStyleFont=NULL;
- HBITMAP hBmpStyleUp,hBmpStyleDn,hBmpStyleDs;
- long CALLBACK __export MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- RECT rc;
- MINMAXINFO FAR *lpmmi;
- POINT pt;
- PAINTSTRUCT ps;
- HPEN hPen;
- DLGPROC lpProcAbout;
- HDC hDC;
- BOOL fInSlip = FALSE;
- HWND hwnd;
- LOGFONT lf;
- switch (message)
- {
- case WM_CREATE:
- hCurSplit = LoadCursor(hInst,"CUR_SPLIT");
- hBmpStyleUp =LoadBitmap(hInst,"BMP_STYLEUP");
- hBmpStyleDn =LoadBitmap(hInst,"BMP_STYLEDN");
- hBmpStyleDs =LoadBitmap(hInst,"BMP_STYLEDS");
- memset(&lf,0,sizeof(lf));
- lf.lfHeight = 13;
- lf.lfWeight = FW_NORMAL;
- lf.lfCharSet = DEFAULT_CHARSET ;
- lf.lfOutPrecision = OUT_DEFAULT_PRECIS ;
- lf.lfClipPrecision = CLIP_DEFAULT_PRECIS ;
- lf.lfQuality = DEFAULT_QUALITY ;
- lf.lfPitchAndFamily = DEFAULT_PITCH;
- strcpy(lf.lfFaceName , "宋体");
- hStyleFont = CreateFontIndirect( &lf ) ;
- if(hStyleFont == NULL)
- {
- ErrorMessage("Create StyleFont Failed");
- return -1;
- }
- break;
- case WM_GETMINMAXINFO:
- lpmmi=(MINMAXINFO FAR *)lParam;
- lpmmi->ptMaxSize.y=100;
- lpmmi->ptMinTrackSize.x=500;
- lpmmi->ptMinTrackSize.y=100;
- lpmmi->ptMaxTrackSize.y=100;
- break;
- case WM_SIZE:
- if(wParam == SIZE_MINIMIZED) break;
- GetClientRect(hWndPrj,&rc);
- MoveWindow(hWndStyle, rc.right+3, rc.bottom-19,
- LOWORD(lParam)-rc.right-3,19,TRUE);
- MoveWindow(hWndCtl, rc.right+3,0,
- LOWORD(lParam)-rc.right-3,rc.bottom-19,TRUE);
- return 0L;
- case WM_SETCURSOR:
- if(isInSlip ==TRUE)
- return TRUE;
- break;
- case WM_CANCELMODE:
- break;
- case WM_LBUTTONDOWN:
- if(isInSlip)
- {
- GetClientRect(hWnd,&rc);
- hDC = GetDC(hWnd);
- SetROP2(hDC,R2_NOT);
- MoveTo(hDC,slipPos+1,0);
- LineTo(hDC,slipPos+1,rc.bottom);
- ReleaseDC(hWnd,hDC);
- SetCapture(hWnd);
- isMouseDown = TRUE;
- }
- return 0L;
- case WM_ACTIVATEAPP:
- if(wParam) SetActiveWindow(hWnd);
- break;
- case WM_MOUSEMOVE:
- if(!isMouseDown)
- {
- fInSlip = isInSlip;
- pt = MAKEPOINT(lParam);
- if(pt.x>slipPos-1 && pt.x<slipPos+3 && pt.y>0)
- isInSlip = TRUE;
- else
- isInSlip=FALSE;
- if(fInSlip !=isInSlip)
- {
- if(isInSlip)
- SetCursor(hCurSplit);
- else SetCursor(LoadCursor(NULL,IDC_ARROW));
- }
- return 0L;
- }
- if(!isInSlip) return 0L;
- GetClientRect(hWnd,&rc);
- hDC=GetDC(hWnd);
- SetROP2(hDC,R2_NOT);
- MoveTo(hDC,slipPos+1,0);
- LineTo(hDC,slipPos+1,rc.bottom);
- pt=MAKEPOINT(lParam);
- slipPos=pt.x;
- MoveTo(hDC,slipPos+1,0);
- LineTo(hDC,slipPos+1,rc.bottom);
- ReleaseDC(hWnd,hDC);
- return 0L;
- case WM_LBUTTONUP:
- if(!isInSlip || !isMouseDown) break;
- isMouseDown = FALSE;
- isInSlip = FALSE;
- ReleaseCapture();
- GetClientRect(hWnd,&rc);
- hDC=GetDC(hWnd);
- pt=MAKEPOINT(lParam);
- slipPos=pt.x;
- SetROP2(hDC,R2_NOT);
- MoveTo(hDC,slipPos+1,0);
- LineTo(hDC,slipPos+1,rc.bottom);
- ReleaseDC(hWnd,hDC);
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- gSlipped =TRUE;
- MoveWindow(hWndPrj, 0,0,slipPos,rc.bottom,TRUE);
- MoveWindow(hWndCtl, slipPos+3,0,
- rc.right-slipPos-3,rc.bottom-19,TRUE);
- MoveWindow(hWndStyle, slipPos+3, rc.bottom-19,
- rc.right-slipPos-3,19,TRUE);
- gSlipped =FALSE;
- return 0L;
- case WM_MENUSELECT:
- if(wParam ==0 && hWndPrev !=NULL)
- {
- SetFocus(hWndPrev);
- hWndPrev =NULL;
- return 0L;
- }
- break;
- case WM_COMMAND:
- switch(wParam)
- {
- case IDW_STYLE:
- SendMessage(hWndCtl, WM_STYLECHANGED, (WPARAM)lParam,0L);
- return 0L;
- case IDM_VIEW_OBJINSP:
- ShowWindow(hWndInsp,SW_SHOW);
- SetFocus(hWndInsp);
- return 0L;
- case IDM_NEWFRM:
- hwnd =CreateNewForm();
- break;
- case IDM_EXIT:
- PostMessage(hWnd,WM_CLOSE,0,0L);
- break;
- case IDM_ABOUT:
- lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About,hInst);
- DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
- FreeProcInstance((FARPROC)lpProcAbout);
- break;
- default:
- break;
- }
- return 0L;
- case WM_PAINT:
- GetClientRect(hWndPrj,&rc);
- BeginPaint(hWnd,&ps);
- hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(ps.hdc,hPen);
- MoveTo(ps.hdc,rc.right+2,0);
- LineTo(ps.hdc,rc.right+2,rc.bottom);
- SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
- DeleteObject(hPen);
- MoveTo(ps.hdc,rc.right,0);
- LineTo(ps.hdc,rc.right,rc.bottom);
- EndPaint(hWnd,&ps);
- break;
- case WM_CLOSE:
- if(MessageBox(NULL,"您 是 否 确 定 退 出nn"
- " CBuilder 系 统?",
- "CBuilder",MB_ICONQUESTION|MB_TASKMODAL|MB_YESNO)
- ==IDYES)
- {
- for(hwnd =FindWindow("LGFORM",NULL);
- GetWindowWord(hwnd,GWW_HINSTANCE)==hInst;
- hwnd =FindWindow("LGFORM",NULL))
- DestroyWindow(hwnd);
- UnregisterClass("LGFORM",hInst);
- if(hWndInsp) DestroyWindow(hWndInsp);
- UnregisterClass("LGINSP",hInst);
- DestroyWindow(hWnd);
- }
- return 0L;
- case WM_DESTROY:
- if(hCurSplit) DeleteObject(hCurSplit);
- if(hStyleFont) DeleteObject(hStyleFont);
- if(hBmpStyleUp) DeleteObject(hBmpStyleUp);
- if(hBmpStyleDn) DeleteObject(hBmpStyleDn);
- if(hBmpStyleDs) DeleteObject(hBmpStyleDs);
- PostQuitMessage(0);
- break;
- default:
- break;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- long CALLBACK __export PrjWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HPEN hPen;
- RECT rc;
- POINT pt;
- HDC hDC;
- int i;
- static HBITMAP hBmpPrjUp=NULL,hBmpPrjDn=NULL,hBmpPrjDs=NULL;
- static int CurSelBtn=-1;
- static WORD gState=0;
- HBITMAP hBmp;
- HDC hMemDC;
- LONG ltmp;
- WORD wState;
- PAINTSTRUCT ps;
- switch(message)
- {
- case WM_CREATE:
- hBmpPrjUp = LoadBitmap(hInst,"BMP_PRJUP");
- if(hBmpPrjUp == NULL){
- ErrorMessage("error load resource BMP_PRJUP");
- DestroyWindow(hWnd);
- return -1;
- }
- hBmpPrjDn = LoadBitmap(hInst,"BMP_PRJDN");
- if(hBmpPrjDn == NULL){
- ErrorMessage("error load resource BMP_PRJDN");
- DestroyWindow(hWnd);
- return -1;
- }
- hBmpPrjDs = LoadBitmap(hInst,"BMP_PRJDS");
- if(hBmpPrjDs == NULL){
- ErrorMessage("error load resource BMP_PRJDS");
- DestroyWindow(hWnd);
- return -1;
- }
- break;
- case WM_DRAWBUTTON:
- hBmp = NULL;
- if(CurSelBtn<0)
- {
- if( hBmpPrjUp == NULL) return 0L;
- hMemDC = CreateCompatibleDC ((HDC)wParam) ;
- SelectObject (hMemDC, hBmpPrjUp) ;
- for(i=0;i<PRJ_BTN_COUNT;i++)
- {
- BitBlt ((HDC)wParam, PrjBtn[i].left, PrjBtn[i].top,
- PRJ_BTN_WIDTH, PRJ_BTN_HEIGHT,
- hMemDC,1+i*(PRJ_BTN_WIDTH+1) , 1, SRCCOPY) ;
- }
- DeleteDC (hMemDC) ;
- return 0L;
- }
- else
- {
- if(CurSelBtn>=PRJ_BTN_COUNT) return 0L;
- switch(lParam)
- {
- case 0L:
- hBmp=hBmpPrjUp;
- break;
- case 1L:
- hBmp=hBmpPrjDn;
- break;
- case 2L:
- hBmp=hBmpPrjDs;
- break;
- }
- if(hBmp==NULL) return 0L;
- hDC=GetDC(hWnd);
- hMemDC = CreateCompatibleDC (hDC) ;
- SelectObject (hMemDC, hBmp) ;
- BitBlt (hDC, PrjBtn[CurSelBtn].left, PrjBtn[CurSelBtn].top,
- PRJ_BTN_WIDTH, PRJ_BTN_HEIGHT,
- hMemDC,1+CurSelBtn*(PRJ_BTN_WIDTH+1) , 1, SRCCOPY) ;
- DeleteDC (hMemDC) ;
- ReleaseDC(hWnd,hDC);
- }
- return 0;
- case WM_SETCURSOR:
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- isInSlip = FALSE;
- return TRUE;
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- pt=MAKEPOINT(lParam);
- for(i=0;i<PRJ_BTN_COUNT;i++)
- {
- SetRect(&rc,PrjBtn[i].left,PrjBtn[i].top,
- PrjBtn[i].left+PRJ_BTN_WIDTH,PrjBtn[i].top+PRJ_BTN_HEIGHT);
- if (PtInRect(&rc, pt))
- break;
- }
- if(i==PRJ_BTN_COUNT) CurSelBtn=-1;
- else
- {
- CurSelBtn=i;
- SetCapture(hWnd);
- StateSet(gState,STATE_MOUSEDOWN);
- SendMessage(hWnd,WM_DRAWBUTTON,0,1L);
- }
- return 0L;
- case WM_MOUSEMOVE:
- if(CurSelBtn==-1) break;
- if(!StateTest(gState,STATE_MOUSEDOWN)) break;
- pt=MAKEPOINT(lParam);
- SetRect(&rc,PrjBtn[CurSelBtn].left,PrjBtn[CurSelBtn].top,
- PrjBtn[CurSelBtn].left+PRJ_BTN_WIDTH,PrjBtn[CurSelBtn].top+PRJ_BTN_HEIGHT);
- wState=gState;
- if(PtInRect(&rc,pt))
- StateClear(gState, STATE_MOUSEOUT);
- else
- StateSet(gState, STATE_MOUSEOUT);
- if (wState!=gState)
- {
- if(StateTest(gState,STATE_MOUSEOUT)) ltmp=0L;
- else ltmp=1L;
- SendMessage(hWnd,WM_DRAWBUTTON,0,ltmp);
- }
- return 0L;
- case WM_LBUTTONUP:
- if(CurSelBtn==-1) return 0L;
- if(!StateTest(gState,STATE_MOUSEDOWN)) return 0L;
- ReleaseCapture();
- if (StateTest(gState, STATE_MOUSEDOWN))
- {
- StateClear(gState, STATE_MOUSEDOWN);
- if(!StateTest(gState,STATE_MOUSEOUT))
- {
- SendMessage(hWnd,WM_DRAWBUTTON,0,0L);
- SendMessage(hWndMain,WM_COMMAND,PrjBtn[CurSelBtn].ID,0L);
- }
- else StateClear(gState,STATE_MOUSEOUT);
- }
- CurSelBtn=-1;
- return 0L;
- case WM_PAINT:
- BeginPaint(hWnd,&ps);
- SelectObject(ps.hdc,GetStockObject(NULL_BRUSH));
- hPen=CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(ps.hdc,hPen);
- GetClientRect(hWnd,&rc);
- Rectangle(ps.hdc,0,0,rc.right,rc.bottom);
- SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
- DeleteObject(hPen);
- MoveTo(ps.hdc,0,rc.bottom-1);
- LineTo(ps.hdc,0,0);
- LineTo(ps.hdc,rc.right-1,0);
- SelectObject(ps.hdc,GetStockObject(BLACK_PEN));
- for(i=0;i<PRJ_BTN_COUNT;i++)
- Rectangle(ps.hdc,PrjBtn[i].left-1,PrjBtn[i].top-1,
- PrjBtn[i].left+PRJ_BTN_WIDTH+1,PrjBtn[i].top+PRJ_BTN_HEIGHT+1);
- SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,0L);
- EndPaint(hWnd,&ps);
- break;
- case WM_DESTROY:
- if(hBmpPrjUp) DeleteObject(hBmpPrjUp);
- if(hBmpPrjDn) DeleteObject(hBmpPrjDn);
- if(hBmpPrjDs) DeleteObject(hBmpPrjDs);
- break;
- default:
- break;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- long CALLBACK __export StyleWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- RECT rc;
- HDC hDC,hMemDC;
- int i;
- HPEN hPen;
- DWORD dwExtent;
- POINT pt;
- PAINTSTRUCT ps;
- int gMouseStart=0L;
- BOOL isStyleMouseDown=FALSE,isStyleMouseOut=FALSE,isLeft =FALSE;
- BOOL fStyleMouseOut =FALSE;
- BITMAP bmp;
- int StyleBtnCount =0;
- int CurSelStyle =1000;
- static int OldSelStyle =0;
- int CurBtnStart =0,CurBtnEnd =0;
- HLOCAL hStyleBtns;
- LPSTYLEBTN lpStyleBtns;
- switch(message)
- {
- case WM_CREATE:
- if(hBrushPat)
- SetClassWord(hWnd,GCW_HBRBACKGROUND,(WORD)(HBRUSH)hBrushPat);
- SetWindowWord(hWnd,STYLE_COUNT, 0);
- SetWindowWord(hWnd,STYLE_START, 0);
- SetWindowWord(hWnd,STYLE_END, 0);
- SetWindowWord(hWnd,STYLE_SELECT,0);
- SetWindowWord(hWnd,MOUSE_STATE, 0);
- hStyleBtns =LocalAlloc(sizeof(StyleBtnInfo),LMEM_MOVEABLE);
- SetProp(hWnd,"StyleBtns",hStyleBtns);
- break;
- case WM_ADDITEM:
- i=(int)GetWindowWord(hWnd,STYLE_COUNT);
- hStyleBtns =GetProp(hWnd,"StyleBtns");
- hStyleBtns =LocalReAlloc(hStyleBtns,(i+1)*sizeof(StyleBtnInfo),LMEM_MOVEABLE);
- SetProp(hWnd,"StyleBtns",hStyleBtns);
- lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
- lpStyleBtns[i].ID =wParam;
- lstrcpy(lpStyleBtns[i].Caption,(LPSTR)lParam);
- hDC =GetDC(hWnd);
- SelectObject(hDC, hStyleFont);
- dwExtent =GetTextExtent(hDC,lpStyleBtns[i].Caption,strlen(lpStyleBtns[i].Caption));
- ReleaseDC(hWnd,hDC);
- if(i==0)
- lpStyleBtns[i].left = 10;
- else
- lpStyleBtns[i].left = lpStyleBtns[i-1].right+5;
- lpStyleBtns[i].right = lpStyleBtns[i].left+LOWORD(dwExtent)+2;
- SetProp(hWnd,"StyleBtns",hStyleBtns);
- SetWindowWord(hWnd,STYLE_COUNT,i+1);
- GetClientRect(hWnd,&rc);
- CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
- if(lpStyleBtns[i].right+20 < rc.right)
- {
- SetWindowWord(hWnd, STYLE_END, i); //CurBtnEnd
- InvalidateRect(hWnd,NULL,TRUE);
- }
- LocalUnlock(hStyleBtns);
- return 0L;
- case WM_SIZE:
- StyleBtnCount =GetWindowWord(hWnd,STYLE_COUNT);
- CurBtnStart =GetWindowWord(hWnd,STYLE_START);
- CurBtnEnd =GetWindowWord(hWnd,STYLE_END);
- hStyleBtns =GetProp(hWnd,"StyleBtns");
- lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
- for(i=CurBtnStart;i<StyleBtnCount;i++)
- {
- if(lpStyleBtns[i].right+20 >=(int)LOWORD(lParam))
- {
- //CurBtnEnd = i-1;
- SetWindowWord(hWnd, STYLE_END, i-1);
- break;
- }
- }
- if(i == StyleBtnCount) SetWindowWord(hWnd, STYLE_END, i-1);
- InvalidateRect(hWnd,NULL,TRUE);
- LocalUnlock(hStyleBtns);
- return 0L;
- case WM_DRAWBUTTON:
- StyleBtnCount =GetWindowWord(hWnd,STYLE_COUNT);
- CurBtnStart =GetWindowWord(hWnd,STYLE_START);
- CurBtnEnd =GetWindowWord(hWnd,STYLE_END);
- CurSelStyle =GetWindowWord(hWnd,STYLE_SELECT);
- hStyleBtns =GetProp(hWnd,"StyleBtns");
- lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
- if(wParam!=0 && lParam!=0L)
- {
- SetTextColor((HDC)wParam,RGB(0,0,0));
- SetBkMode((HDC)wParam,TRANSPARENT);
- SelectObject((HDC)wParam,hStyleFont);
- SelectObject((HDC)wParam,GetStockObject(WHITE_BRUSH));
- SelectObject((HDC)wParam,GetStockObject(BLACK_PEN));
- for(i=CurBtnEnd;i>=CurBtnStart;i--)
- {
- if(i == CurSelStyle) DrawStyleBtn((HDC)wParam,hWnd,i,1,FALSE,lpStyleBtns);
- else DrawStyleBtn((HDC)wParam,hWnd,i,0,FALSE,lpStyleBtns);
- }
- if(CurBtnStart>0 || CurBtnEnd <StyleBtnCount-1)
- {
- hMemDC=CreateCompatibleDC((HDC)wParam);
- GetObject(hBmpStyleUp,sizeof(bmp),(LPSTR)&bmp);
- if(CurBtnStart>0)
- SelectObject(hMemDC, hBmpStyleUp);
- else SelectObject(hMemDC,hBmpStyleDs);
- BitBlt((HDC)wParam,(int)lParam-bmp.bmWidth-1,4,bmp.bmWidth/2+1,
- bmp.bmHeight,hMemDC,0,0,SRCCOPY);
- if(CurBtnEnd <StyleBtnCount-1)
- SelectObject(hMemDC, hBmpStyleUp);
- else SelectObject(hMemDC,hBmpStyleDs);
- BitBlt((HDC)wParam,(int)lParam-bmp.bmWidth/2-1,4,bmp.bmWidth/2,
- bmp.bmHeight,hMemDC,bmp.bmWidth/2+1,0,SRCCOPY);
- DeleteDC(hMemDC);
- }
- }
- else if(wParam ==0)
- {
- if(lParam >0L)
- {
- switch(lParam)
- {
- case 1L: //left up
- break;
- case 2L: //left dn
- break;
- case 3L: //left ds
- break;
- case 4L: //right up
- break;
- case 5L: //right dn
- break;
- case 6L: //right ds
- break;
- default:
- LocalUnlock(hStyleBtns);
- return 0L;
- }
- }
- else if(CurSelStyle >=CurBtnStart && CurSelStyle <=CurBtnEnd)
- {
- if(CurSelStyle == OldSelStyle) return 0L;
- hDC = GetDC(hWnd);
- SelectObject(hDC,GetStockObject(WHITE_BRUSH));
- SelectObject(hDC,GetStockObject(BLACK_PEN));
- SetBkMode(hDC,TRANSPARENT);
- SelectObject(hDC,hStyleFont);
- DrawStyleBtn(hDC, hWnd, OldSelStyle,0,TRUE,lpStyleBtns);
- if(CurSelStyle != OldSelStyle-1)
- DrawStyleBtn(hDC, hWnd,OldSelStyle-1,2,FALSE,lpStyleBtns);
- DrawStyleBtn(hDC, hWnd, CurSelStyle,1,FALSE,lpStyleBtns);
- ReleaseDC(hWnd,hDC);
- }
- LocalUnlock(hStyleBtns);
- }
- return 0;
- case WM_LBUTTONDBLCLK:
- case WM_LBUTTONDOWN:
- CurBtnStart =GetWindowWord(hWnd, STYLE_START);
- CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
- OldSelStyle =GetWindowWord(hWnd, STYLE_SELECT);
- hStyleBtns =GetProp(hWnd, "StyleBtns");
- lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
- pt=MAKEPOINT(lParam);
- for(i=CurBtnStart;i<=CurBtnEnd;i++)
- {
- SetRect(&rc,lpStyleBtns[i].left,0,
- lpStyleBtns[i].right+5,STYLE_BTN_HEIGHT);
- if (PtInRect(&rc, pt))
- break;
- }
- LocalUnlock(hStyleBtns);
- if(i == CurBtnEnd+1) SetWindowWord(hWnd,STYLE_SELECT,1000);
- else
- {
- SetWindowWord(hWnd,STYLE_SELECT ,i);
- SendMessage(hWnd,WM_DRAWBUTTON,0,0L);
- SendMessage(GetParent(hWnd),WM_COMMAND,IDW_STYLE,(LONG)i);
- }
- return 0L;
- case WM_SETCURSOR:
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- isInSlip = FALSE;
- return TRUE;
- case WM_PAINT:
- GetClientRect(hWnd,&rc);
- BeginPaint(hWnd,&ps);
- SelectObject(ps.hdc,hStyleFont);
- hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(ps.hdc,hPen);
- MoveTo(ps.hdc,0,0);
- LineTo(ps.hdc,rc.right,0);
- SelectObject(ps.hdc,GetStockObject(BLACK_PEN));
- DeleteObject(hPen);
- MoveTo(ps.hdc,0,1);
- LineTo(ps.hdc,rc.right,1);
- SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,(LONG)rc.right);
- EndPaint(hWnd,&ps);
- return 0L;
- case WM_DESTROY:
- hStyleBtns =GetProp(hWnd,"StyleBtns");
- LocalFree(hStyleBtns);
- RemoveProp(hWnd,"StyleBtns");
- break;
- default:
- break;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- /*
- long CALLBACK __export CtlWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- RECT rc;
- static int CurSelCtl =-1;
- static int CurStyle =0;
- PAINTSTRUCT ps;
- HPEN hPen;
- HBITMAP hBmp;
- static HBITMAP hBmpUpCtl[STYLE_MAX_COUNT],hBmpDnCtl[STYLE_MAX_COUNT],hBmpDsCtl[STYLE_MAX_COUNT];
- static HBITMAP hBmpUpLeft,hBmpDnLeft,hBmpDsLeft,
- hBmpUpRight,hBmpDnRight,hBmpDsRight,
- hBmpArrow;
- static int CurCtlStart[STYLE_MAX_COUNT],CurCtlEnd[STYLE_MAX_COUNT],CurCtlCount[STYLE_MAX_COUNT];
- static int ctlWidth =0;
- static int ctlXStart =0;
- static BOOL isCtlMouseDown =0,isCtlMouseOut =FALSE,isLeft =0;
- static BOOL fCtlMouseOut =0;
- int xStart =0;
- HDC hMemDC,hDC;
- POINT pt;
- BITMAP bmp;
- int i,j;
- char stmp[100];
- switch(message)
- {
- case WM_CREATE:
- hBmpUpLeft = LoadBitmap(hInst,"BMP_UPLEFT");
- hBmpDnLeft = LoadBitmap(hInst,"BMP_DNLEFT");
- hBmpDsLeft = LoadBitmap(hInst,"BMP_DSLEFT");
- hBmpUpRight = LoadBitmap(hInst,"BMP_UPRIGHT");
- hBmpDnRight = LoadBitmap(hInst,"BMP_DNRIGHT");
- hBmpDsRight = LoadBitmap(hInst,"BMP_DSRIGHT");
- hBmpArrow = LoadBitmap(hInst,"BMP_ARROW");
- if(!hBmpUpLeft || !hBmpUpRight || !hBmpArrow
- || !hBmpDnLeft || !hBmpDsLeft || !hBmpDnRight || !hBmpDsRight)
- {
- ErrorMessage("Error Load Ctl Bitmap");
- return -1;
- }
- //// /////
- for(i=0;i<2;i++)
- {
- wsprintf(stmp,"BMP_UPSTYLE%d",i);
- hBmpUpCtl[i] = LoadBitmap(hInst, stmp);
- wsprintf(stmp,"BMP_DNSTYLE%d",i);
- hBmpDnCtl[i] = LoadBitmap(hInst, stmp);
- if(!hBmpUpCtl[i] || !hBmpDnCtl[i])
- {
- ErrorMessage("Error Load Ctl Bitmap");
- return -1;
- }
- }
- xStart =0;
- GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
- ctlWidth = bmp.bmHeight-1;
- xStart = bmp.bmWidth+5;
- GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
- xStart += bmp.bmWidth*2+10;
- ctlXStart =xStart-bmp.bmWidth;
- GetClientRect(hWnd,&rc);
- for(i=0;i<2;i++)
- {
- GetObject(hBmpUpCtl[i],sizeof(bmp),(LPSTR)&bmp);
- CurCtlStart[i] =0;
- CurCtlCount[i] =bmp.bmWidth/(bmp.bmHeight-1);
- CurCtlEnd[i] =(rc.right-xStart-3)/(bmp.bmHeight-1);
- if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i] =CurCtlCount[i];
- }
- break;
- case WM_SIZE:
- xStart =0;
- GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
- xStart = bmp.bmWidth+5;
- GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
- xStart += bmp.bmWidth*2+10;
- for(i=0;i<2;i++)
- {
- GetObject(hBmpUpCtl[i],sizeof(bmp),(LPSTR)&bmp);
- if(gSlipped)
- {
- if(i==CurStyle)
- j =CurCtlStart[i];
- CurCtlStart[i] =CurCtlEnd[i]-(LOWORD(lParam)-xStart-3)/(bmp.bmHeight-1);
- if(CurCtlStart[i]<0) CurCtlStart[i] =0;
- if(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth<(int)LOWORD(lParam))
- {
- CurCtlEnd[i] +=(LOWORD(lParam)
- -(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth))/ctlWidth;
- if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i] =CurCtlCount[i];
- }
- if(i==CurStyle)
- {
- j =CurCtlStart[i]-j;
- if(CurSelCtl >=0)
- CurSelCtl -=j;
- }
- }
- else
- {
- if(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth<(int)LOWORD(lParam))
- {
- if(i==CurStyle)
- j =CurCtlStart[i];
- CurCtlStart[i] -=(LOWORD(lParam)
- -(xStart+3+(CurCtlEnd[i]-CurCtlStart[i])*ctlWidth))/ctlWidth;
- if(CurCtlStart[i]<0) CurCtlStart[i] =0;
- if(i==CurStyle)
- {
- j =CurCtlStart[i]-j;
- if(CurSelCtl >=0)
- CurSelCtl -=j;
- }
- }
- CurCtlEnd[i] =(LOWORD(lParam)-xStart-3)/(bmp.bmHeight-1)+CurCtlStart[i];
- if(CurCtlEnd[i]>CurCtlCount[i]) CurCtlEnd[i]=CurCtlCount[i];
- }
- }
- InvalidateRect(hWnd,NULL,TRUE);
- return 0L;
- case WM_STYLECHANGED:
- if(CurStyle ==(int)wParam) break;
- CurSelCtl =-1;
- CurStyle =(int)wParam;
- //if(CurStyle>1) return 0L;
- InvalidateRect(hWnd,NULL,TRUE);
- return 0L;
- case WM_DRAWBUTTON:
- if(wParam!=0)
- {
- //draw all the button: CurStyle -- BtnStart to BtnEnd
- hDC = (HDC)wParam;
- hMemDC = CreateCompatibleDC (hDC) ;
- xStart =0;
- //if(hBmpArrow)
- {
- SelectObject(hMemDC,hBmpArrow);
- GetObject(hBmpArrow,sizeof(bmp),(LPSTR)&bmp);
- xStart =5;
- BitBlt (hDC, xStart,5,
- bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
- xStart =xStart+bmp.bmWidth+10;
- }
- //if(hBmpCtlLeft)
- {
- if(CurCtlStart[CurStyle]>0)
- SelectObject(hMemDC,hBmpUpLeft);
- else SelectObject(hMemDC,hBmpDsLeft);
- GetObject(hBmpUpLeft,sizeof(bmp),(LPSTR)&bmp);
- BitBlt (hDC, xStart,5,
- bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
- xStart +=bmp.bmWidth;
- }
- //if(hBmpCtl[CurStyle])
- {
- SelectObject (hMemDC, hBmpUpCtl[CurStyle]) ;
- GetObject(hBmpUpCtl[CurStyle],sizeof(bmp),(LPSTR)&bmp);
- BitBlt (hDC, xStart,5,
- (CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*(bmp.bmHeight-1),
- bmp.bmHeight,hMemDC,
- CurCtlStart[CurStyle]*(bmp.bmHeight-1),0,SRCCOPY) ;
- if(CurSelCtl>=0
- && CurSelCtl<CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])
- {
- SelectObject(hMemDC,hBmpDnCtl[CurStyle]);
- BitBlt (hDC, ctlXStart+CurSelCtl*ctlWidth,5,
- ctlWidth,ctlWidth+1,hMemDC,
- (CurSelCtl+CurCtlStart[CurStyle])*ctlWidth,0,SRCCOPY) ;
- }
- else CurSelCtl =-1;
- xStart += (CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*(bmp.bmHeight-1);
- }
- //if(hBmpCtlRight)
- {
- if(CurCtlEnd[CurStyle]<CurCtlCount[CurStyle])
- SelectObject(hMemDC,hBmpUpRight);
- else SelectObject(hMemDC,hBmpDsRight);
- GetObject(hBmpUpRight,sizeof(bmp),(LPSTR)&bmp);
- BitBlt (hDC, xStart,5,
- bmp.bmWidth,bmp.bmHeight,hMemDC,0,0,SRCCOPY) ;
- }
- DeleteDC (hMemDC) ;
- }
- else if(wParam ==0)
- {
- if(CurSelCtl <0
- || CurSelCtl >=(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle]))
- {
- CurSelCtl =-1;
- return 0L;
- }
- switch(lParam)
- {
- case 0L://hbmp=up
- hBmp =hBmpUpCtl[CurStyle];
- break;
- case 1L://hbmp=down
- hBmp =hBmpDnCtl[CurStyle];
- break;
- case 2L: //hbmp=disable
- break;
- case 3L: //left up
- break;
- case 4L: //left down
- break;
- case 5L: //left disable
- break;
- case 6L: //right up
- break;
- case 7L: //right down
- break;
- case 8L: //right disable
- break;
- default:
- return 0L;
- }
- //draw the button
- hDC=GetDC(hWnd);
- hMemDC =CreateCompatibleDC(hDC);
- SelectObject(hMemDC,hBmp);
- if(lParam <3L)
- BitBlt (hDC, ctlXStart+CurSelCtl*ctlWidth,5,
- ctlWidth,ctlWidth+1,hMemDC,
- (CurSelCtl+CurCtlStart[CurStyle])*ctlWidth,0,SRCCOPY) ;
- DeleteDC(hMemDC);
- ReleaseDC(hWnd,hDC);
- }
- return 0L;
- case WM_SETCURSOR:
- //Set Cursor or Show Hint if in a button or Hide Hint if out a button;
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- isInSlip = FALSE;
- return TRUE;
- case WM_LBUTTONDOWN:
- pt=MAKEPOINT(lParam);
- if(CurCtlStart[CurStyle]>0)
- {
- SetRect(&rc,ctlXStart-ctlWidth/2,5,ctlXStart,5+ctlWidth+1);
- if(PtInRect(&rc,pt))
- {
- isLeft =TRUE;
- SendMessage(hWnd,WM_DRAWBUTTON,0,4L);
- SetCapture(hWnd);
- isCtlMouseDown =TRUE;
- return 0L;
- }
- }
- if(CurCtlEnd[CurStyle]<CurCtlCount[CurStyle])
- {
- SetRect(&rc,ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth,5,
- ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth+ctlWidth/2,
- 5+ctlWidth+1);
- if(PtInRect(&rc,pt))
- {
- isLeft =FALSE;
- SendMessage(hWnd,WM_DRAWBUTTON,0,7L);
- SetCapture(hWnd);
- isCtlMouseDown =TRUE;
- return 0L;
- }
- }
- for(i=0;i<CurCtlEnd[CurStyle]-CurCtlStart[CurStyle];i++)
- {
- SetRect(&rc,ctlXStart+i*ctlWidth,5,
- ctlXStart+(i+1)*ctlWidth,5+ctlWidth+1);
- if (PtInRect(&rc, pt))
- break;
- }
- if(i+CurCtlStart[CurStyle] ==CurCtlEnd[CurStyle]) return 0L;
- else
- {
- SendMessage(hWnd,WM_DRAWBUTTON,0,0L);
- CurSelCtl=i;//+CurCtlStart[CurStyle];
- SendMessage(hWnd,WM_DRAWBUTTON,0,1L);
- //LoadString(hInst, 11000+CurStyle*100+i,(LPSTR)Cur_Ctl_Style, sizeof(Cur_Ctl_Style));
- }
- return 0L;
- case WM_MOUSEMOVE:
- if(!isCtlMouseDown) break;
- pt=MAKEPOINT(lParam);
- if(isLeft)
- SetRect(&rc,ctlXStart-ctlWidth/2,5,ctlXStart,5+ctlWidth/2+1);
- else
- SetRect(&rc,ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth,5,
- ctlXStart+(CurCtlEnd[CurStyle]-CurCtlStart[CurStyle])*ctlWidth+ctlWidth/2,
- 5+ctlWidth+1);
- fCtlMouseOut = isCtlMouseOut;
- if(PtInRect(&rc,pt))
- isCtlMouseOut =FALSE;
- else isCtlMouseOut =TRUE;
- if(fCtlMouseOut !=isCtlMouseOut)
- {
- if(isCtlMouseOut)
- {
- if(isLeft)
- SendMessage(hWnd,WM_DRAWBUTTON, 0,3L);
- else SendMessage(hWnd,WM_DRAWBUTTON,0,6L);
- }
- else
- {
- if(isLeft)
- SendMessage(hWnd,WM_DRAWBUTTON,0,4L);
- else SendMessage(hWnd,WM_DRAWBUTTON,0,7L);
- }
- }
- return 0L;
- case WM_LBUTTONUP:
- if(!isCtlMouseDown) break;
- ReleaseCapture();
- isCtlMouseDown =FALSE;
- if(!isCtlMouseOut)
- {
- if(isLeft)
- {
- CurCtlStart[CurStyle]--;
- CurCtlEnd[CurStyle]--;
- if(CurSelCtl >=0)
- CurSelCtl++; /////
- }
- else
- {
- CurCtlStart[CurStyle]++;
- CurCtlEnd[CurStyle]++;
- if(CurSelCtl >=0)
- CurSelCtl--; /////
- }
- InvalidateRect(hWnd,NULL,TRUE);
- }
- else isCtlMouseOut =FALSE;
- return 0L;
- case WM_PAINT:
- GetClientRect(hWnd,&rc);
- BeginPaint(hWnd,&ps);
- hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(ps.hdc,hPen);
- //MoveTo(ps.hdc,0,rc.bottom-1);
- MoveTo(ps.hdc,rc.right-1,rc.bottom-1);
- LineTo(ps.hdc,rc.right-1,0);
- SelectObject(ps.hdc,GetStockObject(WHITE_PEN));
- DeleteObject(hPen);
- //MoveTo(ps.hdc,0,1);
- LineTo(ps.hdc,0,0);
- LineTo(ps.hdc,0,rc.bottom-1);
- SendMessage(hWnd,WM_DRAWBUTTON,(WPARAM)(HDC)ps.hdc,(LONG)MAKELONG(20,rc.bottom));
- EndPaint(hWnd,&ps);
- break;
- case WM_DESTROY:
- for(i=0;i<2;i++)
- {
- if(hBmpUpCtl[i]) DeleteObject(hBmpUpCtl[i]);
- if(hBmpDnCtl[i]) DeleteObject(hBmpDnCtl[i]);
- if(hBmpDsCtl[i]) DeleteObject(hBmpDsCtl[i]);
- }
- if(hBmpUpLeft) DeleteObject(hBmpUpLeft);
- if(hBmpUpRight) DeleteObject(hBmpUpRight);
- if(hBmpDnLeft) DeleteObject(hBmpDnLeft);
- if(hBmpDnRight) DeleteObject(hBmpDnRight);
- if(hBmpDsLeft) DeleteObject(hBmpDsLeft);
- if(hBmpDsRight) DeleteObject(hBmpDsRight);
- if(hBmpArrow) DeleteObject(hBmpArrow);
- break;
- default:
- break;
- }
- return (DefWindowProc(hWnd, message, wParam, lParam));
- }
- */
- BOOL __export CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return (TRUE);
- case WM_COMMAND:
- if (wParam == IDOK
- || wParam == IDCANCEL)
- {
- EndDialog(hDlg, TRUE);
- return (TRUE);
- }
- break;
- }
- return (FALSE);
- }
- void DrawStyleBtn(HDC hDC,HWND hWnd,int BtnNo, int Style,BOOL fDrawGray,LPSTYLEBTN StyleBtn)
- {
- POINT aPoints[5];
- HPEN hPen;
- int CurBtnStart,CurBtnEnd;
- //HLOCAL hStyleBtns;
- //LPSTYLEBTN lpStyleBtns;
- CurBtnStart =GetWindowWord(hWnd, STYLE_START);
- CurBtnEnd =GetWindowWord(hWnd, STYLE_END);
- if(BtnNo <CurBtnStart || BtnNo >CurBtnEnd) return;
- //hStyleBtns =GetProp(hWnd,"STYLEBTNS");
- //lpStyleBtns =(LPSTYLEBTN)LocalLock(hStyleBtns);
- if(BtnNo == CurBtnStart)
- aPoints[0].x = 5;
- else
- {
- if(Style !=2)
- aPoints[0].x = StyleBtn[BtnNo].left-5;
- else if(Style ==2)
- aPoints[0].x = StyleBtn[BtnNo-1].right+5;
- }
- aPoints[0].y = 1;
- switch(Style)
- {
- case 0:
- case 1:
- aPoints[1].x = StyleBtn[BtnNo].left;
- aPoints[1].y = STYLE_BTN_HEIGHT;
- aPoints[2].x = StyleBtn[BtnNo].right;
- aPoints[2].y = STYLE_BTN_HEIGHT;
- aPoints[3].x = StyleBtn[BtnNo].right+5;
- aPoints[3].y = 1;
- if(Style == 1)
- SelectObject(hDC,GetStockObject(LTGRAY_BRUSH));
- Polygon(hDC,aPoints,4);
- if(Style == 1)
- {
- hPen = CreatePen(PS_SOLID,2,RGB(180,180,180));
- SelectObject(hDC,hPen);
- MoveTo(hDC,aPoints[0].x+2,aPoints[0].y);
- LineTo(hDC,aPoints[3].x-2,aPoints[3].y);
- SelectObject(hDC,GetStockObject(WHITE_PEN));
- DeleteObject(hPen);
- MoveTo(hDC,aPoints[0].x+1,aPoints[0].y);
- LineTo(hDC,aPoints[1].x+1,aPoints[1].y-1);
- hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(hDC,hPen);
- LineTo(hDC,aPoints[2].x-1,aPoints[2].y-1);
- LineTo(hDC,aPoints[3].x-1,aPoints[3].y);
- SelectObject(hDC,GetStockObject(BLACK_PEN));
- DeleteObject(hPen);
- SelectObject(hDC,GetStockObject(WHITE_BRUSH));
- SetTextColor(hDC,RGB(0,0,255));
- }
- else if(fDrawGray)
- {
- hPen = CreatePen(PS_SOLID,1,RGB(80,80,80));
- SelectObject(hDC,hPen);
- MoveTo(hDC,aPoints[0].x,0);
- LineTo(hDC,aPoints[3].x,0);
- SelectObject(hDC,GetStockObject(BLACK_PEN));
- DeleteObject(hPen);
- }
- break;
- case 2:
- aPoints[1].x = StyleBtn[BtnNo].left-3;
- aPoints[1].y = STYLE_BTN_HEIGHT/2;
- aPoints[2].x = StyleBtn[BtnNo].left;
- aPoints[2].y = STYLE_BTN_HEIGHT;
- aPoints[3].x = StyleBtn[BtnNo].right;
- aPoints[3].y = STYLE_BTN_HEIGHT;
- aPoints[4].x = StyleBtn[BtnNo].right+5;
- aPoints[4].y = 1;
- Polygon(hDC,aPoints,5);
- break;
- default:
- //LocalUnlock(hStyleBtns);
- return;
- }
- TextOut(hDC,StyleBtn[BtnNo].left+1,3,(LPSTR)StyleBtn[BtnNo].Caption,
- strlen(StyleBtn[BtnNo].Caption));
- if(Style ==1) SetTextColor(hDC,RGB(0,0,0));
- //LocalUnlock(hStyleBtns);
- }
- HWND CreateNewForm(void)
- {
- static int FormNum =0;
- char tmp[40];
- HWND hWnd;
- FormNum++;
- wsprintf((LPSTR)tmp,"Form%d",FormNum);
- hWnd = CreateWindow( "LGFORM",tmp,
- WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX
- |WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_THICKFRAME,
- 130,100,500,300,
- NULL, NULL, hInst, NULL
- );
- if (!hWnd)
- return NULL;
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- return hWnd;
- }
- void ErrorMessage(LPSTR lpszMsg)
- {
- MessageBox(NULL,lpszMsg,"CBuilder",MB_TASKMODAL |MB_ICONSTOP |MB_OK);
- }
- BOOL isWndClass(HWND hWnd,LPSTR ClassName)
- {
- static char tmp[40];
- if(!GetClassName(hWnd, (LPSTR)tmp, sizeof(tmp))) return FALSE;
- return (lstrcmpi((LPSTR)tmp, (LPSTR)ClassName)==0);
- }