mapgis6.7二次开发vc6_demo 之一(主窗体构架)
本文根据mapgis6.7 sdk开发包中实例程序和help.chm帮助文件
进行的学习心得总结:
//stdafx.h文件内容如下所示 :
#include <windows.h>
//#include "demo.h" 文件内容如下所示 :
//#include "demo.h" #if !defined(AFX_DEMO_H__8E07CFE6_850E_11D4_9287_444553540000__INCLUDED_) #define AFX_DEMO_H__8E07CFE6_850E_11D4_9287_444553540000__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "resource.h" #include "string.h" #include <iostream> #include <comutil.h> using namespace std; //定义函数声明 int DoWMCommand( HWND hWnd, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK GrpProc(HWND, UINT, WPARAM, LPARAM); BOOL _InitWindow(int nCmdShow); BOOL _InitWindowFirst(void); BOOL _InitWindowEvery(int nCmdShow); void _EnableWinMenu(void); short LoadFiles(short type); short SaveFiles(short type); short SaveFilesAs(short type); short CloseFiles(short type); void DispADotLable(HDC hdc,long i); void DispAllDotLable(HDC hdc); void _DispAbout(void); // void _ProcLBUTTONDOWN(HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam); void _ProcLBUTTONUP( HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam); void _ProcMOUSEMOVE( HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam); void _ProcRBUTTONUP(HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam); void _ProcSETCURSOR(HWND hWnd,WPARAM wParam, LPARAM lParam); // void ShowMsg(char* msg); void Vct_Export(); void D2A_test(); //common op function 公共操作函数 char* i2cp(int n); char* l2cp(long n); char* d2cp(double value); char* short2cp(short value); char* getdir_lc(char* s,const char* d); char* getfilename_lc(char* s,const char* d); // char* GetDiskSpace_lc(unsigned char dsk); // char* GetCurDir(void); int WriteToLog(char* str); int WriteToLog(const char* str); int WriteToLog_f_delete(void); char* UnionStr(const char* A,const char* B); char* strcat_lc(const char* A,const char* B); const char* StrCopy(const char* src); char* strcpy_lc(const char* src); bool EqStr(const char* A,const char* B); bool IsNumber(string str); //file op function 文件操作函数 //---------------------------- //文件操作方法 void f_SetFilePath(char* pfilepath); int f_delete(char* pfilepath); bool f_OpenFile_r(void); bool f_OpenFile_w(void); int f_EndFile(void); char* f_NextLine(); int f_WriteLine(char* line); int f_FlushFile(void); int f_CloseFile(void); //---------------------------- bool OutVctHeadBeginEnd(); //输出vct文件头 bool OutVctFeatureCodeBeginEnd(short* ptALst); //输出vct要素代码 bool OutVctTableStructureBeginEnd(short* ptALst); //输出vct表结构 //输出线坐标 OK bool OutVctLineBeginEnd(short ai); //输出属性值 OK bool OutVctAttributeBeginEnd(short ai); //---------------------------- #endif // !defined(AFX_DEMO_H__8E07CFE6_850E_11D4_9287_444553540000__INCLUDED_)
//{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by demo.rc // #define IDMN_NULL 0x0000 #define PAINTING 0x0004 #define IDD_DIALOG_VCT_EXP 102 #define IDR_MENU1 132 #define IDC_DEMO 132 #define IDC_LIST1 1000 #define IDC_EDIT1 1001 #define IDC_BTN_SAVEVCTAS 1002 #define IDMN_LOAD_PNT 32771 #define IDMN_SAVE_PNT 32772 #define IDMN_SAVE_PNT_AS 32773 #define IDMN_CLOSE_PNT 32774 #define IDMN_LOAD_LIN 32775 #define IDMN_SAVE_LIN 32776 #define IDMN_SAVE_LIN_AS 32777 #define IDMN_CLOSE_LIN 32778 #define IDMN_LOAD_REG 32779 #define IDMN_SAVE_REG 32780 #define IDMN_SAVE_REG_AS 32781 #define IDMN_CLOSE_REG 32782 #define IDMN_CLOSE_FILE 32783 #define IDMN_EXIT 32784 #define IDMN_MOD_ENV 32791 #define IDMN_DOT_VIEWABLE 32792 #define IDMN_ARC_VIEWABLE 32793 #define IDMN_ORIGNAL_DISP 32794 #define IDMN_ABOUT 32795 #define IDMN_VCT_EXPORT 40001 #define IDMN_ENLG_WIN_C 40002 #define IDMN_REDU_WIN_C 40003 #define IDMN_MOVE_WIN_C 40004 #define IDMN_REST_WIN_C 40005 #define IDMN_UPDT_WIN_C 40006 #define IDMN_CLEA_WIN_C 40007 #define IDMN_D2A 40008 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 103 #define _APS_NEXT_COMMAND_VALUE 40009 #define _APS_NEXT_CONTROL_VALUE 1003 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif
//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // Chinese (中国) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) #ifdef _WIN32 LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED #pragma code_page(936) #endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // // Menu // IDC_DEMO MENU DISCARDABLE BEGIN POPUP "&F文件" BEGIN MENUITEM "&P装入点", IDMN_LOAD_PNT MENUITEM "存 点", IDMN_SAVE_PNT MENUITEM "换名存点", IDMN_SAVE_PNT_AS MENUITEM "关闭点文件", IDMN_CLOSE_PNT MENUITEM SEPARATOR MENUITEM "&L装入线", IDMN_LOAD_LIN MENUITEM "存 线", IDMN_SAVE_LIN MENUITEM "换名存线", IDMN_SAVE_LIN_AS MENUITEM "关闭线文件", IDMN_CLOSE_LIN MENUITEM SEPARATOR MENUITEM "&R装入区", IDMN_LOAD_REG MENUITEM "存 区", IDMN_SAVE_REG MENUITEM "换名存区", IDMN_SAVE_REG_AS MENUITEM "关闭区文件", IDMN_CLOSE_REG MENUITEM SEPARATOR MENUITEM "关闭文件", IDMN_CLOSE_FILE, GRAYED MENUITEM "&X退 出", IDMN_EXIT END POPUP "&W窗口" BEGIN MENUITEM "&L放大窗口", IDMN_ENLG_WIN_C, GRAYED MENUITEM "&S缩小窗口", IDMN_REDU_WIN_C, GRAYED MENUITEM "&M移动窗口", IDMN_MOVE_WIN_C, GRAYED MENUITEM "&R复位窗口", IDMN_REST_WIN_C, GRAYED MENUITEM "&U更新窗口", IDMN_UPDT_WIN_C, GRAYED MENUITEM "&C清窗口", IDMN_CLEA_WIN_C, GRAYED END POPUP "&O选择" BEGIN MENUITEM "&V修改环境", IDMN_MOD_ENV MENUITEM SEPARATOR MENUITEM "&S坐标点可见?", IDMN_DOT_VIEWABLE MENUITEM "&A弧段可见?", IDMN_ARC_VIEWABLE MENUITEM "&O还原显示?", IDMN_ORIGNAL_DISP END POPUP "&H帮助" BEGIN MENUITEM "关于系统", IDMN_ABOUT END POPUP "&T常用工具" BEGIN MENUITEM "输出VCT top0", IDMN_VCT_EXPORT MENUITEM "doubleToString一个实例", IDMN_D2A END END #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Dialog // IDD_DIALOG_VCT_EXP DIALOG DISCARDABLE 0, 0, 216, 166 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "VCT导出功能" FONT 10, "System" BEGIN DEFPUSHBUTTON "确定",IDOK,78,145,50,14 PUSHBUTTON "关闭",IDCANCEL,159,145,50,14 GROUPBOX "请选择要输出的图层:",IDC_STATIC,7,7,202,99 CONTROL "List1",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_AUTOARRANGE | WS_BORDER | WS_GROUP | WS_TABSTOP,13,18,190,84 LTEXT "输出vct文件路径:",IDC_STATIC,13,110,94,10 EDITTEXT IDC_EDIT1,14,122,192,10,ES_AUTOHSCROLL PUSHBUTTON "...",IDC_BTN_SAVEVCTAS,176,110,29,12 END ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN IDD_DIALOG_VCT_EXP, DIALOG BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 209 TOPMARGIN, 7 BOTTOMMARGIN, 159 END END #endif // APSTUDIO_INVOKED #endif // Chinese (中国) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED
#include "stdafx.h" #include "resource.h" #include <stdio.h> //引用mapgis库头文件 #include "win_area.h" #include "win_oper.h" #include "map_out.h" // #include "demo.h" //应用程序标题 char* AppTitle="mapgis6.7二次开发vc6_demo"; // HINSTANCE HInst; //实例句柄 HWND MainWnd=NULL; //主窗口句柄 HWND GrpWnd=NULL; //图形窗口句柄 HCURSOR DefHCursor=NULL; //绘图窗口缺省光标 HCURSOR LargeHCursor=NULL; //绘图窗口放大光标 HCURSOR ReduceHCursor=NULL; //绘图窗口缩小光标 HCURSOR CrossHCursor=NULL; //绘图窗口十字光标 int ComState=0; //菜单命令状态 int CurState=0; //当前操作状态 AREA_HINST AHInst; //============== 启动入口 ================// int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { MSG msg; HACCEL hlpAccel=NULL; //加速键表 if(hPrevInstance) return(FALSE); //初始化工作区 AHInst=_InitWorkArea(hInstance); HInst = hInstance; //初始化窗体 if(!_InitWindow(nCmdShow)) return(FALSE); //装载快捷键 hlpAccel=LoadAccelerators(HInst,(LPCTSTR)IDC_DEMO); //消息循环 while(GetMessage(&msg,NULL,0,0)){ if(!TranslateAccelerator(MainWnd,hlpAccel,&msg)){ TranslateMessage(&msg); DispatchMessage(&msg); } } return(msg.wParam); } BOOL _InitWindow(int nCmdShow){ if(!_InitWindowFirst()) return(FALSE); if(!_InitWindowEvery(nCmdShow)) return(FALSE); return(TRUE); } //创建窗体 //初始化窗体第一次 BOOL _InitWindowFirst(){ WNDCLASS wc; DefHCursor=LoadCursor(NULL,IDC_ARROW); //绘图窗口缺省光标 wc.style =CS_HREDRAW | CS_VREDRAW ; wc.lpfnWndProc =(WNDPROC)WndProc; //设置回调函数WndProc wc.cbClsExtra =0; wc.cbWndExtra =0; wc.hInstance =HInst; wc.hIcon =NULL; //LoadIcon(hInstance,"MAP_EDIT"); wc.hCursor =DefHCursor; //LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName =(LPCSTR)IDC_DEMO; //指定菜单栏 wc.lpszClassName="ClipMainClass"; RegisterClass(&wc); wc.lpfnWndProc =(WNDPROC)GrpProc; //设置回调函数GrpProc wc.cbClsExtra =sizeof(WORD); wc.hIcon =NULL; wc.lpszMenuName =NULL; wc.hCursor =DefHCursor; //LoadCursor(hInstance,"EditCurPen"); wc.lpszClassName="ClipGrpClass"; RegisterClass(&wc); return(1); } //初始化窗体Every BOOL _InitWindowEvery(int nCmdShow){ HMENU hmn; char wndName[32]; _ShowMapGisBmp(); hmn=LoadMenu(HInst,(LPCSTR)IDC_DEMO); //加载菜单栏 LoadString(HInst,4,wndName,32); //wndName MainWnd=CreateWindow("ClipMainClass",(LPCSTR)AppTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, // Default horizontal position. CW_USEDEFAULT, // Default vertical position. CW_USEDEFAULT, // Default width. CW_USEDEFAULT, // Default height. NULL, // Overlapped windows have no parent. hmn, // Use the window class menu. HInst, // This instance owns this window. NULL); ShowWindow(MainWnd,nCmdShow); UpdateWindow(MainWnd); _CloseMapGisBmp(); if(MainWnd==NULL) return(FALSE); return(TRUE); } //装载我的光标函数(从BAS60.DLL组件中) short LoadMyCursor(void){ HINSTANCE hinst; hinst=GetModuleHandle("BAS60.DLL"); LargeHCursor=LoadCursor(hinst,"LargeCursor"); //绘图窗口放大光标 ReduceHCursor=LoadCursor(hinst,"ReduceCursor"); //绘图窗口缩小光标 CrossHCursor=LoadCursor(hinst,"CrossCursor"); //绘图窗口十字光标 return(1); } //释放我的光标函数 short DestroyMyCursor(void){ DestroyCursor(LargeHCursor); DestroyCursor(ReduceHCursor); DestroyCursor(CrossHCursor); return(1); } //创建Grp窗体 函数 int CreateGrpWindow(HWND hWnd){ //AppTitle GrpWnd=CreateWindow( (LPCSTR)"ClipGrpClass", (LPCSTR)AppTitle, WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, NULL, HInst, NULL ); if(GrpWnd==NULL){ PostQuitMessage(0); return(0); } return(1); } //修改Grp窗体尺寸函数 void ModifyGrpWndSize(LPARAM lParam){ MoveWindow(GrpWnd, 0, 0,LOWORD(lParam),HIWORD(lParam),TRUE); return; } //窗体事件回调函数 LRESULT CALLBACK WndProc (HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam){ switch(msg){ case WM_CREATE: CreateGrpWindow(hWnd); LoadMyCursor(); break; case WM_COMMAND: return(DoWMCommand(hWnd,wParam,lParam)); case WM_SIZE: ModifyGrpWndSize(lParam); break; case WM_CLOSE: //关闭窗体 if(_CloseAllArea(AHInst)==IDCANCEL) break; DestroyWindow(hWnd); break; case WM_DESTROY: DestroyWindow(GrpWnd); DestroyMyCursor(); PostQuitMessage(0); break; case WM_SYSCOMMAND: _ProcSYSCOMMAND(GrpWnd,msg,wParam,lParam); return(DefWindowProc(hWnd,msg,wParam,lParam)); break; case WM_ACTIVATE: _ProcACTIVATE(GrpWnd,msg,wParam,lParam); return(DefWindowProc(hWnd,msg,wParam,lParam)); default: return(DefWindowProc(hWnd,msg,wParam,lParam)); } return(0); } //Grp回调函数 LRESULT CALLBACK GrpProc(HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam){ LRESULT rtn=0; switch(msg){ case WM_CREATE: _SetPaintFunction(hWnd,_OwnerDraw); _LockScrollRange(hWnd); break; case WM_COMMAND: //命令处理函数 return(DoWMCommand(hWnd,wParam,lParam)); case WM_PAINT: _ProcPAINT(hWnd,msg,wParam,lParam); break; case WM_LBUTTONDOWN: //左键按下mouse事件 _ProcLBUTTONDOWN(hWnd,msg,wParam,lParam); break; case WM_LBUTTONUP: //左键按上mouse事件 _ProcLBUTTONUP(hWnd,msg,wParam,lParam); _EnableWinMenu(); break; case WM_MOUSEMOVE: //移动mouse事件 _ProcMOUSEMOVE(hWnd,msg,wParam,lParam); break; case WM_RBUTTONUP: //右键按上mouse事件 _ProcRBUTTONUP(hWnd,msg,wParam,lParam); _EnableWinMenu(); break; case WM_VSCROLL: //水平scroll _PopupWinImage(hWnd); _VscrollMap(hWnd,msg,wParam,lParam); break; case WM_HSCROLL: //垂直scroll _PopupWinImage(hWnd); _HscrollMap(hWnd,msg,wParam,lParam); break; case WM_DESTROY: _DelWinParam(hWnd); break; default: switch(msg) { case WM_SYSCOMMAND: _ProcSYSCOMMAND(hWnd,msg,wParam,lParam); break; case WM_ACTIVATE: _ProcACTIVATE(hWnd,msg,wParam,lParam); break; case WM_SETCURSOR: _ProcSETCURSOR(hWnd,wParam,lParam); break; } rtn=DefWindowProc(hWnd,msg,wParam,lParam); break; } return(rtn); } void SetDotViewableFlag(HWND hwnd){ //修改坐标点可见标志 HMENU hmn; BOOL fOwnerDraw; hmn=GetMenu(MainWnd); fOwnerDraw=GetMenuState(hmn, IDMN_DOT_VIEWABLE, MF_BYCOMMAND)&MF_CHECKED; CheckMenuItem(hmn, IDMN_DOT_VIEWABLE, MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED)); DrawMenuBar(MainWnd); return; } void SetArcViewableFlag(HWND hwnd) {//弧段可见标志 HMENU hmn; BOOL fOwnerDraw; hmn=GetMenu(MainWnd); fOwnerDraw=GetMenuState(hmn, IDMN_ARC_VIEWABLE, MF_BYCOMMAND)&MF_CHECKED; CheckMenuItem(hmn, IDMN_ARC_VIEWABLE, MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED)); DrawMenuBar(MainWnd); return; } void SetOrignalDispFlag(HWND hwnd) {//还原显示标志 HMENU hmn; BOOL fOwnerDraw; hmn=GetMenu(MainWnd); fOwnerDraw=GetMenuState(hmn, IDMN_ORIGNAL_DISP, MF_BYCOMMAND)&MF_CHECKED; CheckMenuItem(hmn, IDMN_ORIGNAL_DISP, MF_BYCOMMAND | (fOwnerDraw ? MF_UNCHECKED : MF_CHECKED)); DrawMenuBar(MainWnd); InvalidateRect(hwnd,NULL,TRUE); UpdateWindow(hwnd); return; } int DoWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { //执行window message命令 if(GetMenuState(GetMenu(MainWnd),LOWORD(wParam),MF_BYCOMMAND)==MF_GRAYED) { //获取菜单状态 return(0); } ComState=LOWORD(wParam); CurState=0; switch(LOWORD(wParam)){ case IDMN_EXIT: SendMessage(hWnd,WM_CLOSE,0,0); break; case IDMN_NULL: break; case IDMN_LOAD_PNT: LoadFiles(PNT); break; case IDMN_LOAD_LIN: LoadFiles(LIN); break; case IDMN_LOAD_REG: LoadFiles(REG); break; case IDMN_SAVE_PNT: SaveFiles(PNT); break; case IDMN_SAVE_LIN: SaveFiles(LIN); break; case IDMN_SAVE_REG: SaveFiles(REG); break; case IDMN_SAVE_PNT_AS: SaveFilesAs(PNT);break; case IDMN_SAVE_LIN_AS: SaveFilesAs(LIN);break; case IDMN_SAVE_REG_AS: SaveFilesAs(REG);break; case IDMN_CLOSE_PNT: CloseFiles(PNT);break; case IDMN_CLOSE_LIN: CloseFiles(LIN);break; case IDMN_CLOSE_REG: CloseFiles(REG);break; case IDMN_CLOSE_FILE:CloseFiles(-1);break; // case IDMN_MOVE_WIN_C: _PopupWinImage(GrpWnd); break; case IDMN_UPDT_WIN_C: _PopupWinImage(GrpWnd); InvalidateRect(GrpWnd,NULL,TRUE); break; case IDMN_ENLG_WIN_C: //放大窗体 DefHCursor=LargeHCursor; //设置光标样式 break; case IDMN_REDU_WIN_C: //缩小窗体 DefHCursor=ReduceHCursor; //设置光标样式 break; case IDMN_PREV_WIN: //"上级窗口" _PrevWindow(GrpWnd); break; case IDMN_REST_WIN_C: _PopupWinImage(GrpWnd); _RestoreWindow(GrpWnd,NULL,RW_SEL_AREA,AHInst); break; case IDMN_CLEA_WIN_C: _PopupWinImage(GrpWnd); InvalidateRect(GrpWnd,NULL,TRUE); break; case IDMN_MOD_ENV: //环境设置 _ModEnv(hWnd); break; case IDMN_DOT_VIEWABLE: /*坐标点可见*/ SetDotViewableFlag(hWnd); break; case IDMN_ARC_VIEWABLE: /*弧段可见*/ SetArcViewableFlag(hWnd); break; case IDMN_ORIGNAL_DISP: /*还原显示*/ SetOrignalDispFlag(GrpWnd); break; case IDMN_ABOUT: //关于系统 _DispAbout(); break; case IDMN_VCT_EXPORT: //VCT导出 topo 0 { Vct_Export(); } break; case IDMN_D2A: //double转string 一个实例 { D2A_test(); } break; default: if((LOWORD(wParam)>=IDMN_NUM_ENLG_1)&& (LOWORD(wParam)<=IDMN_NUM_ENLG_16)) {//固定放大,重新设置窗口显示比例 _ResetWinDispRate(GrpWnd,LOWORD(wParam)-IDMN_NUM_ENLG_1+1.0); _PopupWinImage(GrpWnd); InvalidateRect(GrpWnd,NULL,TRUE); } if((LOWORD(wParam)>=IDMN_NUM_REDU_1)&& (LOWORD(wParam)<=IDMN_NUM_REDU_16)) {//固定缩小,重新设置窗口显示比例 _ResetWinDispRate(GrpWnd,1.0/(LOWORD(wParam)-IDMN_NUM_REDU_1+1.0)); _PopupWinImage(GrpWnd); InvalidateRect(GrpWnd,NULL,TRUE); } break; } _EnableWinMenu(); return(0); } //判断 菜单栏的可用性函数 void _EnableWinMenu(void) { HMENU hmn; UINT flag; short i,n; n=_GetAreaNumber(AHInst); //取打开的工作区数 flag=(n)?MF_ENABLED:MF_GRAYED; //n>0表示可用,n<=0表示不可用 hmn=GetMenu(MainWnd); //文件 EnableMenuItem(hmn, IDMN_CLOSE_FILE ,MF_BYCOMMAND|flag); //窗口 EnableMenuItem(hmn, IDMN_ENLG_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_REDU_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_MOVE_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_REST_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_UPDT_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_CLEA_WIN_C ,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_PREV_WIN ,MF_BYCOMMAND|flag); for(i=0;i<16;i++) { EnableMenuItem(hmn, IDMN_NUM_ENLG_1+i,MF_BYCOMMAND|flag); EnableMenuItem(hmn, IDMN_NUM_REDU_1+i,MF_BYCOMMAND|flag); } DrawMenuBar(MainWnd); if(GetMenuState(GetMenu(MainWnd),ComState,MF_BYCOMMAND)==MF_GRAYED) ComState=0; switch(ComState) { case IDMN_ENLG_WIN: SetClassLong(GrpWnd,GCL_HCURSOR,(LONG)LargeHCursor); break; case IDMN_REDU_WIN: SetClassLong(GrpWnd,GCL_HCURSOR,(LONG)ReduceHCursor); break; case IDMN_MOVE_WIN: case IDMN_UPDT_WIN: case IDMN_REST_WIN: case IDMN_CLEA_WIN: case IDMN_PREV_WIN: default: SetClassLong(GrpWnd, GCL_HCURSOR,(LONG)DefHCursor); break; } return; } //======================================================// ///{文件处理 short LoadFiles(short ftype) { short ai; ai=_OpenArea(AHInst,ftype); if(ai<=0) return(0); if(!_LoadFile(ai)) { _CloseArea(ai); return(0); } _PopupWinImage(GrpWnd); _RestoreWindow(GrpWnd,NULL,RW_ALL_AREA,AHInst); return(ai); } short CloseFiles(short type) { short *ptArea=NULL; char nmStr[32]; short i; LoadString(HInst,3,nmStr,32); ptArea=_SelectAreaList(AHInst,MainWnd,type,nmStr); if(ptArea==NULL) return(0); for(i=1;i<=ptArea[0];i++) _CloseArea(ptArea[i]); _PopupWinImage(GrpWnd); _RestoreWindow(GrpWnd,NULL,RW_ALL_AREA,AHInst); return(1); } short SaveFiles(short type) { short *areaLst; short i; areaLst=_SelectAreaList(AHInst,MainWnd,type,"选择保存文件"); if(areaLst==NULL) return(0); for(i=1;i<=areaLst[0];i++) _SaveFile(areaLst[i]); return(1); } short SaveFilesAs(short type) { short *areaLst; short i; areaLst=_SelectAreaList(AHInst,MainWnd,type,"选择另存文件"); if(areaLst==NULL) return(0); for(i=1;i<=areaLst[0];i++) _SaveFileAs(areaLst[i]); return(1); } //------------------------------------------------// //{显示 线点 函数 short DispLinDot(HDC hdc,WIN_ORG *wxy,short ai) { long i,j,ln; D_DOT *lxy; long len; int x,y; HANDLE hdpen; //选择pen对象 hdpen=SelectObject(hdc, CreatePen(PS_SOLID,1,RGB(255,0,0))); _GetLinNum(ai,&i,&ln); for(i=1;i<ln;i++) { if(_GetLin(ai,i,&lxy,&len,NULL)<=0) continue; for(j=0;j<len;j++,lxy++) { x=(int)((lxy->x-wxy->x0)*wxy->r); y=(int)((lxy->y-wxy->y0)*wxy->r); MoveToEx(hdc,x-2,y,NULL); LineTo(hdc,x+2,y); MoveToEx(hdc,x,y-2,NULL); LineTo(hdc,x,y+2); } } //删除pen对象 DeleteObject(SelectObject(hdc,hdpen)); return(1); } //..........................PAINTSTRUCT *ps //重新显示图形 void _ReDispGraph(HWND hWnd,MyDC myDC,short *dsp) { short ti,i,type; D_RECT frc; RECT rc,wrc; short rt; WIN_ORG wxy; PAINTSTRUCT *ps; HMENU hmn; BOOL arcView; BOOL dotView; if(ComState==IDMN_CLEA_WIN){ ComState=IDMN_NULL; return; } if(dsp==NULL) return; // hmn=GetMenu(MainWnd); if(MF_CHECKED & GetMenuState(hmn, IDMN_ORIGNAL_DISP, MF_BYCOMMAND)) { _SetOriginalDisp(myDC,1); } arcView=GetMenuState(hmn, IDMN_ARC_VIEWABLE, MF_BYCOMMAND)&MF_CHECKED; dotView=GetMenuState(hmn, IDMN_DOT_VIEWABLE, MF_BYCOMMAND)&MF_CHECKED; ps=_GetPaintStruct(myDC); rc=ps->rcPaint; _StartWait(); GetClientRect(hWnd,&wrc); if(!_GetWinDispParam(hWnd,&wxy)) return; frc.xmin=rc.left/wxy.r +wxy.x0-1; frc.xmax=rc.right/wxy.r+wxy.x0+1; frc.ymin=(wrc.bottom-rc.bottom)/wxy.r+wxy.y0-1; frc.ymax=(wrc.bottom-rc.top)/wxy.r +wxy.y0+1; _SetMyDCMode(myDC); _SetMyDCPalette(myDC); _SetDispRect(myDC,&frc); //设置显示范围 _SetDispParam(myDC,wxy.x0,wxy.y0,wxy.r); for(ti=0;ti<4;ti++) //循环3次,依次显示 区,线,点,网 { switch(ti) { case 0: type=REG; break; case 1: type=NET; break; case 2: type=LIN; break; case 3: type=PNT; break; } for(i=1;i<=dsp[0];i++) { if(type!=_GetAreaType(dsp[i])) continue; switch(type) { case PNT: rt=_DispPntArea(myDC,dsp[i]); break; case LIN: rt=_DispLinArea(myDC,dsp[i]); if(dotView) DispLinDot(ps->hdc,&wxy,dsp[i]); break; case REG: rt=_DispRegArea(myDC,dsp[i]); if(arcView) _DispLinArea(myDC,dsp[i]); if(dotView) DispLinDot(ps->hdc,&wxy,dsp[i]); break; case NET: rt=_DispLinArea(myDC,dsp[i]); if(dotView) DispLinDot(ps->hdc,&wxy,dsp[i]); break; default: break; } if(rt==0) goto redispEND; } } redispEND: _EndWait(); return; } //.....................................................................PAINTSTRUCT *ps) //自己绘制函数 void WINAPI _OwnerDraw(HWND hWnd, UINT msg,WPARAM wParam, LPARAM lParam,MyDC myDC) { int state; short *ptALst=NULL; //显示工作区表 state=CurState; CurState=PAINTING; if((ptALst=_GetDispAreaListAddr(hWnd))!=NULL) { _ReDispGraph(hWnd,myDC,ptALst); } CurState=state; return; }
--vp:hsg----
--create date:2012-04-18---