在*.h中新增
CComboBox m_cCUTCOMBO;
在*.cpp中新增
需新增在 DoDataExchange(CDataExchange* pDX) 中
//控制項
DDX_Control(pDX, IDC_COMBCUT, m_cCUTCOMBO);測試環境:MFC
CComboBox m_cCUTCOMBO;
在*.cpp中新增
需新增在 DoDataExchange(CDataExchange* pDX) 中
//控制項
DDX_Control(pDX, IDC_COMBCUT, m_cCUTCOMBO);測試環境:MFC
using System.IO;
取得程式當下檔案目錄資訊: string sPath = this.GetType().Assembly.Location;
string filename = @"C:\Users\123.text"; if (File.Exists(filename)) { MessageBox.Show("取得檔名(不包含附檔名)" + Path.GetFileNameWithoutExtension(filename)); MessageBox.Show("取得副檔名:" + Path.GetExtension(filename)); MessageBox.Show("目錄資料夾路徑:" + Path.GetDirectoryName(filename)); MessageBox.Show("資料根目錄:" + Path.GetPathRoot(filename)); MessageBox.Show("取得路徑:" + Path.GetFullPath(filename)); }
測試環境:c#.net 2015
CString csbuf; USES_CONVERSION; char* chPath = T2A((LPTSTR)(LPCTSTR)csbuf);
測試環境 mfc Unicode
宣告句柄與類定義的指標 宣告一個新函式替代原來的
在初始化的地方
使用"LoadLibrary"呼叫dll
使用"GetProcAddress"定義函式
最後再要使用的地方 直接使用替代的函式 即可
==============================以下範例================================
HMODULE hmod; typedef DXF_PARSE*(*MyAdd)(); typedef DXF_PREVIEW*(*MyAdd2)(); MyAdd Add; MyAdd2 Add2;
寫在init
BOOL CDxftoNcfileDlg::OnInitDialog() { CDialogEx::OnInitDialog();// TODO: 在此加入額外的初始設定 hmod = LoadLibrary(L"DxfLib2.dll"); //load dll if (hmod == NULL) { return 0; } Add = (MyAdd)GetProcAddress(hmod, "GetParsesPtr"); if (!Add) { MessageBox(L"error_GetParsesPtr"); return 0; } Add2 = (MyAdd2)GetProcAddress(hmod, "GetPreviewsPtr"); if (!Add2) { MessageBox(L"error_GetPreviewsPtr"); return 0; }return TRUE; // 傳回 TRUE,除非您對控制項設定焦點}再欲使用的地方加上直接替換add()add2()測試環境:MFC
!!!!!!使用前注意!!!!!!!!! 需加入 #define _CRT_SECURE_NO_WARNINGS 在程式開頭(stdafx.h)
CString csbuf; csbuf.Format(L"cstring"); int cnt = csbuf.GetLength(); TCHAR* Msg = NULL; Msg = new TCHAR[cnt+1];//記得+1 _tcscpy(Msg, csbuf); delete[]Msg;//刪除動態創建
建創一個元件TextBox 命名 tbox
using System.IO;
FolderBrowserDialog path = new FolderBrowserDialog(); path.ShowDialog(); this.tbox.Text = path.SelectedPath;
測試環境:VS2015 C#.NET
========================================================
在主框架中 加入:public Form1() { IntPtr windowHandle; InitializeComponent(); CommonMethod.AllocConsole(); windowHandle = CommonMethod.FindWindow(null, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); IntPtr closeMenu = CommonMethod.GetSystemMenu(windowHandle, IntPtr.Zero); Console.SetWindowPosition(0, 0); uint SC_CLOSE = 0xF060; CommonMethod.RemoveMenu(closeMenu, SC_CLOSE, 0x0); CommonMethod.RemoveMenu(closeMenu, 0x1000000, 0x0); CommonMethod.SetParent(windowHandle, pnConsole.Handle); CommonMethod.MoveWindow(windowHandle, 0, -27, this.pnConsole.Width, this.pnConsole.Height + 27, true); this.componentInitial(); }
========================================================
新增以下檔案using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace Example_CS_Reconlib { class CommonMethod { public const int GWL_STYLE = (-16); public const int WS_VISIBLE = 0x10000000; /// <summary> /// //啟動視窗 /// </summary> /// <returns></returns> [DllImport("Kernel32.dll")] public static extern bool AllocConsole(); /// <summary> /// /釋放窗口,即關閉 /// </summary> /// <returns></returns> [DllImport("kernel32.dll", EntryPoint = "FreeConsole")] public static extern bool FreeConsole(); /// <summary> /// //找出運行的視窗 /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "FindWindow")] public extern static IntPtr FindWindow(string lpClassName, string lpWindowName); /// <summary> /// //取出視窗運行的功能表 /// </summary> /// <param name="hWnd"></param> /// <param name="bRevert"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "GetSystemMenu")] public extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern int GetMenuItemCount(IntPtr hMenu); /// <summary> /// 灰掉按鈕 /// </summary> /// <param name="hMenu"></param> /// <param name="uPosition"></param> /// <param name="uFlags"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "RemoveMenu")] public extern static IntPtr RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); /// <summary> /// 修改標題 /// </summary> /// <param name="strMessage"></param> /// <returns></returns> [DllImport("Kernel32.dll")] public static extern bool SetConsoleTitle(string strMessage); /// <summary> /// 設置控制台(Console)在什麼元件上顯示 /// </summary> /// <param name="hWndChild">Console表單</param> /// <param name="hWndNewParent">顯示Console的元件</param> /// <returns></returns> [DllImport("user32.dll", SetLastError = true)] public static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent); [DllImport("user32.dll", SetLastError = true)] public static extern int GetWindowLong(IntPtr hWnd, int nIndex); /// <summary> /// Remove border and whatnot /// </summary> /// <param name="hwnd"></param> /// <param name="nIndex"></param> /// <param name="dwNewLong"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "SetWindowLongA", SetLastError = true)] public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong); /// <summary> /// 改變表單的大小 /// </summary> /// <param name="hwnd"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="cx"></param> /// <param name="cy"></param> /// <param name="repaint"></param> /// <returns></returns> [DllImport("user32.dll", SetLastError = true)] public static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint); /// <summary> /// 設置字體 /// </summary> /// <param name="hConsoleOutput"></param> /// <param name="wAttributes"></param> /// <returns></returns> [DllImport("kernel32.dll", SetLastError = true)] public static extern int SetConsoleTextAttribute(IntPtr hConsoleOutput, int wAttributes); [DllImport("kernel32.dll")] public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode); } }
CONVERT ( data_type [ ( length ) ] , expression [ , style ] ) CONVERT style參數說明 1 (expression為 money 或 smallmoney型別): 0 : 預設,保留小數位後兩位,並四捨...