::FindWindow()'s problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 16
Reputation: shizu is an unknown quantity at this point 
Solved Threads: 0
shizu shizu is offline Offline
Newbie Poster

::FindWindow()'s problem

 
0
  #1
Dec 17th, 2007
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..
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: ::FindWindow()'s problem

 
0
  #2
Dec 17th, 2007
Originally Posted by shizu View Post
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.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 16
Reputation: shizu is an unknown quantity at this point 
Solved Threads: 0
shizu shizu is offline Offline
Newbie Poster

Re: ::FindWindow()'s problem

 
0
  #3
Dec 17th, 2007
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..??

Originally Posted by dubeyprateek View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: ::FindWindow()'s problem

 
0
  #4
Dec 18th, 2007
Originally Posted by shizu View Post
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
  1. RegisterClassEx
to register a class.

  1. ATOM MyRegisterClass(HINSTANCE hInstance)
  2. {
  3. WNDCLASSEX wcex;
  4.  
  5. wcex.cbSize = sizeof(WNDCLASSEX);
  6.  
  7. wcex.style = CS_HREDRAW | CS_VREDRAW;
  8. wcex.lpfnWndProc = WndProc;
  9. wcex.cbClsExtra = 0;
  10. wcex.cbWndExtra = 0;
  11. wcex.hInstance = hInstance;
  12. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FINDWINDOWSAMPLE));
  13. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  14. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  15. wcex.lpszMenuName = MAKEINTRESOURCE(IDC_FINDWINDOWSAMPLE);
  16. wcex.lpszClassName = szWindowClass;
  17. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  18.  
  19. return RegisterClassEx(&wcex);
  20. }

This application uses this class to create a window.

  1. BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  2. {
  3. HWND hWnd;
  4.  
  5. hInst = hInstance; // Store instance handle in our global variable
  6.  
  7. hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  8. CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  9.  
  10. if (!hWnd)
  11. {
  12. return FALSE;
  13. }
  14.  
  15. ShowWindow(hWnd, nCmdShow);
  16. UpdateWindow(hWnd);
  17.  
  18. return TRUE;
  19. }

It then registers a Private Message

  1. WM_MY_MESSAGE = RegisterWindowMessage(TEXT("WM_MY_MESSAGE"));
and processes that message

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

The comand line application simply calls
  1. FindWindow
and sends the registered message to to Windows Application

  1. int _tmain(int argc, _TCHAR* argv[])
  2. {
  3. HWND hWnd = NULL ;
  4.  
  5. hWnd = FindWindow(szWindowClass,szWindowClass);
  6. if(!hWnd)
  7. {
  8. printf("FindWindow failed %d", GetLastError());
  9. }
  10. WM_MY_MESSAGE = RegisterWindowMessage(TEXT("WM_MY_MESSAGE"));
  11. SendMessage(hWnd,WM_MY_MESSAGE,0,0);
  12.  
  13. return 0;
  14. }


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.
Attached Files
File Type: zip FindWindowSample.zip (104.6 KB, 25 views)
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 16
Reputation: shizu is an unknown quantity at this point 
Solved Threads: 0
shizu shizu is offline Offline
Newbie Poster

Re: ::FindWindow()'s problem

 
0
  #5
Dec 18th, 2007
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..??
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: ::FindWindow()'s problem

 
0
  #6
Dec 19th, 2007
@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.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC