|
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++"
|
|
|
|
|
I am using EnumProcesses functon in my program and also GetModuleBaseName.But its gives linker error.
error is unresolved external symbol for both this function.
|
|
|
|
|
add this in the stdafx.h
#pragma comment(lib, psapi.lib)
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++"
|
|
|
|
|
#pragma comment(lib, "psapi.lib")
(Mr. Prakash forgot the quotes)
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote:
(Mr. Prakash forgot the quotes)
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++"
|
|
|
|
|
Hi
I am try to find one solution but failed ... i had treid hard but not seems to success...
Generally I had download one example from
http://www.codeguru.com/Cpp/W-P/dll/article.php/c3637
In this example One MDI application is in .dll with resouce and Resouce is displaying from Main application.
<cpp>
in .dll describe like this
#define CLSID_APP 0x10
// interface IDs
#define IID_MyIUnknown 0x1000
#define IID_IDocument 0x1001
// document constants
#define C_DOC_1 0x100
#define C_DOC_2 0x101
// instantiate an interface class object
BOOL __declspec(dllexport) App_GetClassObject(int nClsid,
int nId,
void** ppvObj);
struct MyIUnknown
{
MyIUnknown() { TRACE("Entering IUnknown ctor %p\n", this); }
virtual BOOL QueryInterface(int nIid, void** ppvObj) = 0;
virtual DWORD Release() = 0;
virtual DWORD AddRef() = 0;
};
struct AFX_EXT_CLASS IDocument : public MyIUnknown
{
IDocument() { TRACE("Entering IDocument ctor %p\n", this); }
virtual CDocTemplate* CreateDocTempl( CWinApp*, int ) = 0;
virtual void CreateFrame() = 0;
};
//end of .dll
<cpp>
in .exe calling like this
<cpp>
void CExeApp::InitDll()
{
VERIFY( App_GetClassObject(CLSID_APP,
IID_IDocument,
(void**)&pIDoc) );
}
///and
BOOL CExeApp::InitInstance()
{
InitDll();
pIDoc->CreateDocTempl(this, C_DOC_1);
pIDoc->CreateFrame();
}
also
int CExeApp::ExitInstance()
{
// TODO: Add your specialized code here and/or call
// the base class
ReleaseDll();
return CWinApp::ExitInstance();
}
void CExeApp::ReleaseDll()
{
pIDoc->Release();
}
//end of .exe
<cpp>
So this code for loading resouce from .dll. ALl going great it's loading resouce from .dll and taking function also
But Now problem is there in .dll i have one dialog that i am displaying from .exe . SO in this dialog i want to call one function from Button1
so i have to copy my function into .dll but it's useless..
Basically i want to creat this function in .exe and calling from .dll like this
This will be in .dll
<cpp>
CDialog::OnButton1
{
CallFunctionFromexe()
}
<cpp>
This will be in .exe
CFormView::Void CallFunctionFromexe()
{
//my function
}
So i one who can understand all this say me how i do all this ?
This is some ascii work also
Dll has
Contain Resource------>One Dialog with Button1
| |
| |
| |
| Dialog::OnButton1()
| {
| callfunctionfromexe()
| }
|
|
|
exe has
Importing resouce-------->Function ::Void Callfunctionfromexe()
from .dll
SO when button1 will clicked so function will call from .exe using resouce .dll
Suggestion required !!!!!!!!
thanx
naresh
|
|
|
|
|