64,641
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>int main(void)
{
vector <string> m_vecDir;
char szDir[MAX_PATH] = "c:\\2323\\23232.doc";
string strTemp = szDir;
m_vecDir.push_back(strTemp );//
cout<<m_vecDir[0];
system("PAUSE");
return 0;
}
#include <vector>
using namespace std;
#define MAX_PATH 100
int main()
{
std::vector <std::string> m_vecDir;
char szDir[MAX_PATH] = "c:\\2323\\23232.doc";
std::string strTemp = szDir;
m_vecDir.push_back(strTemp );//此句出错,为什么?
return 0;
}
std::vector <std::string> m_vecDir;
std::string strDir("c:\\2323\\23232.doc");
m_vecDir.push_back(strDir);
//h
class MainDlg
{
public:
MainDlg(HINSTANCE hInst);
~MainDlg();
bool CreateMainDialog(HINSTANCE hInst, const HWND hWnd,LPARAM lparam);
static LRESULT CALLBACK MainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void InitMainDlg(HWND hWnd);
void ShowDlg(int iTabId);
void SetApplicationPath();
bool GenerateDir();
bool GetAppName(char *szAppPath);
HWND m_hWnd;
HINSTANCE m_hInst;
HWND m_hPageWnd[6];
int m_iTabCount;
HWND m_hTab;
RECT m_rcTab;
char m_szAppPath[MAX_PATH+1];
char m_szAppName[MAX_PATH+1];
char m_szDir[MAX_PATH+1];
std::vector<std::string> m_vecMainDir;
};
//cpp
#include"stdafx.h"
#include"MainDlg.h"
char g_szTestItemDir[6][32] = {"1",
"2",
"3",
"4",
"5",
"6"};
MainDlg::MainDlg(HINSTANCE hInst)
{
this->m_hInst = hInst;
}
MainDlg::~MainDlg()
{
m_hInst = NULL;
}
bool MainDlg::CreateMainDialog(HINSTANCE hInst, const HWND hWnd,LPARAM lparam)
{
INT_PTR iRet;
iRet = DialogBoxParam(m_hInst,MAKEINTRESOURCE(IDD_MAIN),hWnd,(DLGPROC)MainDlg::MainProc,(LPARAM)&lparam);
DWORD DError = GetLastError();
if(iRet == 0 || iRet == -1)
return false;
else
return true;
}
void MainDlg::InitMainDlg(HWND hWnd)
{
//initial value
m_hWnd = hWnd;
m_iTabCount = 6;
ZeroMemory(m_szDir, MAX_PATH+1);
strcpy(m_szDir, "C:\\tt");
ZeroMemory(m_szAppName, MAX_PATH+1);
//end init
m_hTab = ::GetDlgItem(m_hWnd,IDC_TAB);
for( int i = 0; i < m_iTabCount; i++)
{
TCITEM item;
item.mask = TCIF_TEXT;
item.cchTextMax = strlen(g_szTestItemDir[i]);
item.pszText = g_szTestItemDir[i];
TabCtrl_InsertItem(m_hTab,i,&item);
}
GetClientRect(m_hTab, &m_rcTab);
m_rcTab.top+=20;
//m_rcTab.left+=1;
m_rcTab.right-=1;
m_rcTab.bottom-=1;
MoveWindow(m_hPageWnd[0],m_rcTab.left,m_rcTab.top,m_rcTab.right-m_rcTab.left,m_rcTab.bottom-m_rcTab.top,TRUE);
ShowWindow(m_hPageWnd[0],TRUE);
for(int i = 1;i < m_iTabCount; i++)
ShowWindow(m_hPageWnd[i],FALSE);
}
void MainDlg::ShowDlg(int iTabId)
{
MoveWindow(m_hPageWnd[iTabId],m_rcTab.left,m_rcTab.top,m_rcTab.right-m_rcTab.left,m_rcTab.bottom-m_rcTab.top,TRUE);
for(int i = 0;i < m_iTabCount; i++)
{
if(i == iTabId)
ShowWindow(m_hPageWnd[i],TRUE);
else
ShowWindow(m_hPageWnd[i],FALSE);
}
}
void MainDlg::SetApplicationPath()
{
ZeroMemory(m_szAppPath, MAX_PATH+1);
OPENFILENAME ofn;
ZeroMemory(&ofn , sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.Flags = OFN_EXPLORER;
ofn.hInstance = NULL;
ofn.hwndOwner = m_hWnd;
ofn.lpstrTitle = "Select the Application";
ofn.lpstrFilter = "*.exe\0*.exe\0\0";
ofn.lpstrInitialDir = "c:\\";
ofn.lpstrFile = m_szAppPath;
ofn.nMaxFile = MAX_PATH;
if(GetOpenFileName(&ofn))
{
SetDlgItemText(m_hWnd,IDC_APPPATH,m_szAppPath);
if(!GetAppName(m_szAppPath))
MessageBox(m_hWnd,"Please Input Application Path that includes \".exe\"!","Warning",MB_OK);
}
}
bool MainDlg::GetAppName(char *szAppPath)
{
ZeroMemory(m_szAppName, MAX_PATH+1);
if(szAppPath == NULL || strlen(szAppPath) == 0)
return false;
if(strlen(szAppPath) > 0)
{
char *szBuf = NULL, *szExeStartPos = NULL;
szBuf = strrchr(szAppPath,'\\')+1;
szExeStartPos = szAppPath + strlen(szAppPath) - 4;//Get ".exe"
if(_strnicmp(szExeStartPos,".exe",4))//lowercase and uppercase is ok
return false;
if(szBuf != NULL)
{
strncpy(m_szAppName, szBuf, strlen(szBuf) - 4);
return true;
}
else
return false;
}
else
return false;
}
bool MainDlg::GenerateDir()
{
if(strlen(m_szAppName) == 0)
return false;
char szProjectDir[MAX_PATH+1];
memset(szProjectDir, 0 , MAX_PATH+1);
bool bRetCreateDir = false;
//Generate test project folder
COleDateTime cdt(COleDateTime::GetCurrentTime());
strcpy(szProjectDir, m_szDir);
strcat(szProjectDir,"\\");
strcat(szProjectDir,m_szAppName);
strcat(szProjectDir,cdt.Format("_%Y-%m-%d-%H-%M-%S"));
bRetCreateDir = CreateDirectory(szProjectDir, NULL);
if(bRetCreateDir == 0)
{
MessageBox(m_hWnd,"Can't Create a test project folder!","Warning",MB_OK);
return false;
}
//Generate test item folder and log folder
char szTestItemDir[MAX_PATH+1];
if(m_vecMainDir.size() > 0)
m_vecMainDir.clear();
for(int i = 0;i < 6; i++)
{
memset(szTestItemDir, 0 , MAX_PATH+1);
strcpy(szTestItemDir, szProjectDir);
strcat(szTestItemDir,"\\");
strcat(szTestItemDir,g_szTestItemDir[i]);
strcat(szTestItemDir,"\0");
bRetCreateDir = CreateDirectory(szTestItemDir, NULL);
if(bRetCreateDir == 0)
{
MessageBox(m_hWnd,"Can't Create a test item folder!","Warning",MB_OK);
RemoveDirectory(szProjectDir);
return false;
}
std::string strTemp = szTestItemDir;
m_vecMainDir.push_back(strTemp); //error
strcat(szTestItemDir,"\\log");
bRetCreateDir = CreateDirectory(szTestItemDir, NULL);
if(bRetCreateDir == 0)
{
MessageBox(m_hWnd,"Can't Create a test log folder!","Warning",MB_OK);
RemoveDirectory(szProjectDir);
return false;
}
}
return true;
}
LRESULT CALLBACK MainDlg::MainProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static MainDlg *dlgPtr;
switch (uMsg)
{
case WM_INITDIALOG:
{
dlgPtr = (MainDlg*)lParam;
dlgPtr->InitMainDlg(hWnd);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_BROWSEPATH:
dlgPtr->SetApplicationPath();
break;
case IDC_GENERATESCRIPT:
dlgPtr->GenerateDir();
break;
}
break;
case WM_NOTIFY: //Tab Control WM_NOTIFY
if (((LPNMHDR)lParam)->code == TCN_SELCHANGE )//Tab Contro TCN_SELCHANGE /TCN_SELCHANGING
{
int i = (int)SendDlgItemMessage(hWnd,IDC_TAB,TCM_GETCURSEL,0,0);
dlgPtr->ShowDlg(i);
}
break;
case WM_CLOSE:
{
EndDialog(hWnd, wParam);
dlgPtr->m_hWnd = NULL;
return TRUE;
}
break;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hDeskTopWnd = GetDesktopWindow();
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_HOTKEY_CLASS | ICC_LISTVIEW_CLASSES | \
ICC_PROGRESS_CLASS | ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS | \
ICC_USEREX_CLASSES | ICC_PAGESCROLLER_CLASS ;
InitCommonControlsEx (&iccx);
MainDlg mainDlg(hInstance);
mainDlg.CreateMainDialog(hInstance, hDeskTopWnd, (LPARAM)&mainDlg);
return 0;
}