0

I have this code below and want know if CompareStr() can will work like this:

    function xGetClassName(_Handle: HWND): String;
    var
      Buffer: array [0 .. MAX_PATH] of Char;
    begin
      GetClassName(_Handle, @Buffer, MAX_PATH);
      Result := String(Buffer);
    end;

    //...

    if CompareStr(xGetClassName(hWndWindow), #32768) = 0 then

Note that second arg in CompareStr() above is a Char.

lupaulus
  • 358
  • 5
  • 22
FLASHCODER
  • 1
  • 7
  • 24
  • 2
    Yes, CompareStr will work like this. It will turn the character constant into a string of one char. I am however not sure that you can find a menu (#32768 is a menu class name) this way. – Rudy Velthuis Apr 17 '19 at 06:27
  • Note that the documentation link is outdated. Use [this](http://docwiki.embarcadero.com/Libraries/en/System.SysUtils.CompareStr) instead. – LU RD Apr 17 '19 at 06:31
  • 6
    Your `CompareStr` usage is wrong in this context. You need to compare the class name as a *String*. a simple `if xGetClassName(hWndWindow) = '#32768'` will do just fine. – kobik Apr 17 '19 at 06:37
  • @kobik: I couldn't check (at that moment), but that is what I thought to remember too. Hence my comment. – Rudy Velthuis Apr 17 '19 at 06:52
  • 2
    @BrowJr: note that the # syntax is something used in Delphi and some other Pascals. But Windows names are not in Pascal, so the # is the real character #. – Rudy Velthuis Apr 17 '19 at 06:54

0 Answers0