• Advertisement
Sign in to follow this  

win32 and button

This topic is 4248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am learning some win32 programs do desing a UI for directx, but i have win32 questions. I just want to creat UI items on a screen using VC++ express , so I have no resource editor. I can create the UI items no problem but not interacting with them, I am having trouble finding examples without resource editor vc++ express has no resource editor. q) Is there a way to detect if a certain button has clicked without going through the CALLBACK proc. I want to be able to detect this through my own procedure eg callback prog, I don't want to do this case WM_COMMAND: { switch (LOWORD(wParam)) { case IDB_BUTTON: { switch (HIWORD(wParam)) { case BN_CLICKED: -------------------------------------------- I want to do void moOwn(..){ detect if the button on the window has been clicked.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by jagguy
I am learning some win32 programs do desing a UI for directx, but i have win32 questions.

I just want to creat UI items on a screen using VC++ express , so I have no resource editor. I can create the UI items no problem but not interacting with them, I am having trouble finding examples without resource editor vc++ express has no resource editor.

q)
Is there a way to detect if a certain button has clicked without going through the CALLBACK proc. I want to be able to detect this through my own procedure

eg callback prog, I don't want to do this
{code]
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDB_BUTTON:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:

--------------------------------------------
I want to do
void moOwn(..){

detect if the button on the window has been clicked.


You have to catch the Windows message (WM_COMMAND) and then test if the command comes from a button click. You can't do anything else. However, you can factorize this code in a checkButtonClick() method, which will in turn call another function (onBtnSomething()).

You can also try to work with function pointers of methods pointers (check Oluseyi's article and perhaps my journal entry on this subject).

Regards,

Share this post


Link to post
Share on other sites
can you test the WM_COMMAND somewhere else in the code, to make it easier to fit into your general way of thinking?
Does it have to be tested in the windows message handler?

Share this post


Link to post
Share on other sites
Quote:
Original post by jagguy
can you test the WM_COMMAND somewhere else in the code, to make it easier to fit into your general way of thinking?
Does it have to be tested in the windows message handler?

You have to test the WM_COMMAND in your message handler.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by jagguy
Is there a way to detect if a certain button has clicked without going through the CALLBACK proc. I want to be able to detect this through my own procedure



The way your program knows that a Windows control is being pressed is by your callback function being CALLED BACK with the message that the button was pressed. This sounds like more of a design issue than anything. You could have a function that takes an argument which designates if the button is pressed or not.. because it seems like you want to call some function like that outside of your handling of the button being depressed.. so when you handle the button down message, just call that function: is_my_button_pressed_and_do_other_stuff(1); and where ever else that you want to call that function you can pass zero instead.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by jagguy
Is there a way to detect if a certain button has clicked without going through the CALLBACK proc. I want to be able to detect this through my own procedure



The way your program knows that a Windows control is being pressed is by your callback function being CALLED BACK with the message that the button was pressed. This sounds like more of a design issue than anything. You could have a function that takes an argument which designates if the button is pressed or not.. because it seems like you want to call some function like that outside of your handling of the button being depressed.. so when you handle the button down message, just call that function: is_my_button_pressed_and_do_other_stuff(1); and where ever else that you want to call that function you can pass zero instead.


that is my question though, how do you do this?

I must say i have found UI the worst thing to find information on, it is dreadful and time consuming over simple stuff.

Share this post


Link to post
Share on other sites
What the AP meant was that when you handle WM_COMMAND when a button is pushed you call a function which tells the rest of your program that the button was pushed. In any case, you still have to handle this in your message handler.

Share this post


Link to post
Share on other sites
Quote:
Original post by Colin Jeanne
What the AP meant was that when you handle WM_COMMAND when a button is pushed you call a function which tells the rest of your program that the button was pushed. In any case, you still have to handle this in your message handler.



OK tkanks for that. I wanted a shortcut and there isn't one.


What about custom made UI, where you simply make the controls and use say directInput to find out where and if a mouse has been clicked.
Can you display 2d static image below the part rendered screen in d3d, with say a surface object .

Share this post


Link to post
Share on other sites
It's possible, yes. But the question is, why? What makes you want to avoid a message handler so badly? They're things you only need to write once and then you can pretty much ignore. For example:


LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
OnPaint(hdc, ps);
EndPaint(hwnd, &ps);
}
break;

case WM_COMMAND:
{
UINT code = HIWORD(wParam);
UINT id = LOWORD(wParam);
switch (id) {
case IDC_BUTTON1:
if (code == BN_PUSHED) {
OnButton1Pushed();
}
break;
}
}
break;

default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}



Once you set up which functions should be called you can ignore the fact that the message handler exists and just pretend that your functions are being called automatically. You can combine this with the methods mentioned in the two articles Emmanuel posted to do this with classes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement