|
Hi,
I have created dialog box in SDK(c++) and there is one button "B1" with style owner draw and other "B2" with default style.
When I press enter key then "B2" gets pressed but when "B1" is highlighted it doesn't respond.
I tried many styles of button and also tried subclassing but I am unbale to handle enter key event.
Is any one knows how to solve it?
Manish
|
|
|
|
|
You have three buttons on your dialog when you press one key you dont get any action,right?
|
|
|
|
|
No I have two buttons:
Button "B1" with owner draw style and button "B2" with default style.
On mouse click both get action.
On space bar when highlighted both get actions.
But when I press enter key when highlighted "B2" gets action but "B1" when highlighted doesn't respond to it.
Any sugestions?
Manish
|
|
|
|
|
Do you set Default Button to true (On property window) for B2?
|
|
|
|
|
In property page:
B2 having style: visible
B1 having style : visible and owner draw.
Please suggest any solution so that when B1 is highlighted,on pressing enter ket it should get action.
Manish
|
|
|
|
|
Not visible I said Default button on proeprty window of each button
|
|
|
|
|
I haven't set any default button on my dialog.
All other styles are set to false and only those wnich are mentioned are set.
With these styles I want to handle enter key event for "B1".
How will it be done?
Manish
|
|
|
|
|
if you run this code what happens?
<br />
#define IDC_TEST 1000<br />
<br />
BEGIN_MESSAGE_MAP(CAnswerDlg, CDialog)<br />
ON_BN_CLICKED(IDC_TEST, OnBnClickedTest)<br />
END_MESSAGE_MAP()<br />
<br />
void CAnswerDlg::DoDataExchange(CDataExchange* pDX)<br />
{<br />
DDX_Control(pDX, IDC_TEST, m_Test);<br />
}<br />
<br />
BOOL CAnswerDlg::OnInitDialog()<br />
{<br />
m_Test.Create("AS",WS_TABSTOP|WS_CHILD|WS_VISIBLE|BS_NOTIFY,CRect(0,0,100,23),this,IDC_TEST);<br />
}<br />
<br />
void CAnswerDlg::OnBnClickedTest()<br />
{<br />
MessageBox("A");<br />
}<br />
<br />
afx_msg void OnBnClickedTest();<br />
CButton m_Test;<br />
I run this code and it works for me does this code solve your problem?
|
|
|
|
|
Hi,
Regret for late reply...
I am using Win32 SDk application,no MFC is there.
I have implemented subclaasing of child controls(buttons in this case) to adrees this issue.Now I am able to handle enter key events as well.
Manish
|
|
|
|
|
I glad you find it
|
|
|
|
|
Hi all,
I'm trying to get the data from a file and assigning each of the lines to a variable (array or something)
I have tried the following:
<br />
HANDLE hFile;<br />
DWORD dwNumRead;<br />
BOOL bTest;<br />
char dwBuffer[256];<br />
<br />
hFile = CreateFile("client.cnf", GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);<br />
bTest= ReadFile(hFile, dwBuffer, sizeof(char)*256, &dwNumRead,NULL);<br />
printf("%s",dwBuffer);<br />
I receive data from the file (dwBuffer), but how can I assign each line to an variable (array element or something)
Lets say the file has the following data:
[SEND]
file1.txt
file2.txt
[RECEIVE]
file3.txt
file4.txt
Thanx in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Why don't you use the MFC class CStdioFile it can read a file line by line.
Help your local Search & Rescue. Get lost!
|
|
|
|
|
Thanx for the reply Monty, but I'm not using MFC...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Then you can parse the string and break at every '\r\n' , alternatively you can use strtok
You can't see me
|
|
|
|
|
Thank you Monty, I'll check out MSDN...
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
« Programm3r » wrote: The only programmers that are better than C programmers are those who code in 1's and 0's.....
You forgot the assembly guys
OK, so what's the speed of dark?
|
|
|
|
|
LOL ... My bad....
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Monty2 wrote: You forgot the assembly guys
...and the C# and HTML guys, from what they tell me.
|
|
|
|
|
|
|
Hi, I want to add ItemData as a string in my list box using win32 APIs. But when I try to get it back from list box I am getting blank string. Can I know what is wrong with my code?
Thanks in advance.
char setStr[20] = "test";<br />
char* getStr;<br />
<br />
::SendMessage(hLbox,LB_SETITEMDATA,listIndex,(LPARAM)setStr);<br />
testStr = (char*):: SendMessage (hLbox, LB_GETITEMDATA, listIndex, NULL);
|
|
|
|
|
priyank_ldce wrote: char setStr[20] = "test";
You are passing address of a local variable.
Create it on heap instead.
|
|
|
|
|
If you always pass constant strings like in your example, then try a different definition of setStr :
const char * setStr = "test";
::SendMessage(hLbox, LB_SETITEMDATA, listIndex, (LPARAM)setStr);
I hope this helps.
|
|
|
|
|
Hi, Thanks for the help. Actually I get that string in the form of char[]. Can I know how can I cast it to const char*. I tried strcpy() but it is not working.
|
|
|
|
|
In case of variable string values, I think you can try the following (old-fashioned) solution:
char setStr[20] = ...;
::SendMessage( hLbox, LB_SETITEMDATA, listIndex, (LPARAM)_strdup(setStr));
const char * str = (const char*)::SendMessage( hLbox, LB_GETITEMDATA, listIndex, NULL);
Note that these strings are allocated on the "heap" and therefore must be freed when the list control is destroyed, or new data are set. This can be done in OnDestroy handler of your dialog. You have to loop through list-box’s items and execute:
free((const char*)::SendMessage( hLbox, LB_GETITEMDATA, listIndex, NULL));
Modern solutions use functions other than strdup and free . I am not sure which is simpler.
I hope this helps.
|
|
|
|