系统:Shell和GDI Thread和杂项等

Q如何判断是文件,还是目录?急!! 
T请各位高手指教,在c 语言中,用程序怎样判断要操作的是一个目录还是一个文件?
在c语言中要调用api函数时许包含什么头文件?
具体要用到什么函数请多多帮忙!!谢谢!!
APathIsDirectory
#include <shlwapi.h>
Q用程序怎么打印一个Word或者RTF文档啊? 
T比如有C:/a.rtf
我怎么可以把它送到打印机打出来呢?
AShellExecute C:/a.rtf with print command
Q继续昨天的有关任务管理器的问题!
T1、我现在用EnumProcess()、EnumProcessModules()和GetModuleBaseName()这几个函数来获得进程名称,出现问题:pid为0和8的两个进程得不到HMODULE(值为0)。怎样能得到该进程名称?

2、用如下方法判断进程是否是窗口出现偏差
 if (!m_bVisible || (GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)) {
  DWORD pidwin;
  GetWindowThreadProcessId(hwnd, &pidwin);
  if (pidwin==m_pid)
   return TRUE;
有时候得不到所有的应用程序。
然后用GetWindowText()获得不了explorer应用程序的窗口名称。为什么?

3、用如下方法结束explorer进程会弹出关机画面,为什么?
//
// Kill a process cleanly: Close main windows and wait.
// bZap=TRUE to force kill.
//
BOOL CEnumKillProcess::KillProcess(DWORD pid, BOOL bZap)
{
 CMainWindowIterator itw(pid);
 for (HWND hwnd=itw.First(); hwnd; hwnd=itw.Next()) {
  DWORD bOKToKill = FALSE;
  SendMessageTimeout(hwnd, WM_QUERYENDSESSION, 0, 0,
   SMTO_ABORTIFHUNG|SMTO_NOTIMEOUTIFNOTHUNG, 100, &bOKToKill);
  if (!bOKToKill)
   return FALSE;  // window doesn't want to die: abort
  PostMessage(hwnd, WM_CLOSE, 0, 0);
 }

 // I've closed the main windows; now wait for process to die.
 BOOL bKilled = TRUE;
 HANDLE hp=OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE,FALSE,pid);
 if (hp) {
  if (WaitForSingleObject(hp, 5000) != WAIT_OBJECT_0) {
   if (bZap) { // didn't die: force kill it if zap requested
    TerminateProcess(hp,0);
   } else {
    bKilled = FALSE;
   }
  }
  CloseHandle(hp);
 }else
  bKilled = FALSE;

 return bKilled;
}

A现在http://expert.csdn.net/Expert/topic/1113/1113085.xml
使用了两种方式来枚举进程……toolhelp和WTS
http://msdn.microsoft.com/msdnmag/issues/02/06/debug/default.aspx
两种都有
Q想要一个能像压下CTRL+ALT+DEL后出现的效果一样的对话框!!
T我想做一个对话框,当它起动的时候要达到的效果是:像2000里按CTRL+ALT+DEL一样,窗口最下面的工具栏没有了,桌面上的东东也不见了。后者还好做一点,前者,把工具栏搞没了,这还得请各位老师指点指点,谢谢!!

(BTW:我不是想要对话框,而是想知道怎么能实现把工具栏隐藏!对了,我要隐藏工具栏,不是简单的隐藏,而是说一些功能键也失去做用,如WINDOW键,WINDOW+D,WINDOW+E键等!能做到吗?)
A看这里
http://expert.csdn.net/Expert/TopicView1.asp?id=1113085
要调用那个对话框,广播一个WM_HOTKEY就可以
Q请教关于MFC扩展Dll导出类碰到的一些问题?????? 
T我有一个工程要做十几个dll载入到主程序中,而且要求导出整个类,我采用了MFC扩展Dll导出类的方法,首先碰到了一个问题,工程要求导出的类可以被RUNTIME_CLASS宏转换,然后提供给主程序(因为dll中要导出的类都是派生于CFormView的类),我试了半天,只好采用主程序中新建一个类A,然后类A继承dll中导出的类B,接着类A就可以被RUNTIME_CLASS宏转换,可是采用这种方法有下述问题无法解决:
1主程序需要包含dll导出类的头文件,这样我今后更改某一个dll岂不是要重新编译整个主程序?那么做dll还有什么意义?
2最头疼的是这个问题,十几个dll每一个都有自己的资源文件,由于我采用继承的方法,再加上每个类的资源文件经常同时出现,因此无法使用AfxSetResourceHandle()函数在适当的时候让系统指向适当的资源,所以就要求主程序和十几个dll的资源文件中的资源ID不能重名,不能相同(如果资源ID重名或相同会造成错误),而要想做到主程序和十几个dll的资源文件中的资源ID不重名,不相同在多人开发时几乎是不可能的,我又想让主程序和十几个dll使用相同的Resource.h和/res目录下的内容,可发现vc中对于每一个工程在用资源编辑器时编辑时总是操作该工程目录下的Resource.h,导致开发极不方便,所以我想大型工程一定不是这样做的,另外我记得以前看过一个工程成功的解决了上述问题,可惜我没仔细看,记不清了,请问谁知道该如何解决?谢谢
A1 use com(use com interfaces instead of classes)
2 build a resource only dll which contains all resources in all projects,or call AfxSetResourceHandle before and after the dll load internal resources

class CLocalRes 
{
public:
 CLocalRes();
 virtual ~CLocalRes();
protected:
 HINSTANCE m_hOldRes;
};
CLocalRes::CLocalRes()
{
 m_hOldRes=AfxGetResourceHandle();
 HINSTANCE hRes=AfxGetInstanceHandle();
 if(hRes)
  ::AfxSetResourceHandle(hRes);
}

CLocalRes::~CLocalRes()
{
 if(m_hOldRes)
  ::AfxSetResourceHandle(m_hOldRes);
}
construct this object just binternal resourcesefore u use internal resources,and destruct it just after done useing
Q怎样获得当前桌面变化的部分
T并将它保存到一个位图中  类似vncview的效果!
Avnc的原理是捕获可能造成窗口内容变化的消息,比如WM_PAINT,WM_KEYDOWN,WM_CONTEXTMENU之类,用了很多机制(比如copyrect,窗口位置监测之类)来查找可能的窗口内容变化,另外它可以假定活动窗口总是有变化。这样处理对大多数应用程序基本没有问题,但是它可能会漏过一些自发的窗口内容变化(例如编辑控件的闪烁光标,视频播放窗口,或者DirectX游戏)。
Q如何获取局域网内远程计算机硬盘的分区,以及如何得到具体分区的大小/使用情况。 高分 
T如何获取局域网内远程机器硬盘分区,以及如何得到具体分区的的 字节数/已使用字节数。

我想应该是有办法可以得到的,因为我用Win2000自带的性能查看器时,当选择远程机器的physical disk这个对象时,是可以看到远程机器有几个盘的,但就是不知道VC中如何得到,另外也不知道如何得到这些盘的使用情况。
AWMI啊,不过要有权线
http://www.codeproject.com/useritems/WMI.asp?target=wmi
MSDN Home >  MSDN Library >  SDK Documentation >  Using WMI >  Supporting Features for WMI >  Managing Objects on a Network
http://www.codeguru.com/system/WMI_using.html
说错了,应该是Win32_LogicalDisk对象
和Win32_DiskPartition对象
也有-2147024891的错误……原因可能和安全设置有关,你看看连98行不行……
Q字符串的使用!! 求救!!太难!! 
T已知
CString csClassName;//值为CMyClass

如何使用csClassName生成一个 CMyClass的对象?
A// This example creates an object if CMyClass is defined.
//first need a CRuntimeClass object
CRuntimeClass* pMyRTClass= pMyObject->GetRuntimeClass();

CRuntimeClass* pClass = pMyRTClass->FromName("CMyClass");
if (pClass == NULL)
{
  // not found, display a warning for diagnostic purposes
  AfxMessageBox("Warning: CMyClass not defined");
  return NULL;
}

// attempt to create the object with the found CRuntimeClass
CObject* pObject = pClass->CreateObject();
Q请问:从HBITMAP我们可以获取哪些关于位图的信息?
T能不能根据HBITMAP取得BITMAPINFO?
我用loadImage从位图文件中获得了一个HBITMAP
想查看其颜色表RGBQUAD,但是怎么得到BITMAPINFO呢?
另外,HBITMAP指向的是设备相关的还是设备无关的?

HBITMAP中应该包括颜色表才对呀,因为当我要在一个dc上显示位图时,只需要提供HBITMAP就行了,没有告诉把颜色表传给啊

HTIBMAP中到底包含关于一个bitmap的哪些信息?
APBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp)
{
    BITMAP bmp;
    PBITMAPINFO pbmi;
    WORD    cClrBits;

    // Retrieve the bitmap color format, width, and height.
    if (!GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp))
        errhandler("GetObject", hwnd);

    // Convert the color format to a count of bits.
    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);
    if (cClrBits == 1)
        cClrBits = 1;
    else if (cClrBits <= 4)
        cClrBits = 4;
    else if (cClrBits <= 8)
        cClrBits = 8;
    else if (cClrBits <= 16)
        cClrBits = 16;
    else if (cClrBits <= 24)
        cClrBits = 24;
    else cClrBits = 32;

    // Allocate memory for the BITMAPINFO structure. (This structure
    // contains a BITMAPINFOHEADER structure and an array of RGBQUAD
    // data structures.)

     if (cClrBits != 24)
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
                    sizeof(BITMAPINFOHEADER) +
                    sizeof(RGBQUAD) * (1<< cClrBits));

     // There is no RGBQUAD array for the 24-bit-per-pixel format.

     else
         pbmi = (PBITMAPINFO) LocalAlloc(LPTR,
                    sizeof(BITMAPINFOHEADER));

    // Initialize the fields in the BITMAPINFO structure.

    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    pbmi->bmiHeader.biWidth = bmp.bmWidth;
    pbmi->bmiHeader.biHeight = bmp.bmHeight;
    pbmi->bmiHeader.biPlanes = bmp.bmPlanes;
    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;
    if (cClrBits < 24)
        pbmi->bmiHeader.biClrUsed = (1<<cClrBits);

    // If the bitmap is not compressed, set the BI_RGB flag.
    pbmi->bmiHeader.biCompression = BI_RGB;

    // Compute the number of bytes in the array of color
    // indices and store the result in biSizeImage.
    // For Windows NT, the width must be DWORD aligned unless
    // the bitmap is RLE compressed. This example shows this.
    // For Windows 95/98/Me, the width must be WORD aligned unless the
    // bitmap is RLE compressed.
    pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits +31) & ~31) /8
                                  * pbmi->bmiHeader.biHeight;
    // Set biClrImportant to 0, indicating that all of the
    // device colors are important.
     pbmi->bmiHeader.biClrImportant = 0;
     return pbmi;
 }
The following example code defines a function that initializes the remaining structures, retrieves the array of palette indices, opens the file, copies the data, and closes the file.

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
                  HBITMAP hBMP, HDC hDC)
 {
     HANDLE hf;                 // file handle
    BITMAPFILEHEADER hdr;       // bitmap file-header
    PBITMAPINFOHEADER pbih;     // bitmap info-header
    LPBYTE lpBits;              // memory pointer
    DWORD dwTotal;              // total count of bytes
    DWORD cb;                   // incremental count of bytes
    BYTE *hp;                   // byte pointer
    DWORD dwTmp;

    pbih = (PBITMAPINFOHEADER) pbi;
    lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, pbih->biSizeImage);

    if (!lpBits)
         errhandler("GlobalAlloc", hwnd);

    // Retrieve the color table (RGBQUAD array) and the bits
    // (array of palette indices) from the DIB.
    if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
        DIB_RGB_COLORS))
    {
        errhandler("GetDIBits", hwnd);
    }

    // Create the .BMP file.
    hf = CreateFile(pszFile,
                   GENERIC_READ | GENERIC_WRITE,
                   (DWORD) 0,
                    NULL,
                   CREATE_ALWAYS,
                   FILE_ATTRIBUTE_NORMAL,
                   (HANDLE) NULL);
    if (hf == INVALID_HANDLE_VALUE)
        errhandler("CreateFile", hwnd);
    hdr.bfType = 0x4d42;        // 0x42 = "B" 0x4d = "M"
    // Compute the size of the entire file.
    hdr.bfSize = (DWORD) (sizeof(BITMAPFILEHEADER) +
                 pbih->biSize + pbih->biClrUsed
                 * sizeof(RGBQUAD) + pbih->biSizeImage);
    hdr.bfReserved1 = 0;
    hdr.bfReserved2 = 0;

    // Compute the offset to the array of color indices.
    hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
                    pbih->biSize + pbih->biClrUsed
                    * sizeof (RGBQUAD);

    // Copy the BITMAPFILEHEADER into the .BMP file.
    if (!WriteFile(hf, (LPVOID) &hdr, sizeof(BITMAPFILEHEADER),
        (LPDWORD) &dwTmp,  NULL))
    {
       errhandler("WriteFile", hwnd);
    }

    // Copy the BITMAPINFOHEADER and RGBQUAD array into the file.
    if (!WriteFile(hf, (LPVOID) pbih, sizeof(BITMAPINFOHEADER)
                  + pbih->biClrUsed * sizeof (RGBQUAD),
                  (LPDWORD) &dwTmp, ( NULL))
        errhandler("WriteFile", hwnd);

    // Copy the array of color indices into the .BMP file.
    dwTotal = cb = pbih->biSizeImage;
    hp = lpBits;
    if (!WriteFile(hf, (LPSTR) hp, (int) cb, (LPDWORD) &dwTmp,NULL))
           errhandler("WriteFile", hwnd);

    // Close the .BMP file.
     if (!CloseHandle(hf))
           errhandler("CloseHandle", hwnd);

    // Free memory.
    GlobalFree((HGLOBAL)lpBits);
}

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_4v1h.asp
Q在由CreateRemoteThread插入的dll文件中如何截获注销和关机消息?help!如搞定,可另开贴加分!
T在由CreateRemoteThread插入的dll文件中如何截获注销和关机消息?help!如搞定,可另开贴加分!
Aexpert.csdn.net/Expert/topic/1113/1113085.xml
自己看怎么子类化别人的窗体的……

http://expert.csdn.net/Expert/topic/1113/1113085.xml
自己看怎么子类化别人的窗体的……

去看我的代码里面怎么卸载注入的DLL……
Q用vc开发怎么实现 build number? 
T用vc开发怎么实现 build number?

现在很多软件都象 windows 那样除了版本号还有一个 build number。
这个东东还是很不错的,可以让你知道手头的这个exe是不是最新的,
也可以帮助你确定手头的源程序是不是最新的。这对于自己开发特别
有好处。
一般使用 make 系列工具开发都可以用一些脚本程序来修改一个公共
头文件,比如 buildno.h 来设定本次创建的创建号。但是对于用vc
集成开发环境创建的就不行了。以前看到过一个 vc 集成环境的 add-on
可以创建和修改一个 buildno.h 来实现自动 build number,但是用起来
不舒服。
不知道还有没有别的更好的方法?
Ause macro? I wrote one and ported to board CLanguage on http://club.163.com/.

当前位置:网易精华区>>讨论区精华>>编程开发>>● C语言>>编辑、编译、调试与发行>>Macro to set version info(VC6) 

主题:Macro to set version info(VC6)
发信人: jiangsheng()
整理人: wenbobo(2002-12-27 15:59:45), 站内信件 
I have tens of projects in my workspace. It is so boring to update ver
sion info(mainly,the version number) and I wrote this macro to replace
 version info for every project.
Usage:
Input version information,include following:
1.company name.
2.Trademark.
3.Copyright.
4.File Version.
5.Product Version.
Note:if you input an empty string,then no changes are made on correspo
nd version information.
The macro will prompt you if you want the changes applies to all proje
ct. If you select NO, the macro will prompt for every project just bef
ore apply changes.You can stop the macro by clicking "Cancel".
Note: hide wizard bar to skip reloading RC file for better performance
.
Sub SetProjectVersionInfo()
'DESCRIPTION: Set version information in rc script for one or more pro
ject(s) in current workspace .Company Name,Trademark,LegalCopyright,an
d version number.If some information is empty, then no changes are mad
e on correspond version information.
'Created by Jiang Sheng at 2000-6-21 16:48
DIM strCompanyName
DIM strTrademark
DIM strLegalCopyright
DIM strFileVersion
DIM strProductVersion
DIM bAllProject
DIM bApply
DIM nResult
bAllProject=1
Dim oneProject
if Application.Projects.Count =0 then
MsgBox("No project available.")
Exit Sub
end if
strCompanyName= InputBox ("Please input company name:"& Chr(13) & Chr
(10)&"Empty means no changes.","Input Company Name")
strTrademark= InputBox ("Please input legal trademarks:"& Chr(13) & C
hr(10)&"Empty means no changes.","Input Legal Trademarks")
strLegalCopyright= InputBox ("Please input legal copyright:"& Chr(13)
 & Chr(10)&"Empty means no changes.","Input Legal Copyright")
strFileVersion= InputBox ("Please input file version:"& Chr(13) & Chr
(10)&"Empty means no changes."& Chr(13) & Chr(10)& "Version must in x,
x,x,x format.","Input File Version")
strProductVersion= InputBox ("Please input product version:"& Chr(13)
 & Chr(10)&"Empty means no changes."& Chr(13) & Chr(10)& "Version must
 in x,x,x,x format.","Input Product Version")

nResult=MsgBox("Apply changes for all projects?",VbYesNoCancel)
SELECT CASE nResult
case vbYes
bAllProject=1
case vbNo
bAllProject=0
case vbCancel
Exit Sub
End SELECT 
For Each oneProject in Application.Projects
if bAllProject=0 then 
nResult=MsgBox("Apply changes for project "+oneProject.Name+"?",VbY
esNo)
else
bApply=1
end if
SELECT CASE nResult
case vbYes
bApply=1
case vbNo
bApply=0
case vbCancel
Exit Sub
End SELECT 
if bApply then
set ActiveProject=Projects(oneProject.Name)
Dim strTemp
Dim documentObject
' open the project's resource script:

strTemp = ActiveProject.FullName
Wnd = Left(strTemp, Len(strTemp) - 3) + "rc"

Documents.Open (Wnd), "Text"
For Each documentObject in Application.Documents
if documentObject.FullName = Wnd then 
documentObject.Active = True
exit for
end if 
Next

  ' SAVE BACK-UP OF FILE >>>>
ActiveDocument.Save (Wnd+"~")

ActiveDocument.Close() 
Documents.Open Wnd, "Text"
if strCompanyName<>"" then 
ActiveDocument.Selection.FindText "VALUE ""CompanyName"", """, dsM
atchForward + dsMatchFromStart + dsMatchCase
ActiveDocument.Selection.CharRight
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.CharLeft dsExtend, 3 
ActiveDocument.Selection.Text=strCompanyName
end if
if strTrademark<>"" then 
ActiveDocument.Selection.FindText "VALUE ""LegalTrademarks"", """,
 dsMatchForward + dsMatchFromStart + dsMatchCase
ActiveDocument.Selection.CharRight
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.CharLeft dsExtend, 3 
ActiveDocument.Selection.Text=strTrademark
end if
if strLegalCopyright<>"" then 
ActiveDocument.Selection.FindText "VALUE ""LegalCopyright"", """,
dsMatchForward + dsMatchFromStart + dsMatchCase
ActiveDocument.Selection.CharRight
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.CharLeft dsExtend, 3 
ActiveDocument.Selection.Text=strLegalCopyright
end if
if strFileVersion<>"" then 
ActiveDocument.Selection.FindText "FILEVERSION", dsMatchForward +
dsMatchFromStart + dsMatchCase + dsMatchWord
ActiveDocument.Selection.WordRight
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.Text=strFileVersion

ActiveDocument.Selection.FindText "VALUE ""FileVersion"",", dsMatc
hForward + dsMatchFromStart + dsMatchCase  
ActiveDocument.Selection.WordRight dsMove,2
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.CharLeft dsExtend, 3 
ActiveDocument.Selection.Text=strFileVersion
end if

if strProductVersion<>"" then 
ActiveDocument.Selection.FindText "PRODUCTVERSION", dsMatchForward
 + dsMatchFromStart + dsMatchCase + dsMatchWord
ActiveDocument.Selection.WordRight
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.Text=strFileVersion
ActiveDocument.Selection.FindText "VALUE ""ProductVersion"",", dsM
atchForward + dsMatchFromStart + dsMatchCase  
ActiveDocument.Selection.WordRight dsMove,2
ActiveDocument.Selection.EndOfLine dsExtend
ActiveDocument.Selection.CharLeft dsExtend, 3 
ActiveDocument.Selection.Text=strProductVersion
end if
ActiveDocument.Save()
ActiveDocument.Close() 
End if
Next
End Sub

--
HE WHO CONTROLS THE PAST, COMMANDS THE FUTURE.
HE WHO CONTROLS THE FUTURE CONQUERS THE PAST.

※ 来源:.网易虚拟社区 http://club.netease.com.[FROM: 202.96.44.196]
Q请教:CreateProcessAsUser 为什么不能执行? 
TBOOL okay = ::OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,&hToken);
TCHAR pszCmdLine[] = {"d://tt.exe dd dd"};
if(okay)
  okay = ::CreateProcessAsUser(hToken,NULL,pszCmdLine,NULL,NULL,FALSE,
   CREATE_NO_WINDOW,NULL,NULL,&sti,&pi);

运行总是不成功.
谁知道这是为什么?最好有实例.谢谢.
ARunAs Service
在不同凭据下启用启动过程
WINNT/system32/services.exe
http://www.codeguru.com/misc/RunUser.html
Q我要从Windows资源管理器中用鼠标拖曳文件到我的程序的列表框,并不是拷贝文件,而是在列表框中显示文件的大小路径等信息,如何实现? 
T
是不是用到COleDropTarget类,以及 begindrag和enddrag消息,更进一步,不知是资源管理器中的文件,或者拖曳其他类型的数据源到自己程序的列表框中呢
AIf an application can accept dropped files, it must call the DragAcceptFiles function. Once an application registers itself, the user can drag an object from the File Manager onto the application. When the user drops a file, the application receives a WM_DROPFILES message. When the client calls the DragQueryFile function, Windows provides the number and names of the dropped files. The DragQueryPoint function provides the location in the application's window where the user dropped the files.

The recommended procedure to provide drag-drop support in an OLE client application is as follows:


Call the DragAcceptFiles function during application initialization. Specify the handle of a container document window for the hwnd parameter and specify TRUE for the fAccept parameter to indicate that the window will accept dropped files.
When the application receives a WM_DROPFILES message, perform the following five steps:


Call the DragQueryFile function to determine how many files are dropped.
Call the DragQueryFile function to obtain the names of the dropped files.
Call the OleCreateFromFile function once for each dropped file to create a package for each dropped file. Specify "Package" as the object class for each new object.
Check the value returned from OleCreateFromFile and act accordingly.
Call the DragFinish function to free the memory used to store the names of the dropped files.
The Code to insert a drag-drop object in an application might resemble the following:
char       szFile[80];      // Used to store name of dropped file
OLESTATUS  OleStatus;       // Code returned from OLE functions
WORD       wNumFiles, cb;

case WM_DROPFILES:
   // Retrieve number of dropped files
   wNumFiles = DragQueryFile((HANDLE)wParam, 0xFFFF, NULL, 0);

   // Simple case of one dropped file; more than one can be dropped
   if (wNumFiles == 1)
      {
      cb = DragQueryFile((HANDLE)wParam, 0, szFile, 80);

      // If no characters copied, there were no files
      if (cb == 0)
         return(0L);

      // Call OleCreateFromFile to insert a Package object containing
      // the dropped file as an embedded object or call
      // OleCreateLinkFromFile to insert a Package object containing a
      // link to the dropped file.
      OleStatus = OleCreateFromFile("StdFileEditing", lpOleClient,
         "Package", (LPSTR)szFile, lhDoc, lpszUniqueName, lplpObject,
         olerender_draw, 0);

      // Follow the procedure to create an object from the clipboard

      DragFinish((HANDLE)wParam);
      }

The following seven steps demonstrate how to implement drag-drop in an edit control. The procedure to implement drag-drop in a combo box is identical.
Add SHELL.LIB to the list of libraries required to build the file.
Add the name of the subclass procedure (MyDragDropProc) to the EXPORTS section of the module definition (DEF) file.
Include the SHELLAPI.H file in the application's source code.
Declare the following procedure and variables:
      BOOL FAR PASCAL MyDragDropProc(HWND, unsigned, WORD, LONG);

      FARPROC lpfnDragDropProc, lpfnOldEditProc;
      char    szTemp64[64];
    
Add the following code to the initialization of the dialog box:
      case WM_INITDIALOG:
         // ... other code

         // ------- edit control section --------
         hWndTemp = GetDlgItem(hDlg, IDD_EDITCONTROL);
         DragAcceptFiles(hWndTemp, TRUE);

         // subclass the drag-drop edit control
         lpfnDragDropProc = MakeProcInstance(MyDragDropProc, hInst);

         if (lpfnDragDropProc)
            lpfnOldEditProc = SetWindowLong(hWndTemp, GWL_WNDPROC,
                  (DWORD)(FARPROC)lpfnDragDropProc);
         break;
    
Write a subclass window procedure for the edit control.
      BOOL FAR PASCAL MyDragDropProc(HWND hWnd, unsigned message,
                                     WORD wParam, LONG lParam)
      {
         int wFilesDropped;

         switch (message)
            {
         case WM_DROPFILES:
            // Retrieve number of files dropped
            // To retrieve all files, set iFile parameter
            // to -1 instead of 0
            wFilesDropped = DragQueryFile((HDROP)wParam, 0,
                  (LPSTR)szTemp64, 63);

            if (wFilesDropped)
               {
               // Parse the file path here, if desired
               SendMessage(hWnd, WM_SETTEXT, 0, (LPSTR)szTemp64);
               }
            else
               MessageBeep(0);

            DragFinish((HDROP)wParam);
            break;

         default:
            return CallWindowProc(lpfnOldEditProc, hWnd, message,
                  wParam, lParam);
            break;
         }
         return TRUE;
      }
    
After the completion of the dialog box procedure, free the edit control subclass procedure.
      if (lpfnDragDropProc)
         FreeProcInstance(lpfnDragDropProc);
To retrieve the dropped file names from a drop source, modify the sample code included with 135299, "SAMPLE: Using MFC OLE Drag & Drop to Drag Text Between Windows" as follows:
Sample Code
   // OnDrop is called by OLE DLLs when an item is dropped in a window
   // that is registered with the OLE DLLs.
   //
   BOOL COleEditDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject,
      DROPEFFECT dropEffect, CPoint point )
   {
    HGLOBAL  hGlobal;
    LPCSTR   pData;

    FORMATETC fmtetc =
   { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
    STGMEDIUM stgmed;
    TCHAR szFileName[_MAX_PATH + 1];

    if(pDataObject->GetData(CF_HDROP, &stgmed, &fmtetc))
    {
        HDROP hdrop = (HDROP)GlobalLock(stgmed.hGlobal);

        if (NULL != hdrop)
        {
            UINT nFiles = DragQueryFile(hdrop, (UINT)-1, NULL, 0);

            for(UINT nNames = 0; nNames < nFiles; nNames++)
            {
                ZeroMemory(szFileName, _MAX_PATH + 1);
                DragQueryFile
                    (hdrop, nNames, (LPTSTR)szFileName, _MAX_PATH + 1);
                // Do something with szFileName.
            }
            GlobalUnlock(hdrop);

        }
        ReleaseStgMedium(&stgmed);
      return TRUE;

    } else {

   // Get text data from ColeDataObject.
   hGlobal=pDataObject->GetGlobalData(CF_TEXT);

   // Get a pointer to data.
   pData=(LPCSTR)GlobalLock(hGlobal);
   ASSERT(pData!=NULL);

   // Set text in the dropped window.
   ((CEdit*)pWnd)->SetWindowText(pData);

   // Unlock memory.
   GlobalUnlock(hGlobal);

   return TRUE;
   }
   }


Q请问高手:如何将file:///c:/aa.txt转换成c:/aa.txt 
T是不是在vc中有函数将file:///c:/aa.txt转换成c:/aa.txt
              或者将c:/aa.txt转换成file:///c:/aa.txt
是否还有其它方法。
A#define  UrlIsFileUrlA(pszURL) UrlIsA(pszURL, URLIS_FILEURL)
#define  UrlIsFileUrlW(pszURL) UrlIsW(pszURL, URLIS_FILEURL)
UrlGetPart
Q如何将EMF格式的图片转化为BMP格式
T 
A#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
   UINT  num = 0;          // number of image encoders
   UINT  size = 0;         // size of the image encoder array in bytes

   ImageCodecInfo* pImageCodecInfo = NULL;

   GetImageEncodersSize(&num, &size);
   if(size == 0)
      return -1;  // Failure

   pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
   if(pImageCodecInfo == NULL)
      return -1;  // Failure

   GetImageEncoders(num, size, pImageCodecInfo);

   for(UINT j = 0; j < num; ++j)
   {
      if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
      {
         *pClsid = pImageCodecInfo[j].Clsid;
         free(pImageCodecInfo);
         return j;  // Success
      }   
   }

   free(pImageCodecInfo);
   return -1;  // Failure
}


INT main()
{
   // Initialize GDI+.
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   CLSID   encoderClsid;
   Status  stat;
   Image*   image = new Image(L"Bird.emf");

   // Get the CLSID of the BMP encoder.
   GetEncoderClsid(L"image/bmp", &encoderClsid);

   stat = image->Save(L"Bird.bmp", &encoderClsid, NULL);

   if(stat == Ok)
      printf("Bird.bmpwas saved successfully/n");
   else
      printf("Failure: stat = %d/n", stat);

   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}

Q如何用程序控制一个文件夹的访问权限? 
T
win2000Server系统,通过程序动态建立新文件夹,然后根据需要自动设置这个新文件夹的访问权限。
现在我遇到的问题就是如何通过程序对文件夹的访问权限进行控制。
ASP、VB、API、COM都可以考虑。
请问各位大仙如何解决?
小弟是VC的门外汉,所以不求各位给源代码,自需要给个API说明之类的冬冬。
A
А все оказалось очень просто. Вот примерный код:
BOOL My_SetFolderSecurity(WCHAR* szPath)
{
SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
PSID pSidSystem = NULL;
PSID pSidAdmins = NULL;
PSID pSidWorld = NULL;
PACL pDacl = NULL;
EXPLICIT_ACCESS ea[4];
SECURITY_DESCRIPTOR SecDesc;

ULONG lRes = ERROR_SUCCESS;

__try
{
// create SYSTEM SID
if (!AllocateAndInitializeSid(&sia, 1, SECURITY_LOCAL_SYSTEM_RID,
0, 0, 0, 0, 0, 0, 0, &pSidSystem))
{
lRes = GetLastError();
__leave;
}

// create Local Administrators alias SID
if (!AllocateAndInitializeSid(&sia, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0,
0, 0, &pSidAdmins))
{
lRes = GetLastError();
__leave;
}


// create Authenticated users well-known group SID
if (!AllocateAndInitializeSid(&sia, 1, SECURITY_AUTHENTICATED_USER_RID,
0, 0, 0, 0, 0, 0, 0, &pSidWorld))
{
lRes = GetLastError();
__leave;
}

// fill an entry for the SYSTEM account
ea[0].grfAccessMode = GRANT_ACCESS;
ea[0].grfAccessPermissions = FILE_ALL_ACCESS;
ea[0].grfInheritance = OBJECT_INHERIT_ACE|CONTAINER_INHERIT_ACE;
ea[0].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
ea[0].Trustee.pMultipleTrustee = NULL;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR)pSidSystem;

// fill an entry entries for the Administrators alias
ea[1].grfAccessMode = GRANT_ACCESS;
ea[1].grfAccessPermissions = FILE_ALL_ACCESS;
ea[1].grfInheritance = OBJECT_INHERIT_ACE|CONTAINER_INHERIT_ACE;
ea[1].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
ea[1].Trustee.pMultipleTrustee = NULL;
ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[1].Trustee.TrusteeType = TRUSTEE_IS_ALIAS;
ea[1].Trustee.ptstrName = (LPTSTR)pSidAdmins;

// fill an entry for the Authenticated users well-known group
ea[2].grfAccessMode = GRANT_ACCESS;
ea[2].grfAccessPermissions = FILE_GENERIC_READ|FILE_GENERIC_WRITE ;
ea[2].grfInheritance = OBJECT_INHERIT_ACE|CONTAINER_INHERIT_ACE;
ea[2].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
ea[2].Trustee.pMultipleTrustee = NULL;
ea[2].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[2].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[2].Trustee.ptstrName = (LPTSTR)pSidWorld;


// create a DACL
lRes = SetEntriesInAcl(3, ea, NULL, &pDacl);
if (lRes != ERROR_SUCCESS)
__leave;

// initialize security descriptor
if(!InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
__leave ;

if(!SetSecurityDescriptorDacl(&SecDesc, TRUE, pDacl, FALSE))
__leave ;

// assign security descriptor to the key
//lRes = RegSetKeySecurity(hKey, DACL_SECURITY_INFORMATION, &SecDesc);

lRes = SR_SetFileSecurityRecursive(szPath, DACL_SECURITY_INFORMATION, &SecDesc);
//lRes = SetFileSecurity(szPath, DACL_SECURITY_INFORMATION, &SecDesc);


}
__finally
{
if (pSidSystem != NULL)
FreeSid(pSidSystem);
if (pSidAdmins != NULL)
FreeSid(pSidAdmins);
if (pSidWorld != NULL)
FreeSid(pSidWorld);
if (pDacl != NULL)
LocalFree((HLOCAL)pDacl);
}

SetLastError(lRes);
return lRes != ERROR_SUCCESS;
}



Command what is yours
Conquer what is not

Q   如何在屏幕拷贝的时候把鼠标光标也拷贝进去? 
T在得到屏幕DC之后,使用BitBlt函数,并不能把鼠标拷贝进去。
请问如何才能解决这个问题?
A
LPBITMAPINFOHEADER captureScreenFrame(int left,int top,int width, int height,int tempDisableRect)
{
#ifndef _DIRECTX_captureScreenFrame
 HDC hScreenDC = ::GetDC(NULL);
#else
 theApp.DirectXInit();
#endif
 
 //if flashing rect
 if (flashingRect && !tempDisableRect) {

  if (autopan) {   
     
   pFrame->SetUpRegion(left,top,width,height,1);   
   DrawFlashingRect( TRUE , 1);  

  }
  else 
   DrawFlashingRect( TRUE , 0);

 }
 
#ifndef _DIRECTX_captureScreenFrame
 HDC hMemDC = ::CreateCompatibleDC(hScreenDC);    
 HBITMAP hbm;
 
    hbm = CreateCompatibleBitmap(hScreenDC, width, height);
 HBITMAP oldbm = (HBITMAP) SelectObject(hMemDC, hbm); 
 BitBlt(hMemDC, 0, 0, width, height, hScreenDC, left, top, SRCCOPY);  
#else
 theApp.DirectXCapture(left, top,width, height);
 HDC hMemDC = NULL;
 theApp.DirectXGetDC(hMemDC);
#endif
 
 //Get Cursor Pos
 POINT xPoint;
 GetCursorPos( &xPoint );
 HCURSOR hcur= FetchCursorHandle();
 xPoint.x-=left;
 xPoint.y-=top;

 
 //Draw the HighLight
 if (g_highlightcursor==1) {

  POINT highlightPoint;  

  highlightPoint.x = xPoint.x -64 ;
  highlightPoint.y = xPoint.y -64 ; 
 
  InsertHighLight( hMemDC, highlightPoint.x, highlightPoint.y);

 }
 
 //Draw the Cursor
 if (g_recordcursor==1) {
 
 
 
  ICONINFO iconinfo ;
  BOOL ret;
  ret = GetIconInfo( hcur,  &iconinfo );
  if (ret) {

   xPoint.x -= iconinfo.xHotspot;
   xPoint.y -= iconinfo.yHotspot;

   //need to delete the hbmMask and hbmColor bitmaps
   //otherwise the program will crash after a while after running out of resource
   if (iconinfo.hbmMask) DeleteObject(iconinfo.hbmMask);
   if (iconinfo.hbmColor) DeleteObject(iconinfo.hbmColor);

  } 
 
 
  ::DrawIcon( hMemDC,  xPoint.x,  xPoint.y, hcur);       

 }
 //CString strText=COleDateTime::GetCurrentTime().Format();
 //CRect rc(0,0,640,480);
    //DrawText(hMemDC,strText,-1,&rc,DT_LEFT);
#ifndef _DIRECTX_captureScreenFrame 
 SelectObject(hMemDC,oldbm);    
 LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, bits));
 //LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(Bitmap2Dib(hbm, 24));
#else
 theApp.DirectXReleaseDC(hMemDC);
 LPBITMAPINFOHEADER pBM_HEADER = (LPBITMAPINFOHEADER)GlobalLock(theApp.DirectXGetCaptureBitmap(bits));
#endif
 if (pBM_HEADER == NULL) {
  
  //MessageBox(NULL,"Error reading a frame!","Error",MB_OK | MB_ICONEXCLAMATION);    
  AfxMessageBox(IDS_CAPTURE_FAIL);
  AfxPostQuitMessage(0);
  //exit(1);
 }   
#ifndef _DIRECTX_captureScreenFrame 
 DeleteObject(hbm);  
 DeleteDC(hMemDC);
#endif
 //if flashing rect
 if (flashingRect && !tempDisableRect) {
 
  if (autopan) {
   DrawFlashingRect(FALSE , 1);
  }
  else
   DrawFlashingRect(FALSE , 0);

 }
#ifndef _DIRECTX_captureScreenFrame 
 ReleaseDC(NULL,hScreenDC) ;
#else
 theApp.DirectXUninit();
#endif
 return pBM_HEADER;   
}

Command what is yours
Conquer what i
Qjiangsheng、BCB_FANS(四大名捕之追杀令)请进!
T截取SAS Window的hotkey后,怎么让dll通知消息给应用程序桌面的主窗口呢?难道又注入dll来查找当前的主窗口吗?
A简单的通知可以用命名事件,复杂的就要加上命名的共享内存
注意创建共享内存的时候要指定其他用户可以访问这个内存,默认只有管理员和创建者可以访问
Q如何在dialog程序中。
T实现mdi中的enableshellopen功能。即双击文件图标可以运行程序并且读出文件。
A
Q 
I wrote a dialog-based application and I'm able to open an associated file when the user double-clicks a file in Windows&reg; Explorer. However, each time the user double-clicks a new file, Windows starts a new instance of my app. I know how to make sure my application only runs one instance, but how do I tell the sole instance the name of the file to open?
Hafeez JafferA 
The official way to handle this is to use Dynamic Data Exchange (DDE), which is a general-purpose interprocess communication mechanism that lets an application send a command such as open the document foo.txt to another application. You may already have noticed that some apps have registry entries like
HKCR/foofile/shell/open/ddeexec = Open("%1")

 
which tell Windows to send the DDE Open command with the file name as an argument to the running instance when the user double-clicks a .foo file. I won't go into DDE details here (read the docs), except to say that MFC has functions OnDDEInitiate, OnDDEExecute, and so on to support DDE. Unfortunately, these functions belong to CFrameWnd, which doesn't help if you have a dialog-based app where your main window derives from CDialog.
      Well, never fear. You don't really need DDE to implement the only-one-instance behavior. You can do it easily enough yourself. You just need a way to find the other running instance and a way to make it open a new file. I encapsulated both capabilities into a class called COneInstance (see Figure 4). COneInstance works in any kind of app that has a main window, whether it is derived from CFrameWnd or CDialog. To demonstrate this, I wrote two test apps: MyEdit (a frame-based text editor) and Dlg1Inst (a dialog-based app). You can download both apps from the link at the top of this article.
      To use COneInstance, you must do three things: instantiate, initialize, and then call the object from your app's InitInstance function. Since you only need one COneInstance object for the entire app, and since COneInstance works through your app's main window, it's best to instantiate it is as a global (static) member of your main window class. For example:
// in mainfrm.h
class CMainFrame : public CFrameWnd {
public:
  static COneInstance OnlyInstance;
};

 
      The reason for making OnlyInstance static is that you need to call it before CMainFrame has been created, as you'll soon see. When you instantiate COneInstance, you must supply two arguments: the name of your main window class and an integer message ID different from any other WM_ message ID your main window uses. I call this the ident message. For MyEdit, it looks like the following:
// in mainfrm.cpp
static LPCTSTR MYCLASSNAME = _T("MyEditApp10");
const WM_MAINFRM_ISME = RegisterWindowMessage
  ("WM_MyEditApp10_IsMe");
COneInstance CMainFrame::OnlyInstance
  (MYCLASSNAME, WM_MAINFRM_ISME);

 
      The window class name is MyEditApp10 and the ident message ID is WM_MAINFRM_ISME. Note that you must modify your main window's PreCreateWindow function to register and use MYCLASSNAME. (Oops, I guess there are four things you have to do.) COneInstance uses the class name and ident message to find other instances of your app.
CWnd* COneInstance::FindOtherInstance() const
{
  CWnd* pWnd = CWnd::FindWindow(m_sClassName, NULL);
  return (pWnd && pWnd->SendMessage(m_iIdentMsg)) ? pWnd : NULL;
}

 
      FindWindow finds the other window with the same class name as yours and, to ensure it really is yours, sends the special ident message looking for a TRUE response. COneInstance handles the message itself, so you don't have to do anything to make this part work, except supply the message ID.
LRESULT COneInstance::WindowProc(...)
{
  if (msg==m_iIdentMsg)
    return 1;
  return CSubclassWnd::WindowProc(...);
}

 
      If some other window happened to have the same class name as yours, it still wouldn't handle m_iIdentMsg (in this case WM_ MAINFRM_ISME), so its WindowProc would return zero. Of course, you must remember to hook up the COneInstance object after your main window is created—that's step number two.
int CMainFrame::OnCreate(...)
{
&#8226;&#8226;&#8226;
  OnlyInstance.Init(this);
  return 0;
}

 
      For a dialog, the place to call Init is OnInitDialog. Whatever! Once you've instantiated your COneIn-stance object and called Init, you're ready to invoke it. All you need is few lines in your app's InitInstance function.
// standard MFC
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// do only-one-instance behavior
if (CMainFrame::OnlyInstance.
  OpenOtherInstance(cmdInfo.m_strFileName))
    return FALSE; // exit this instance

 
      OpenOtherInstance does everything you want: if no other instance is running, it returns NULL and control flows through the rest of InitInstance. If there is another instance, OpenOtherInstance tells it to open the new file and activates the window (there's an optional argument to prevent activation). My sample code assumes the file name is the first argument on the command line, which MFC parses for you into cmdInfo.m_strFileName.
      I've already shown you how COneInstance uses FindWindow and the ident message to find the other instance of your app, but how does it make this instance open a new file? The obvious thing would be to have another WM_ message and pass the file name as LPARAM—except for just one little problem: you can't pass a pointer from one process to another; it has no meaning in the other address space.
      Fortunately, Windows has just the message for passing a string from one app to another: WM_COPYDATA. You fill out a little struct called—what else?—a COPYDATASTRUCT and pass it as LPARAM. Windows copies your data into the other process's address space and, presto, it can read the string. Once again, COneInstance handles WM_COPYDATA so you don't have to.
LRESULT COneInstance::WindowProc(...)
{
  if (msg==WM_COPYDATA) {
    CString sFileName =
      // get from COPYDATASTRUCT
    AfxGetApp()->OpenDocumentFile(sFileName);
    return TRUE; // handled
  }
  return CSubclassWnd::WindowProc(...);
}

 
      This is fine and dandy, but what happens if you're already using WM_COPYDATA for something else? WM_COPYDATA lets you specify a code in the COPYDATASTRUCT. You can use different codes to disambiguate different types of WM_COPYDATA messages. COneInstance has an optional third constructor argument I didn't tell you about, the WM_COPYDATA code to use.
      So far I've been assuming you have a frame-based app. For your dialog-based app there are two other tricks you need to know. First, you need the window class name. Quick—what's the window class name for a dialog? (This would be a good question for the Windows edition of Trivial Pursuit.) Answer: It's #32770. All dialogs have this class name. That's why COneInstance needs the ident message—to distinguish your dialog from others that could be running.
      Dialog trick number two: you have to override CWinApp:: OpenDocumentFile to open the new file. Normally, this function works only in doc/view apps; if you call it in a dialog-based app, you'll have a major boo-boo. In my sample Dlg1Inst app, I overrode OpenDocumentFile like so:
CDocument* CMyApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
  CString s;
  s.Format("My Dialog: %s",lpszFileName);
  m_pMainWnd->SetWindowText(s);
  return NULL;
}

 
My implementation just sets the caption to show the name of the currently open file. In a real application, you would actually do something useful.
      Now, there is just one little bug in my implementation of COneInstance as I've presented it. I have no doubt that astute readers have already anticipated the problem. Can you guess? Hint: what if there's some other dialog running that's not an instance of your app? For the answer, you'll have to read the source—or download it from the link at the top of this article. Ciao!


 

--------------------------------------------------------------------------------
Paul DiLascia is the author of Windows++: Writing Reusable Windows Code in C++ (Addison-Wesley, 1992) and a freelance consultant and writer-at-large. He can be reached at askpd@pobox.com or http://www.dilascia.com.
 

Q如何对一WMV文件切换声道
T我可以对VCD、MPEG等MPEG1格式的文件切换声道(不是音道),但是不能对MPEG4格式的WMV文件进行左右声道切换。
AWMV文件里面一般只有一个音频流啊
可以读取WMV的文件头来获得文件信息
http://www.blogcn.com/user3/jiangsheng/main.asp?id=280152
http://www.blogcn.com/user3/jiangsheng/main.asp?id=283404
Q有哪位大虾知道发送超文本的原理和方法
T有哪位大虾知道发送超文本的原理和方法,或者能提供有关资料的链接?
A
CDO for Windows 2000
CreateMHTMLBody Method
The CreateMHTMLBody method converts the contents of an entire Web page into a MIME Encapsulation of Aggregate HTML Documents (MHTML) formatted message body.
Example
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg  as New CDO.Message
Dim iConf as New CDO.Configuration
Dim Flds  as ADODB.Fields
Set Flds = iConf.Fields
Flds(cdoURLProxyServer)      = "myserver:80"
Flds(cdoURLProxyBypass)      = "<local>"
Flds(cdoURLGetLatestVersion) = True
Flds.Update

With iMsg
   Set .Configuration = iConf
   .CreateMHTMLBody "http://InternalNTLMAuthRequiredServer", _
                    "domain/username", _
                    "password"
   .To      = "MyCustomer@microsoft.com"
   .From    = "me@microsoft.com"
   .Subject = "an example mhtml formatted message with attachment"
   .AddAttachment "http://www.microsoft.com"
   .Send
End With

