|
Alternatively you can override PreTranslateMessage
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if ((pMsg->wParam == 13) || (pMsg->wParam == 27))
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
Sorry cant remember the VK defns (its too late!)
Ant.
|
|
|
|
|
I would like to know the basic Difference Between CListCtrl and CListView.
Does each of them behave differently ?
laiju
|
|
|
|
|
The CListCtrl wraps a Win32 Common Controls List View. It's a straight control. The CListView is actually derived from CView and wraps the List View so that it can be used in the Document / View architecture of MFC. The controls behave the same, the difference is the intended use.
|
|
|
|
|
First I do appreciate your help .But iam sorry to say that I have not understood the basic difference between CListView and CListCtrl.
I would appreciate if you could elaborate on the fundamentals.
laiju
|
|
|
|
|
CListCtrl is the MFC wrapper class for a Windows list control.
CListView is the corresponding 'view' class in MFC, when you want one of the views in your document/view application to be implemented using a list control. One of the member functions of CListView returns a reference to the underlying CListCtrl.
If you are building a document/view application, and want one of your views to be a list control, you will use CListView. Within dialog boxes, you use CListCtrl.
Software Zen: delete this;
|
|
|
|
|
In the MFC SDI applications how can get a pointer to the frame object from the view or documect object?
|
|
|
|
|
AfxGetMainWnd()
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
I use the following code to set the cursor of a window:
HCURSOR cursor = theApp.LoadStandardCursor(IDC_ARROW);<br />
<br />
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(),<br />
GCL_HCURSOR,<br />
(LONG) cursor);<br />
The problem is that I get the following compiler warning:
warning C4311: 'type cast' : pointer truncation from 'HCURSOR' to 'LONG'
How do I do this the right way??
Øivind
|
|
|
|
|
Original function is:
ULONG_PTR SetClassLongPtr(
HWND hWnd,
int nIndex,
LONG_PTR dwNewLong
);
That mean the you have poenter on cursor and need write:
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(),
GCL_HCURSOR,
(LONG_PTR) &cursor);
HCURSOR is "typedef unsigned int HCURSOR" but you need poenter on address.
|
|
|
|
|
With your code, I don't get any warnings, but the cursor doesn't change.. =(
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(), <br />
GCL_HCURSOR,<br />
(LONG_PTR) &cursor);
|
|
|
|
|
Weee! I got it right. I only needed to cast the cursor to (LONG_PTR) and not reference it:
SetClassLongPtr(GetDlgItem(IDC_COLORDISPLAY)->GetSafeHwnd(), <br />
GCL_HCURSOR,<br />
(LONG_PTR) cursor);
|
|
|
|
|
I made an empty Win32 project in VC++ v7, and then added a C++ file to it. I made an exact copy of one of the Direct3D working tutorials and pasted it into the empty C++ file. I copied all of the DirectX include files and library's into the directories tbat VC++ uses. When I try to build it, it gives me the following errors:
Linking...
AnotherOne.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "long __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAJPAUHWND__@@@Z)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXCreateTextureFromFileA@12 referenced in function "long __cdecl InitGeometry(void)" (?InitGeometry@@YAJXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXLoadMeshFromXA@32 referenced in function "long __cdecl InitGeometry(void)" (?InitGeometry@@YAJXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
AnotherOne.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "void __cdecl SetupMatrices(void)" (?SetupMatrices@@YAXXZ)
Debug/AnotherOne.exe : fatal error LNK1120: 7 unresolved externals
Yes, I named the project "AnotherOne," this is because of several attempts If anyone could help me out, that would be great.
-Dev578
|
|
|
|
|
did you set the lib that needs to be linked to use DirectX.
i dont know the lib name, you can either put in the link section in the project settings or
#pragma comment(lib,"libname.lib")
in stdafx.h
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
did you linked the libraries for D3D
(in OpenGl : glaux.lib...)
|
|
|
|
|
You should specify the directX libs in the project settings.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
Hi everyone,
i'm trying to write a real-time image processing program.I've made the following class, how can i improve it further?
array[] contains all the image bits from a CBitmap
using GetBitmapBits. First 8 bits=Blue, next 8 Green,
next 8 Red and next 8 unused.
BitDepth=4;
How can i improve the Threshold, Grayscale & Rotate functions? It must be timecritical.
Usage,
uImage image;
image.Create(bmp_x_width,bmp_y_width,32);
image.GetImage(&memDCLoad);
image.Grayscale();
image.Rotate(45);
image.SetImage(&memDCLoad);
pDC->StretchBlt(243,30,stretch_x,stretch_y,&memDCLoad,0,0,bmp_x_width,bmp_y_width,SRCCOPY);
class uImage
{
private:
int height_y;
int width_x;
int bitDepth;
int imgDepth;
public:
BYTE *array;
BYTE *array_copy;
CBitmap *pBitmap;
void Create(int x,int y,int depth);
void GetImage(CDC *MemDC);
void SetImage(CDC *MemDC);
void Delete();
BYTE GetR(int x,int y);
BYTE GetG(int x,int y);
BYTE GetB(int x,int y);
void SetR(int x,int y, BYTE value);
void SetG(int x,int y, BYTE value);
void SetB(int x,int y, BYTE value);
void Threshold(int value);
void Grayscale();
void Rotate(double degree);
};
void uImage::GetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->GetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::SetImage(CDC *MemDC)
{
pBitmap =MemDC->GetCurrentBitmap();
pBitmap->SetBitmapBits(bitDepth*width_x*height_y,array);
}
void uImage::Create(int x,int y, int depth)
{
bitDepth=depth/8;
imgDepth=depth;
array=new BYTE[x*y*bitDepth];
array_copy=new BYTE[x*y*bitDepth];
height_y=y;
width_x=x;
}
void uImage::Delete()
{
delete[] array;
delete[] array_copy;
}
BYTE uImage::GetR(int x, int y)
{
return array[(x+y*width_x)*bitDepth+2];
}
BYTE uImage::GetG(int x, int y)
{
return array[(x+y*width_x)*bitDepth+1];
}
BYTE uImage::GetB(int x, int y)
{
return array[(x+y*width_x)*bitDepth+0];
}
void uImage::SetR(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+2]=value;
}
void uImage::SetG(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+1]=value;
}
void uImage::SetB(int x, int y, BYTE value)
{
array[(x+y*width_x)*bitDepth+0]=value;
}
void uImage::Threshold(int value)
{
BYTE gray;
int temp;
for(int i=0;i<width_x*height_y;i++)
{
="" temp="i*4;
" gray="array[temp];
" if(gray<="value)
" array[temp++]="0;//blue
" }
="" else
="" }
}
void="" uimage::grayscale()
{
=""
="" byte="" gray;
="" int="" temp;
for(int="" i="0;i<width_x*height_y;i++)
" +array[temp+2]*0.299);
="" array[temp]="gray;
" array[temp+1]="gray;
" array[temp+2]="gray;
" }
}
void="" uimage::rotate(double="" degree)
{
double="" pi="3.1415926535897932384626433832795;
double" angle_rad="PI/180*degree;
double" cos="cos(angle_rad);
double" sin="sin(angle_rad);
int" center_x="width_x/2;
int" center_y="height_y/2;
int" xs;
int="" ys;
for(int="" xd="0;xd<width_x;xd++)
" for(int="" yd="0;yd<height_y;yd++)
" xs="(int)" (xd*cos-yd*sin+center_x*(1-cos)+center_y*sin);
="" ys="(int)" (xd*sin+yd*cos-center_x*sin+center_y*(1-cos));
="" if(!((xs<0)||(ys<0)||(xs="">(width_x-1))||(ys>(height_y-1))))
{
array_copy[(xd+yd*width_x)*bitDepth]=array[(xs+ys*width_x)*bitDepth];
array_copy[(xd+yd*width_x)*bitDepth+1]=array[(xs+ys*width_x)*bitDepth+1];
array_copy[(xd+yd*width_x)*bitDepth+2]=array[(xs+ys*width_x)*bitDepth+2];
}
else
{
array_copy[(xd+yd*width_x)*bitDepth]=255;
array_copy[(xd+yd*width_x)*bitDepth+1]=255;
array_copy[(xd+yd*width_x)*bitDepth+2]=255;
}
}
array=array_copy;
}
|
|
|
|
|
in what way ?
do you really need to create the array_copy when you create your object ? maybe delay it when you actually need it.
maybe put array and array_copy in private part of the class ?
when you rotate an image, me think the size of the array needs to be changed ? no ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
I want to improve the code, to speed it up. I mean, perhaps using some MMX, more pointers etc to really speed the code...
The .create will only be executed once, so creating an array_copy is ok there, other functions like Threshold, Grayscale, Rotate will be called over and over again, and if i declare array_copy there will cause overhead.
Yeah, you are right, i'll put array & array_copy in private.
The size of the image need not be changed, coz anything that goes beyond the current size of the image, i will ommit.
So, how can i speed the code to be faster? Can you see any bottlenecks anywhere?
Thx
|
|
|
|
|
Nothing really stands out to me from a quick look. However, one thing you could improve - in the Rotate function the array indexes are this :
array_copy[(xd+yd*width_x)*bitDepth]=array[(xs+ys*width_x)*bitDepth];
the values (xd+yd*width_x)*bitDepth and (xs+ys*width_x)*bitDepth are computed three times per loop. You could save those into temporary variables and speed things up a bit.
Also, the code appears garbled for the loop terms. You could possibly save any factors from the outer loop so that they are not recalculated for each term of the inner loop.
These may seem minor but when they are done hundreds or thousands of times per pass they can add up.
a two cent stamp short of going postal.
|
|
|
|
|
You are right, i can cut some time there, thanks. Anything else?
|
|
|
|
|
I have one CSplitterWnd inside my CFrameWnd with 3 rows and one column. In the first two rows are two different CFormViews and in the last row is a new CSplitterWnd with 1 row and 2 columns, which contain a CFormView each. The creation works with the following code in CFrameWnd::OnCreateClient:
<br />
m_wndSplitterMain.CreateStatic( this, 3, 1 ) )<br />
m_wndSplitterMain.CreateView( 0, 0, RUNTIME_CLASS(CFunctionsDlg), size, pContext );<br />
<br />
m_wndSplitterMain.CreateView( 1, 0, RUNTIME_CLASS(CPlaylistDlg), size, pContext );<br />
<br />
m_wndSplitterBrowser.CreateStatic(&m_wndSplitterMain, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitterMain.IdFromRowCol(2, 0));<br />
<br />
m_wndSplitterBrowser.CreateView(0, 0, RUNTIME_CLASS(CDirectoryDlg), size, pContext);<br />
m_wndSplitterBrowser.CreateView(0, 1, RUNTIME_CLASS(CFilelistDlg), size, pContext);
The problem is, that I use the WM_SIZE messages within the 4 CFormViews to resize the controls, but I don't get a WM_SIZE message for the first two CFormViews (within the first CSplitterWnd), with a safe (GetSafeHwnd() != NULL) handle of the dialog controls of that CFormView. Only the last 2 CFormViews (within the second CSplitterWnd) get correct WM_SIZE messages.
Even if I call RecalcLayout( true ); from within CFrameWnd only the last two CFormViews get the WM_SIZE messages. Is that bug already confirmed by Microsoft? What is a workaround for that?
Thanks for any help!
Konrad
|
|
|
|
|
In the WM_SIZE handler for your CFrameWnd, you will need to call m_wndSplitterMain.RecalcLayout() and m_wndSplitterBrowser.RecalcLayout().
Software Zen: delete this;
|
|
|
|
|
So there is no bug in the MFC???
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|
Mr.Prakash wrote:
So there is no bug in the MFC???
I don't think so. I'll grant you, however, that the CSplitterWnd class is difficult to work with. I spent two days this week working on splitter-related problems in an application.
Software Zen: delete this;
|
|
|
|
|
Thanx for a good answer. but my question was sarcastic.
MSN Messenger.
prakashnadar@msn.com
Tip of the day of visual C++ IDE.
"We use it before you do! Visual C++ was developed using Visual C++"
|
|
|
|
|