📄 dialogpathprinter.cpp
字号:
//#include "stdafx.h"
#include "DialogPathPrinter.h"
#include "resource.h"
#include "Logger.h"
IMPLEMENT_MESSAGE_HANDLER(CBaseDialog, CDialogPathAndPrinter)
BEGIN_MESSAGE_MAP(CDialogPathAndPrinter)
ADD_MESSAGE_HANDLER(WM_COMMAND, On_WM_COMMAND)
ADD_MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
END_MESSAGE_MAP()
CDialogPathAndPrinter::CDialogPathAndPrinter(int nResId, HWND hParent) : CBaseDialog(nResId, hParent)
{
sPrinterNamePhysics[0]=0;
sPath[0]=0;
ENABLE_MESSAGE_MAP();
}
CDialogPathAndPrinter::~CDialogPathAndPrinter()
{
}
void CDialogPathAndPrinter::On_WM_COMMAND(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case IDC_BUTTON_BROWSE_PATH:
{
BROWSEINFO bi;
bi.hwndOwner=NULL;
bi.pidlRoot=NULL;
TCHAR buf[MAX_PATH];
bi.pszDisplayName=buf;
bi.lpszTitle=_T("您好大侠,请选择输出的目录:");
bi.ulFlags=BIF_RETURNONLYFSDIRS;
bi.lpfn=NULL;
bi.lParam=0;
int iImage=0;
bi.iImage=iImage;
ITEMIDLIST *pidl=SHBrowseForFolder(&bi);
if(pidl)//user did not cancel
{
SHGetPathFromIDList(pidl,sPath);
HWND hwndPath=GetDlgItem(hDlg, IDC_EDIT_PATH);
::SetWindowText(hwndPath,sPath);
IMalloc *pMalloc;
SHGetMalloc(&pMalloc);
pMalloc->Free(pidl);
pMalloc->Release();
}
}
break;
case IDC_COMBO_PRINTER:
break;
case IDOK:
{
HWND hwndPath=GetDlgItem(hDlg, IDC_EDIT_PATH);
GetWindowText(hwndPath,sPath,100);
HWND hwndCombo=GetDlgItem(hDlg, IDC_COMBO_PRINTER);
GetWindowText(hwndCombo,sPrinterNamePhysics,100);
if(sPrinterNamePhysics[0]==0)
{
SendMessage(hwndCombo, LB_GETTEXT,
SendMessage(hwndCombo, LB_GETCURSEL, 0, 0),
(LPARAM) sPrinterNamePhysics);
}
OnOK();
}
break;
case IDCANCEL:
OnCancel();
}
}
void CDialogPathAndPrinter::OnInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
DWORD dwSizeNeeded;
DWORD dwNumItems;
DWORD dwItem;
LPPRINTER_INFO_2 lpInfo = NULL;
// TCHAR s[1000];
// Get buffer size
EnumPrinters ( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &dwSizeNeeded, &dwNumItems );
// Error(formatLastError(s));
// allocate memory
lpInfo = (LPPRINTER_INFO_2)HeapAlloc ( GetProcessHeap (), HEAP_ZERO_MEMORY, dwSizeNeeded );
if ( lpInfo == NULL )
{
Error(_T("无法为枚举打印机分配内存,枚举失败"));
return ;
}
if ( EnumPrinters ( PRINTER_ENUM_LOCAL, // what to enumerate
NULL, // printer name (NULL for all)
2, // level
(LPBYTE)lpInfo, // buffer
dwSizeNeeded, // size of buffer
&dwSizeNeeded, // returns size
&dwNumItems // return num. items
) == 0 )
{
// free memory
HeapFree ( GetProcessHeap (), 0, lpInfo );
return ;
}
HWND hwndCombo=GetDlgItem(m_hWnd, IDC_COMBO_PRINTER);
if(hwndCombo!=NULL&&dwNumItems>0)
{
SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);
// display printers
for ( dwItem = 0; dwItem < dwNumItems; dwItem++ )
{
SendMessage(hwndCombo, CB_ADDSTRING,
0, (LPARAM) lpInfo[dwItem].pPrinterName);
}
SendMessage(hwndCombo, WM_SETTEXT, 0, (LPARAM) lpInfo[0].pPrinterName);
}
// free memory
HeapFree ( GetProcessHeap (), 0, lpInfo );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -