请告诉我如何用API函数来实现。不要用MFC的类库。请多关照。

解决方案 »

  1.   

    //知道系统进程的ID,获得该进程主窗口的句柄
    #include "windows.h"typedef struct tagWNDINFO
    {
      DWORD dwProcessId;
      HWND hWnd;
    } WNDINFO, *LPWNDINFO;BOOL CALLBACK YourEnumProc(HWND hWnd, LPARAM lParam)
    {
      DWORD dwProcessId;
      GetWindowThreadProcessId(hWnd, &dwProcessId);
      LPWNDINFO pInfo = (LPWNDINFO)lParam;
      if(dwProcessId == pInfo->dwProcessId)
      {
        pInfo->hWnd = hWnd;
        return FALSE;
      }
      return TRUE;
    }HWND GetProcessMainWnd(DWORD dwProcessId)
    {
      WNDINFO wi;
      wi.dwProcessId = dwProcessId;
      wi.hWnd = NULL;
      EnumWindows(YourEnumProc,(LPARAM)&wi);
      return wi.hWnd;

    得到进程据柄,再调用GetModuleBaseName或GetModuleFileName得到路径和文件名.
      

  2.   

    #include "stdafx.h"
    #include "afx.h"
    #include "Afxwin.h"
    int main(int argc, char* argv[])
    {
    char strFileName[MAX_PATH];
    GetModuleFileName(NULL, strFileName, sizeof(strFileName));
    return 0;
    }
    strFileName就是了.
      

  3.   

    fly_pig:
    DWORD GetModuleBaseName(
      HANDLE hProcess,    // handle to process
      HMODULE hModule,    // handle to module
      LPTSTR lpBaseName,  // base name buffer
      DWORD nSize         // maximum characters to retrieve
    );
    其中,hModule如何获取?
      

  4.   

    相信victorlee_lq(victor)的吧,GetModuleFileName是对的!
      

  5.   

    哦,天哪,这麽简单的问题需要那么多语句吗?
    在任何地方加入这句话,试试看。不要说你没有定义_pgmptr,不需要定义,运行期全局变量。MessageBox(0,_pgmptr,0,MB_OK); 或者CString  strTemp = _pgmptr;那么strTemp就是你要的东西。更简单的说,_pgmptr就是你要的东西。