15,979
社区成员
发帖
与我相关
我的任务
分享
TipBox(hWnd,L"TipBox TEST",L"TWIN",0);
Button(NULL,L"关闭",175,170,IDC_CLOSE)
TipBox(hWnd,L"TipBox TEST",L"TWIN",0);
Button(NULL,L"关闭",175,170,IDC_CLOSE)
这样,整个过程不就毫无难度了吗?
-----------
再说回去,很多帖子里都能看到你的足迹,真就像机器人在刷一样,一页就都被占了...
如果你这样是纯粹为了回复分的话,很可能没人会给你分了,真的想得分,哪怕就到网上去搜代码,别人都有可能会给分啊,但是你这样就像打广告,对解决问题没有用处,又有谁能给你分呢
void CMainFrame::OnFileDownload()
{ // let the user selects a file name
// which will be sent to a target.
// TODO: Add your command handler code here
char CurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,CurDir);
//
if (DownLoadFileName.IsEmpty())
DownLoadFileName=RFileList->m_arrNames[0];
// if m_arrNames[0] also ="" ,then dir=CurDir; fname=""
char drive[MAX_PATH];
char dir[MAX_PATH];
char fname[MAX_PATH];
char ext[10];
_splitpath(DownLoadFileName,drive,dir,fname,ext);
//
CFileDialog fd(TRUE);
fd.m_ofn.lpstrTitle="Down Load File";
fd.m_ofn.lpstrInitialDir=strcat(drive,dir);
fd.m_ofn.lpstrFile=strcat(fname,ext);
fd.m_ofn.lpstrFilter="Any file(*.*)\0*.*\0ARC file (*.arc)\0*.arc\0BMP file (*.bmp)\0*.bmp\0DLL file (*.dll)\0*.dll\0";
if (stricmp(ext,".arc")==0) fd.m_ofn.nFilterIndex=2;
else if (stricmp(ext,".bmp")==0) fd.m_ofn.nFilterIndex=3;
else if (stricmp(ext,".dll")==0) fd.m_ofn.nFilterIndex=4;
else fd.m_ofn.nFilterIndex=1;
fd.m_ofn.Flags|=OFN_FILEMUSTEXIST;
fd.m_ofn.Flags|=OFN_ALLOWMULTISELECT;// must
fd.m_ofn.Flags|=OFN_EXPLORER; // default by Afx
fd.m_ofn.Flags|=OFN_ENABLEHOOK;// default by Afx
fd.m_ofn.lpfnHook=DNHookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
//UINT CALLBACK _AfxCommDlgProc(HWND hWnd,UINT message,
// WPARAM wParam,LPARAM lParam);
//
CStringArray cstrArr;
BOOL fDllFile=FALSE;
BOOL fBmpFile=FALSE;
if (fd.DoModal()==IDOK)
{// invalid file name will be prompted.
// file existence will be checked
// may be multi selection under one same directory
POSITION pos=fd.GetStartPosition( );
while (pos)
{
cstrArr.Add(fd.GetNextPathName(pos));
}
if (cstrArr.GetSize()==1)
{ // 1
DownLoadFileName=cstrArr[0];
if(!cstrArr[0].Right(3).CompareNoCase("dll"))
fDllFile=TRUE;// 1 dll
if(!cstrArr[0].Right(3).CompareNoCase("bmp"))
fBmpFile=TRUE;// 1 bmp
}
else
{ // >1
if (IsAllDll(cstrArr))
{ // all dlls
fDllFile=TRUE;
}
else
{ // not all dll
AfxMessageBox("Except all \"dll\" files,"
"only 1 file can be selected !");
return;
}
}
// GetCurrentDirectory(MAX_PATH,CurDir);
// directory changed
SetCurrentDirectory(CurDir);
//
CDload dl;
// make dll arc
if (fDllFile) dl.DllToArc(cstrArr);
// make bmp arc
if (fBmpFile) dl.BmpToArc(DownLoadFileName);
//
AfxGetApp()->AddToRecentFileList(DownLoadFileName);
// do downloading
dl.DoModal();
} // end ID_OK
else
{// CANCEL. directory changed
// GetCurrentDirectory(MAX_PATH,CurDir);
SetCurrentDirectory(CurDir);
}
}
// for CFileDialog down load
// in debug version there is an error : ASSERT(m_p...==NULL)
UINT CALLBACK DNHookProc(HWND hDlg,UINT uMsg,WPARAM wPar,LPARAM lPar)
{ // hdlg is a child
HWND hWndParent;
CWinApp *pApp=AfxGetApp();
HICON hIcon;
HWND hw; // SHELLDll_defView
HWND hcw;// SysListView32
DWORD dwStyle;
//
if (hDlg == NULL) return 0;
// from "_AfxCommDlgProc()" of the file "dlgcomm.cpp"
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
if (pThreadState->m_pAlternateWndInit != NULL)
// not pThreadState->m_pAlternateWndInit->SubclassWindow(hWnd);
pThreadState->m_pAlternateWndInit = NULL;
//
hWndParent=GetParent(hDlg);// needed
switch (uMsg)
{
case WM_INITDIALOG:
hIcon=pApp->LoadIcon(IDI_ICONDN);
SendMessage(hWndParent,WM_SETICON,(WPARAM)0,(LPARAM)hIcon);
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
DestroyIcon(hIcon);
break;
case WM_NOTIFY:
LPOFNOTIFY lpon=(LPOFNOTIFY)lPar;
UINT Notify=lpon->hdr.code;
if (Notify==CDN_TYPECHANGE ||
Notify==CDN_SELCHANGE )
{ // after window shown
hw=GetDlgItem(hWndParent,0x0461);// SHELLDll_defView
hcw=GetDlgItem(hw,1);// SysListView32
dwStyle=GetWindowLong(hcw,GWL_STYLE);
// change multi-selection of ListView
if (lpon->lpOFN->nFilterIndex==4) // "dll"
{
dwStyle &= ~LVS_SINGLESEL;// Multi
}
else
{
dwStyle |= LVS_SINGLESEL;// Single
}
SetWindowLong(hcw,GWL_STYLE,dwStyle);
}
if (Notify==CDN_FOLDERCHANGE)
{
HWND hLv=GetDlgItem(hWndParent,0x0461);//lst1
if(hLv) SendMessage(hLv,WM_COMMAND,0x7029,0);//ODM_WIEW_ICONS
}
break;
}
return 0;
}
// if no ! dlgFile.m_ofn.lpfnHook=CDN_HookProc;//="_AfxCommDlgProc" see"dlgcomm.cpp" <>NULL!
// for CFileDialog
LRESULT CALLBACK NewDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) //子类化过程
{
WORD wNotifyCode;
WORD wID;
// int idCtrl;
LPNMHDR pnmh;
HWND hwndCtl;
LPHELPINFO lphi;
char name[256];
//
switch(Msg)
{
#if 1
case WM_COMMAND:// 0x0111
{
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
// afxDump << wID << " =ID\n";
hwndCtl = (HWND) lParam; // handle of control
switch (wID)
{
case IDOK:
hwndCtl=GetDlgItem(hWnd,1148);// comboBox "file name"
GetWindowText(hwndCtl,name,256);
afxDump << name << " OK\n";
// if fold !
break;
case IDCANCEL:
// afxDump << " CANCEL\n";
break;
case 1148:// CBN_SELENDCANCEL 0x047C
if(CBN_SELCHANGE==wNotifyCode) //=1
{
GetWindowText(hwndCtl,name,256);
//afxDump << wNotifyCode << " 1148\n";
afxDump << name << "\n";
}
break;
// default:
// afxDump << LOWORD(wParam) << " =Command ID\n";
}
}
break;
case WM_SYSCOMMAND:
wParam &= 0xFFFF;
switch (wParam)
{
case SC_CLOSE:
// afxDump << "Close\n";
break;
case SC_CONTEXTHELP:
// afxDump << "Help\n";
break;//return 1;//
}
break;
case WM_HELP:
lphi = (LPHELPINFO) lParam;
// afxDump << lphi->iCtrlId << " Help\n";
break;
//
case WM_SETCURSOR://0x0020
{
HWND hwnd = (HWND) wParam; // handle to window with cursor
WORD nHittest = LOWORD(lParam); // hit-test code
WORD wMouseMsg = HIWORD(lParam); // mouse-message identifier
if(hwnd)
{
int id=GetDlgCtrlID(hwnd);
// afxDump << id << " =ID\n";
}
break;
}
case WM_NCMOUSEMOVE://0x00A0
{
// INT nHittest = (INT) wParam; // hit-test value
// POINTS pts = MAKEPOINTS(lParam); // position of cursor
// afxDump << pts.x << ";" << pts.y << " pts\n";
break;
}
case WM_DELETEITEM:// 0x2D
// afxDump <<"WM_DELETEITEM\n";
break;
case WM_PARENTNOTIFY://0x0210
{
WORD fwEvent = LOWORD(wParam); // event flags
WORD idChild = HIWORD(wParam); // identifier of child window
//lValue = lParam; // child handle, or cursor coordinates
// WM_LBUTTONDOWN 0x0201=513
if(fwEvent==WM_LBUTTONDOWN)
// afxDump << idChild << " id WM_PARENTNOTIFY\n";
break;
}
case WM_NCHITTEST://WM_MOUSEMOVE:
{
int xPos = LOWORD(lParam); // horizontal position of cursor
int yPos = HIWORD(lParam); // vertical position of cursor
break;
}
case WM_SETFOCUS:// 0x0007
{
HWND hwndLoseFocus = (HWND) wParam;
char name[80];
GetClassName(hwndLoseFocus,name,80);
int id=GetDlgCtrlID(hwndLoseFocus);
// afxDump << name << " ID=" << id <<" WM_SETFOCUS\n";
break;
}
case WM_CTLCOLORSTATIC:// 0x0138
{
HDC hdcStatic = (HDC) wParam; // handle to display context
HWND hwndStatic = (HWND) lParam; // handle to static control
int id=GetDlgCtrlID(hwndStatic);
if(id==1090) SetTextColor(hdcStatic,RGB(255,0,0));// "文件名"
else if(id==1089) SetTextColor(hdcStatic,RGB(0,255,0));// "文件类型"
else SetTextColor(hdcStatic,RGB(0,0,255));// 1091 "查找范围"
SetBkMode(hdcStatic,TRANSPARENT);
char name[80];
GetClassName(hwndStatic,name,80);
// afxDump << name << " ID=" << id <<"\n";
return 1;//break;
}
#endif
case WM_NOTIFY:// 0x004E
{
pnmh = (LPNMHDR) lParam;
char name[80];
GetClassName(pnmh->hwndFrom,name,80);
// ComboBoxEx32 ID=1148 code=0xFFFFFCDA CBEN_BEGINEDIT ;FFFFFCE0-6
PNMCBEENDEDIT pnmEditInfo = (PNMCBEENDEDIT) lParam;
//
// afxDump << CBEN_ENDEDITW << "\n";// 0xFFFFFCDA
// afxDump << name << " ID=" << (int)pnmh->idFrom << " code=" << pnmh->code << "\n";//
break;
}
case WM_CTLCOLORBTN:// 0x0135
{
HDC hdcBTN = (HDC) wParam; // handle to display context
HWND hwndBTN = (HWND) lParam; // handle to static control
char name[80];
GetClassName(hwndBTN,name,80);
int id=GetDlgCtrlID(hwndBTN);
// Button ID=1
// Button ID=2
// afxDump << name << " ID=" << id <<"\n";// =1;2
return 1;// break;
}
case WM_CTLCOLOREDIT:// 0x0133
{
HDC hdcEdit = (HDC) wParam; // handle to display context
HWND hwndEdit = (HWND) lParam; // handle to static control
char name[80];
GetClassName(hwndEdit,name,80);
int id=GetDlgCtrlID(hwndEdit);
// ComboBox ID=1136
// ComboBox ID=1137
if(id == 1136)
{
SetTextColor(hdcEdit,RGB(255,0,0));//
}
else if(id == 1137)
{
SetWindowText(hwndEdit,"no name");//
SetTextColor(hdcEdit,RGB(0,255,0));// "文件类型"
}
// afxDump << name << " ID=" << id <<"\n";
return 1;//break;
}
case WM_CTLCOLORLISTBOX:// 0x0134
{
HDC hdcLB = (HDC) wParam; // handle to list box display context
HWND hwndLB = (HWND) lParam; // handle to list box
char name[80];
GetClassName(hwndLB,name,80);
int id=GetDlgCtrlID(hwndLB);
// ComboLBox ID=1000
SetTextColor(hdcLB,RGB(255,0,0));
// afxDump << name << " ID=" << id <<"\n";
return 1;//break;
}
case WM_MOUSEMOVE:
//CWnd* ChildWindowFromPoint( POINT point ) const;
break;
default:
// afxDump << Msg << " Msg\n";
break;
}
//
return CallWindowProc((WNDPROC)::GetProp(hWnd,"ExpFileOpen"), hWnd, Msg, wParam, lParam);
}
using namespace std;
static OPENFILENAME ofn;
void PopFileInitialize(HWND hwnd)
{
static TCHAR szFilter[] = TEXT("*.*\0") \
TEXT("* (*.*)\0*.*\0\0");
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.hInstance = NULL;
//ofn.lpstrFilter = szFilter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 0;
ofn.lpstrFile = NULL; // Set in Open and Close functions
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFileTitle = NULL; // Set in Open and Close functions
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.Flags = 0; // Set in Open and Close functions
ofn.nFileOffset = 0;
ofn.nFileExtension = 0;
ofn.lpstrDefExt = TEXT("...");
ofn.lCustData = 0L;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
}
BOOL PopFileOpenDlg(HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
{
ofn.hwndOwner = hwnd;
ofn.lpstrFile = pstrFileName;
ofn.lpstrFileTitle = pstrTitleName;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT;
return GetOpenFileName(&ofn);
}
case WM_CREATE:
{
PopFileInitialize(hWnd); //初始化ofn
PopFileOpenDlg(hWnd, szFileName, szTitleName);//打开文件对话框
PostQuitMessage(0);
}