3

I was searching through the Window Properties of a normal Application-Window in Windows. There are winapi functions like:

HWND WINAPI FindWindow(
  _In_opt_  LPCTSTR lpClassName,
  _In_opt_  LPCTSTR lpWindowName
);

...which return a Window handle if they find a window.

The WindowName is pretty obvious but I don't get the explanation:

The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.

How can I (for example) set (or register) the class name for a C# Windows Form App so that I can find it via FindWindow in C++? I sadly cannot use NULL for the class name because I cannot alter the source program which searches for the class name.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
Vinz
  • 3,030
  • 4
  • 31
  • 52
  • Not sure why this was downvoted.. At a guess its because your title is misleading, Possibly should be called "What does lpClassName represent?" – Sayse Jul 05 '14 at 12:26
  • Maybe simple googling before asking. – user2120666 Jul 05 '14 at 12:28
  • 2
    @user2120666 - The OP has obviously googled since they have included a quote from what is likely to be msdn – Sayse Jul 05 '14 at 12:30
  • And where is the problem? – user2120666 Jul 05 '14 at 12:30
  • The problem is, that I can't find a way on myself to set the lpClassName for an C# App... And some help would be really nice :) – Vinz Jul 05 '14 at 12:50
  • 2
    This is an XY question. You cannot make this work, Winforms windows have a dynamically generated class name. You don't have enough info to know what the name might look like. Scratch FindWindow, you'll have to use another way to find the window back. EnumThreadWindows() gives you a much better shot at it. And do consider using a UI Automation library to get this working. – Hans Passant Jul 05 '14 at 13:10
  • oh really? :( I kinda need that as my program searches for a specific class. No only the window name... – Vinz Jul 05 '14 at 14:10
  • Use Spy++ to find out the classname used by winforms apps. See how it related to the c# class name – David Heffernan Jul 06 '14 at 06:44

0 Answers0