|
The CMDIFrameWndEx class extends CMDIFrameWnd , so it should work exactly the same.
|
|
|
|
|
I have applied the same technique:
if(! m_wndMDIClient.SubclassWindow(m_hWndMDIClient))
{
TRACE0(_T("Failed to create the MDI client window\n"));
return -1;
}
but get me ASSERT error: wincode.cpp , line 330, but at "Retry" the IDE led me here:
extern "C" int WINAPI
_tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine, int nCmdShow)
#pragma warning(suppress: 4985)
{
return AfxWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
}
I don't think it is so simple now, with new CMDIFrameWndEx ... I nthe meantime, I have found this: Debug Assertion Failed While Subclassing MDIClient Window VC++ 2008[^]
|
|
|
|
|
I don't see that that has anything to do with your original question. And since you are subclassing the Window, it may well be that you are doing something wrong.
If you go and look at the MSDN documentation you will see that the CMDIFrameWndEx does not block any of the methods of CMDIFrameWnd .
|
|
|
|
|
Applying old code, simply not working in this new case ... hmm ... I have to dig in ...
|
|
|
|
|
|
Hello everyone,
I have created a list view(Declared in CDataDialog) with data . I want the list view to have as rows-cells as the conductors so I used :for (int i = 1; i<= m_DialogCon; i++) (m_DialogCon is the variable which representes the number of conductors but was declared in CFeaturesDialog). How could I use m_DialogCon variable in CDataDialog?
Here is the code:
void CDataDialog::InsertItems()
{
HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST1);
LVCOLUMN list;
list.mask = LVCF_TEXT | LVCF_WIDTH |
LVCF_FMT | LVCF_SUBITEM;
list.fmt = LVCFMT_LEFT;
list.cx = 50;
list.pszText = L"Conductor";
list.iSubItem = 0;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)0, (WPARAM)&list);
list.cx = 100;
list.pszText = L"Resistivity";
list.iSubItem = 1;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)1, (WPARAM)&list);
list.cx = 100;
list.pszText = L"Permeability";
list.iSubItem = 2;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)2, (WPARAM)&list);
list.cx = 100;
list.pszText = L"Outer Diameter";
list.iSubItem = 3;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)3, (WPARAM)&list);
list.cx = 100;
list.pszText = L"Inner Diameter";
list.iSubItem = 4;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)4, (WPARAM)&list);
list.cx = 100;
list.pszText = L"Rdc";
list.iSubItem = 5;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)5, (WPARAM)&list);
list.cx = 100;
list.pszText = L"x component";
list.iSubItem = 6;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)6, (WPARAM)&list);
list.cx = 100;
list.pszText = L"y component";
list.iSubItem = 7;
::SendMessage(hWnd, LVM_INSERTCOLUMN,
(WPARAM)7, (WPARAM)&list);
for (int i = 1; i<= m_DialogCon; i++)
{
SetCell(hWnd, L"1", 0, 0);
SetCell(hWnd, L"0.0000386063", 0, 1);
SetCell(hWnd, L"1", 0, 2);
SetCell(hWnd, L"0.025146", 0, 3);
SetCell(hWnd, L"0.00971", 0, 4);
SetCell(hWnd, L"0.09136", 0, 5);
SetCell(hWnd, L"0", 0, 6);
SetCell(hWnd, L"15.24", 0, 7);
}
}
void CDataDialog::SetCell(HWND hWnd1,
CString value, int nRow, int nCol)
{
TCHAR szString[256];
wsprintf(szString, value, 0);
LVITEM lvItem;
lvItem.mask = LVIF_TEXT;
lvItem.iItem = nRow;
lvItem.pszText = szString;
lvItem.iSubItem = nCol;
if (nCol >0)
::SendMessage(hWnd1, LVM_SETITEM,
(WPARAM)0, (WPARAM)&lvItem);
else
ListView_InsertItem(hWnd1, &lvItem);
}
class CDataDialog : public CDialog
{
DECLARE_DYNAMIC(CDataDialog)
public:
CDataDialog(CWnd* pParent = NULL);
virtual ~CDataDialog();
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG2 };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedExit();
void InsertItems();
void SetCell(HWND hWnd1, CString value, int nRow, int nCol);
CString GetItemText(HWND hWnd, int nItem, int nSubItem) const;
afx_msg void OnClickList1(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnOK();
BOOL OnInitDialog();
int nItem;
int nSubItem;
};
|
|
|
|
|
Just pass it as argument to InsertItems() . If you need it also with other functions save it in a member variable.
But it is actually not used in a meaningful context in your code. You are just overwriting the cell content multiple times with the same values.
|
|
|
|
|
Yes this is actually what I want to do! But how can I pass it as an argument?? Sorry for asking again, I'm new in programming.
|
|
|
|
|
When InsertItems() is called from the parent dialog:
class CDataDialog : public CDialog
{
void InsertItems(int nCon);
};
void CDataDialog::InsertItems(int nCon)
{
for (int i = 0; i < nCon)
}
If it is not called from the parent dialog pass it using a setter function:
class CDataDialog : public CDialog
{
void SetCon(int nCon) { m_nCon = nCon; }
int m_nCon;
};
|
|
|
|
|
But by this way how Can I give the value of the variable when the executable runs?Variable m_DialogCon was declared in CFeaturesDialog and when I give the value in the first dialog of executable I want to create the list in the second dialog (CDataDialog).
|
|
|
|
|
It depends on when and how you are creating the dialog and calling its member functions:
void CFeaturesDialog::SomeFunc()
{
CDataDialog *pDlg = new CDataDialog(this);
pDlg->InsertItems(m_DialogCon);
pDlg->SetCon(m_DialogCon);
pDlg->DoModal();
delete pDlg;
}
|
|
|
|
|
Thank you very much for your help!!!
|
|
|
|
|
I tried this
CDataDialog *pDlg = new CDataDialog(this);
pDlg->InsertItems(m_DialogCon);
as you wrote me above but I have one more function where error appears in function InsertItems()
BOOL CDataDialog::OnInitDialog()
{
ListView_SetExtendedListViewStyle(::GetDlgItem
(m_hWnd, IDC_LIST1), LVS_EX_FULLROWSELECT |
LVS_EX_GRIDLINES);
InsertItems ();
::ShowWindow(::GetDlgItem(m_hWnd, IDC_EDIT1), SW_HIDE);
return TRUE;
}
Thank you in advance!
|
|
|
|
|
You are calling InsertItems() from OnInitDialog() . Then you can't pass the variable from the parent dialog and have to call SetCon() from the parent dialog. Remove the argument from InsertItems() and use m_nCon within that function.
|
|
|
|
|
Well, the whole point of C++, any object oriented code in fact, is that you DONT share variable.
So, you need to rethink your design, and how these two classes interact.
|
|
|
|
|
|
I was not sure I should make that point, since it isnt really very helpful, but fundamentally this isnt a programming question, its an architecture one, and the OP clearly needs to go back to basics on this and rework his architecture.
Of course you can use 'friend' classes, or use the classic C# hack Getxxxx() Setxxx() functions. A hack so bad you wonder why bother using C# and why not just use C.
Anyway, enough of my ramblings.
|
|
|
|
|
I try everything you propose!!every answer is helpful as I trying something like this for the first time!!thank you for your proposes!!
|
|
|
|
|
We have an application exe developed in VC++ under VS2008.
We are using an external software named HASP SRM for license protection. When we protect our Application exe using the software, its size is changed. I could understand that the exe is being encrypted.
Now I want to find a way in the application at runtime to identify if it is protected or encrypted or not for some logging purpose.
Is it possible to write a code inside the application to find it at runtime.
Can anyone help me in this regard
|
|
|
|
|
You may open and read the binary file (argv[0] ) and check if that contains a signature inserted by the encryption software.
Ask the maker of the software if you don't know the signature. They may also already have a documented method to perform such checks.
|
|
|
|
|
Our Application is a MFC application. Can you please provide me the C++ source code and detail me the steps to do so.
|
|
|
|
|
I can't because I don't know what to look for.
Therefore, I suggested to ask the maker of the encryption software.
Alternatively, do a binary file compare of an encrypted and original version of your sofware to find out where they are different. But only you can do that beacuse I neither have your software nor the encryption software.
If you know what to look for (binary pattern, length, and offset):
const unsigned char pattern[] = { 0x00, 0x01 };
char buf[sizeof(pattern)];
FILE *f = fopen(argv[0], "rb");
fseek(f, offset, SEEK_SET);
fread(buf, 0, sizeof(pattern), f);
fclose(f);
if (0 == memcmp(pattern, buf, sizeof(pattern)))
{
}
|
|
|
|
|
Hi,
manoharbalu wrote: Is it possible to write a code inside the application to find it at runtime.
Maybe.
manoharbalu wrote: Can anyone help me in this regard
One of the first thing at occurs after the executable begins execution... (For brevity I will not describe the NT loader) is that it jumps to the IMAGE_OPTIONAL_HEADER.AddressOfEntryPoint and begins executing some code there.
Do the following:
1.) Protect around a dozen files with the packer/protector.
2.) Read some bytes at the IMAGE_OPTIONAL_HEADER.AddressOfEntryPoint offset on all these protected files. (maybe 16 bytes of instructions)
3.) Save those bytes into an array.
4.) If all those bytes are the same... use that for your signature detection.
All PE packers and protections add the decryption/decompressing functions at the IMAGE_OPTIONAL_HEADER.AddressOfEntryPoint
Note that in the old days some vendors used polymorphic instruction generators to avoid detection... but these days most vendors are using static instructions so that anti-virus vendors can detect the unpacker signature.
Note that you can also iterate through the PE sections...
A typical PE file from a Microsoft based compiler will contain:
.text
.bss
.rdata
.data
.idata
.reloc
... few others
I believe the HASP SRM packer/protector generates an additional PE section:
.protect
Keep in mind that you are performing a statistical analysis so...
if the instructions at IMAGE_OPTIONAL_HEADER.AddressOfEntryPoint are the same as instructions from other binaries packed with HASP SRM
{
if There is an additional section named .protect which is consistent with the HASP SRM product.
{
Probably protected by HASP SRM
}
}
Best Wishes,
-David Delaune
modified 17-Mar-17 14:38pm.
|
|
|
|
|
Hi everyone! I have problem using list control in visual c++. I tried to create a table which appears on a dialog window but when I run the executable on dialog appears only an empty "window" without the data I wrote. I used the "report view". Here is the code:
void CDataDialog::OnLvnItemchangedStoreItems(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
m_StoreItems.InsertColumn(
0,
L"ID",
LVCFMT_LEFT,
100);
m_StoreItems.InsertColumn(1, L"Resistivity", LVCFMT_CENTER, 80);
m_StoreItems.InsertColumn(2, L"Permeability", LVCFMT_LEFT, 100);
m_StoreItems.InsertColumn(3, L"Rdc", LVCFMT_LEFT, 80);
int nItem;
nItem = m_StoreItems.InsertItem(0, L"1");
m_StoreItems.SetItemText(nItem, 1, L"0.000869");
m_StoreItems.SetItemText(nItem, 2, L"1");
m_StoreItems.SetItemText(nItem, 3, L"0.09136");
nItem = m_StoreItems.InsertItem(0, L"2");
m_StoreItems.SetItemText(nItem, 1, L"0.0008603");
m_StoreItems.SetItemText(nItem, 2, L"1");
m_StoreItems.SetItemText(nItem, 3, L"0.09136");
nItem = m_StoreItems.InsertItem(0, L"3");
m_StoreItems.SetItemText(nItem, 1, L"0.000869");
m_StoreItems.SetItemText(nItem, 2, L"1");
m_StoreItems.SetItemText(nItem, 3, L"0.09136");
}
void CInputView::OnLinefeaturesData()
{
CInputDoc* pDoc = GetDocument();
CDataDialog DialogWindow;
DialogWindow.DoModal();
}
|
|
|
|
|
OnLvnItemchangedStoreItems seems to be a LVN_ITEMCHANGED notification code (Windows)[^] handler. That is called whenever an item of a list control is changed but you are trying to create columns and add items there. But that handler is never called while you are not adding and changing items (and will produce a stack overflow or dead lock when adding items from within the handler).
Move the code from the handler to CDataDialog::OnInitDialog . That will populate the list and show it.
|
|
|
|
|