Qwaterpig:还是那个问题,我已经发了三次贴不能发了,问题如下:
Twaterpig:还是那个问题,我已经发了三次贴不能发了,问题是:何时何处适合用EnumChildWindows?我在OnInitDialog用的,直接EnumChildWindows(m_hWnd, EnumChildProc, (LPARAM)this);它怎么说是未定义啊?
A
typedef struct xcontrol_info
{
 HWND hwnd;     // handle of child control
 char mnemonic_char;   // mnemonic character key for the control
}CONTROL_INFO;
class CChoiceDeptDialog : public CDialog
{
.....
// Implementation

protected:
 CArray<CONTROL_INFO, CONTROL_INFO> m_ControlInfo;
 // Generated message map functions
 //{{AFX_MSG(CChoiceDeptDialog)
 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
 DECLARE_MESSAGE_MAP()
};
extern  BOOL CALLBACK EnumControlChildProc(CDialog* pDialog, CArray<CONTROL_INFO, CONTROL_INFO>* paControlInfo);
BOOL CChoiceDeptDialog::OnInitDialog()
{
.....
EnumControlChildProc(this,&m_ControlInfo);
.....
}
void CChoiceDeptDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
 // TODO: Add your message handler code here and/or call default

 // If user pressed an accelerator keystroke, loop through the
 // array to find out if it is one of the access keys for a
 // child control in the Visual Basic ActiveX control.
 BOOL  bTrapAccel = nID == SC_KEYMENU;
 if (bTrapAccel)
 {
  int size =    m_ControlInfo.GetSize();
  for (int i = 0; i < size; i++)
  {
   if (toupper(LOWORD(lParam)) ==toupper(m_ControlInfo[i].mnemonic_char))
   {
    HWND child = m_ControlInfo[i].hwnd;
    ::SetFocus(child);
    ::SendMessage(child, BM_CLICK, 0, 0L);  // OPTIONAL!!!
   }
  }
 }
 
 CDialog::OnSysCommand(nID, lParam);
}
BOOL CALLBACK EnumControlChildProc(CDialog* pDialog, CArray<CONTROL_INFO, CONTROL_INFO>*paControlInfo)
{
 paControlInfo->RemoveAll();
 CString strTemp;
 CWnd*   pWndControl = pDialog->GetWindow(GW_CHILD);
 while(pWndControl){
  pWndControl->GetWindowText(strTemp);
  int index = strTemp.Find('&');   // look for mnemonic
  // character keycode
  if (index > -1)
  {
   if(strTemp.GetLength()>index+1){//check if is the last
    CONTROL_INFO info;
    info.hwnd = pWndControl->GetSafeHwnd();;
    info.mnemonic_char = strTemp[index+1];
    paControlInfo->Add(info);
   }
  }
  pWndControl=pWndControl->GetWindow(GW_HWNDNEXT);
 }
 return TRUE;
}

Q为什么我用了两种取得计算机名称的方法都不行呀?高手帮帮忙!!!
T
为什么我用了两种取得计算机名称的方法都不行呀?高手帮帮忙!!!
(注:我用的是98)
1、char buff[128];
   memset(buff,0,sizeof(buff)
   gethostname(buff,128);
   CString hostname=CString(buff);
   MessageBox(hostname);//输出为空
2、WORD wVersionRequested=MAKEWORD(2,2);
    WSADATA wsaData;
    if( WSAStartup(wVersionRequested,&wsaData) == 0) 
    {   
      struct hostent * phost;
      if((phost = gethostbyname(""))!=NULL)
            m_computername = (CString)phost->h_name; 
      WSACleanup();
    }//得到的却是另一台2000机子的名称
A
#include <LMCONS.H>
const CString g_GetCurrentComputerName()
{
 static CString strComputerName;
 if(strComputerName.IsEmpty()){
  TCHAR szComputerName[MAX_COMPUTERNAME_LENGTH  + 1];
  ULONG nComputerBufSize=MAX_COMPUTERNAME_LENGTH + 1 ;
  if(::GetComputerName(szComputerName,&nComputerBufSize))
   strComputerName=szComputerName;
 }
 return strComputerName;
}
检查一下gethostbyname的返回值
QPicture控件属于哪个类?
T另外,怎样将picture控件上显示的东东
保存为磁盘bmp文件?谢谢
ACPictureHolder::CreateFromBitmap
IPicture::SaveAsFile
用CPictureHolder载入图像,通过访问它的IPicture类型的成员IPicture::SaveAsFile保存到文件
QI have no idea,如何统一的给CArray变量中的每个单元赋初始值
T如题。
A
int nTemplate;

class CFoo{
CFoo();
}
extern CFoo FooTemplate[10];
CFoo::CFoo()
{
    *this=FooTemplate[nTemplate];
}

Q大侠们:请帮帮我!一个老问题加一个新问题!
T    感谢您阅读我的帖子。我从网上下载了读jpeg格式的源程序:它采用IPicture类读取jpeg,但它返回的是GDI句柄,我想得到打开文件的DIB句柄应如何做呢?另外有个老问题,如何将24位真彩图变为256级灰度图,希望有源程序(关键部分),能否用DIB句柄解决这个图像转变问题,望各位大侠能拔刀想助,我必慷慨给分!
A
Here is a reply of jiangsheng
用GDI+都可以处理
#include <windows.h>
#include <gdiplus.h>
#include <stdio.h>
using namespace Gdiplus;

INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid);  // helper function

INT main()
{
   // Initialize GDI+.
   GdiplusStartupInput gdiplusStartupInput;
   ULONG_PTR gdiplusToken;
   GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

   CLSID   encoderClsid;
   Status  stat;
   Image*   image = new Image(L"Bird.bmp");

   // Get the CLSID of the PNG encoder.
   GetEncoderClsid(L"image/png", &encoderClsid);

   stat = image->Save(L"Bird.png", &encoderClsid, NULL);

   if(stat == Ok)
      printf("Bird.png was saved successfully/n");
   else
      printf("Failure: stat = %d/n", stat);

   delete image;
   GdiplusShutdown(gdiplusToken);
   return 0;
}

Q菜鸟问题:如何知道指定的目录是否存在?
T
比如说用openPath来存放要打开的文件路径
CString openPath;
openPath = _T("c://temp");
之后,我如何知道该路径在磁盘中是否存在呢?
Thx
A
PathFileExists
#include <shlwapi.h>
Q关于共享内存区的问题
T


我建立了一个共享内存区。
/*
 将用户信息写到共享内存区
*/
 
        HANDLE hmap;
 usb_info p_lizhi;
 hmap = ::CreateFileMapping((HANDLE)-1, NULL,
  PAGE_READWRITE, 0, sizeof(struct USB_info), _T("share"));
 if (hmap != NULL && GetLastError() == ERROR_ALREADY_EXISTS)
 {
    p_lizhi = (usb_info)::MapViewOfFile(
        hmap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
 
 strcpy(p_lizhi->logindomain,usbinfo.logindomain);
 strcpy(p_lizhi->loginname,usbinfo.loginname);
 strcpy(p_lizhi->loginpassword,usbinfo.loginpassword);
 strcpy(p_lizhi->username,usbinfo.username);
 }


我想修改共享内存区的内容的内容,为什么会失败(执行hmap = ::OpenFileMapping(FILE_MAP_WRITE, FALSE, "share");失败)?

                     HANDLE hmap,m_handle;
              usb_info p_lizhi;
     hmap = ::OpenFileMapping(FILE_MAP_WRITE, FALSE, "share");
              if (hmap != NULL)
     {
                     p_lizhi = (usb_info)::MapViewOfFile(
                                                          hmap, FILE_MAP_WRITE, 0, 0, 0);

A
class CShareRestrictedSD 
{
public:
 CShareRestrictedSD();
 virtual ~CShareRestrictedSD();
 SECURITY_ATTRIBUTES* GetSA();
protected:
 PVOID  ptr;
 SECURITY_ATTRIBUTES sa;
 SECURITY_DESCRIPTOR sd;
};
//
// Construction/Destruction
//
PVOID BuildRestrictedSD(PSECURITY_DESCRIPTOR pSD) {

   DWORD  dwAclLength;

   PSID   psidEveryone = NULL;

   PACL   pDACL   = NULL;
   BOOL   bResult = FALSE;

   PACCESS_ALLOWED_ACE pACE = NULL;

   SID_IDENTIFIER_AUTHORITY siaWorld = SECURITY_WORLD_SID_AUTHORITY  ;
  
   SECURITY_INFORMATION si = DACL_SECURITY_INFORMATION;
  
   __try {

      // initialize the security descriptor
      if (!InitializeSecurityDescriptor(pSD,
            SECURITY_DESCRIPTOR_REVISION)) {
         printf("InitializeSecurityDescriptor() failed with error %d/n",
               GetLastError());
         __leave;
      }

      // obtain a sid for the Authenticated Users Group
      if (!AllocateAndInitializeSid(&siaWorld, 1,
            SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0,
            &psidEveryone)) {
         printf("AllocateAndInitializeSid() failed with error %d/n",
               GetLastError());
         __leave;
      }

      // NOTE:
      //
      // The Authenticated Users group includes all user accounts that
      // have been successfully authenticated by the system. If access
      // must be restricted to a specific user or group other than
      // Authenticated Users, the SID can be constructed using the
      // LookupAccountSid() API based on a user or group name.

      // calculate the DACL length
      dwAclLength = sizeof(ACL)
            // add space for Authenticated Users group ACE
            + sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD)
            + GetLengthSid(psidEveryone);

      // allocate memory for the DACL
      pDACL = (PACL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
            dwAclLength);
      if (!pDACL) {
         printf("HeapAlloc() failed with error %d/n", GetLastError());
         __leave;
      }

      // initialize the DACL
      if (!InitializeAcl(pDACL, dwAclLength, ACL_REVISION)) {
         printf("InitializeAcl() failed with error %d/n",
               GetLastError());
         __leave;
      }
     
      // add the Authenticated Users group ACE to the DACL with
      // GENERIC_READ, GENERIC_WRITE, and GENERIC_EXECUTE access
      if (!AddAccessAllowedAce(pDACL, ACL_REVISION,
            GENERIC_ALL,
            psidEveryone)) {
         printf("AddAccessAllowedAce() failed with error %d/n",
               GetLastError());
         __leave;
      }

      // set the DACL in the security descriptor
      if (!SetSecurityDescriptorDacl(pSD, TRUE, pDACL, FALSE)) {
         printf("SetSecurityDescriptorDacl() failed with error %d/n",
               GetLastError());
         __leave;
      }

      bResult = TRUE;
    
   } __finally {

      if (psidEveryone) FreeSid(psidEveryone);
   }

   if (bResult == FALSE) {
      if (pDACL) HeapFree(GetProcessHeap(), 0, pDACL);
      pDACL = NULL;
   }

   return (PVOID) pDACL;
}

// The following function frees memory allocated in the
// BuildRestrictedSD() function
VOID FreeRestrictedSD(PVOID ptr) {

   if (ptr) HeapFree(GetProcessHeap(), 0, ptr);

   return;
}


CShareRestrictedSD::CShareRestrictedSD()
{
 ptr=NULL;
 sa.nLength = sizeof(sa);
 sa.lpSecurityDescriptor = &sd;
 sa.bInheritHandle = FALSE;
 // build a restricted security descriptor
 ptr = BuildRestrictedSD(&sd);
 if (!ptr) {
  TRACE("BuildRestrictedSD() failed/n");
 }
}

CShareRestrictedSD::~CShareRestrictedSD()
{
 if(ptr){
  FreeRestrictedSD(ptr);
 }
}
SECURITY_ATTRIBUTES* CShareRestrictedSD::GetSA()
{
 if(ptr){
  return &sa;
 }
 else
  return NULL;
}
usage:
 CShareRestrictedSD ShareRestrictedSD;
 m_hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,    // Current file handle.
    ShareRestrictedSD.GetSA(),                              // custom security.
    PAGE_READWRITE,                    // Read/write permission.
    0,                                 // Max. object size.
    FileSize,                                 // Size of hFile.
    MapName);            // Name of mapping object.
Q请教csdn里的高手,怎样在资源管理器中增加一个类似控制面板的目录。(Windows shell 编程)
T
实际上windows中已经有很多这样的应用。比如[网上邻居],[web folders] ,[我的文档]等,都是这样的应用,请问这些是怎样实现的?

我想在资源管理器中(也就是我的电脑中)增加一个自己的目录,比如[我的CD]
大概如下图:

我的电脑
  ├c:
  ├d:
    ...
  ├控制面板
  ├我的CD
    ├摇滚
    ├抒情
    ├爵士
    ├周华建专集
    └周杰伦专集
  └网上邻居

 并且我自己添加的目录能够响应相应事件。

我记得好像看到过这样的例子,是把注册表的内容加了进来。

望高手指点。谢了





ASee RegView Sample in MSDN

1 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/Shell/programmersguide/shell_adv/namespaceextension/namespace.asp

2 Krishna Kotipalli 
Shell Namespace Extensions 
March 1999 issue of Microsoft Internet Developer
T做过Shell相关程序或Namespace的过来看看!!!
A
1,我在控件中用一个方法传出一个LPITEMIDLIST,该方法返回为OLE_HANDLE(就是unsigned int),在客户端程序调用时,老在LPITEMIDLIST解析时出错,控件里却没问题,这是为什么???

2,已知一以关联文件的full ITEMIDLIST,如何获得该文件的文件全名???

3,已知一个文件的路径及全名(如c:/123.txt),如何将其Parse回一个Full ItemIDLIST?IShellFolder::ParseDispayName好像只能处理不了...


谢谢!!!

Q
3
HRESULT ItemIdListFromPath( LPITEMIDLIST& pidl,LPCSTR szPath)
//szPath is assumpted MAX_PATH size
{ 
 LPSHELLFOLDER pDesktopFolder;
 OLECHAR       olePath[MAX_PATH];
 ULONG         chEaten;
 ULONG         dwAttributes;
 HRESULT       hr;
 //
 // Get a pointer to the Desktop's IShellFolder interface.
 //
 if (FAILED(SHGetDesktopFolder(&pDesktopFolder))){
  return -1;
 }
 //
 // IShellFolder::ParseDisplayName requires the file name be in
 // Unicode.
 //
 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szPath, -1, olePath, MAX_PATH);
 // Convert the path to an ITEMIDLIST.
 hr = pDesktopFolder->ParseDisplayName(NULL,NULL,olePath,&chEaten,
 &pidl,&dwAttributes);
 if (FAILED(hr)){
  // Handle error.
  ::AfxMessageBox (IDS_FAIL_PARSING_PATH);
 }
 // pidl now contains a pointer to an ITEMIDLIST for ./readme.txt.
 // This ITEMIDLIST needs to be freed using the IMalloc allocator
 // returned from SHGetMalloc().
 //release the desktop folder object
 pDesktopFolder->Release();
 return 0;
}

SHParseDisplayName Function

--------------------------------------------------------------------------------

Translates a Shell namespace object's display name into an item identifier list and returns the attributes of the object. This function is the preferred method to convert a string to a pointer to an item identifier list (PIDL).

Syntax

HRESULT SHParseDisplayName(
    PCWSTR pszName,
    IBindCtx *pbc,
    LPITEMIDLIST *ppidl,
    SFGAOF sfgaoIn,
    SFGAOF *psfgaoOut
);

Parameters

pszName
[in]  Pointer to a zero-terminated wide string that contains the display name to parse.
pbc
[in]  Optional bind context that controls the parsing operation. This parameter is normally set to NULL.
ppidl
[out]  Address of a pointer to a variable of type ITEMIDLIST that receives the item identifier list for the object. If an error occurs, then this parameter is set to NULL.
sfgaoIn
[in] ULONG value that specifies the attributes to query. To query for one or more attributes, initialize this parameter with the flags that represent the attributes of interest. For a list of available SFGAO flags, see IShellFolder::GetAttributesOf.
psfgaoOut
[out]  Pointer to a ULONG. On return, those attributes that are true for the object and were requested in sfgaoIn will be set. An object's attribute flags may be zero or a combination of SFGAO flags. For a list of available SFGAO flags, see IShellFolder::GetAttributesOf.
Return Value

Returns S_OK if successful, or an error value otherwise.
Function Information

Stock Implementation shell32.dll version 6.0 or later
Custom Implementation No
Header shlobj.h
Import library shell32.lib
Minimum operating systems Windows XP


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值