|
-
May 20th, 2002, 02:10 PM
#1
Try re-posting - the fourms are hosed. I see no post at ll.
-
May 22nd, 2002, 12:36 AM
#2
Lively Member
The heck happened?
Oh well, here's my problem:
This is a WinAPI application. I have a textbox and a pushbutton. The user clicks on it, and a message box would appear and say what the textbox says. Well my problem is this, what messages does my program need to catch in order to know that the user pushed the pushbutton? I know to use BM_CLICK, but can someone write it in code so the program knows what pushbutton I pressed?
- Justin Patrick Butler
Comme je trouve. "As I find."
- Butler family quote
Beneficia sumptos procul superant. "The benefits far exceed the costs."
- Myself
-
May 22nd, 2002, 11:43 PM
#3
Lively Member
Dang, you people are picky. Well anyway here's my code:
#include <windows.h>
#include "resource.h"
#include "zstedit.h"
#define CYA 9000
#define LATER 9001
#define SECOND_TIME 9002
const char g_szClassName[] = "myWindowClass";
HINSTANCE hinstance;
HWND hEdit, hButton;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
HMENU hMenu, hSubMenu;
HFONT hfDefault;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, CYA, "Goodbye");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT) hSubMenu, "File");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, LATER, "Haha!");
AppendMenu(hSubMenu, MF_STRING, SECOND_TIME, "Hmmm!");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT) hSubMenu, "Edit");
SetMenu(hwnd, hMenu);
hEdit = CreateWindowEx(0, "EDIT", "",
WS_CHILD | WS_VISIBLE | ES_NUMBER |
ES_AUTOHSCROLL | WS_DLGFRAME,
20, 20, 200, 20, hwnd, NULL, hinstance, NULL);
if(!hEdit)
break;
hfDefault = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
SendMessage(hEdit, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE,0));
hButton = CreateWindowEx(0, "BUTTON", "Push me",
WS_CHILD | WS_VISIBLE | BS_CENTER,
240, 20, 100, 20, hwnd, NULL, hinstance, NULL);
if(!hButton)
break;
SendMessage(hButton, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM(FALSE,0));
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CYA:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case LATER:
MessageBox(hwnd, "Haha! Fooled Ya!", "Read below", 0);
break;
case SECOND_TIME:
MessageBox(hwnd, "Yea! It works!", "Read it and weep, antiprogs!", 0);
break;
}
/* my prob */ switch(HIWORD(wParam))
case BM_CLICK:
if (((HWND) lParam)==hButton)
{
char get[100];
GetWindowText(hEdit, get, 100);
MessageBox(hwnd, get, "Hello", 0);
break;
} /* my prob */
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
hinstance = hInstance;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
100, 100, 500, 250,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
- Justin Patrick Butler
Comme je trouve. "As I find."
- Butler family quote
Beneficia sumptos procul superant. "The benefits far exceed the costs."
- Myself
-
May 23rd, 2002, 12:37 AM
#4
New Member
This is the time we go on with OOP. Why don't we change our manner.
That is ever easy to be done just with MS VC++ 6.0.
In the MFC project wizard, choose the dialog-based appication.
Open the dialog box resource then add the two controls we needed: an edit box and a push button.
Press the combound key: Ctrl+W (Class wizard), then choose message tab. Select the ID of the push button in the list below, then choose the On_Click option in the next message list, then click OK. Select the 'Edit Code' button to go to the edit window, we type the following code in the On_?????_Click function
CString s;
CEdit* ed = (CEdit*) GetDialogItem(ID_BUTTON???);
s = ed->GetWindowText();
MessageBox(s, "Message Typed", MB_OK);
That is all.
Note: I have no ready VC++6.0 software on the computer i used to answer your question. So, my code may take some mistakes. Please correct it for me. Thank you.
-
May 23rd, 2002, 10:07 AM
#5
Frenzied Member
In the future can you put your code in the correct tags, so we can read it better
Ok any way, you are close. The way I do it is to define a resource to it. You can do that by using define:
#define ID_BUTTONME 114
Then in your button creation:
hButton = CreateWindowEx(0, "BUTTON", "Push me",
WS_CHILD | WS_VISIBLE | BS_CENTER,
240, 20, 100, 20, hwnd, (HMENU)ID_BUTTONME , hinstance, NULL);
Then in your message handler:
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_BUTTONME:
break;
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
May 24th, 2002, 10:31 AM
#6
dubae: MFC was not made for those who don't know how to do API. It was made for those who know API and don't want to do the same things for every app they make.
To differ between different notifications, do a switch on HIWORD(wParam)
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 24th, 2002, 12:21 PM
#7
Lively Member
I still can't get it to work. I did this (even outside the WM_COMMAND case and any other switch and with no control-specific information, which I don't believe is required),
switch (HIWORD(wParam) {
case BM_CLICK:
{
//my code
}
}
, and it still didn't do anything when I pressed the button! I have no clue what to do in this matter! I really truly would like some sample code posted. Thanks.
- Justin Patrick Butler
Comme je trouve. "As I find."
- Butler family quote
Beneficia sumptos procul superant. "The benefits far exceed the costs."
- Myself
-
May 24th, 2002, 12:28 PM
#8
Lively Member
Never mind! Figured it out! I was supposed to be using the notification messages, not the normal messages. I was supposed to use BN_CLICKED not BM_CLICK.
- Justin Patrick Butler
Comme je trouve. "As I find."
- Butler family quote
Beneficia sumptos procul superant. "The benefits far exceed the costs."
- Myself
-
May 24th, 2002, 01:04 PM
#9
Monday Morning Lunatic
Just as a FYI, Microsoft are fairly consistent (I said fairly, before anyone starts picking holes) in their naming:
BN_CLICKED => BN = Button Notification
BM_CLICK => BM = Button Message
Chances are, you want to catch the version with the "N" in for everything, for example EN_CHANGED for an edit box...similarly, you send the message which is ?M_WHATEVER
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|