question

how do i make this pushbuttton do something?

example:

1
2
3
4
5
6
7
hEdit =CreateWindow(TEXT("button"), TEXT("Save/Open DB"),    
		             WS_VISIBLE | WS_CHILD ,
		             240, 260, 110, 25,        
		             hWnd, (HMENU) 1, NULL, NULL);
		             
		             if ("button"=="PRESSED")//not legit command
		              MessageBox(NULL, "test", NULL, NULL);
You need to catch the WM_COMMAND message that corresponds to someone clicking the button.
the whole WM_COMMAND LOWORD wParam thing doesnt work


full codes here http://pastebin.com/ZcQCPXXw
Last edited on
Paste this into your code editor and try it. There is a main file and a header. Then tell me if the buttons work...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//Form8.cpp -- compiler switches /O1 /Oi /Os /GL /D   -- 7168 bytes;  113 lines
#include <windows.h>
#include <tchar.h>
#include "Form8.h"


long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
 HWND hCtl;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 hCtl=CreateWindowEx(0,_T("button"),_T("Love"),WS_CHILD|WS_VISIBLE,40,40,80,30,Wea->hWnd,(HMENU)IDC_LOVE,Wea->hIns,0);
 hCtl=CreateWindowEx(0,_T("button"),_T("Hate"),WS_CHILD|WS_VISIBLE,190,40,80,30,Wea->hWnd,(HMENU)IDC_HATE,Wea->hIns,0);

 return 0;
}


long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
 switch(LOWORD(Wea->wParam))
 {
   case IDC_LOVE:
     MessageBox(Wea->hWnd,_T("...More Love!"),_T("This Is What You Want..."),MB_OK);
     break;
   case IDC_HATE:
     MessageBox(Wea->hWnd,_T("...More Hate!"),_T("This Is What You Want..."),MB_OK);
     break;
 }

 return 0;
}


long fnWndProc_OnClose(lpWndEventArgs Wea)
{
 DestroyWindow(Wea->hWnd);
 PostQuitMessage(0);
 return 0;
}


LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
 WndEventArgs Wea;

 for(unsigned int i=0; i<dim(EventHandler); i++)
 {
     if(EventHandler[i].Code==msg)
     {
        Wea.hWnd=hwnd,Wea.lParam=lParam,Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(&Wea);
     }
 }

 return (DefWindowProc(hwnd,msg,wParam,lParam));
}


int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 TCHAR szClassName[]=_T("The Buttons Work!");
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 wc.lpszClassName=szClassName;                wc.lpfnWndProc=fnWndProc;
 wc.cbSize=sizeof (WNDCLASSEX);               wc.style=CS_DBLCLKS;
 wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);     wc.hInstance=hIns;
 wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION);  wc.hCursor=LoadCursor(NULL,IDC_ARROW);
 wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;    wc.cbWndExtra=0;
 wc.lpszMenuName=NULL;                        wc.cbClsExtra=0;
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,200,100,325,160,HWND_DESKTOP,0,hIns,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
  TranslateMessage(&messages);
  DispatchMessage(&messages);
 }

 return messages.wParam;
}


Header...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Form8.h
#define IDC_LOVE  1500
#define IDC_HATE  1505
#define dim(x) (sizeof(x) / sizeof(x[0]))

typedef struct           WindowsEventArguments
{
 HWND                    hWnd;
 WPARAM                  wParam;
 LPARAM                  lParam;
 HINSTANCE               hIns;
}WndEventArgs,           *lpWndEventArgs;

long fnWndProc_OnCreate  (lpWndEventArgs Wea);
long fnWndProc_OnCommand (lpWndEventArgs Wea);
long fnWndProc_OnClose   (lpWndEventArgs Wea);

struct EVENTHANDLER
{
 unsigned int            Code;
 long                    (*fnPtr)(lpWndEventArgs);
};

const EVENTHANDLER EventHandler[]=
{
 {WM_CREATE,             fnWndProc_OnCreate},
 {WM_COMMAND,            fnWndProc_OnCommand},
 {WM_CLOSE,              fnWndProc_OnClose}
};

Last edited on
they worked
Topic archived. No new replies allowed.