|
Try
CString text;
GetDlgItemText(IDC_STATIC_1, text);
CSize csText = pDC->GetTextExtent(text);
GetDlgItem(IDC_STATIC_1)->SetWindowPos(this, 0, 0, csText.cx, csText.cy, SWP_NOMOVE);
|
|
|
|
|
i using this on OnInitDialog but there is no change
|
|
|
|
|
Insert a breakpoint on the line GetDlgItem(IDC_STATIC_1)->SetWindowPos(this, 0, 0, csText.cx, csText.cy, SWP_NOMOVE) by clicking on the grey stripe to the left of the code and run the project.
When the breakpoint is hit hover over the variables text and csText to make sure their values are something that you would expect.
|
|
|
|
|
I just want the click event and cursor on mouse move is not set on blank space at the end of text in control,
variables text having the caption of control and csText (cx=92 and cy=16) and on the dialog the cordinates of control (x=10,y=233,width=100,height=10)
|
|
|
|
|
Sorry, I forgot to say that you need to select the font:
CWnd *pStatic = GetDlgItem(IDC_STATIC_1);
CDC *pDC = GetDC();
CString text;
pStatic->GetWindowText(text);
CFont *pOldFont = pDC->SelectObject(pStatic->GetFont());
CSize szText = pDC->GetTextExtent(text);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
pStatic->SetWindowPos(this, 0, 0, csText.cx, csText.cy, SWP_NOMOVE);
There is another way of doing this rather than in the OnInitDialog, still using GetTextExtent.
You can check if the mouse is inside the text rect in the event (OnClick or OnMouseMove), but this requires more code
|
|
|
|
|
so now where i can use this
|
|
|
|
|
I would suggest sticking with OnInitDialog unless you want the static to keep the same dimensions for appearances sake (border, ...)
|
|
|
|
|
I have an MFC app, which uses an accelerator for DEL, ctrl+X and others. I also have an ATL dll which opens a modeless dialog with an edit control. Problem is, when I hit DEL or ctrl+X in this edit control, it's routed to the main app, which, need I say, leaves the user quite surprised. Any ideas on how to solve this?
EDIT: hmm, well what do you know... This site[^] is a great souce of knowledge...
home
modified on Monday, January 17, 2011 8:03 AM
|
|
|
|
|
I have installed Netbeans for C++ but i think it requires a separate installation of compiler also, kindly guide me from where can i download a free compiler of C++ for NetBeans IDE 6.9.1 (Build 201007282301)
|
|
|
|
|
Directly on the NetBeans web site they say it works with CygWin and MinGW.
Find them here CygWin[^] and here MinGW[^].
Hope that helps!
|
|
|
|
|
Since we're on a more Microsoft centric webbie, I could suggest downloading the Visual Studio Express Edition.
Maybe you can use the VS compiler in NetBean.
Watched code never compiles.
|
|
|
|
|
Why not check this[^] out on the NetBeans site?
I must get a clever new signature for 2011.
|
|
|
|
|
Why, you can use loads of free C++ compilers!
There DJGPP (GNU suite) for Windows and Linux, Borland C++ for Windows. There is also an excellent compiler called TCC that can compile HUGE sources with lightning speed because it does not use intermediate assembly.
Search these names on any search engine and you will get the web-address!
|
|
|
|
|
hello guys... I am trying to connect to database using ADO in MFC dialog based app. Now I get error at the first step when I try to create new connection and recordset using COM but I getting 4 errors stating "unresolved external symbol"
- "error LNK2001: unresolved external symbol _CLSID_CADORecordset"
- "error LNK2001: unresolved external symbol _IID_IADORecordset"
- "error LNK2001: unresolved external symbol _CLSID_CADOConnection"
- "error LNK2001: unresolved external symbol _IID_IADOConnection"
#include <adoid.h>;
#include <adoint.h>;
#include <comdef.h>;
CComPtr<ADORecordset> m_pSet;
CComPtr<ADOConnection> m_pConn;
::CoCreateInstance(CLSID_CADOConnection, NULL, CLSCTX_INPROC_SERVER, IID_IADOConnection, (LPVOID*) &m_pConn);
::CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_INPROC_SERVER, IID_IADORecordset,(LPVOID *) &m_pSet);
Thats is what I was trying to do. What can be the reason?? thnx
|
|
|
|
|
According to this[^], it should be fixed if you include initguid.h before adoid.h.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
thanx...it worked for me.
|
|
|
|
|
I use these[^] classes in order to use ADO in my MFC apps. Sure beats the heck out of reinventing the wheel yet again.
You may be right
I may be crazy
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
i want to know what is ":" operator in C++ called. i know how it is used in access specifiers but i saw something new for me.
destructor.hpp
class A {
int i;
public:
A(); //
A(int a);//
~A(); //
};
destructor.cpp
#include "destructor.hpp"
#include <iostream>
using namespace std;
A::A() : i(0) // WHAT IS ": i(0)" ?, WHAT IS ":" MEAN HERE ?
{
cout << "default constructor of A" << endl;
}
A::A(int a) : i(a)
{
cout << "constructor of A(" << i << ")" << endl;
}
A::~A()
{
cout << "Destructor of A (i=" << i << ")" << endl;
}
|
|
|
|
|
This is just a shorthand way of initialising variables in the constructor, and is equivalent to coding:
A::A()
{
i = 0;
...
I must get a clever new signature for 2011.
|
|
|
|
|
ok, then what is going on here please?
class A {
public:
A() { cout << "(1)"; }
A(A &a) { cout << "(2)"; }
};
class B {
A a;
public:
B() : a() { cout << "(3)"; }
};
…
B b;
B b2(b);
|
|
|
|
|
It's initialising the object a of class A . In each case it is merely calling the object's constructor, and for primitive types (such as int ) that just means setting them to the value in parenthesis.
Take a look at your C++ notes or manual for further discussion of instantiation, inheritance etc.
I must get a clever new signature for 2011.
|
|
|
|
|
The : is called a colon by me - and many other people
It does different jobs in different places.
Ie:
switch (iValue)
{
case Bob:
goto finished;
....
finished:
return bIUseGotos;
}
bSuccess = (pFunction != NULL) ? pFunction->DoSomething () : false;
And in your case, I'll pick a more common example:
class A
{
public:
A (int i);
};
class B : public A
{
public:
A ();
}
Now we make a constructor...
B::B ()
{
}
This will not compile - you will get a complaint about A not getting having a constructor with no parameters.
So, we need:
B::B ()
: A (7)
{
}
The principle is exactly the same for member variables.
In your example, i's constructor is being called with 0. In the case of basic variables, there's an implicit constructor for this. It's not a real one.
As for what you'd call it, I have no idea. Inheritance operator?
Iain.
I am one of "those foreigners coming over here and stealing our jobs". Yay me!
|
|
|
|
|
In the case you're asking about the colon marks the start of an initialiser list. These describe how to initialise a class's base class or member variables. Each element of the initialiser list has the syntax:
A( x, ... )
where A is either the name of the base class or the name of the member variable to be initialised and x,... is the list of arguments to the constructor of the base class or member.
I'd suggest grabbing a copy of "The C++ Programming Language" by Bjarne Stroustrup. He describes the initialisation of member objects and base classes in loads of detail in part 2 of the book. And explains why you'd prefer to write initialisers rather than making assignments in the body of a constructor.
Cheers,
Ash
|
|
|
|
|
all i can recall is that the ":" is the resolution operator in c++ which basically mean that A() is a method in the A namespace
google it or buy yourself a good c++ book
|
|
|
|
|
How to get computer color setting,
such as 256 colors and 16 or 32 bits?
|
|
|
|