// Wndxx.cpp : implementation file
//
#include "stdafx.h"
#include "123.h"
#include "Wndxx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWndxx
CWndxx::CWndxx()
{
}
CWndxx::~CWndxx()
{
}
BEGIN_MESSAGE_MAP(CWndxx, CWnd)
//{{AFX_MSG_MAP(CWndxx)
ON_WM_DROPFILES()
ON_WM_CREATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_BN_CLICKED(2000, OnButton1)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWndxx message handlers
BOOL CWndxx::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.hMenu = NULL;
return CWnd::PreCreateWindow(cs);
}
LRESULT CWndxx::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if(message == WM_DROPFILES){
// DROPFILES *pdrop_f = (DROPFILES *)wParam;
//
//
// //DragQueryFile()
// DROPFILES *pdrop_f2 = (DROPFILES *)( *((ULONG *)(wParam)));
//
// wchar_t *s = (wchar_t *)(pdrop_f2+1);
// CString s_c(s);
// AfxMessageBox(s_c);
}
return CWnd::DefWindowProc(message, wParam, lParam);
}
void CWndxx::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
int i = sizeof(DROPFILES);
DROPFILES *pdrop_f = (DROPFILES *)GlobalLock(hDropInfo);
wchar_t file_s[MAX_PATH];
UINT nFiles = DragQueryFileW(hDropInfo, -1, file_s, MAX_PATH);
for(i=0; i<nFiles; i++) {
int nLen = DragQueryFileW(hDropInfo, 0, file_s, MAX_PATH);
CString s = file_s;
AfxMessageBox(s);
}
DragFinish(hDropInfo);
CWnd::OnDropFiles(hDropInfo);
}
int CWndxx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
btn.Create("C", WS_CHILD| WS_VISIBLE, CRect(0,0,100,20), this, 2000);
LPCSTR sClassName = AfxRegisterWndClass(NULL);
wnd2.CreateEx(0,
sClassName,
"Win",
WS_CHILD|WS_VISIBLE,
CRect(200,200,400,400),
this,
3030);
return 0;
}
void CWndxx::OnButton1()
{
// TODO: Add your control notification handler code here
setlocale(LC_ALL, "chs");
CFileDialog cFileDialog( TRUE, NULL, NULL,
OFN_HIDEREADONLY, "Any File(*.*) |*.*" );
if(cFileDialog.DoModal() != IDOK) return;
CString s(cFileDialog.GetPathName());
wchar_t s_f[MAX_PATH] = {0};
mbstowcs(s_f, s, s.GetLength());
size_t size_n = sizeof(DROPFILES) + (wcslen(s_f)+4)*2;
HGLOBAL hGLOBAL = GlobalAlloc(
GMEM_MOVEABLE|GMEM_ZEROINIT, size_n);
char *c_buf = (char *)GlobalLock(hGLOBAL);
DROPFILES *pdrop_f = (DROPFILES *)c_buf;
pdrop_f->pFiles = sizeof(DROPFILES);
pdrop_f->pt.x = 4;
pdrop_f->pt.y = 4;
pdrop_f->fNC = 0;
pdrop_f->fWide = 1;
ASSERT(CString(s_f) == s);
wcscpy( (wchar_t *)(pdrop_f+1), s_f);
PostMessage( WM_DROPFILES, (WPARAM)hGLOBAL, 0 );
}
void CWndxx::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
wnd2.UpdateWindow();
}
评论0