I was trying to make windres compile a resource file from Visual Studio. I properly converted all the files (and the one included) to ANSI, but I still get this error every time I try to compile it :
windres.exe -J rc -O coff -i C:\Users\Gabriel\DOCUME~1\DoConfig\DoConfig\DoConfig.rc -o Debug\DoConfig.res
mingw32-g++.exe -o ..\Debug\DoConfig.exe Debug\DoConfig.o Debug\stdafx.o Debug\DoConfig.res -lwinmm.lib -lcomctl32.lib -lkernel32.lib -luser32.lib -lgdi32.lib -lwinspool.lib -lcomdlg32.lib -ladvapi32.lib -lshell32.lib -lole32.lib -loleaut32.lib -luuid.lib -lodbc32.lib -lodbccp32.lib -mwindows
C:\Users\Gabriel\DOCUME~1\DoConfig\DoConfig\DoConfig.rc:4:0: fatal error: when writing output to : Invalid argument
^
compilation terminated.
windres.exe: C:\\Users\\Gabriel\\DOCUME~1\\DoConfig\\DoConfig\\DoConfig.rc:22: syntax error
windres.exe: preprocessing failed.
Process terminated with status 1 (0 minute(s), 3 second(s))
3 error(s), 0 warning(s) (0 minute(s), 3 second(s))
Here is the start of the source code of the corresponding file :
#include "resource.h"
#include <windows.h>
IDI_DOCONFIG ICON "DoConfig.ico"
STRANGE_LAYOUT BITMAP "Strange_Layout.bmp"
NORMAL_LAYOUT BITMAP "Normal_Layout.bmp"
MENU_MAIN MENU
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
{
MENUITEM "Quit", 40001
MENUITEM "Note", 40002
}
DLG_CONFIG DIALOGEX 0, 0, 387, 281
STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Doukutsu Monogatari - Settings"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
FONT 9, "Arial"
{
CONTROL "Use Gamepad", Button_Use_Gamepad, BUTTON, BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE | WS_TABSTOP, 12, 16, 100, 12
CONTROL "", Button_Jump_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP, 52, 48, 12, 12
CONTROL "", Button_Attack_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 52, 64, 12, 12
CONTROL "", Button_Weapon_Plus_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 52, 80, 12, 12
CONTROL "", Button_Weapon_Minus_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 52, 96, 12, 12
CONTROL "", Button_Item_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 52, 112, 12, 12
CONTROL "", Button_Map_1, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 52, 128, 12, 12
CONTROL "", Button_Jump_2, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP, 68, 48, 12, 12
CONTROL "", Button_Attack_2, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 68, 64, 12, 12
CONTROL "", Button_Weapon_Plus_2, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 68, 80, 12, 12
CONTROL "", Button_Weapon_Minus_2, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 68, 96, 12, 12
CONTROL "", Button_Item_2, BUTTON, BS_AUTORADIOBUTTON | WS_CHILD | WS_VISIBLE, 68, 112, 12, 12
EDIT : Note that I looked at the .rc file with a hex editor and all the newlines are fine, the conversion to ANSI worked properly
EDIT 2 : The path to the .rc file doesn't have any spaces or anything that should screw with windres :
C:\Users\Gabriel\Documents\DoConfig\DoConfig\DoConfig.rc
EDIT 3 : The windows.h file is in my include directory, I checked manually. Plus, the .cpp file uses it and it didn't fail to compile.
EDIT 4 : Removing the line that includes the windows.h file doesn't change anything, it still gives the same error.
EDIT 5 : Naming every class by string instead of by name directly worked and eliminated all error messages.
Control's class name should be "BUTTON", not BUTTON
Button_Use_Gamepad should be defined as an integer
Corrected format:
CONTROL "Use Gamepad", 101, "BUTTON", BS_AUTOCHECKBOX | WS_TABSTOP, 12, 16, 100, 12
Related
I try to use AdjustWindowRectEx() function to get the sizes of the window frame with aero theme enabled.
But I found that AdjustWindowRectEx() function returns different results in Visual Studio 2012 and C++ Builder XE7.
All tests performed on Windows 7.
Firstly I try to get the window frame sizes for these styles (it is which corresponds to BorderStyle = bsDialog in C++ Builder):
DWORD styles = WS_CAPTION | WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU;
DWORD ex_styles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW;
RECT r = {0};
AdjustWindowRectEx(&r, styles, false, ex_styles);
It returns:
VS: left: -8; top: -30; right: 8; bottom: 8
CB: left: -3; top: -25; right: 3; bottom: 3
Here, the code executed in Visual Studio returns the correct result. And on C++Builder - there are wrong return values.
Let's try another styles (it is equivalent to BorderStyle = bsToolWindow in C++ Builder):
DWORD styles = WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_OVERLAPPED;
DWORD ex_styles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW;
It returns:
VS: left: -8; top: -26; right: 8; bottom: 8
CB: left: -3; top: -21; right: 3; bottom: 3
Here, the code executed in Visual Studio returns the correct result also. But in Builder not.
But I found that return values are equal both on Visual Studio and C++ Builder with these styles (it is corresponds to BorderStyle = bsSizeable in C++ Builder):
DWORD styles = WS_CAPTION | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_SYSMENU | WS_THICKFRAME | WS_OVERLAPPED | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
DWORD ex_styles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT | WS_EX_APPWINDOW;
It returns:
VS: left: -8; top: -30; right: 8; bottom: 8
CB: left: -8; top: -30; right: 8; bottom: 8
And my question is: why AdjustWindowRectEx() function returns different values for the same request styles on Visual Studio and C++ Builder?
By experience, I found out that to get correct window frame sizes using AdjustWindowRectEx() function compiled in C++ Builder (and Visual Stuidio also), it is necessary to add the WS_THICKFRAME style to request.
Also to adapt the code to different window styles, it is necessary to check whether it is appropriate to add WS_THICKFRAME: namely, if the styles WS_CAPTION and WS_THICKFRAME aren't set (in case when the window has no frames), the WS_THICKFRAME style isn't added to request.
RECT r = {0};
DWORD styles = GetWindowLongPtr(Handle, GWL_STYLE);
styles |= (!(styles & WS_CAPTION) && !(styles & WS_THICKFRAME)) ? 0 : WS_THICKFRAME;
AdjustWindowRectEx(&r, styles, false, GetWindowLongPtr(Handle, GWL_EXSTYLE));
Of course, the real reason stays unknown.
I'm completely new to MFC and have been working on this issue for a couple of days now and can't find any solution that works.
Problem:
I have a dialog class (Modal Dialog Box) with a style defined in an .rc file (Code below) and get the resource id of the icon (int m_icon is the same as IDR_MAINFRAME) from another class (OtherClass.rc).
All the text information inside the Dialog Box is set dynamically (Code below) but the same doesn't work with the Icon. The marked Icon in the image below is what I'm trying to set.
The Icon Resource is defined in another .rc file and the LoadImage seems to work as I can set the small Icon in the top left of the window. The only problem is setting the big icon in this image. (Not shown at all, just an empty space)
OtherClass.rc
IDR_MAINFRAME ICON "res\\MyIcon.ico"
Dialog.rc
ABOUTBOX DIALOGEX 0, 0, 285, 77
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "<<Aboutbox>>"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
ICON ABOUT_ICON, ABOUT_ICON, 11, 10, 21, 20
LTEXT "", IDC_STATIC, 40, 10, 163, 8, SS_NOPREFIX
LTEXT "<<Package Name 1.00>>", ABOUT_NAME, 40, 20, 163, 8, SS_NOPREFIX
LTEXT "<<FileName>>", ABOUT_FILENAME, 40, 30, 163, 8, SS_NOPREFIX
DEFPUSHBUTTON "OK", IDOK, 217, 7, 60, 14, WS_GROUP
END
Dialog.cpp
BOOL AboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Window Title
SetWindowText(L"About " + m_title);
// Set Icon
HICON hIcon = (HICON)LoadImage(GetModuleHandleW(NULL), MAKEINTRESOURCE(m_icon), IMAGE_ICON, 96, 96, LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
SetIcon(hIcon, FALSE);
// Text
SetDlgItemText(ABOUT_NAME, m_name);
SetDlgItemText(ABOUT_FILENAME, m_filename);
return TRUE;
}
What I've tried doing is:
1. GetDlgItem(ABOUT_ICON)->SetIcon(hIcon, TRUE);
2. SendMessage(WM_SETICON, ICON_BIG, (LPARAM)hIcon);
and many more things along those lines but the icon space just remains empty. Neither the LoadImage nor the GetDlgItem(ABOUT_ICON) returns a nullptr (already checked that).
You shouldn't have to do any thing like SetIcon or SendMessage to get an icon to show. What's wrong is your RC file is wrong. It should look like this:
ABOUTBOX DIALOGEX 0, 0, 285, 77
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "<<Aboutbox>>"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
ICON ABOUT_ICON, IDC_STATIC, 11, 10, 21, 20
LTEXT "", IDC_STATIC, 40, 10, 163, 8, SS_NOPREFIX
LTEXT "<<Package Name 1.00>>", ABOUT_NAME, 40, 20, 163, 8, SS_NOPREFIX
LTEXT "<<FileName>>", ABOUT_FILENAME, 40, 30, 163, 8, SS_NOPREFIX
DEFPUSHBUTTON "OK", IDOK, 217, 7, 60, 14, WS_GROUP
END
Take a look at the ICON line after the BEGIN line.
You had it as ABOUT_ICON, ABOUT_ICON, 11, 10, 21, 20, but the 2nd parameter tells the framework what the ID of the control is. Since you want a Static control, you use the ID of IDC_STATIC which tells the framework there is no ID, but instead it should create a generic Static control.
If this doesn't fix it, I would investigate if ABOUT_ICON is wired up correctly, that it actually is pointing at an icon.
Also, why are you working in the RC file? MFC gives you a great GUI editor. For example, you could modify it using the UI:
I managed to get custom text color in REC, but I can't make it to use the desired font (Consolas).
(EDIT) Creating REC:
LoadLibrary(TEXT("Msftedit.dll"));
hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, MSFTEDIT_CLASS, L"",
WS_CHILD | WS_VISIBLE | ES_MULTILINE,
0, 0, 300, 300,
hwnd, NULL, GetModuleHandle(NULL), NULL);
-
CHARFORMAT cf = {};
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_FACE;
cf.crTextColor = RGB(255, 0, 255);
cf.bPitchAndFamily = DEFAULT_PITCH | FF_MODERN;
memcpy(cf.szFaceName, L"Consolas", sizeof(L"Consolas"));
SendMessage(hEdit, EM_SETCHARFORMAT, NULL, (LPARAM)&cf);
I'm using
#ifndef UNICODE
#define UNICODE
#endif
Few answers that i found but didn't help me much...
Win32 : set default font and text color for rich edit,
How to set a font in rich edit 4?
Note: the REC has no text in it
This is what i get...
5 'i' and 5 '0' should have same spacing with Consolas, Right?
I am trying to create a button dynamically. I have read some other resource and make the following code:
BEGIN_MESSAGE_MAP(Cdynamic_button_sdiView, CView)
// Standard printing commands
ON_BN_CLICKED(MYBUTTONID, OnMyBN_Click)
END_MESSAGE_MAP()
void Cdynamic_button_sdiView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_Button.Create(_T("Rearrange"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 128, 32), this, MYBUTTONID); // here will create a button
}
I can make a button successfully when I start the MFC application. The problem is that when I try to open a new document by clicking:
I get an error and my app crashed at m_Button.Create(_T("Rearrange"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 128, 32), this, MYBUTTONID);
I solved the problem with the following code:
Cdynamic_button_sdiView::Cdynamic_button_sdiView()
{
// TODO: add construction code here
m_Button = NULL;
}
Cdynamic_button_sdiView::~Cdynamic_button_sdiView()
{
if (m_Button != NULL)
delete m_Button;
}
void Cdynamic_button_sdiView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if (m_Button != NULL)
delete m_Button;
m_Button = new CButton;
m_Button->Create(_T("Rearrange"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CRect(0, 0, 128, 32), this, MYBUTTONID); // here will create a button
}
May be the problem is I should not re-create the window inside the OnInitialUpdate()
I am using Windows 10 (Visual Studio 2015).
Alright I just want to start off by saying is that I am using an edit box for the user to write a directory,appname,comboboxname then having wofstream output the directory,appname,comboboxname into a .txt file.
My problem is that some directories have spaces so when wifstream reads those spaces then cuts off the directory to early and stores the cut off version into one of the wchar_t variables.
What I need for the program to do (I am not sure if its possible) is output line by line.
Example:
C:\Program Files (x86)\Minecraft
MinecraftLauncher
Minecraft
Then use getline to read the whole line including the spaces, store that line into a variable and then get the next line. (But it also can't grab any extra white spaces that aren't in the directory otherwise it won't work) you guys probably know how directories work lol)
So you guys don't have to look that hard, I want this to occur in the case IDB_CLICK_ME.
Here is my code currently, something I am tinkering with before I decide to add it to my main application:
This is where I am trying to read the file (without whitespaces)
case WM_CREATE:
{
wchar_t testData[20] = L"Hai";
CreateWindow(L"button", L"CLICK ME", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5, 5, 200, 25, hwnd, (HMENU)IDB_CLICK_ME, NULL, NULL);
comboBox = CreateWindow(L"combobox", L" ", WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST, 5, 50, 100, 100, hwnd, (HMENU)4, NULL, NULL);
hProgramName = CreateWindow(L"edit", L"Program Name", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 100, 200, 25, hwnd, NULL, NULL, NULL);
hProgramDirectory = CreateWindow(L"edit", L"Program Directory", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 130, 200, 25, hwnd, NULL, NULL, NULL);
hProgramNameComboBox = CreateWindow(L"edit", L"Name listed in ComboBox", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 160, 200, 25, hwnd, NULL, NULL, NULL);
std::wifstream myfile;
myfile.open("LaunchLocations.txt");
myfile >> std::noskipws >> gameLaunchtest.directory;
myfile >> std::noskipws >> gameLaunchtest.AppName;
myfile >> std::noskipws >> gameLaunchtest.ComboBoxName;
This is where I am writing it, so far this works correctly
ComboBox_AddString(comboBox, gameLaunchtest.directory);
break;
case WM_COMMAND:
switch (LOWORD(wparam))
{
case IDB_CLICK_ME:
GetWindowText(hProgramDirectory, gameLaunchtest.directory, MAX_PATH);
GetWindowText(hProgramName, gameLaunchtest.AppName, MAX_PATH);
GetWindowText(hProgramNameComboBox, gameLaunchtest.ComboBoxName, MAX_PATH);
wofstream launchLocations;
launchLocations.open("LaunchLocations.txt");
launchLocations << gameLaunchtest.directory << endl;
launchLocations << gameLaunchtest.AppName << endl;
launchLocations << gameLaunchtest.ComboBoxName << endl;
launchLocations.close();
So the way I fixed my problem (I was told by some very helper member that I must use the wifstream getline instead of the string getline)
std::wifstream myfile;
while (myfile.getline(test[number].directory, 100))
{
myfile.getline(test[number].AppName, 100);
myfile.getline(test[number].ComboBoxName, 100);
test[number].ID;
ComboBox_AddString(comboBox, test[number].ComboBoxName);
number++;
test[number].ID = test[number].ID + 1;