Delphi를 사용하여 삭제 된 디렉토리 이름을 허용해야하는 간단한 응용 프로그램을 코딩하고 있습니다. 비록 내가 델파이를 사용하고 있지만,이 프로그램은 일반 C와 마찬가지로 똑 바른 Windows API (VCL없이 객체 지향적 인 것)가 아니다.대화 상자를 사용할 때 DragAcceptFiles를 사용할 수 없습니다.
나는 CreateWindowEx). 대화 상자를 사용하도록 해당 코드를 변환 할 때 끌어서 놓기 기능이 중단되어 이유를 파악할 수 없습니다.
procedure ExecWM_INITDIALOG(wnd : hWnd); begin { ensure that the listbox isn't accepting dropped files } DragAcceptFiles(GetDlgItem(Wnd, IDC_DIRECTORIES), FALSE); { ensure the main dialog window accept dropped files } DragAcceptFiles(Wnd, TRUE); { load the current values in the registry } LoadRegistrySettings(RegistryKey, RegistrySettings, RegistrySettingsCount) end; procedure ExecWM_DROPFILES(Wnd : hWnd; wParam : word; lParam : longint); const DROPPED_FILE_COUNT = -1; var FileCnt : integer; { number of files dropped } Filename : packed array[0..MAX_PATH] of char; { filename buffer } DropInfo : HDROP absolute wParam; { wParam points to Drop...} I : integer; { for loop } begin { one or more files have been dropped on us! } { -->>> The problem seems to show up at this statement: } { the DropInfo (wParam) has a value that seems too low ($20) } { when using the code that works the value is much larger } FileCnt := DragQueryFile(DropInfo, DROPPED_FILE_COUNT, nil, 0); for I := 0 to FileCnt - 1 do begin { get the dropped files names and add them to the listbox } DragQueryFile(DropInfo, I, Filename, sizeof(Filename)); ListBox_AddString(GetDlgItem(Wnd, IDC_DIRECTORIES), Filename); end; { tell Windows that we are done grabbing the dropped files } DragFinish(DropInfo); end; function BackupConfigProc(wnd : hWnd; msg : word; wParam : word; lParam : longint) : bool; stdcall; begin BackupConfigProc := FALSE; { default return value } case msg of WM_COMMAND: begin ExecWM_COMMAND (wnd, wParam, lParam); BackupConfigProc := TRUE; end; WM_DROPFILES: begin ExecWM_DROPFILES(Wnd, wParam, lParam); //BackupConfigProc := TRUE; { this was a shot in the dark } end; WM_INITDIALOG: begin ExecWM_INITDIALOG (wnd); BackupConfigProc := TRUE; end; WM_CLOSE: begin EndDialog(wnd, 0); { and return the default FALSE } end; end; end; begin DialogBox(hInstance, 'BackupConfigDlg', 0, @BackupConfigProc); end.
그것은 DropInfo (의 wParam)의 값과 같은 수신 :
function WndProc (Wnd : hWnd; Msg, wParam, lParam : DWORD) : DWORD; stdcall; { main application/window handler function } const DROPPED_FILE_COUNT = -1; var FileCnt : integer; { number of files dropped } Filename : packed array[0..MAX_PATH] of char; { filename buffer } DropInfo : HDROP absolute wParam; { wParam points to Drop...} I : integer; { for loop } begin WndProc := 0; { let the Windows default handler take care of everything } case msg of WM_CREATE: begin InitCommonControls; if CreateWindowEx(WS_EX_CLIENTEDGE or WS_EX_RIGHTSCROLLBAR, 'LISTBOX', nil, WS_CHILD or WS_HSCROLL or WS_VSCROLL or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or WS_VISIBLE or LBS_NOINTEGRALHEIGHT, 0, 0, 0, 0, Wnd, IDC_LISTBOX, hInstance, nil) = 0 then begin MessageBox(Wnd, 'Couldn''t create the listbox', 'Main Window', MB_OK); WndProc := -1; end; { let Windows know that we accept files being dragged over our client} { area. } DragAcceptFiles(Wnd, TRUE); { tell the listbox to use a nice font } SendMessage(GetDlgItem(Wnd, IDC_LISTBOX), WM_SETFONT, GetStockObject(DEFAULT_GUI_FONT), 0); exit; end; { WM_CREATE } WM_DROPFILES: begin { one or more files have been dropped on us! } FileCnt := DragQueryFile(DropInfo, DROPPED_FILE_COUNT, nil, 0); for I := 0 to FileCnt - 1 do begin { get the dropped files names and add them to the listbox } DragQueryFile(DropInfo, I, Filename, sizeof(Filename)); ListBox_AddString(GetDlgItem(Wnd, IDC_LISTBOX), Filename); end; { tell Windows that we are done grabbing the dropped files } DragFinish(DropInfo); exit; end; { WM_DROPFILES } ... followed by other stuff that has nothing to do with drag and drop ...
내가이 것을 변환 :
이것은 (의 일부) 나는 그것이 잘 작동했다 코드입니다 대화 상자가 유효하지 않습니다 (작동하지 않는 대화 코드에서받은 값보다 훨씬 더 값이.습니다).
Dialog 버전이 작동하지 않는 이유와 작동시키기 위해 수행해야 할 작업에 대해 알려 주신 모든 분들께 감사드립니다.
감사합니다.
존.
당신은 내 위대한 당혹감에 절대적으로 맞습니다! 방금 복사 한 코드 중 일부는 Windows 3.1 시대에 작성한 프로그램에서 가져온 것임을 알게되었습니다. 매개 변수의 크기를 적절하게 조정 한 후에도 올바르게 작동합니다. 오히려 멍청한 실수에 대해 사과드립니다. – Hex440bx