|
I've been looking through the examples her at Code Project, but I can't see one that shows me how to create a button or a test edit window entirely in code (i.e. not on the dialog template).
Can someone help me out here ?
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
OK - got that working like this:
RECT rc = {10, 10, 50, 50};
m_btn.Create(m_hWnd, rc, "", WS_CHILD | WS_VISIBLE);
m_btn.ShowWindow(SW_SHOW);
I actually didn't notice that I was creating a button on screen in the corner - why isn't WS_CHILD a default value ?
Anyhow, now I need to know how to get messages from the button in my dialog. From memory it's subclass window, is that right ?
I'm editing this message now - it's not SubclassWindow, which allows me to attach a variable to a control on the dialog. I want to create a CButton and capture it's being pressed ( actually I want to be able to do that to lots of them ). Can anyone suggest how this is done ?\
Editing yet again. I discovered if I overrode WM_COMMAND I could catch the button press, with lParam equalling the hWnd of the button. I've used this prototype:
LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
and found that wParam is always 0 and uMsg is 0x0111 ( WM_COMMAND ). Surely WM_COMMAND will be called for things other than buttons ? How can I tell how I got there so I can respond intelligently to the event ?
Thanks
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
I tried to do like you did:
RECT rc = {10, 10, 50, 50};
m_btn.Create(m_hWnd, rc, "", WS_CHILD | WS_VISIBLE);
m_btn.ShowWindow(SW_SHOW);
But I'm using a CView class to display the button, not a CDialog. Is that a problem?
If I want a button to be visible "on" a CView client area, where would I call m_btn.ShowWindow(SW_SHOW)?
Thx,
/Tommy
|
|
|
|
|
I'm not sure how ( or why ) you'd put a button onto a normal CView.
I am actually using the Windows Template Library, but to put buttons onto a CView in MFC, you can use a CFormView, which allows you to set them up using a dialog template.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
|
Um... not quite. There you (very helpfully) showed me how to hook up buttons and so on into a message map. Now I want to create them dynamically, not by putting them on a dialog template and calling SubclassWindow, but by having a vector of controls to which I can dynamically add them, and have the code able to respond to their being pushed. The idea is that we create a set of classes by which people can script the creation of a dialog box and it's controls, so it needs to be ultra flexible.
I've worked out that I can respond to OnCommand, and the lParam ( from memory, the code is at work and I am not ) is the HWND of the control, but none of the other paramters seen to contain anything meaningful. Is this the way to capture buttons I've created on the fly, and if so, does OnCommand respond to anything but controls being pushed ? Either way, when I have a lot of different elements on the dialog, I'm not sure how I'm going to be able to figure out what was interacted with and how, in order to respond to it meaningfully. The Create method didn't seem to take an ID I could assign, for example, and I'm trying not to think about intercepting messages on a dynamically created listview, for example.
Any suggestions you may have on how to deal with a variable number of controls on a dialog that will not be known until runtime will be greatly appreciated.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
Ah, gotcha, I see what you're asking now. Here's a snippet that creates a button at runtime. This came from the CP toolbar, actually, and creates an edit box on the toolbar.
m_wndToolbar.GetItemRect ( 1, &rect );
DWORD dwEditStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL;
DWORD dwEditExStyle = WS_EX_CLIENTEDGE;
HWND hwndEditbox = CreateWindowEx ( dwEditExStyle, _T("EDIT"), _T(""), dwEditStyle,
rect.left+5, rect.top, rect.right - rect.left-10,
rect.bottom - rect.top, m_wndToolbar,
(HMENU) uSearchEditboxID, NULL, 0 );
m_wndSearchEdit.Attach ( hwndEditbox ); This uses member variables for the windows (CContainWindow objects) but this would work equally well for objects you create at runtime.
As for your WM_COMMAND question - lParam is the HWND of the button, HIWORD(wParam) is BN_CLICKED (which is 0), and LOWORD(wParam) is the button control ID. If wParam is coming in as 0, I'd say double-check the control IDs in your CreateWindow() or analogous calls.
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
Gotcha - thanks for the help.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
There's a main project which consists of many VC & VB components as sub projects . Now I need to build a package which gives me an option to install these components by selecting them from the various options of the components - the installation of one of the componenets need to be in the remote machine. How can i do this???
Pl. suggest me some topics to get an idea on this.
Thanx.
regards
Sankar
|
|
|
|
|
Can someone please point out to me what I am missing.
I have a number of classes (Stored Procedures) derived from a base class (CRecordset). The base class has functionality common to all the derived classes (Open, Execute, Close fuctions), so I am trying to create a function where I can pass the object to operate on as a pointer to the base class, find the derived class from the RTTI and call the appropriate functions.
However my problem is that the compiler sees the void * from the dynamic_cast and complains when I try and call members associated with a void *. I can see why this would be a problem, the compiler has no information on the object pointed to by the void *, after all this is only available at runtime, but is there anyway around this problem?
I wondered if I could use pointers to members to create offsets into the class, but again the compiler complains that the left side of the argument points to a void *.
I believe what I am trying to do can be done, I'm just not sure what I am missing.
Thanks,
Richard
|
|
|
|
|
Correct me if I'm wrong, but could you not use the base class instead of void to declare your pointers?
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Here's how to use dynamic_cast. Supposing CMyRecordset is derived from CRecorset.
void somefunc()
{
CMyRecordset objMyRecordset;
CRecordset* pRecordset;
pRecordset = dynamic_cast<CRecordset*>(&objMyRecordset);
if (pRecordset)
{
pRecordset->Open(); //or whatever...
}
}
Good Luck,
Asif
|
|
|
|
|
It's not clear why you're using void * in this context, or, for that matter, why you can't do whatever it is you're trying to do with virtual methods.
dynamic_cast is generally used for up-casting, that is casting something stored in the routine as a pointer to a more generic class to a more specific class (which it must actually be). It should very rarely be needed. You could do something like:
<br />
GeneralClass *p = ......<br />
<br />
SpecificClass *sp = dynamic_class<SpecificClass *>p;<br />
<br />
if(sp) {
...<br />
}<br />
but it's almost always cleaner to do the same thing with virtual methods.
|
|
|
|
|
Hello,
I've created an MDI application based on a CCtrlView.
After that, I copied some code of msdn to create 2 header columns and some list data.
The problem is that I can see the header, but not the data. I know there is data in the grid because if I double click on the small | in the header, the header resizes as if there is data.
Is it due to the fact that the text is also drawn in a white color, or am I doing something wrong here (forgot to initialize something, call a procedure, ... ).
Some info;
In PreCreateWindow I set my style in detail view:
cs.style |= LVS_REPORT
In OnInitialUpdate, I try to create the 'grid':
CListView::OnInitialUpdate();
// this code only works for a report-mode list view
ASSERT(GetStyle() & LVS_REPORT);
CListCtrl& theCtrl = GetListCtrl();
// Insert a column. This override is the most convenient.
theCtrl.InsertColumn(0, _T("Player Name"), LVCFMT_LEFT);
LVCOLUMN col;
col.mask = LVCF_FMT | LVCF_TEXT;
col.pszText = _T("Jersey Number");
col.fmt = LVCFMT_LEFT;
theCtrl.InsertColumn(1, &col);
// Set reasonable widths for our columns
theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);
for (int i=0;i < 10;i++)
{
strText.Format(TEXT("item %d"), i);
// Insert the item, select every other item.
theCtrl.InsertItem(
LVIF_TEXT|LVIF_STATE, i, strText,
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
0, 0);
// Initialize the text of the subitems.
for (int j=1;j < nColumnCount;j++)
{
strText.Format(TEXT("sub-item %d %d"), i, j);
theCtrl.SetItemText(i, j, strText);
}
}
Thanks a lot
Wim Jans
|
|
|
|
|
Works fine for me, exept I just had to add in two lines (in bold bellow)
<br />
ASSERT(GetStyle() & LVS_REPORT);<br />
<br />
CListCtrl& theCtrl = GetListCtrl();<br />
theCtrl.InsertColumn(0, _T("Player Name"), LVCFMT_LEFT);<br />
LVCOLUMN col;<br />
col.mask = LVCF_FMT | LVCF_TEXT;<br />
col.pszText = _T("Jersey Number");<br />
col.fmt = LVCFMT_LEFT;<br />
theCtrl.InsertColumn(1, &col);<br />
theCtrl.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);<br />
theCtrl.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);<br />
<br />
for (int i=0;i < 10;i++)<br />
{<br />
strText.Format(TEXT("item %d"), i);<br />
<br />
theCtrl.InsertItem(<br />
LVIF_TEXT|LVIF_STATE, i, strText, <br />
(i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,<br />
0, 0);<br />
<br />
CString strText;<br />
int nColumnCount = theCtrl.GetHeaderCtrl()->GetItemCount();<br />
<br />
for (int j=1;j < nColumnCount;j++)<br />
{<br />
strText.Format(TEXT("sub-item %d %d"), i, j);<br />
theCtrl.SetItemText(i, j, strText);<br />
}<br />
}
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
The code in Bold was actualy in my view, I only forgot to copy/paste it in
The form I was testing with uses the BCG library but I've just created an normal MDI mfc program based on CListView, copied the code and it worked fine indeed.
After that, I installed the new version of the BCG library and copied the code over to the view, and guess what: the list appeared.
So, I think I will upgrade my library at home too and I can continue to try to get a grip of Visual C++ - which is a lot easier thanks to CodeProject.
Thanks for your time!
Wim
|
|
|
|
|
Has anyone got experiance with extracting features from a bitmap image.
|
|
|
|
|
what do you mean by "features" ?
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Yes I guess my question was rather broad.
What I have is two finger print bitmaps that I would like to compare the connection points to. This is not generalized graphics but rather a science of forensics.
There are books available on the subject, there seems to be no code guidelines available on who to do this in C++.
Can you help.
|
|
|
|
|
Sorry to ask again but how do I read INTEGER or LONG length values in from a binary file?
At the moment I can only get single bytes.
Do I use GET or READ?
How to I modify the following code to read an integer length value from address 4110 in the DAT file?
==============================================
ofstream path("c:\\windows\\desktop\\debug.dat");
........................
int pos = 4110;
path.seekg(pos);
int bytevalue = path.get();
================================================
Sorry to be dumb, tried to work it out myself but failed (& no online helpfile)
cheers
Richard Edwards
|
|
|
|
|
Hi,
I'm not sure, since I don't often use C++ streams to do I/O, but it seems you should use: path.read((char*)&myInt, 4); if you're using ifstream.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
Hi all,
When I use the code below to enumerate the shell namespace, a second thread seems to get started by the IEnumIDList::Next(...) function. This function executes normally and gives me the desired results, but for some reason when my program exits, the second thread (not the application thread) always terminates with a return code of -1 and not 0 (like the main thread). This second thread delays the termination of my program quite considerably and is rather annoying. It would seem to suggest that I'm not using IEnumIDList properly, because if I take out the while(...) loop with the ::Next(...) call in it, the second thread never appears. So, my question is, what is wrong with the following call? What am I not doing to stop this second thread that appears out of nowhere??
------ CODE -------
void CFileTreeView::OnInitialUpdate()
{
HTREEITEM rNode;
ITEMIDLIST *pidl;
IShellFolder *pShellRoot;
DWORD iGot;
// Called inherited constructor.
CTreeView::OnInitialUpdate();
// Clear the view.
GetTreeCtrl().DeleteAllItems();
// Get a pointer to the IShellFolder namespace.
pShellRoot = GetDocument()->GetShellRoot();
// Iterate through the shell namespace for devices.
if(SHGetSpecialFolderLocation(m_hWnd, CSIDL_DESKTOP, &pidl) == NO_ERROR)
{
rNode = AddNode( pShellRoot, pidl, pidl );
IEnumIDList *pidlList;
if(pShellRoot->EnumObjects(m_hWnd, SHCONTF_FOLDERS |
SHCONTF_INCLUDEHIDDEN, &pidlList) == NO_ERROR)
{
while( pidlList->Next(1, &pidl, &iGot) == NO_ERROR )
AddNode( pShellRoot, pidl, pidl, rNode );
pidlList->Release();
}
GetTreeCtrl().Expand( rNode, TVE_EXPAND );
}
else AfxMessageBox("SHGetSpecialFolderLocation() failed! No namespace!");
GetDocument()->ReleaseShellRoot();
}
The AddNode(...) function simply fills out a TV_ITEM structure and creates a node, I am aware that the pidl's from the IEnumIDList(...) are not freed, they are dealt with in an OnDelete() handler for the individual tree nodes.
GetShellRoot() and ReleaseShellRoot() simply wrap the AddRef() and Release() functions for IShellFolder and display TRACE messages if I forget to release an instance.
Any help would be appreciated.
Jonathan Thorpe
|
|
|
|
|
Hello All!
I am perplexed and am hoping that someone out there could help me figure this out. I have an application that uses a CListCtrl. When the application window is resized, I would like to dynamically resize each of the columns to fit the view. I have had a little success, however, as the application is resizing, the horizontal scroll bar flickers on and off as the columns are being resized .
This happens only when I have "show window contents while dragging" enabled in Windows, when this is turned off you don't notice the problem. What I am trying to do is similar to Outlook where the columns are resized as the window is resized.
Please help, as I have exhausted all resources trying to find an answer to this, but have had no success.
Warm Regards,
Scott Evans
|
|
|
|
|
Need more detailed info - post your OnSize handler or routine you're using to change the widths.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi,
It could be that you're resizing when the scrollbar has already been shown.
Try to do it in OnSizing (WM_SIZING) or try to SetRedraw(FALSE) before, then SetRedraw(TRUE) after the resizing process.
Hope this helps,
Paolo.
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|