Search code examples
cwinapimingw32

Is it feasible to pass HANDLE(S) to another function?


When compiling like this:

void DisplayPos (void)
{
    SetWindowPos (ConsoleWindow, HWND_TOPMOST, 0, 0, 600, 600, SWP_SHOWWINDOW);
}

int main (void)
{
    HWND ConsoleWindow = GetConsoleWindow();
    DisplayPos ();
}

GCC will report:

Line 3 | error: 'ConsoleWindow' undeclared (first use in this function) // expected

But is it feasible to pass HANDLE to another function without declaring a new one? Thanks.


Solution

  • Appreciate @cHao 's help. :-)

    I answered my own question.

    void DisplayPos (HWND ConsoleWindow)
    {
        SetWindowPos (ConsoleWindow, HWND_TOPMOST, 0, 0, 600, 600, SWP_SHOWWINDOW);
    }
    
    int main (void)
    {
        HWND ConsoleWindow = GetConsoleWindow();
        DisplayPos (ConsoleWindow);
    }