Remove Icon from Top Left Corner of App Window in C
When developing applications in C, you may want to remove the icon that appears by default in the top left corner of the application window. This article will provide a detailed explanation of how to modify the source code to achieve this.
Identifying the Window Style
The first step in removing the icon from the top left corner of the app window is to identify the current window style. This can be done by using the GetWindowLong() function with the GWL_EXSTYLE parameter, like so:
long extendedStyle = GetWindowLong(m_hWnd, GWL_EXSTYLE);
The m_hWnd variable in this example represents the handle of the window for which you want to retrieve the window style.
Modifying the Window Style
Once you have identified the current window style, you can modify it to remove the icon. To do this, you will need to create a new style by performing a bitwise OR operation with the current style and the WS_EX_DLGMODALFRAME style, like so:
long newStyle = extendedStyle | WS_EX_DLGMODALFRAME;
This new style removes the icon from the top left corner of the app window. However, it is important to note that this style also changes the appearance of the window border and caption, so you should ensure that this meets your application's requirements.
Applying the New Style
After creating the new window style, you can apply it by using the SetWindowLong() function with the GWL_EXSTYLE parameter, like so:
SetWindowLong(m_hWnd, GWL_EXSTYLE, newStyle);
This applies the new style to the window, removing the icon from the top left corner. However, it is important to note that you may need to call the SetWindowPos() function to ensure that the changes take effect immediately:
SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
- Identify the current window style using
GetWindowLong()with theGWL_EXSTYLEparameter. - Create a new window style by performing a bitwise OR operation with the current style and the
WS_EX_DLGMODALFRAMEstyle. - Apply the new style to the window using
SetWindowLong()with theGWL_EXSTYLEparameter. - Call
SetWindowPos()with theSWP_FRAMECHANGEDflag to ensure that the changes take effect immediately.
References
- GetWindowLongA function (Microsoft Docs)
- SetWindowLongA function (Microsoft Docs)
- SetWindowPos function (Microsoft Docs)