我试图从我的客户端矩形中使用成员变量,但他们持有极其负值,如-858993460。即使当我调用rect.Width()时,它也会返回一个极其负数的数字。当我选择我在屏幕上绘制的波时,我需要这些值来确定要播放的波形文件的相应部分。有谁会碰巧知道为什么可以这样做?CRect成员变量有奇怪的值
注意:为了看看它们保留的是什么值,我抛出了int的右,左和宽。我真的只需要rect.Width()来缩放选择,以便能够访问我的wave文件的数据数组。
void CWaveEditView::OnToolsPlay32775()
{
// TODO: Add your command handler code here
CWaveEditDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!pDoc){
return;
}
if(pDoc->wave.hdr==NULL){
return;
}
if(selectionStart!=selectionEnd){
CRect rect;
GetClientRect(&rect);
rect.NormalizeRect();
int right = rect.right;
int left = rect.left;
int width = rect.Width();
int startms=(1000.0*pDoc->wave.lastSample/pDoc->wave.sampleRate)*selectionStart/rect.Width();
int endms=(1000.0*pDoc->wave.lastSample/pDoc->wave.sampleRate)*selectionEnd/rect.Width();
WaveFile * selection = new WaveFile(pDoc->wave.numChannels, pDoc->wave.sampleRate, pDoc->wave.bitsPerSample);
while(startms<=endms){
selection->add_sample(pDoc->wave.get_sample(startms));
startms++;
}
selection->updateHeader();
selection->play();
delete selection;
}
-858993460是0xCCCCCCCC,这是调试器表达“未初始化的变量”的方式。我的猜测是'GetClientRect'调用由于某种原因失败,并且使'rect'未初始化。或许你的观点在某种程度上目前还没有一个有效的'HWND'。 –
你知道会导致什么吗?我的观点工作得很好,因为它吸收了它应有的一切。 – Otto45
那么,你可以先检查'GetClientRect'的返回值,如果失败,用'GetLastError'检查原因。 –