设置它的字体时,我遇到了CEdit的尴尬行为:对于某个字体大小,像'g'或'j'这样的字母缺少底部,无论CEdit的rect高度如何.这是两个例子:
CFont *ctrlFont = new CFont();
ctrlFont ->CreatePointFont(80, "Arial Black");
CEdit m_editName;
m_editName.SetFont(ctrlFont);
Run Code Online (Sandbox Code Playgroud)
结果如下:

但对于
ctrlFont ->CreatePointFont(100, "Arial Black");
Run Code Online (Sandbox Code Playgroud)
一切都好

如您所见,在两种情况下,CEdit的rect高度都大于文本的高度.父控件是CDialog; 设置字体::OnInitDialog,CEdit的大小设置为SetWindowPos方法打开::OnShowWindow.什么可能导致这种情况,我应该如何处理它?
编辑:我已经尝试过@rrirower的建议,现在我很困惑; 添加CEdit CDC到CFont的初始化改变了文本的掩码很多(你可能没有看到它从开始,但我有其他编辑与旧字体在同一页面,并有很大的区别):
ctrlFont1->CreatePointFont(80, "Arial Black", m_editName.GetDC());
Run Code Online (Sandbox Code Playgroud)

我有一个头文件global.h,我声明了一些我打算在其他文件中使用的变量.
#ifndef GLOBAL_H_
#define GLOBAL_H_
#include <stdio.h>
typedef struct tag_KG_Data
{
int nKGStationID;
int nKGComPort;
}GLOBAL_VAR;
GLOBAL_VAR g_GlobalVar;
BOOL b_newDataReady;
BOOL b_startedSocketClient;
#endif
Run Code Online (Sandbox Code Playgroud)
起初,我只申报GLOBAL_VAR g_GlobalVar文件test1.cpp与extern GLOBAL_VAR g_GlobalVar;和工作就好了.然后我宣布2 BOOLs并使用它们test2.cpp,但我得到一个error LNK2005: "struct tag_KG_Data g_GlobalVar" (?g_GlobalVar@@3Utag_KG_Data@@A) already defined in test1.obj和每个全局变量我得到一个类似的错误.问题是我不使用GLOBAL_VAR g_GlobalVarin test2.cpp或任何BOOLs in test1.cpp.
我尝试更新编辑控件的文本,使用它添加的变量,这是一个,CString但我失败了.
m_sNrAuto = "some text";
UpdateData(TRUE);
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用UpdateWindow(),但编辑控件仍然是空白的.我知道我可以通过使用来实现它SetWindowText(),但我也看到了一些SetWindowText()不使用它的片段,更新是通过将值传递给附属的CString来完成的.
我有2个组合框和一个微调器,其工作方式如下:如果第一个组合的所选项目发生了更改,则第二个组合会保留其选定的项目但重新调用微调器(微调器仅链接到第二个框).我的问题是,当我这样做时,我无法触发微调器的stateChange监听器.
这是强制第二个盒子在第一个盒子改变时重新选择它的最后一个项目的代码(这里没有错,它工作得很好):
String orientare = (String) orientareComboBox.getSelectedItem();
orientareComboBox.setSelectedItem(orientare);
Run Code Online (Sandbox Code Playgroud)
这是第二个框actionListener的代码:
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
String value = combo.getSelectedItem().toString();
if (value.equalsIgnoreCase("oblica"))
{
unghiSpinner.setEnabled(true);
double unghi = (double) unghiSpinner.getValue();
unghiSpinner.setValue(new Double(unghi));
}
}
Run Code Online (Sandbox Code Playgroud)
锭床工人的听众:
public void stateChanged(ChangeEvent e)
{
if (unghiSpinner.isEnabled())
{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道我应该用什么命令unghiSpinner来触发它的监听器,因为setValue()不能这样做.
我正在尝试复制CString到一个char*使用memcpy(),我很难做到这一点.实际上,只复制第一个字符.这是我的代码:
CString str = _T("something");
char* buff = new char();
memcpy(buff, str, str.GetLength() + 1);
Run Code Online (Sandbox Code Playgroud)
在此之后,所有buff内容都是字母s.
我有一个像这样的定义结构:
typedef struct tag_GLOBAL_VAR
{
int array1[4];
int array2[5];
.......
int array20[40];
}GLOBAL_VAR;
Run Code Online (Sandbox Code Playgroud)
此结构用于在某个类中定义变量:
GLOBAL_VAR g_GlobalVar;
Run Code Online (Sandbox Code Playgroud)
然后在另一个类中使用,如下所示:
extern GLOBAL_VAR g_GlobalVar;
class constructor;
class destructor;
int class::Start()
{
//g_GlobalVar.array1 = {1,2,3,4};
//g_GlobalVar.array4 = {1,2,3};
some code;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,我无法初始化(注释行)这样的2个数组,我得到了error C2059: syntax error : '{'VS. 为什么这是错误的,哪个是解决方案呢?
使用此代码我得到一个错误的atoi的转换,从CString到int:
int nrCentrala; CString idCentrala;
GetDlgItem(IDC_EDIT_IDCENTRALA)->GetWindowText(idCentrala);
nrCentrala = atoi(&idCentrala);
Run Code Online (Sandbox Code Playgroud)
哪里IDC_EDIT_IDCENTRALA是编辑控件.
Error 7 error C2664: 'atoi' : cannot convert parameter 1 from 'CString *' to 'const char *'
我尝试完成本教程,但我不知道VS 2008项目要使用什么,因为我尝试过的所有内容都给了我一个error C2731: 'wWinMain' : function cannot be overloaded错误(对于Win32项目,我从教程中更改了APIENTRY _tWinMain()with WINAPI WinMain()方法),或许多错误就像error LNK2019: unresolved external symbol _closesocket@4 referenced in function _WinMain@16.
我有3个类:A,B和C.C #include由B编辑,B #includ由A编辑.在C类中,我为按钮定义了一个处理程序,当按下按钮时,C将PostMessage对象A.我在C中包含A,我将有一个循环引用,那么我该怎么做才能避免这种循环引用?
编辑:所有包含都是在实现文件中.
我需要将unsigned char数组从一个方法传递给另一个方法,我尝试使用此代码:
{
unsigned char *lpBuffer = new unsigned char[182];
ReceiveSystemState(lpBuffer);
}
BOOL ReceiveSystemState(unsigned char *lpBuffer)
{
unsigned char strRecvBuffer[182] = { 0 };
//strRecvBuffer construction
memcpy(lpBuffer, strRecvBuffer, sizeof(strRecvBuffer));
return TRUE;
}
Run Code Online (Sandbox Code Playgroud)
这三种方法(用于ReceiveSystemState)都没有像我预期的那样工作.在使用它们中的每一个之后,它被复制的所有内容都是来自的第一个字符strRecvBuffer,仅此而已.的strRecvBuffer具有从单元到单元空字符,但我需要那些,因为它们是,因为该字符串是从一个硬件设备的消息和该消息将使用的协议来anallysed.我在这里想念什么?我初始化lpBuffer错了吗?
编辑:我用一种简单的memcpy方法来完成这项工作.结果仍然相同:它被复制的全部是第一个字符strRecvBuffer.
EDIT2:工作代码:
{
unsigned char *lpBuffer = new unsigned char[182];
ReceiveSystemState(lpBuffer);
for (int i = 0; i < 144; i++)
{
memcpy(&c_dateKG[i], lpBuffer + i * sizeof(unsigned char), sizeof(unsigned char) );
}
}
BOOL ReceiveSystemState(unsigned …Run Code Online (Sandbox Code Playgroud)