[C++] WIN32 Buttons

Junior Spellweaver
Joined
Jun 10, 2008
Messages
117
Reaction score
0
ok i am getting a few problems that i need help with. One isn't really a problem but more of an explanation and another is an error.


First:

Bloodshed Dev-C++
-----------------------

When i am creating a button with this program and i put this into the Primary.rc file:
Code:
/* -- Dialog Box: Primary -- */

IDD_PRIMARY_DLG DIALOGEX 0, 0, 263, 159
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE |
    WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Calling One Dialog Box From Another"
FONT 8, "MS Shell Dlg"
BEGIN
    PUSHBUTTON      "Close",IDCANCEL,204,12,50,16
    PUSHBUTTON      "Second",IDC_SECOND_BTN,12,12,50,14
END

/* -- Dialog Box: Second -- */

IDD_SECOND_DLG DIALOGEX 0, 0, 186, 90
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
    WS_SYSMENU
CAPTION "Second"
FONT 8, "MS Shell Dlg"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,129,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,129,24,50,14
END
I am getting a Syntax Error for Style DS_SETFONT.....


for the STYLE DS_SETFONT...
part.



Second:
---------------
When i use this code in Dev-C++:
Code:
hButton = CreateWindowEx( // creates a button
                                NULL,
                               "Button",
                               "Wont Work",
                               WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                               50, 15,
                               **** 30,
                               hwnd, NULL,
                               hInstance,
                               NULL);
It just sits there and does nothing when i compile. i want to do something with it.

I don't know how to make that button do anything.


Please help!!!!!!!!!



Help Greatly appreciated.




-Alex
AKA
Black Nemo
 
As for the button creation, after the hWnd parameter supply the function with an identifier, say ID_BUTTON1 (have it defined to an unique value before). Then, in your application's WinProc you will check for messages, msg WM_MESSAGE means there's a custom message and wParam will hold the id (which will be ID_BUTTON1).
Code:
switch (msg)
{
case WM_MESSAGE:
  switch (wParam)
  {
  case (ID_BUTTON1):
    break;
  case (ID_BUTTON2):
  case (ID_FUNNYBUTTON):
  }
}

Instead of defining an ID for the button, I suppose you can use your hButton in place of ID_BUTTON1 when you call your CreateWindowEx like that.

This thread may be helpful: http://www.cplusplus.com/forum/windows/3933/
 
I know i am not supposed to post lots of code on here but i really need help cause i got confused.

Code:
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
       HWND hButton, hCombo, hEdit, hList, hScroll, hStatic; // include everything

       switch(Message) {
               case WM_CREATE: // starts the creation process
                       hButton = CreateWindowEx( // creates a button
                                NULL,
                               "Button",
                               "Wont Work",
                               WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                               50, 15,
                               **** 30,
                               hwnd, NULL,
                               zhInstance,
                               NULL);
                               hButton = CreateWindowEx( // creates a button
                                NULL,
                               "Button",
                               "Wont Work",
                               WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                               319, 30,
                               **** 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;
}

where would i create the ID of the button? Im not very far in WIN32 programming.
 
where would i create the ID of the button? Im not very far in WIN32 programming.
Anywhere you can define a constant: usually a .hh file or beginning of the .cpp can work, too. It's just a number. I've done very little win32 programming myself, so any examples you find on the net are probably better help than me.
 
I can still define a button for this?
Code:
 case WM_CREATE: // starts the creation process
                       hButton = CreateWindowEx(
how would i do that?
 
Last edited:
Back