GetWindowLong (int hWnd, GWL_STYLE) returns weird numbers in C #

I used the GetWindowLong api window to get the current state of the window window in C #.

    [DllImport("user32.dll")]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);


    Process[] processList = Process.GetProcesses();
    foreach (Process theprocess in processList)
    {

        long windowState = GetWindowLong(theprocess.MainWindowHandle, GWL_STYLE);

        MessageBox.Show(windowState.ToString());

    }

I expected to get numbers at http://www.autohotkey.com/docs/misc/Styles.htm , but I get numbers like -482344960, -1803550644 and 382554704.

Do I need to convert the windowState variable? if so, then what?

+3
source share
3 answers

What is strange about these values? For example, it is 482344960equivalent 0x1CC00000, which looks as if you can see it as a window style. By looking at the link to the styles you are attached to, this WS_VISIBLE | WS_CAPTION | 0xC000000.

If you want to test for WS_VISIBLE, for example, you would do something like:

int result = GetWindowLong(theprocess.MainWindowHandle, GWL_STYLE);
bool isVisible = ((result & WS_VISIBLE) != 0);
+6

, () GetWindowLong, , :

long windowState = GetWindowLong(...);
+1

, , , GetWindowLongPtr long. LONG_PTR, , .

GetWindowLong http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx

LONG GetWindowLong(      
    HWND hWnd,
    int nIndex
);

GetWindowLongPtr http://msdn.microsoft.com/en-us/library/ms633585(VS.85).aspx

LONG_PTR GetWindowLongPtr(      
    HWND hWnd,
    int nIndex
);

MSDN, 64- Windows, GetWindowLongPtr, GetWindowLong 32- LONG, , 32- . , GetWindowLong GetWindowLongPtr, , , .

This is an import that you should use to return a value from GetWindowLongPtr.

[DllImport("user32.dll")]
static extern long GetWindowLongPtr(IntPtr hWnd, int nIndex);

.NET uses 64-bit longregardless of platform.

+1
source

Source: https://habr.com/ru/post/1715060/


All Articles