|
i am trying to figure out if the user has 3 keys held down, if so i wanna popup my credits for my program.. the code i see referrences VK_CONTROL, VK_SHIFT, VK_ENTER, but what about normal letters? i tried to override OnKeyDown() but it never gets called.. here is what im using now:
BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN)
{
BOOL bS = (GetKeyState(VK_ENTER) & 0x8000);
if (bS)
AfxMessageBox("ding!");
}
return CDialog::PreTranslateMessage(pMsg);
}
thanks for any suggestions!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
You can pass ASCII code to Get[Async]KeyState.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
i tried that.. i found an article on MSDN that said to do that.. i tried using 100 and 115 which are supposed to correspond to 'd' and 's'.. didnt wanna work.. i figured out something else that'll work tho.. thanks a bunch!;)
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
hey dz,
how about posting your thing that works on CP?!
cheers
Adam.
www.beachwizard.com/travelogue[^]
"I spent a lot of my money on booze, birds and fast cars. The rest I just squandered"
George Best.
|
|
|
|
|
I would replace this:
BOOL bS = (GetKeyState(VK_ENTER) & 0x8000);
with this:
BOOL bS = (GetKeyState(VK_ENTER) & 0x10000000);
And yes, it does work with alphabetic characters, but you must use the upper case versions of the characters. Here's a comment from winuser.h:
/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
Chris Richardson
|
|
|
|
|
I have several columns in report view. I want to make sure that each column will sort itself if I click its columheader. Is this true? Or is it only the first column that sorts when you click the columnheader? I didnt see this mentioned in the MSDN
Appreciate your help,
ns
|
|
|
|
|
|
I have some CStrings which look like
"1234", "4567" ...so they are numbers in it
"1234efg", efg433" ...so a mix
"199809271234.17:00" which is a date.
I need to do stuff depending on what "type" the CString is: If its all numbers I have to change it into a double or something.
so (I dont see any CString function for this conversion) I'll have to use atoi, strtod etc. Except I have to make sure its totally numeric before I apply these functions.
How to tell if the CString is all numeric?
Appreciate your help,
ns
|
|
|
|
|
I'd use std::ostringstream or strtod (which returns back the pointer where string-to-double conversion has ended).
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
So if I have *pc = "123456" then I do strtod(pc, &pc,10). I stil dont know which strings I can safely operate on. Do I have to somehow infer from the position of the pointer whether it was the whole length of the string where it ended up (so the whole thing is numbers). If so what exactly tells me the length traversed by the pointer in reaching the location where it breaks off so I can compare it with strlen(original)? Am I missing something or is that a detail that needs dealt with? I have to find out if its all numbers...
Appreciate your help,
ns
|
|
|
|
|
You know that you subtract two pointer, don't you? This will give you the length of processed sequence.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
well, I think you oughta consider a different class than CString for storing your data....for example a variant type class that can can be a string, number or date with a 'marker' in the class to state what the data is. For ex:
class X
{
private:
time_t m_xTheTime;
string m_oTheString;
long m_lTheNumber;
int m_iType;
public:
enum
{
eIsTime;
eIsNumber;
eIsString;
}
X( string s )
{
m_iType = eIsString;
m_oTheStrign = s;
}
X( long l )
{
m_iType = eIsNumber;
m_lTheNumber = l;
}
X( time_t t )
{
m_iTheType = eIsTime;
m_xTheTime = t;
}
string AsString();
long AsNumber();
time_t AsTime();
int GetType();
}
etc etc
but if you don't wanna do that then to answer your other question:
for each char in your string call isdigit which will check if the character
is '0'..'9'
Just trying to keep the forces of entropy at bay
|
|
|
|
|
ns wrote:
How to tell if the CString is all numeric?
use isdigit(x) to test each character in the string
-c
All you have to do is tell the people they are being attacked, and denounce the opposition for lack of patriotism and exposing the country to danger.
-- Herman Goering, on how to control the public
|
|
|
|
|
Hi,
I have an MFC app with a web browser in it, and I'm getting some strange memory usage. When I first start up the app, it intially takes ~28 M of memory. When I minimize it, it drops to about 1.6M (which I expected). Then when I restore the app and then start using it, it takes only about 12 M...
What's strange is why it initially takes up 28 M of memory, when it really on needs 12M later on.... any ideas what's going on and how I can make it so the app only takes up about 12 M initially?
Thanks!
"If at any time I announce that a nation or kingdom is to be uprooted, torn down and destroyed, and if that nation I warned repents of its evil, then I will relent and not inflict on it the disaster I had planned. And if at another time I announce that a nation or kingdom is to be built up and planted, and if it does evil in my sight and does not obey me, then I will reconsider the good I had intended to do for it." -- Jeremiah 18:7-10 (God, commenting on the value of the United Nations)
|
|
|
|
|
Windows calls ::SetProcessWorkingSetSize when you minimize applications. You can call this API yourself, but it may hit the performance - your app will generate more page faults.
Unless you have bitching customer who spends too much time in Task Manager, it's best to leave this to OS.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
I have a CListctrl (has an extended style so there are checkboxes) for which in design view I have the multiselect option. THere are two questions.
When you click on one item, the itemchanged function runs and you can do stuff in them. I am pushing the name of the item clicked onto a vector. It allows me to hold down shift and select a range of elements, but they dont get automatically checked.
SO:
1. How do I push the name of every item selected in the multiselect operation onto my vector since I dont know what is happening in response with the itemchanged event?
2. How do I check every item that was highlighted in the multiselect operation automatically?
BOth these questions I cant find any documentation on. Please help, since I have to add this multiselect feature today...
Appreciate your help,
ns
|
|
|
|
|
You should get LVN_ITEMCHANGED for each item. To check the item with given index, use CListCtrl::SetCheck.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
In a regular (no checkbox) listctrl, if you click an item, it highlights and the itemcchanged fires (in response to LVN_ITEMCHANGED correct?) Well, with checkboxes, it only fires if I check the box, not if I just click on the name, which does get highlighted ( but itemchanged function doesnt run.). Do you think that if I set the check automatically when clicking on the name , it will fire the itemchanged?
And if I understand you correctly, if I select three items (lets say it did respond to shift select), the itemchanged runs three times in succession,....once for each item?
Appreciate your help,
ns
|
|
|
|
|
I was going to try to see if automatically setting the check when highlighting the item name would fire the itemchanged. But I'm going in circles because I was going to SetCheck(nIndex) in the itemchanged (which is what I want to invoke and it doesnt get invoked by merely clicking on the box, only by checking the box). So I cant test my hypothesis using that event. WHy does it fire for a regular listctrl when clicking on the name, but not for a checkbox extended list ctrl when you click on the name? I need to make it fire when I select the name...not check the check box (for either event actually....)
Appreciate your help,
ns
|
|
|
|
|
It works for me even with checkboxes enabled. There are multiple LVN_ITEMCHANGED notifications when you change the selection for each selected/deselected item. Can you post the handler for LVN_ITEMCHANGED?
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Your response is very reassuring. Heres my code:
void CDlgLists::OnItemchangedList2(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if (pNMListView->uOldState == 0 && pNMListView->uNewState == 0)
return;
BOOL bPrevState = (BOOL)(((pNMListView->uOldState &
LVIS_STATEIMAGEMASK)>>12)-1);
if (bPrevState < 0)
bPrevState = 0;
BOOL bChecked=(BOOL)(((pNMListView->uNewState & LVIS_STATEIMAGEMASK)>>12)-1);
if (bChecked < 0)
bChecked = 0;
BOOL bNameClicked = (bChecked < 0);
if (bPrevState == bChecked)
return;
DWORD dwPos = ::GetMessagePos();
CPoint point((int) LOWORD(dwPos), (int) HIWORD(dwPos));
m_list2.ScreenToClient(&point);
int nIndex;
if ((nIndex = m_list2.HitTest(point)) == -1) return;
OptStateMap &optStateMap = keyOptMap[activeKey];
if (optStateMap.empty())
GetOpts(activeKey,optStateMap);
CString temp;
temp.Format("index is %d ",nIndex);
AfxMessageBox (temp);
CString opt = m_list2.GetItemText(nIndex,0);
keyOptMap[activeKey][opt] = !keyOptMap[activeKey][opt];
*pResult = 0;
}
Do you think its the HitTest thats causing trouble and not letting it respond? My msgbox is beyond the hittest line (for testing).
So you can make the function run just by clicking the name? (or selecting a range of names, regardless of checkbox state)?
I thank you for your interest.
Appreciate your help,
ns
|
|
|
|
|
1) try to replace the LVIS_STATEIMAGEMASK magic with calls to CListCtrl::GetCheck and CListCtrl::SetCheck
2) use TRACE instead of AfxMessageBox. There's a non-zero probability that displaying msgboxes in the handler interferes with notifications.
3) You should use NMLISTVIEW::uChanged if you want to check which item properties were changed.
4) I'm not sure if you should change the item state in LVN_ITEMCHANGED handler - this may lead to infinite recursion.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|
|
Would you post your code that works so I can pattern mine after yours? That would help a lot.
Appreciate your help,
ns
|
|
|
|
|
I don't have any real code - just dummy handle which displays the NMLISTVIEW::iItem using TRACE. I think you should start with that and ensure you're getting LVN_ITEMCHANGED for each item.
Tomasz Sowinski -- http://www.shooltz.com
*** Si fractum non sit, noli id reficere. ***
|
|
|
|