HWND FindWindow(
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
在VC中我怎么找到我当前项目的类名:lpClassName
我要做的操作是:
HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);
if (hWnd)
{
::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
AfxWinTerm();
ExitProcess(1);
return FALSE;
}
LPCTSTR lpClassName,
LPCTSTR lpWindowName
);
在VC中我怎么找到我当前项目的类名:lpClassName
我要做的操作是:
HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);
if (hWnd)
{
::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
AfxWinTerm();
ExitProcess(1);
return FALSE;
}
LPTSTR lpClassName,
int nMaxCount
);
ParametershWnd
[in] Handle to the window and, indirectly, the class to which the window belongs.
lpClassName
[out] Pointer to the buffer that is to receive the class name string.
nMaxCount
[in] Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter. The class name string is truncated if it is longer than the buffer and is always null-terminated.
Return ValueIf the function succeeds, the return value is the number of TCHAR copied to the specified buffer.If the function fails, the return value is zero. To get extended error information, call GetLastError.
ResWindows 95/98/Me: GetClassNameW is supported by the Microsoft® Layer for Unicode (MSLU). To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.Function InformationHeader Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP See AlsoWindow Classes Overview, FindWindow, GetClassInfo, GetClassLong, GetClassWord
Rainfall - Microsoft Visual C++ [design] - Rainfall.cpp
这是显示的结果:RainFall就是类名吗?
如果是由VC自己起的会有一个类名字符串,你可以用
FindWindow(szClassName,NULL);
FindWindow(NULL,lpWindowName);同样可以返回窗体的句柄。
BOOL CRainfallApp::InitInstance()
{
HWND hWnd = ::FindWindow("RAINFALL_CLASS", 0);
if (hWnd)
{
::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
AfxWinTerm();
ExitProcess(1);
return FALSE;
}
}
我的这段代码其实是为了完成程序只运行一个实例的效果。
这段代码只是在系统运行了这个程序时才会调用的!
用spy++好像行到的不对
if (hWnd)
{
::ShowWindow(hWnd, SW_SHOWMAXIMIZED);
}
因为小弟要将VC程序代码读懂。有很多不明白的地方(没办法公司要求这么做的!)因为以后我要修改这个程序!!!对于VC很多细节方面还请多多帮忙
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if (className==NULL) {
WNDCLASS wndcls;
::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wndcls);
wndcls.lpszClassName="RAINFALL_CLASS";
wndcls.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
VERIFY(AfxRegisterClass(&wndcls));
className=RAINFALL_CLASS;
}
cs.lpszClass=className;
return TRUE;
问题已解决:希望大家如果遇到同类问题能从上面的代码得到启发。也就是在MFC中有一个奇怪的窗口类名称!修改它为你自己想要的名称就可以了!!谢谢!大家的回复!!
{
static LPCSTR className=NULL;
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if (className==NULL) {
WNDCLASS wndcls;
::GetClassInfo(AfxGetInstanceHandle(),cs.lpszClass,&wndcls);
wndcls.lpszClassName=RAINFALL_CLASS;
wndcls.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
VERIFY(AfxRegisterClass(&wndcls));
className=RAINFALL_CLASS;
}
cs.lpszClass=className;
return TRUE;
}