I want to lock my console window and prevent it from moving/being able to be moved.
Currently I have
::SetWindowPos(hConsole, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
But "SWP_NOMOVE", I'm still able to move my console around and resize it.
::SetWindowPos(hConsole, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
Related
How can i make so user can't scroll down console.
for now this is what i have:
HWND consoleWindowHandle = GetConsoleWindow();
SetWindowPos(
consoleWindowHandle,
HWND_TOPMOST,0, 0,0, 0,
SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(
consoleWindowHandle, SW_NORMAL);
ShowScrollBar(GetConsoleWindow(), SB_VERT, 0);
EnableScrollBar(consoleWindowHandle, SB_BOTH,ESB_DISABLE_BOTH);
SetWindowLong(consoleWindowHandle, GWL_STYLE, GetWindowLong(consoleWindowHandle, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_SIZEBOX);
When I create my window, it is smaller than the width and height specified, that should be 840x840. The actual window created is only approx 825x782 (not including menus etc). I can't work out why the window is small and have never had this problem before. Thanks in advance.
CreateWindowW(wc.lpszClassName, L"Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 200, 840, 840,
NULL, NULL, NULL, NULL);
The solution is to use AdjustWindowRect function as commented by Simon Mourier, where rect is the size of the client window.
RECT rect = {0, 0, width, height};
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, true);
CreateWindowW(wc.lpszClassName, L"Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 200,
rect.right - rect.left, rect.bottom - rect.top,
NULL, NULL, hPrevInst, NULL);
Using win32 I create a window like this:
RECT windowRect = {0, 0, width, height};
AdjustWindowRectEx(&windowRect, WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME, FALSE, WS_EX_APPWINDOW);
mWindowHandle = CreateWindow(wcex.lpszClassName, wcex.lpszClassName, WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME,
CW_USEDEFAULT, CW_USEDEFAULT, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top,
nullptr, nullptr, mInstanceHandle, nullptr);
For example, right now I have 1920x1080 max, if I pass those values the client area will have 1920x1080, but the overall window size will be too large, dissapearing off-screen.
width and height are arbitary values passed to the function. The effect I want to achieve is that if it is set to the maximum (or above) the resolution of the screen, the whole window will be clamped to fit the screen.
Is there an easy way to do this in win32?
I develop a c++ application with MinGW compiler.
I changed the CreateWindow() functions default font, something like this:
HFONT font;
font = CreateFont(15, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0, 0, 0, "Tahoma");
HWND btn;
btn = CreateWindowEx(BS_PUSHBUTTON, "BUTTON", "Title",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, 0, 0,
hwnd,
(HMENU)ID_BUTTON,
GetModuleHandle(NULL),
0);
SendMessage(btn, WM_SETFONT, (WPARAM) font, TRUE);
But I created menu:
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenuW(hSubMenu, MF_STRING, ID_FILE_OPEN_BTN, "Open" );
AppendMenuW(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "File" );
But I dont know how to change the font in the AppendMenuW(), can anybody help me?
Here is the code from MSDN to create a toolbar. I have modified a little to use a custom icon instead.
HWND hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, 0,
TBSTYLE_FLAT | CCS_ADJUSTABLE | CCS_NODIVIDER | WS_CHILD | WS_VISIBLE | TBSTYLE_WRAPABLE,
0, 0, 0, 0, hwnd, (HMENU)ID_TOOLBAR, g_hInstance, 0);
if ( !hToolbar )
return FALSE;
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
const int numButtons = 12;
HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, numButtons, 0);
SendMessage(hToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);
SendMessage(hToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
TBBUTTON tbButtons[numButtons] =
{
// IDI_ICON1 - the custom icon
{ MAKELONG(0, 0), IDI_ICON1, TBSTATE_ENABLED,
BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Add Download" }
};
SendMessage(hToolbar, TB_ADDBUTTONS, numButtons, (LPARAM)tbButtons);
SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);
But the custom icon is not getting displayed. Its just blank. I will post a screenshot if needed. What am i doing wrong? Thanks in advance.