When using the windows SDK to compile a program writen in C++, if I specify -subsystem:windows,6.1,
the width of the window is smaller. If I don't, or do -subsystem:windows without the 6.1, the width is normal.
I'm curious why this does this, and if there's a way to make it stay the same width regardless of what command line I pass to link.
EDIT: So it's also height, height and width are both different. And if i look at it with Inspect.exe, it says the size is the same each time.
EDIT2: Also it's a window application created with CreateWindow, not a console.
EDIT3: Here's the full code that initializes my window:
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(SMALL_ICON));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(SMALL_ICON));
g_hMainWnd = CreateWindow(
g_szWindowClass,
t_szWindowTitle,
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT,
392, 250,
NULL,
NULL,
hInstance,
NULL
);
And I resize the window with this:
SetWindowPos(hWnd, NULL,
(GetSystemMetrics(SM_CXFULLSCREEN)/2)- (392/2),
(GetSystemMetrics(SM_CYFULLSCREEN)/2) - (250/2),
392, 120, SWP_NOZORDER);
I'm suspecting you are specifying some windows styles that are only supported in Windows7 (Win7 = 6.1). Post the full CreateWindow call with arguments and also try turning off Aero. The window border may be included in the width/height for example in one scenario.
Related
I am writing a C/C++ windows app which calls CreateWindow as follows:
HWND hWnd = CreateWindow(pszClassName, title_.c_str(), WS_OVERLAPPED | WS_VISIBLE | WS_POPUP | WS_SIZEBOX, 50, 50, 400, 100, NULL, NULL, hInst, this);
Nothing particularly complex about it, however, it is appearing on every desktop on my computer when I switch from one desktop to another with CTRL-WIN < or >.
How do you make window you create in an app remain only on the desktop that you created it on?
I am compiling this app in 64bit and running it on Windows 10.
Code:
Global:
WNDCLASSEX wc;
Window procedure:
case WM_KEYDOWN:
if(wParam == VK_F11)
{
wc.style = HWND_DESKTOP;//The window is child
//of desktop
}
break;
WinMain:
LPCSTR windowName = "Answer on StackOwerflow";
MSG messages;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "The classname";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
wc.lpszClassName,
windowName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
ShowWindow(hWnd);
UpdateWindow(hWnd);
while(GetMessage(&messages, NULL, 0, 0) > 0)
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return 0;
How to set these icons for application?
I am using visual studio.
The icon on application window is empty.
I have already added a project.rc file to project and have added icon resource into it
And it shows the correct icon on the task bar when I dock it to the task bar.
I've found 2 methods of doing this after a quick search, assuming you are dealing the the WIN32 API in some form. This is by no measure a complete list of available methods.
1.Set the hIcon member of the WNDCLASSEX structure used to register your main window to an appropriate value like the following code does. (Where EXAMPLE_ICON is your icon resource)
WNDCLASSEX wcex = {};
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(EXAMPLE_ICON));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = nullptr;
wcex.lpszClassName = "ExampleIconWindowClass";
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
2.You can send a WM_SETICON message to your main window like the following (Again, where EXAMPLE_ICON is your icon resource)
HICON hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(EXAMPLE_ICON));
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
Here is the end result of either of these methods:
Sorry about the poor formatting, I'm still unfamiliar with this website.
I'm trying to add a child window to my main window, but the function CreatWindow is throwing an exception saying that can't access address at 0x00000, but it works fine when I try to create a button, I tracked the variables and none of them are null, here it is:
WNDCLASSEX windowClass;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.hInstance = hInstance;
windowClass.lpfnWndProc = NULL;
windowClass.lpszClassName = className;
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.lpszMenuName = NULL;
if (!RegisterClassEx(&windowClass)){
return;
}
window = CreateWindowEx(0,
className,
(LPCTSTR)NULL,
WS_CHILD | WS_BORDER,
0, 0, 0, 0,
owner,
(HMENU)ID,
hInstance,
NULL);
the code above giving the error, the important variables come from here:
gl = new OpenGLContainer("hellogl", hInstance);
addChild(gl);
the first parameter is the className, the constructor only performs an attribution, the addChild method call gl->setOwner(window_handler) and gl->create() which is the first piece of code I posted.
I also saw the stack list, and the problem is after the program enter in the CreateWindow function, which is very strange because the debugger shows that none of the values(pointers) are null.
Could it be failing because lpfnWndProc is NULL?
ParentSadly I didn’t find an answer with google by searching for "laggy/slow mouse wheel-scrolling in Rich Edit control" and similar sentence.
I created a rich edit control (5.0) as a child, added the styles WS_VISIBLE, WS_CHILD, WS_VSCROLL, ES_READONLY, ES_MULTILINE, ES_NOHIDESEL, ES_AUTOVSCROLL and subclassed the messagehandler callback. After appending ~200 text lines the VScroll moves very laggy if I use the mouse wheel. With laggy I mean that the thumb of the rich edit Vscrollbar is still scrolling while I already stopped scrolling with my mouse wheel. Scrolling by clicking the thumb and move it around works fine.
Currently I have no idea why this happens.
Someone maybe know why the mouse wheel scrolling is so laggy and how to fix this crazy issue?
Edit:
I tested it now also without subclassing directly new project with only a parent window. It has still the same issue there if i write ~ 200 lines. This is the code i use to creat the rich edit control:
ATOM MyRegisterClass(HINSTANCE hInstance){
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_BUGTEST));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_BUGTEST);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){
HWND hWnd;
hInst = hInstance;
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
LoadLibraryA("Msftedit.dll");
wstring w_classname = wstring(MSFTEDIT_CLASS);
string classname = string(w_classname.begin(), w_classname.end());
HWND richedit = CreateWindowExA(
WS_EX_CLIENTEDGE,
classname.c_str(),
"richedit",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_NOHIDESEL | ES_MULTILINE | ES_AUTOVSCROLL | ES_LEFT,
200, 300,
400, 500,
hWnd,
NULL,
hInstance,
NULL
);
UpdateWindow(hWnd);
return TRUE;
}
K so after spending again some hours in this issue I found now some advice that the rich edit control uses the SMOOTH VSCROLL.Even Wordpad use this Smoothscroll and has threfore the same "laggy" issue.
(http://simonscodes.blogspot.de/2014/12/hello.html)
So sadly I can’t get the example code from this page which maybe solve the problem but after reading this post -> Disabling Smooth Scrolling on Richtextbox I created now an own solution.
The way I’m using now is to subclass the rich edit control and block the WM_MOUSEWHEEL message and handle it by my own by sending the WM_VSCROLL message. This avoids the SMOOTH VSCROLL and stops this crazy laggy scrolling issue.
Here the code in my subclassed messagehandler callback:
case WM_MOUSEWHEEL:{
if (GET_WHEEL_DELTA_WPARAM(wParam) > 0) // A positive value indicates that the wheel was rotated forward, away from the user;
SendMessageA(hRichEdit, WM_VSCROLL, SB_LINEUP, NULL);
else if (GET_WHEEL_DELTA_WPARAM(wParam) < 0) //A negative value indicates that the wheel was rotated backward, toward the user.
SendMessageA(hRichEdit, WM_VSCROLL, SB_LINEDOWN, NULL);
return TRUE; //block the message
}
For more info how parts of this code works or about the WM_MOUSEWHEEL message read here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645617%28v=vs.85%29.aspx
I just switched the game to use WNDCLASSEX so I can change the hIconSm, but for some reason there isn't an icon in the title bar anymore. The cursor and icon on the task bar and the icon for the EXE are all working fine though. Here is the main part of the window creation code:
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WinProc;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_ERROR);
wc.hIconSm = LoadIcon(NULL, IDI_ASTERISK);
wc.hCursor = LoadCursorFromFile((LPCSTR)"FierceCursor.cur");
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszClassName = "FierceWindow";
RegisterClassEx(&wc);
game->hinstance = hInstance;
hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
"FierceWindow", "Fierce",
WS_OVERLAPPED, 400, 100,
game->SCREEN_WIDTH, game->SCREEN_HEIGHT,
NULL, NULL, hInstance, NULL);
I've tried a few different settings for CreateWindowEx in hopes that maybe I used a style without an icon, but no luck. I'm using default icons right now to test.
Won't compile:
error: cast from 'CHAR*' to 'WORD' loses precision
Thanks for the edit btw.
Edit - Got it to compile by changing it to:
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(32513));
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(32513));
It's because of your window style. The icon appears only if you add WS_SYSMENU style.
WS_OVERLAPPED|WS_SYSMENU