|
Have you tried the ISensNetwork interface?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I am very much stuck in an urgent assignment and in need of help as i have committed a Excel like Grid to a client.
My requirement is to have a Grid just like Excel and to take input from user using only Win API and GDI etc (No MFC allowed). I have already created the Grid but the problem is how to show the cursor in the rectangular boxes in grid and to take input form user?
One option is to use 'Text Box' control already provided in WinAPI but the problem is that its width would be fixed and only a part of text written in it is viewable to user depending on its width.
What i want is the input functionality just like MS Excel in which the input text is automatically extended to next cell when it exceeds the limit of a cell.
I would really appreciate if any one can provide me with the source code of such a control or could help me out in this difficult task?
Thanks and Regards,
Zeeshan Malik
zeemalik78@yahoo.com
To do what can be done is Intelligence and To do what should be done is Genious
|
|
|
|
|
It's relatively simple to use the caret APIs and catch keystroke messages for simple text
input. Maybe you have some of the code already to use arrow keys to navigate the grid.
Here's an example of a modal text edit loop (with probably more keys checked than you need for
single-line editing). The CaretUp()/CaretDown()/CaretLeft()/CaretRight()/MoveCaret() set the
caret position based on a row/column and the font size (fixed pitch fonts make this easy):
MSG LoopMsg;
bool fRedraw = false;
bool fEditing = true;
while (fEditing)
{
if (::PeekMessage(&LoopMsg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&LoopMsg);
::DispatchMessage(&LoopMsg);
if (LoopMsg.message == WM_LBUTTONDOWN)
{
}
if (WM_KEYDOWN == LoopMsg.message)
{
switch (LoopMsg.wParam)
{
case VK_RETURN:
fEditing = false;
break;
case VK_HOME:
MoveCaret(view, 0, nCurRow);
break;
case VK_END:
MoveCaret(view, nCharColumns, nCurRow);
break;
case VK_PRIOR:
MoveCaret(view, nCurColumn, 0);
break;
case VK_NEXT:
MoveCaret(view, nCurColumn, nCharRows - 1);
break;
case VK_LEFT:
CaretLeft(view);
break;
case VK_RIGHT:
CaretRight(view);
break;
case VK_UP:
CaretUp(view);
break;
case VK_DOWN:
CaretDown(view);
break;
case VK_DELETE:
DeleteChar();
fRedraw = true;
break;
case VK_BACK:
if (nInsertOffset > 0)
{
CaretLeft(view);
DeleteChar();
fRedraw = true;
}
break;
}
}
else if (WM_CHAR == LoopMsg.message)
{
switch (LoopMsg.wParam)
{
case 0x08:
break;
case 0x09:
break;
case 0x0D:
break;
case 0x0A:
break;
case 0x1B:
fEditing = false;
break;
default:
InsertChar((TCHAR)LoopMsg.wParam);
fRedraw = true;
break;
}
}
else if (WM_SETFOCUS == LoopMsg.message)
{
::MessageBeep(-1);
}
else if (WM_KILLFOCUS == LoopMsg.message)
{
fEditing = false;
}
if (fRedraw)
{
fRedraw = false;
HideCaret(view);
ShowCaret(view);
}
}
}
|
|
|
|
|
Hi for all
I'm trying to pass some data between 2 windows. This is the class that I pass between my 2 windows. It's just a single class with a based pointer:
<br />
<br />
#ifndef TESTE_H<br />
#define TESTE_H <br />
#include <windows.h> <br />
void * vValue; <br />
class Teste <br />
{ <br />
public: <br />
Teste(); <br />
~Teste(); <br />
void SetMsg(char * cMsg);<br />
void ExibeMsg(); <br />
Teste __based(vValue) * Single;<br />
private: <br />
char * m_cMsg;<br />
char * m_cClassName;<br />
}; <br />
Teste::Teste()<br />
{<br />
if(m_cClassName == 0)m_cClassName = "Classe Teste";<br />
}<br />
Teste::~Teste(){}<br />
void Teste::SetMsg(char * cMsg)<br />
{<br />
m_cMsg = cMsg;<br />
}<br />
void Teste::ExibeMsg()<br />
{<br />
if(m_cMsg != NULL)MessageBox(NULL, m_cMsg, "msg", MB_OK);}<br />
#endif TESTE_H<br />
This is the code that sends the data and handles the data:
<br />
<br />
case WM_COPYDATA:<br />
{<br />
COPYDATASTRUCT * dataReceived = (COPYDATASTRUCT*)lParam; <br />
Teste * tempTeste = (Teste*)dataReceived->lpData; <br />
Teste * ttt = tempTeste->Single; <br />
char cResult[256] = {0}; <br />
int nCount = 0; <br />
if(ttt != NULL)<br />
{<br />
MessageBox(NULL, "exibindo msg janela 1", "", MB_OK); <br />
ttt->ExibeMsg();<br />
}<br />
break;<br />
}<br />
<br />
case WM_COMMAND:<br />
{ <br />
switch(LOWORD(wParam))<br />
{<br />
case IDC_BUTTON1:<br />
{<br />
char cLength[20], cSize[5]; <br />
if(HIWORD(wParam) == BN_CLICKED)<br />
{<br />
if(GetDlgItemText(hwnd, IDC_EDIT1, cLength, 20) != 0)<br />
{<br />
Teste teste1; <br />
teste1.SetMsg("aaa");<br />
vValue = (void*)&teste1;<br />
COPYDATASTRUCT dataToSend;<br />
dataToSend.cbData= sizeof(void*);<br />
dataToSend.lpData = vValue;<br />
dataToSend.dwData = 0;<br />
HWND tempHwnd = FindWindow(NULL, "Janela 2");<br />
if(tempHwnd != NULL)<br />
{<br />
SendMessage(tempHwnd, WM_COPYDATA, wParam, (LPARAM)&dataToSend);<br />
}<br />
}<br />
else<br />
{<br />
MessageBox(NULL, "EditBox with no text", "info", MB_OK);<br />
}<br />
}<br />
break;<br />
}<br />
}<br />
break;<br />
}<br />
The problem is, when I call the ExibeMsg() func with my object in the WM_COPYDATA message, the application crashes. What I'm doing wrong? Anyone can suggest me a solution?
Thanks for help
|
|
|
|
|
The Memory that you point to, is only valid in the function because it goes out of scope. It is better with static memory or allocated with GlobalAlloc.
Attention: I think with most above written you 'may' run into trouble on the new MS Windows Vista.
Greetings from Germany
|
|
|
|
|
KarstenK wrote: allocated with GlobalAlloc
why don't you just new it ?
|
|
|
|
|
if it is in the same app/process it is OK, but he didnt say that.
In the same app I would use a global (memory) object.
Greetings from Germany
|
|
|
|
|
but GlobalAlloc() is not portable...
|
|
|
|
|
In a site(www.flounder.com), I read this:
"The problem of storing pointers is a little bit misleading. You must not store pointers in the structure you pass, even if they are pointers into the same area you are passing, because when the message is received the recipient has no control over where it is placed, and the pointers are likely to be nonsense. Obviously, you can't store pointers to other areas of your own memory because they will be completely nonsensical in the receiving process; they will be interpreted in its own address space.
But the misleading aspect is that if you have a structure which is entirely self-contained in the data area you are sending over (that is, every pointer refers to another structure in the area you are sending), then you can use based pointers to encode them. Based pointers are actually relative offsets measured from a specific starting point (such as the start of the area being transmitted), and are automatically adjusted by the recipient (as long as you set up the correct base value) so they are valid pointers."
So I have a based pointer in my class that is the same type of the class. This pointer must have to arrive(I think) to the other window safetly.
toxcct, if I use new I lose the control over the pointer in the other window.
|
|
|
|
|
Try use GlobalAlloc()/GlobalFree, but check/test it on Vista. Read the MSDN.
Greetings from Germany
|
|
|
|
|
What about GlobalAlloc()/GlobalFree changed on Vista? I see nothing in the PSDK.
Mark
|
|
|
|
|
Alex Cutovoi wrote: Teste __based(vValue) * Single;
So what address is 4 bytes from vValue ? Unless it is the beginning of ExibeMsg() , there's no way that the following could work:
ttt->ExibeMsg();
What you're doing seems very unreliable and dangerous. What is the receivng window supposed to do with the data it receives?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The code that I put in my question is the same for both windows. It doesn't change. If the way I choose is unreliable and dangerous, what you suggest for me to solve this??
I need a big help
|
|
|
|
|
Alex Cutovoi wrote: The code that I put in my question is the same for both windows.
Which is irrelevant. What matters is that vValue plus 4 bytes does not reference ExibeMsg() , but references m_cMsg instead.
Again I ask, what is it that you are trying to do?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ok, I need to pass an entire object between 2 windows. In both windows they recieve different handles.
I only get to pass structs(which is very easy).
|
|
|
|
|
Try this:
class MyStruct
{
public:
MyStruct()
{
m_pMsg = new char[128];
lstrcpy(m_pMsg, "Hello World");
}
~MyStruct()
{
delete [] m_pMsg;
m_pMsg = NULL;
}
char *m_pMsg;
void Exec( void )
{
AfxMessageBox(m_pMsg);
}
};
MyStruct myStruct;
COPYDATASTRUCT dataToSend;
dataToSend.cbData = sizeof(MyStruct);
dataToSend.lpData = &myStruct;
dataToSend.dwData = 0;
::SendMessage(GetSafeHwnd(), WM_COPYDATA, (WPARAM) GetSafeHwnd(), (LPARAM)&dataToSend);
COPYDATASTRUCT *dataReceived = (COPYDATASTRUCT *)pCopyDataStruct;
MyStruct *pStruct = (MyStruct *) dataReceived->lpData;
pStruct->Exec();
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
You cannot pass a pointer between processes. All the data has to be self-contained in the block of memory that you refer to in the COPYDATASTRUCT .
|
|
|
|
|
Exactly, like I said to toxcct, if I do this, I lost the control of the pointer.
And I did this before, Michael, can you tell me how can I solve?
I've tested with structures, works very fine, but what I want is a object. Hence I'm trying to solve this using based pointers. It's my very first time using based pointers.
|
|
|
|
|
You cannot pass a pointer between processes. A based pointer doesn't solve this, because it's just an offset from another pointer.
|
|
|
|
|
That means, it's not possible to send an object to another window right? If an object is a pointer, there's not a way to send it. My app actually is passing structs, but what I want to pass is an object.
|
|
|
|
|
Hello,
I have two strings username and password and I want to create a hash of it at the server side and at the client side where the data is reached I want to compare the hash again with another hash. So two questions
How do you hash two strings in C++
How do you compare two hashes in C++?
Please let me know.
Thanks
vg
|
|
|
|
|
There are many different ways to hash values, a simple CRC can be considered a hash, all the way to an MD5 message digest hash.
Usually, comparing them is just comparing the hash results. Compare the binary values, or convert them to strings and then compare them, it is all the same.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Dear James,
In that case can you please show me around two ways to calculate a hash for username and password strings. Also how would you compare by using ==?
Thanks.
vg
|
|
|
|
|
As alreasy posted, CryptHashData(...) and its related functions can generate a hash value from your raw data (username/password).
You will not be able to just use == to compare the hash values unless you have the hash values encapsulated in an object that overrides that operator. You can always use memcmp(...) to compare the raw data.
One thing - some systems store password hashes in a database instead of the plaintext password, and then just have to compare the hash values to verify it - that way, you do not risk the plaintext password if someone gets into the database.
However, do not try to do the same thing usernames - depending on the hashing technique, there exists a chance (however slim it may be) for two different usernames produce the same hash value. If this happens, you will be unable to disambiguate one from the other in the database and will not know which one is logging in, or which password hash to compare against.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Dear James,
I don't think CryptHashData can be used for creating hashes for strings and comparing. For example if I do CryptCreateHash I have to do
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0))
before that and infact if you try to do CryptCreateHash two times you'll see that you don't actually get the same hashes so this will not work when you need to compare hash. This I believe is used for encryption.
What I need is to make a hash from username and password and make another one at the client side and compare the two.
Thanks.
vg
vg
|
|
|
|