 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Aug 01, 2007 9:07 am Post subject: c++ making a button do something |
|
|
| Code: | LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
HWND hButton;
switch(Message) {
case WM_CREATE:
hButton = CreateWindowEx(NULL, "Button", "Button Example",
WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0,
110, 30,
hwnd, NULL,
zhInstance, NULL);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
} |
heres my cases for WndProc
as you can tell i added a button onto the form, but how do i make the button do something?
and can anyone point me to a good c++ gui tutorial (in-depth is nice)
and appal your right, the little bit of masm i know lets me understand that code ^.^
_________________
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Aug 01, 2007 9:13 am Post subject: |
|
|
| Create it in InitInstance();
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Aug 01, 2007 10:03 am Post subject: |
|
|
the following compiles fine*
| Code: | #include <windows.h>
#define IDC_BUTTON 100
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static char sClassName[] = "MyClass";
static HINSTANCE zhInstance = NULL;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow) {
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
zhInstance = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = zhInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = sClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass)) {
MessageBox(0, "Error Registering Class!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_STATICEDGE, sClassName, "but", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT,
110, 60, NULL, NULL, zhInstance, NULL);
if(hwnd == NULL) {
MessageBox(0, "Error Creating Window!", "Error!", MB_ICONSTOP | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0)) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
void onClickMyButton(HWND hWnd)
{
MessageBox(hWnd, "You you clicked me!!", "I was Clicked", MB_OK);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
HWND hButton;
switch(Message) {
case WM_CREATE:
hButton = CreateWindowEx(NULL, "Button", "Button Example",
WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0,
110, 30,
hwnd, (HMENU)IDC_BUTTON,
zhInstance, NULL);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_BUTTON)
{
HWND hWnd;
onClickMyButton(hWnd);
}
else{}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
} |
ok i defined my button name
i put in the WM_COMMAND code to check for my buttons name
i put in the onClickMyButton function
i called it...
wtf is wrong?
_________________
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Wed Aug 01, 2007 10:31 am Post subject: |
|
|
did u create that function urself or did u actually double clikc the button on ur UI....
_________________
|
|
| Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Wed Aug 01, 2007 10:39 am Post subject: |
|
|
Weren't you coding in Delphi like a week ago and now you want to code GUI in C++? I suggest you to start with CLI first and learn the basics.
Anyways, did you check this out http://www.winprog.org/tutorial/
_________________
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Wed Aug 01, 2007 10:43 am Post subject: |
|
|
i used to code c++ awhile ago, so i remember alot
i did all cmd line so now im gonna do gui
i quit because dev cpp was fucking up everything
edit: lurc im using code blocks not vc++
there is no fancy button to drag and drop
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Aug 01, 2007 10:56 am Post subject: |
|
|
Getting a nice resource editor would make things easier for one. If the IDE doesn't have one, ResEd is good.
Also seconding http://www.winprog.org/tutorial/
|
|
| Back to top |
|
 |
assaf84 Expert Cheater
Reputation: 0
Joined: 03 Oct 2006 Posts: 238
|
Posted: Wed Aug 01, 2007 11:29 am Post subject: |
|
|
Idk a lot about coding GUI's in C++, but this looks not ok:
| Code: |
HWND hWnd;
onClickMyButton(hWnd);
|
You pass the function an "empty" HWND u just created? I don't know a lot about this, but try using hwnd instead of hWnd..
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Wed Aug 01, 2007 11:32 am Post subject: |
|
|
edit: nevermind, I was wrong about the hmenu identifier. Second of all, it's a local variable, make it global, else you won't be able to use it the next time it's called. Third of all, what you need to do is:
when you button is clicked, it will send a WM_COMMAND message to the parent window (the window for which you have a wndproc). the hi word of wParam will be BN_CLICKED. the low word of wParam will be the button identifier (hwnd)
want to learn by example? see this.
Last edited by appalsap on Thu Aug 02, 2007 10:14 am; edited 1 time in total |
|
| Back to top |
|
 |
Stallios How do I cheat?
Reputation: 0
Joined: 02 Aug 2007 Posts: 3
|
Posted: Thu Aug 02, 2007 10:04 am Post subject: |
|
|
here's how I got it done :
| Code: |
//Global Variable
#define BTN_OK 1
//WinMain
bBTN_OK = CreateWindow(
"BUTTON",
"Go!",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
15,
10,
100,
40,
hMainWindow,
(HMENU)BTN_OK,
hInstance,
NULL);
//Windows Process
switch(msg)
{
case WM_COMMAND:
switch(wParam)
{
case BTN_OK:
break;
}
}
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Thu Aug 02, 2007 9:53 pm Post subject: |
|
|
lawl i just reformatted and had to get this file again thank god i put it up a few posts
i was looking and
| Code: | void onClickMyButton(HWND hWnd)
{
MessageBox(hWnd, "You you clicked me!!", "I was Clicked", MB_OK);
} |
notice the way i pass hWnd not hwnd -_-
i overlooked it
_________________
|
|
| 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
|
|