Originally Posted by
Ivory348
This code is flawed, I changed it to look like so:
-----------------------------------------------------
(Below is the * code . . . the corrected code)
Code:
extern void disableMinimizeAndMaximizeButtons(void)
{
HWND hwnd;
LONG_PTR ws;
hwnd = GetConsoleWindow();
SetWindowLong(hwnd, GWL_STYLE,
GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
}
No, the code that you changed it to is equivalent. Here's why:
- The extern keyword is unnecessary because function names have external linkage by default.
- Whether you call GetConsoleWindow() as an actual argument of the function, or call it to provide an initial value to a local variable within the function, it is the same: either way hwmd is set to the return value of GetConsoleWindow().
- When you're providing a non-static local variable with the return value of a function call immediately after declaring it, it is equivalent to initialising it with the return value of that function call.
- In your "corrected code", ws is unused, therefore its declaration can be deleted.
This means that your "corrected code" is equivalent to:
Code:
void disableMinimizeAndMaximizeButtons(void)
{
HWND hwnd = GetConsoleWindow();
SetWindowLong(hwnd, GWL_STYLE,
GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
}
This is in turn equivalent to:
Code:
void disableMinimizeAndMaximizeButtons(HWND hwnd)
{
SetWindowLong(hwnd, GWL_STYLE,
GetWindowLong(hwnd, GWL_STYLE) & ~(WS_MAXIMIZEBOX|WS_MINIMIZEBOX));
}
// ...
disableMinimizeAndMaximizeButtons(GetConsoleWindow());
except that having hwnd as a parameter is more flexible since you could call the function with a different argument.
Originally Posted by
Ivory348
After making a test environment for the second time in order to try out everything that was proposed to me again, I found that the * code did in fact work.
After searching for a cause I discovered that in the original test environment there was a routine that blocked the * code from working. Who would think of the possibility of two routines biting each other?
The naughty routine is a security check, requiring a pin code to be entered. Why it is getting in the way of the * code, I have not found out yet.
Yeah, it looks like that was the key to the puzzle as to why john.c's code failed to work. You should find that if you substitute john.c's code back into your code to replace your * code, along with the correct function call, it will now work.