I was updating some turn of the century code when I ran into this anomaly using Visual Studio 2015 Community c++.
It appears to be a display issue because I have an app that produces source (PowerBASIC) from a running applications window. The sizes for the window and the edit controls match the sizes used in the c++ code for both displays .
I tested with the TDM-GCC compiler (http://tdm-gcc.tdragon.net/) for the c++ code and also using PellesC compiler.
I did a few preliminary tests compiling on Win10 and running on Win7 and Compiling on Win7 and running on Win7. I also tested on different computers with different monitor resolutions just to be sure. All results were the same. The Visual Studio 2015 created app did not display correctly. Any insights?
Thank you for your time.
James
Code:
#include <windows.h>
// *************************************************
// User Defined Constants
// *************************************************
#define AppName "Ec03"
#define Caption "Edit Controls"
#define ID_Edit1 101
#define ID_Edit2 102
// *************************************************
// User Global Variables
// *************************************************
static HWND Form1;
static HWND Edit1;
static HWND Edit2;
// *************************************************
// Standard Macros
// *************************************************
#define BOR |
// *************************************************
// User Prototypes
// *************************************************
void FormLoad (HINSTANCE);
int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void FormLoad (HINSTANCE hInst)
{
float fHeight = 312;
float fWidth = 330;
Form1 = CreateWindowEx( WS_EX_WINDOWEDGE, AppName, Caption, WS_POPUP BOR WS_VISIBLE BOR WS_CLIPSIBLINGS BOR WS_CAPTION BOR WS_SYSMENU BOR DS_MODALFRAME, ( GetSystemMetrics( SM_CXSCREEN) - fWidth) / 2, ( GetSystemMetrics( SM_CYSCREEN) - fHeight) / 2, fWidth, fHeight, NULL, (HMENU) NULL, hInst, NULL);
Edit1 = CreateWindowEx( 0, "edit", NULL, WS_CHILD BOR WS_VISIBLE BOR WS_BORDER BOR ES_AUTOVSCROLL BOR ES_WANTRETURN BOR ES_AUTOHSCROLL BOR ES_MULTILINE, 14, 16, 300, 110, Form1, (HMENU) ID_Edit1, hInst, NULL);
Edit2 = CreateWindowEx( 0, "edit", NULL, WS_CHILD BOR WS_VISIBLE BOR WS_BORDER BOR ES_AUTOVSCROLL BOR ES_WANTRETURN BOR ES_AUTOHSCROLL BOR ES_MULTILINE, 14, 158, 300, 116, Form1, (HMENU) ID_Edit2, hInst, NULL);
ShowWindow(Form1, SW_SHOW);
}
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int CmdShow)
{
MSG uMsg = {0};
WNDCLASSEX wcx = {0};
wcx.cbSize = sizeof( wcx);
wcx.style = CS_HREDRAW BOR CS_VREDRAW;
wcx.lpfnWndProc = WndProc;
wcx.cbClsExtra = 0;
wcx.cbWndExtra = 0;
wcx.hInstance = hInst;
wcx.hIcon = LoadIcon( NULL, IDI_WINLOGO);
wcx.hCursor = LoadCursor( NULL, IDC_ARROW);
wcx.hbrBackground = ( HBRUSH) GetStockObject( WHITE_BRUSH);
wcx.lpszMenuName = NULL;
wcx.lpszClassName = AppName;
RegisterClassEx( &wcx);
FormLoad(hInst);
while(GetMessage( &uMsg, NULL, 0, 0))
{
TranslateMessage( &uMsg);
DispatchMessage( &uMsg);
}
return uMsg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
Visual Studio 2015 batch file
@SETLOCAL
@ECHO OFF
SET XTYPE=x86_amd64
CALL "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%
ECHO ON
cl.exe /O1 /Gd /EHsc /MT %1.cpp /Fe"%1.exe" /link /SUBSYSTEM:WINDOWS kernel32.lib user32.lib gdi32.lib
TDM-GCC batch file
@SETLOCAL
@ECHO OFF
SET MINGW=C:\TDM-GCC-64
SET PATH=%MINGW%\bin;%PATH%
ECHO ON
g++ %1.cpp -o %1.exe -mwindows -lmingw32 -lkernel32 -luser32 -lgdi32
Last edited by jcfuller; March 23rd, 2016 at 01:04 PM.
...
I did a few preliminary tests compiling on Win10 and running on Win7 and Compiling on Win7 and running on Win7. I also tested on different computers with different monitor resolutions just to be sure. All results were the same. The Visual Studio 2015 created app did not display correctly. Any insights?
Well, which one of the two images is correct and how was it built?
Well, which one of the two images is correct and how was it built?
The image on the left is the correct display created with TDM-GCC.
The image on the right is not correct created with visual studio 2015 community.
The visual studio version was created using the visual studio 2015 batch file from a normal command prompt.
The TDM-GCC version was created using the TDM-GCC batch file from a normal command prompt.
The display produced from the code in post #1 and the attached zip doesn't produce the expected image - even the window caption is different
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
On my Windows 7 system using VS2015, to get a display like the required left image, fHeight is 335 rather than 312 and fWidth is 345 rather than 330. I don't have access to the other compilers so can't comment upon what these numbers will show with them. However, how the created windows are displayed surely seems more inclined to be based upon the version of user32.dll used than the compilers - as all the compilers are doing is creating code that calls the functions in the windows dll files?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
I tried it with vs2013 Express on Win7 with the same results as VS 2015 community.
All other languages I tried create what I believe is the correctly displayed window.
PellesC
TDM-GCC
NUWEN
FreeBasic
PowerBASIC
I don't know if this is a clue but:
On Win10 with the exe built on Win10, if I change compatibility in File Explorer->propterties of the exe to Windows 7 it displays correctly.
On Win7 with the exe built on Win7 no difference on any compatibility changes.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.