Hihi..

I would like to ask about ::FindWindow's function..
I execute a program call ABC.exe..
I have coding like below..

HWND window = ::FindWindow("ABC", NULL);

but I get the window value is NULL..

may I know what is my mistake..??

I had execute the ABC program, suspose it can return me it's hwnd..
I didn't use the second variable from FindWindow's function because it's title is different..

pls advise..

thank you..

Hihi..

I would like to ask about ::FindWindow's function..
I execute a program call ABC.exe..
I have coding like below..

HWND window = ::FindWindow("ABC", NULL);

but I get the window value is NULL..

may I know what is my mistake..??

I had execute the ABC program, suspose it can return me it's hwnd..
I didn't use the second variable from FindWindow's function because it's title is different..

pls advise..

thank you..

Please do not get confused. FindWindow does not have do anything the name of the executable.

ABC.exe is windows application or a command line application?
Did you register any class or atom in ABC.exe by the name "ABC" by calling RegisterClass ? If so, are you using same class name in CreateWindow call in ABC.exe ?
If you have already done both of the above things verify if it is a problem with UICODE and ANSII version of the string. Make sure you are using either UNICODE or ANSII in both of the applications.

thank you for replying..
I think I got confusing already..
I didn't call any RegisterClass or CreateWindow..
May I know that how do I call RegisterClass and CreateWindow..??

Please do not get confused. FindWindow does not have do anything the name of the executable.

ABC.exe is windows application or a command line application?
Did you register any class or atom in ABC.exe by the name "ABC" by calling RegisterClass ? If so, are you using same class name in CreateWindow call in ABC.exe ?
If you have already done both of the above things verify if it is a problem with UICODE and ANSII version of the string. Make sure you are using either UNICODE or ANSII in both of the applications.

thank you for replying..
I think I got confusing already..
I didn't call any RegisterClass or CreateWindow..
May I know that how do I call RegisterClass and CreateWindow..??

Here is a sample application which demonstrates the solution.

This sample has 2 projects.
1) Windows Application.
2) Command Line App.

Windows Application calls

RegisterClassEx

to register a class.

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FINDWINDOWSAMPLE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_FINDWINDOWSAMPLE);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

This application uses this class to create a window.

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

It then registers a Private Message

WM_MY_MESSAGE = RegisterWindowMessage(TEXT("WM_MY_MESSAGE"));

and processes that message

if(message == WM_MY_MESSAGE) {
		MessageBox(hWnd,TEXT("Messsage From Command Line App"),TEXT("Message"),MB_OK);
	}

The comand line application simply calls

FindWindow

and sends the registered message to to Windows Application

int _tmain(int argc, _TCHAR* argv[])
{
	HWND hWnd = NULL ;

	hWnd = FindWindow(szWindowClass,szWindowClass);
	if(!hWnd) 
	{
		printf("FindWindow failed %d", GetLastError());
	}
	WM_MY_MESSAGE = RegisterWindowMessage(TEXT("WM_MY_MESSAGE"));
	SendMessage(hWnd,WM_MY_MESSAGE,0,0);

	return 0;
}

To run the sample.

1) Build both of the projects.
2) Run Windows Application.
3) Run Command Line application.

Please let me know if you have any questions.

thank you for ur explanation..
but i dont really understand it..
i am using VC6++..
I had call..
UINT m_uiFindApp = RegisterWindowMessage("FIND_B");
at constractor..

then what is the next step i need to do..??
Am I need to call RegisterClass just after RegisterWindowMessage's function..??

@Shizu You can still open cpp files and understand the flow of the program.
RegisterWindowMessage and RegisterClass do not have any relation as such.
Let me try and get the sample done in VC6.0.

This question has already been answered. Start a new discussion instead.