 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Thu Oct 23, 2008 2:43 pm Post subject: [C++] Dropdownlist |
|
|
| I'm trying to make an dropdownlist using CreateWindowEx, it creates the window but I don't know how to add the options to it. I want to use this in my bot so the user can choose any key for ie attacking, looting etc. I have searched and tried myself but no luck :/. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Oct 23, 2008 2:52 pm Post subject: |
|
|
Use Messages.
In your situation, you would want to use CB_ADDSTRING _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Thu Oct 23, 2008 3:07 pm Post subject: |
|
|
You mean like this? | Code: | | SendMessage(DropList, CB_ADDSTRING, (WPARAM)"Test", NULL); | Cuz that didn't work. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Oct 23, 2008 3:11 pm Post subject: |
|
|
| TraxMate wrote: | You mean like this? | Code: | | SendMessage(DropList, CB_ADDSTRING, (WPARAM)"Test", NULL); | Cuz that didn't work. |
Try searching the proper way of using the message before you just throw it in SendMessage MSDN _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Thu Oct 23, 2008 4:26 pm Post subject: |
|
|
Hehe always forgetting about MSDN ^^. I got it to work now. Thx again lurc .
Edit: How do I use it? I mean when I select "Test" in the droplist how do I make it so ie a messagebox popups when i choose it? I tried using a switch statement but I have very little knowledge about it so it didn't work for me:/. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Oct 23, 2008 5:06 pm Post subject: |
|
|
Filter the notifications that Combo Box's send to the Window Procedures. (MSDN)
CBN_SELCHANGE - MSDN
Sounds good eh?
Example:
| Code: | case WM_COMMAND:
// ...
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
// Use CB_GETCURSEL to get the current selection,
// CB_GETLBTEXT to get the string
// lstrcmp or _tcscmp to compare the string to your specified string.
// After that message box.
} |
Entire ComboBox MSDN if you haven't been there: http://msdn.microsoft.com/en-us/library/bb775792.aspx _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 26, 2008 10:02 am Post subject: |
|
|
| lurc wrote: | Filter the notifications that Combo Box's send to the Window Procedures. (MSDN)
CBN_SELCHANGE - MSDN
Sounds good eh?
Example:
| Code: | case WM_COMMAND:
// ...
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
// Use CB_GETCURSEL to get the current selection,
// CB_GETLBTEXT to get the string
// lstrcmp or _tcscmp to compare the string to your specified string.
// After that message box.
} |
Entire ComboBox MSDN if you haven't been there: http://msdn.microsoft.com/en-us/library/bb775792.aspx | I must be honest here. All that is only confusing me :s. I've been trying to understand this in the last few days. I've searched and I still don't know how to do it... MSDN is not straight forward so it's hard for a novice like me to understand it. So if you cold post a whole example code I'd be so happy ^^- |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 26, 2008 10:05 am Post subject: |
|
|
What do you want the example code to do? _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 26, 2008 10:08 am Post subject: |
|
|
| Just to show a MessageBox so that I can see how it's done. I think I can work from there. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 26, 2008 10:25 am Post subject: |
|
|
| Code: | /*
Already happened:
CreateWindowEx(...)
- Created ComboBox with dwStyle being (WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST)
SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_ADDSTRING, 0, (LPARAM)_T("Test"));
- Added "Test" to the list, at position 0 (first.)
*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_COMBOBOX:
switch (HIWORD(wParam))
{
// Simple: Just compares the current selection pos with 0.
case CBN_SELCHANGE:
if (SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_GETCURSEL, 0, 0) == 0) // 0 = Test's position.
MessageBox(hWnd, _T("Chosen Test"), _T("CBN_SELCHANGE"), MB_OK);
break;
/*
More Complicated: (Gets position, length of chosen string, allocates memory for that string,
gets the string, Then MessageBox's it. If the text chosen is a match to "Test" it
MessageBox's that as a notification.)
case CBN_SELCHANGE:
{
INT Pos = 0, Len = 0;
Pos = SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_GETCURSEL, 0, 0);
if (Pos != -1)
{
Len = SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_GETLBTEXTLEN, Pos, 0);
if (Len > 0)
{
LPTSTR lpSel = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*Len+1);
if (lpSel != NULL)
{
SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_GETLBTEXT, Pos, lpSel);
MessageBox(hWnd, lpSel, _T("Chosen Text:"), MB_OK);
if (!lstrcmp(_T("Test"), lpSel))
MessageBox(hWnd, _T("Test was chosen!"), _T("Specific text chosen"), MB_OK);
HeapFree(GetProcessHeap(), 0, (LPVOID)lpSel);
}
}
}
}
*/
}
break;
}
break;
}
} |
_________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 26, 2008 11:01 am Post subject: |
|
|
| Why is the second one so complicated if it does the same thing? |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 26, 2008 11:16 am Post subject: |
|
|
It doesn't really do the same thing. Instead of relying on a constant position, it relies on the string that the position contains. When dealing with strings and you want to be efficient, you want to grab exactly how much memory you need, so that gives u another message to call before getting there, along with allocating the new string to hold that data. _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Sun Oct 26, 2008 12:02 pm Post subject: |
|
|
| lurc wrote: | | It doesn't really do the same thing. Instead of relying on a constant position, it relies on the string that the position contains. When dealing with strings and you want to be efficient, you want to grab exactly how much memory you need, so that gives u another message to call before getting there, along with allocating the new string to hold that data. | In other words, it's better to use the second? I have another question related to this. How do I preset a selection? I know there's CB_SETCURSEL and I think it's that one I should use, I checked MSDN but I'm still unsure how to use it. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Oct 26, 2008 6:24 pm Post subject: |
|
|
It all depends on what you plan to do with the Drop-Down list. If there isn't going to be any difference or change to it, positions are good and reliable because they are constant.
But if you're adding, editing, or removing things from it, than the second one is better because it relies on the contents, not the position.
CB_SETCURSEL does exactly what it says in the name. Set Current Selection. On MSDN, the parameters are:
| Quote: | (WPARAM) wParam,
// = (WPARAM) () wParam;
(LPARAM) lParam
// = 0; not used, must be zero
wParam
Specifies the zero-based index of the string to select. If this parameter is –1, any current selection in the list is removed and the edit control is cleared.
lParam
This parameter is not used.
|
So you would do:
SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_SELCURSEL, Position, 0); _________________
|
|
| Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Mon Oct 27, 2008 3:30 am Post subject: |
|
|
| lurc wrote: | It all depends on what you plan to do with the Drop-Down list. If there isn't going to be any difference or change to it, positions are good and reliable because they are constant.
But if you're adding, editing, or removing things from it, than the second one is better because it relies on the contents, not the position.
CB_SETCURSEL does exactly what it says in the name. Set Current Selection. On MSDN, the parameters are:
| Quote: | (WPARAM) wParam,
// = (WPARAM) () wParam;
(LPARAM) lParam
// = 0; not used, must be zero
wParam
Specifies the zero-based index of the string to select. If this parameter is –1, any current selection in the list is removed and the edit control is cleared.
lParam
This parameter is not used.
|
So you would do:
SendDlgItemMessage(hWnd, ID_COMBOBOX, CB_SELCURSEL, Position, 0); | I did that with SendMessage but it didn't work then >_<. I think I will start using SendDlgItemMessage instead =p. I'll defently(lol can't spell it..) give you credits for all that you helped me with! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|