|
If you can't use google, the SDK's will be of no use to you when you buy them.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi, i am a newbie, and i am trying to implement a control array as its called in VB, in VC. I have put the following code in a dialog's OnInitDialog() method:
pButton[0] = new CButton;
pButton[0]->Create(_T("My button1"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);
pButton[0]->ShowWindow(SW_SHOW);
pButton[1] = new CButton;
pButton[1]->Create(_T("My button2"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(110,10,200,30), this, 2);
pButton[1]->ShowWindow(SW_SHOW);
But i dont know how to catch their events. Actually, i want to create a dialog which on the basis of a number creates that many buttons. I can read the text of that button and know which button it is. but first i have to catch the event. Please if any of u have any alternatives to this do tell me.
and which library do u prefere for such tasks MFC, ATL or ... (i m not sure about).
To hit 3rd floors window you have to AIM for 5th or Higher.
|
|
|
|
|
you can doit inside OnCommand by filtering the controls by the id
in this case 1 or 2
...100,30), this, 1);
something like this
BOOL CYourClass::OnCommand(WPARAM wParam, LPARAM lParam) <br />
{<br />
switch(LOWORD(wParam)) <br />
{<br />
case 1:<br />
DoSomething1(); <br />
break;<br />
case 2:<br />
DoSomething2();<br />
}<br />
}
|
|
|
|
|
Well, im using MFC and the situation is something like this:
class CExperimentButtonsDlg : public CDialog
{
...
protected:
HICON m_hIcon;
CButton* pButton[2];
}
BOOL CExperimentButtonsDlg::OnInitDialog()
{
. . .
CDialog::OnInitDialog();pButton[0] = new CButton;
pButton[0]->Create(_T("My button1"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, 1);
pButton[0]->ShowWindow(SW_SHOW);
. . .
}
So u know the windowproc is not in my control, its in MFC's. Now, what would be the solution.
To hit 3rd floors window you have to AIM for 5th or Higher.
|
|
|
|
|
you could overwrite the CButton and manage its callback manually ...
but you will still need some kind of ID with each button ...
for example in pseudo-pseudo-code
pButton[0]->Create( this, eButton1 ); // eButton1 is a enum
pButton[1]->Create( this, eButton2 ); // eButton2 is a enum
pButton[2]->Create( this, eButton3 ); // eButton3 is a enum
pButton[3]->Create( this, eButton4 ); // eButton4 is a enum
and in your button class, you could do something like
void MyInheritedButton::Create( CWnd* pParent, enum eButtonID )
{
m_pParent = pParent;
m_eButtonID = eButtonID;
}
void MyInheritedButton::OnButtonClick()
{
m_pParent->SendMessage( eButtonID );
}
and in the parent ( or whereever you can catch the message ) you just do whatever you do on each button depending on the enum.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
you can use the soluction i gave you.
BOOL CExperimentButtonsDlg::OnCommand()
|
|
|
|
|
one easy way whereby which u can do thiz is by deriving ur own class from the CButton Class and adding in the eventz(messages) u need by using the classwizard.....
eitheR way i think then itz best u make ur own buTton class from the scratch with CStatic.....
Happy programmin.....
cheerz.....
"faith, hope, love remain, these three.....; but the greatest of these is love" -1 Corinthians 13:13
|
|
|
|
|
I think there is an easier solution instead of subclassing your own control.
If I understood well your question, you want to display X (which is only known at runtime) buttons on a dialog and create them dynamically on initialisation of your dialog. Then, when a specific button is pressed, you want to call a function.
The first thing you made is correct: this way you create dynamically the button and place it where you want. The only thing that is not really clean is that you give your own Id's. These Id's may already been used for other controls so it's not a good idea. What you need to do is reserve a range of id's in the resources.h file, something like:
#define IDC_BUTTON1 32000<br />
#define IDC_BUTTON100 32100
Then when creating your buttons:
for (int i=0;i<iNumButtons;i++)<br />
{<br />
pButton[i] = new CButton;<br />
pButton[i]->Create(_T("My button1"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(10,10,100,30), this, IDC_BUTTON1+i);<br />
pButton[i]->ShowWindow(SW_SHOW);<br />
}<br />
Of course, in the loop you'll need to change the rectangle of the button and the title...
Now, to associate a function with each of these buttons, you can make use of the ON_COMMAND_RANGE macro (in the message map):
ON_COMMAND_RANGE(IDC_BUTTON1,IDC_BUTTON100,OnButtonRange)
Take a look at the documentation to have a complete help on this macro and how to use it.
Hope this helps
|
|
|
|
|
You all guyz, thank you for u responses. But cedric moonen, got my point 120% right. and his solution is exactly what i needed. I was going through the Wrox "Professional MFC programming with Visual C++", and there the writer took me through the disection of the Different macros used by MFC to declare the Message Maps. they are defined in Afxwin.h.
As suggested by him, too,
ON_COMMAND_RANGE(IDC_BUTTON1, IDC_BUTTON100, OnButtonRange)
will work just fine.
Since i got some inside information from my research, i would like to share it with you guyz. Actually there is a structure for each message handler entry in the message map which is hidden from the programmers. MFC maintains an array of this structure in every class where you use
BEGIN_MESSAGE_MAP( class, baseClass)
That entry structure is something like this:
struct THESTRUCT
{
UINT nMessage;
UINT nID;
UINT nLastID;
UINT nSig;
pointerToFunctionHandler;
};
nMessage is, of course, the message to handle.
nID is, of course, of course, the of target control (for which the message is intended)
nLastID, this is the essence. If you want one function to handle multiple controls having their IDs with in a specific range. Then nID is the Lowest ID inclusive and nLastID is the highest ID.
nSig is a long value that specifies the function Signature of the handler function.
Hope this is helpful.
and Thanks, you've all been very useful.
To hit 3rd floors window you have to AIM for 5th or Higher.
|
|
|
|
|
I'm working on an email app and would like to add an "auto-fill" style functionality as they address a message.
I have an edit box where they can enter the addresses. If they hit PageDown while addressing, then a small dialog appears with a listctrl that displays all the address book aliases that match the portion of the address they have typed.
(See http://www.specialtysound.com/autofill.jpg for a screen shot)
Here's the problem: I would like the dialog to disappear if they click anywhere outside of it.
I'm creating a standard dialog with the following styles:
WS_POPUP, WS_VISIBLE, WS_CLIPSIBLINGS, WS_BORDER, WS_OVERLAPPED, DS_3DLOOK, DS_SETFONT and WS_EX_LEFT, WS_EX_LTRREADING, WS_EX_RIGHTSCROLLBAR, WS_EX_TOOLWINDOW, WS_EX_CONTROLPARENT
I instantiate the class and call DoModal().
Any help would be great. Thanks!
|
|
|
|
|
Hi,
How to add CString member variable to mfc application. FYI, I am building mfc application using visual studio .net.
Thanks
Vinay
|
|
|
|
|
Oh, man.
I suggest buying a book like 'teach youself C++ in 24 hours', or 'C++ for dummies'. For every thing like this you get answered on a forum, there will be 5 things you never think to ask, and you need to know.
In your header file, put the member variable declaration. If you look up from where you put it, the last one of these: public:, private:, protected:, will define the scope of the variable. Now you can use it within the class.
It's best to make your members private first, then expand the scope if you need to. It's also best not to make member variables public, that exposes implimentation details. Provide get and ( if warranted ) set methods instead.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I know enogh c++ but do not know the ever changing development environment under different conditions.
I think, just by looking at the subject of my posting, readers who are looking for great/advanced questions, can skip .
comign to the actual problem.....
If I want to add a member variable in VC++ 6.0, I used to do following.
1.Select the class(in class view)
2.right click
3.choose add member variable
4.enter variable name and variable type. I can enter any type of variable because variable type is an edit box.
But in VC++ 7.0(visual studio .net), variable type is a list box which allows to choose inegral type of variables. So how to choose CString.
I entered CString manually in header file. But CString variable was taken from atl library but I want it to be taken from MFC libraries.
|
|
|
|
|
Both ways that you describe are useful only if you want to be clueless forever. The more you rely on the IDE for such simple tasks, the longer it will take for you to ever have any idea how to program, or how things are working in your chosen language/framework. I've never used that stuff, in VC6 or VC7. I'll put variables where I want them, how I want them.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Do you think, I always use wizard to add a variable?
Wizards add code to the project and sometimes user does not know where the code was written.
But when a variable is added to project using wizard, does the programmer does not know where it was added? hhhaa
|
|
|
|
|
vchedalla wrote:
Do you think, I always use wizard to add a variable?
I dunno, you're telling the story.
vchedalla wrote:
But when a variable is added to project using wizard, does the programmer does not know where it was added? hhhaa
It's not as hard to find as when you use a wizard to add a COM method, but the principle is the same - someone who uses wizards all the time is unlikely to really understand what's going on. Besides, if you don't use them, why the question ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
My icons look great on XP but they look totally crappy on NT. I have True Color selected on both machines. Is this a known NT issue?
Thanks,
Ian
|
|
|
|
|
I believe NT and 2K only support icons using 4 or 8 bit (16 or 256 colors).
there is this too (from MSDN "Design Specifications and Guidelines - Visual Design" excerpt):
Note
To display icons at 48 x 48 pixel resolution, the registry value Shell Icon Size must be increased to 48. To display icons in color resolution depth higher than 16 colors, the registry value Shell Icon BPP must be set to 8 or more. These values are stored in HKEY_CURRENT_USER\Desktop\WindowMetrics.
Steve
|
|
|
|
|
Thank you much, Steve. I'll look into these registry values.
Thanks again!
-Ian
|
|
|
|
|
Steve,
Mucking with that registry value did the trick. Thank you for the fantastic and spot-on answer!
-Ian
|
|
|
|
|
Glad I could help
Steve
|
|
|
|
|
Hello,
Is it possible to make a text over the sceen?
I dont want to use a dialog only text and I want it to cover the desktop. It that possible?
|
|
|
|
|
Draw text directory onto the DC of the HWND from GetDesktopWindow()
|
|
|
|
|
|
Erh, by drawing on the HDC for the HWND returned from GetDesktopWindow(). Are there some hidden abstractions in the answer that I've missed
#include <windows.h>
int main()
{
HDC hDC = NULL;
HWND hWnd = GetDesktopWindow();
RECT rect;
if (hWnd)
{
hDC = GetWindowDC(hWnd);
if (hDC)
{
rect.top = 100;
rect.left = 100;
rect.right = 300;
rect.bottom = 300;
DrawText(hDC, TEXT("Hello World!"), 12, &rect, DT_LEFT);
ReleaseDC(hWnd, hDC);
}
}
return 0;
}
"After all it's just text at the end of the day. - Colin Davies
"For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
|
|
|
|
|