|
A message handler is just another function.
In your header file add this declaration:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
In your implementation file where it says,
BEGIN_MESSAGE_MAP(CYourWindow, CWnd)
this is where you tell it what method is going to handle which message.
Add this ON_WM_CREATE() somewhere in the MESSAGE_MAP.
Then add your function to the implementation file like this:
int CYourWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
}
BTW, I'm assuming MFC is used. Otherwise you'll have this huge switch statement to modify.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
|
Yes, but I was getting tierd of writing code like that and wanted the wizard to do it for me. I just can't seem to find the "Add Message Handler"-wizard in VC 7.0.
|
|
|
|
|
If its in a dialog, you can right click on the control.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
|
But it's not. My book tells me to "Right-click CMainFrame in the ClassView window, select Add Windows Message Handler, double-click WM_CREATE, and click Edit Existing. You'll find yourself in the empty message handler body, poised to type in the finished code. ClassWizard has already done everything else, including adding an ON_WM_CREATE entry to the message map."
But there's no "add windows message handler" in VC 7.0(at least I can't spot it)
|
|
|
|
|
You can also go to class view, click on the class, right-click and go to properties. Then click on the messages button and add your handler.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
|
Aah, thank you.. Exactly what I was looking for!
|
|
|
|
|
join the freaking club
why oh why did they get rid of class wizard???
"there is no spoon" biz stuff about me
|
|
|
|
|
In MFC (VC6.0) how do I remove a start-menu folder?
I can delete all of the items, but however I try to delete the folder (_rmdir, SHFileOperation) I get a permission denied error.
Any suggestions? It looks like the shell keeps a lock on the folder.
|
|
|
|
|
I'm curious why you'd want to remove the Start Menu folder. Trying it yields a "Start Menu is a Windows system folder and is required for Windows to run properly. It cannot be deleted." message.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Bad wording on my part. A menu ON the start menu. We have an application that re-installed itself somewhere different during an update leaving people with a bad shortcut on the start menu.
I've worked out a program to delete all of the .lnk files pointing to the old directory, but was having trouble deleting the directory.
Since my original post I've realized that the problem was that I was trying to remove the directory while a FindFile was still pending on the directory. Once I moved the delete routine to another part of the program all worked fine.
Thanks
|
|
|
|
|
How can I change the language at run-time. I use resource-only dll's for the different languages and set it in the MFC method CWinApp::InitInstance with AfxSetResourceHandle before the MainFrame is loaded. How can I do this, when the MainFrame is already loaded. What do I have to do besides the AfxSetResourceHandle, that even the Menu and all the dialogs are now in the new language? Thanks for any help.
Konrad
|
|
|
|
|
Hi
In one column of List Control i want to show the image but not the values, but with my code(pasted below) it is showing both the image and values. Can any body help me how can i achieve this.But i need to associate the values also because i am doing sorting also on that column
//Set up Record Status
Holder = pRecordSet->GetCollect("RecordStatus");
status = Holder.iVal;
temp.Format("%d",status);
m_RecordList->SetItemText(iNew,5,temp);
// setup record status
lvI.mask=LVIF_IMAGE ;
lvI.iItem= iNew;
lvI.iSubItem=5;
if(status == eCIT_STATUS_COMPLETE)
lvI.iImage = 1;
else if(status == eCIT_STATUS_VOID)
lvI.iImage = 3;
else
lvI.iImage = 0;
m_RecordList->SetItem(&lvI);
Thanks
Shailesh
|
|
|
|
|
aman2006 wrote:
i want to show the image but not the values
Isn't the call to SetItemText() what's showing the value?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
SetItemText() is showing the value but how can i associate a value with the image so that i can sort by clicking on header. But it is showing both values and Image.
Thanks
shailesh
|
|
|
|
|
aman2006 wrote:
how can i associate a value with the image...
Call SetItemData() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hey this is the situation now but it is not sorting when i click on the header column.
//Set up Record Status
Holder = pRecordSet->GetCollect("RecordStatus");
status = Holder.iVal;
m_RecordList->SetItemData(iNew,status);
// setup record status
lvI.mask=LVIF_IMAGE ;
lvI.iItem= iNew;
lvI.iSubItem=5;
if(status == eCIT_STATUS_COMPLETE)
lvI.iImage = 1;
else if(status == eCIT_STATUS_VOID)
lvI.iImage = 3;
else
lvI.iImage = 0;
m_RecordList->SetItem(&lvI);
Any Suggestion
Thanks
|
|
|
|
|
aman2006 wrote:
...it is not sorting when i click on the header column
And what does the handler code for that look like?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
David this the full code
while(!pRecordSet->EndOfFile)
{
// Insert the first item
lvI.mask = LVIF_TEXT| LVIF_PARAM | LVIF_STATE;
lvI.state = 0;
lvI.stateMask = 0;
lvI.iItem = counter;
lvI.iSubItem = 0;
Holder = pRecordSet->GetCollect("CitationID");
if(Holder.vt!=VT_NULL)
{
temp = (char*)_bstr_t(Holder);
lvI.pszText = (LPTSTR)(LPCTSTR)(temp);
}
else
lvI.pszText = _T("");
//lvI.pszText = _T("");
lvI.lParam = counter;
int iNew = m_RecordList->InsertItem(&lvI);
Holder = pRecordSet->GetCollect("CitationNo");
if(Holder.vt!=VT_NULL)
{
temp = (char*)_bstr_t(Holder);
lvI.pszText = (LPTSTR)(LPCTSTR)(temp);
}
else
lvI.pszText = _T("");
m_RecordList->SetItemText(iNew,1,temp);
//Citation date
Holder = pRecordSet->GetCollect("CitationDate");
if(Holder.vt!=VT_NULL)
{
temp = (char*)_bstr_t(Holder);
lvI.pszText = (LPTSTR)(LPCTSTR)(temp);
}
else
lvI.pszText = _T("");
m_RecordList->SetItemText(iNew,2,temp);
//Citation Time
Holder = pRecordSet->GetCollect("CitationTime");
if(Holder.vt!=VT_NULL)
{
temp = (char*)_bstr_t(Holder);
lvI.pszText = (LPTSTR)(LPCTSTR)(temp);
}
else
lvI.pszText = _T("");
m_RecordList->SetItemText(iNew,3,temp);
//Subject First Name
strFName.Empty();
Holder = pRecordSet->GetCollect("FirstName");
if(Holder.vt!=VT_NULL)
strFName = (char*)_bstr_t(Holder);
else
strFName = _T("");
//Subject Last Name
Holder = pRecordSet->GetCollect("LastName");
if(Holder.vt!=VT_NULL)
{
temp = (char*)_bstr_t(Holder);
// lvI.pszText = (LPTSTR)(LPCTSTR)(temp);
}
else
temp = _T("");
strFName += _T(" ") + temp;
lvI.pszText = (LPTSTR)(LPCTSTR)(strFName);
m_RecordList->SetItemText(iNew,4,strFName);
//Set up Record Status
Holder = pRecordSet->GetCollect("RecordStatus");
status = Holder.iVal;
m_RecordList->SetItemData(iNew,status);
// setup record status
lvI.mask=LVIF_IMAGE;
lvI.iItem= iNew;
lvI.iSubItem=5;
if(status == eCIT_STATUS_COMPLETE)
lvI.iImage = 1;
else if(status == eCIT_STATUS_VOID)
lvI.iImage = 3;
else
lvI.iImage = 0;
m_RecordList->SetItem(&lvI);
//Set up Sync Status
Holder = pRecordSet->GetCollect("IsSynchronized");
status = Holder.iVal;
temp.Format("%d",status);
m_RecordList->SetItemText(iNew,6,temp);
// setup record status
lvI.mask=LVIF_IMAGE;
lvI.iItem= iNew;
lvI.iSubItem=6;
if(status == eCIT_STATUS_SYNCED)
lvI.iImage = 2;
else
lvI.iImage = -1;
m_RecordList->SetItem(&lvI);
counter++;
pRecordSet->MoveNext();
}
Thanks
shailesh
|
|
|
|
|
This is the code that populates the list control. I wanted to see the code that handles the clicking of the column heading, and the sorting-compare routine.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Here u go:
typedef struct _tagSORTDATA
{
INT isortSubItem;
CListCtrl *m_pointer;
INT iUPDOWN;
BOOL StringComp;
} SORTDATA;
enum{
eSORT_UP = 1,
eSORT_DOWN
};
void CEditForm::OnColumnclickHistoryList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
static WORD nSort;
SORTDATA sortData;
m_RecordList =(CListCtrl*)GetDlgItem(IDC_HISTORY_LIST);
if(nSort == eSORT_UP)
nSort = eSORT_DOWN;
else
nSort = eSORT_UP;
sortData.isortSubItem = pNMListView->iSubItem;
sortData.iUPDOWN = nSort;
sortData.m_pointer = (CListCtrl*)m_RecordList;
sortData.StringComp = TRUE;
if(m_RecordList->SortItems(ListViewCompProc, (DWORD)(LPARAM)&sortData) != TRUE)
AfxMessageBox(_T("Error"));
*pResult = 0;
}
int CALLBACK CEditForm::ListViewCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3)
{
static LVFINDINFO lvf;
static INT nItem1, nItem2;
CString buf1, buf2;
SORTDATA *lpsd;
lpsd = (SORTDATA *)lp3;
CListCtrl *m_RecordList = (CListCtrl*)lpsd->m_pointer;
lvf.flags = LVFI_PARAM;
lvf.lParam = lp1;
// nItem1 = ListView_FindItem(lpsd->hwndList, -1, &lvf);
nItem1 = m_RecordList->FindItem(&lvf);
lvf.lParam = lp2;
//nItem2 = ListView_FindItem(lpsd->hwndList, -1, &lvf);
nItem2 = m_RecordList->FindItem(&lvf);
//ListView_GetItemText(lpsd->hwndList, nItem1, lpsd->isortSubItem, buf1, sizeof(buf1));
buf1 = m_RecordList->GetItemText(nItem1,lpsd->isortSubItem);
//ListView_GetItemText(lpsd->hwndList, nItem2, lpsd->isortSubItem, buf2, sizeof(buf2));
buf2 = m_RecordList->GetItemText(nItem2,lpsd->isortSubItem);
if (lpsd->isortSubItem != 9)
{
// string comparision
if (lpsd->iUPDOWN == eSORT_UP)
{
return(buf1.Compare(buf2));
}
else
{
return(buf1.Compare(buf2) * -1);
}
}
else
{
// digit comparision
if (lpsd->iUPDOWN == eSORT_UP)
{
if (_ttoi(buf1) > _ttoi(buf2))
return 1;
else if (_ttoi(buf1) == _ttoi(buf2))
return 0;
else
return -1;
}
else
{
if (_ttoi(buf1) > _ttoi(buf2))
return -1;
else if (_ttoi(buf1) == _ttoi(buf2))
return 0;
else
return 1;
}
}
return 0;
}
|
|
|
|
|
In the ListViewCompProc() routine, don't call FindItem() or GetItemText() . Use the lp1 and lp2 parameters instead. See MSDN article Q250614.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi.
I am using ::CreateProcess(...) to start a new console process. When the process finishes the job, the console window closes, avoiding the user to see messages or process results.
Is there any way to keep the window opened after process end?
Thanks.
|
|
|
|
|
A hack might be to create a batch file that launches the process, and then has a PAUSE statement, so that it won't finish until the user presses a key.
Or, if you own the concole process, you could change its code to ask for a keypress before closing. (Perhaps make it a command-line parameter.)
There might be a way to keep the console window open until you, say, click its close button, look at the CreateProcess parameters and see if there is anything. But I don't know for sure.
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|
I have created a MFC ActiveX control to interface with a finger print scanner. For that
i had to create a DLL (MFC Extension) which was used to interface between the MFC ActiveX
and the Win32 based API supplied by the scanner vendor. I had to do this since i wanted to
do some drawing on MFC created objects. I was forced to create the MFC Extension DLL coz
MFC pointers are only allowed to be passed across MFC Extension DLL's and not to ordinary
DLL's(that is what i know). The DLL that i created should also work as an interface between
any program who want to manipulate the scanner from different languages (like Java and Visual
Basic). I have two questions here
1) How can i create the DLL not as MFC Extension DLL but as ordinary DLL and still
access MFC pointers?
2) I am not able to load this DLL and call its functions in VB.
Any kind of help is appretiated.
Thank you in advance.
Jobby
|
|
|
|
|
Jobby Joseph wrote:
1) How can i create the DLL not as MFC Extension DLL but as ordinary DLL and still
access MFC pointers?
Use a window handle (HWND ), not a CWnd pointer.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|