请高手进来看看,小弟感激不尽,在线等待!

hsd2004 2006-02-16 03:23:29
编一个程序,获取所有打开窗口的可执行程序的路径。换一个问法,如何可以避免某个程序第二次被打开执行?谢谢了。
...全文
192 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hsd2004 2006-02-16
  • 打赏
  • 举报
回复
谢谢学海无涯,问题搞定。结题。
逸学堂 2006-02-16
  • 打赏
  • 举报
回复
如果是自己的程序不让启动两个,
可以加上互斥变量。
// Create mutex, because there cannot be 2 instances of Updater for same application
HANDLE hMutex = CreateMutex(NULL, FALSE, "update_" + pSettings->GetAppName());
这样就可以了!
hsd2004 2006-02-16
  • 打赏
  • 举报
回复
to iamcaicainiao(菜菜鸟)
大侠说的意思,偶不是很明白啊。可否具体点?
哪位可以告知我贴出来的编译错误是什么啊。谢谢了。
iamcaicainiao 2006-02-16
  • 打赏
  • 举报
回复
hWnd_new = FindWindow(NULL, "窗口名称");
然后你想对这个窗口干吗,就再继续干吗吧。
iamcaicainiao 2006-02-16
  • 打赏
  • 举报
回复
HWND hWnd_new = NULL;
hWnd_new = FindWindos(NULL, "窗口名称");
hsd2004 2006-02-16
  • 打赏
  • 举报
回复
楼上的兄弟,我怎么编译出错?------ Rebuild All started: Project: www, Configuration: Debug Win32 ------

Deleting intermediate files and output files for project 'www', configuration 'Debug|Win32'.
Compiling...
gggg.cpp
Linking...
gggg.obj : error LNK2019: unresolved external symbol _GetModuleBaseNameA@16 referenced in function "void __cdecl PrintProcessNameAndID(unsigned long)" (?PrintProcessNameAndID@@YAXK@Z)
gggg.obj : error LNK2019: unresolved external symbol _EnumProcessModules@16 referenced in function "void __cdecl PrintProcessNameAndID(unsigned long)" (?PrintProcessNameAndID@@YAXK@Z)
gggg.obj : error LNK2019: unresolved external symbol _EnumProcesses@12 referenced in function _main
Debug/www.exe : fatal error LNK1120: 3 unresolved externals

Build log was saved at "file://c:\Documents and Settings\andy.huang.01\My Documents\Visual Studio Projects\www\Debug\BuildLog.htm"
www - 4 error(s), 0 warning(s)


---------------------- Done ----------------------
cenlmmx 2006-02-16
  • 打赏
  • 举报
回复

//查询(也可以用CreateToolhelp32Snapshot())
#include <windows.h>
#include <stdio.h>
#include "psapi.h"

void PrintProcessNameAndID( DWORD processID )
{
char szProcessName[MAX_PATH] = "unknown";

// Get a handle to the process.

HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );

// Get the process name.

if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;

if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
}
else return;
}
else return;

// Print the process name and identifier.

printf( "%s (Process ID: %u)\n", szProcessName, processID );

CloseHandle( hProcess );
}

void main( )
{
// Get the list of process identifiers.

DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;

if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return;

// Calculate how many process identifiers were returned.

cProcesses = cbNeeded / sizeof(DWORD);

// Print the name and process identifier for each process.

for ( i = 0; i < cProcesses; i++ )
PrintProcessNameAndID( aProcesses[i] );
}
hsd2004 2006-02-16
  • 打赏
  • 举报
回复
能否具体些了,谢了先。我大概找了相关的一些函数,但不知道具体如何实现。楼上的两个大侠能否指点详细些呢?
iamcaicainiao 2006-02-16
  • 打赏
  • 举报
回复
捕获窗口句柄
snowbirdfly 2006-02-16
  • 打赏
  • 举报
回复
使用函数FindWindow~~~
应该可以`~

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