Results 1 to 11 of 11

Thread: Controls On An Win 32 Form

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    I have created a form in wein 32 yet i dont know how to create controls on the form and how to see when theyre clicked. How do i add controls and now when a button is pressed or something like that ?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Example - a button. When that button is clicked, a WM_COMMAND message will be sent to your application. The wParam information will contain the Dialogue ID of the button. You can use this in your WndProc:
    Code:
    WndProc(...) {
        if(uMsg == WM_COMMAND && wParam == IDD_MYBTN) {
            MessageBox(hwnd, "Button pressed", "Msg", MB_OK);
        }
    }
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Thanks (i can use that), But how do i create the button

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    In a dialogue, you need to put it into the resource file. Select the "Resources" tab in the VC IDE, and open up the dialogue. It's pretty much like VB from there, apart from there's no event handling AT ALL (unless you use MFC, which it's not a good idea to until you understand how Windows works). I'll email you a small generic app.
    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    I know that part but with win 32 where you hard code all of the controls how do u do that

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It's all in there - you should get an email with a couple of projects in...Yahoo!'s mail system notwithstanding

    I'll be finished in about 5mins
    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

  7. #7
    Guest
    Use CreateWindowEx.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Thanks :-))))

  9. #9
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    If there's anything about CreateWindowEx in parksie's project you don't understand, this describes every part of CreateWindowEx:

    http://msdn.microsoft.com/library/ps...ndows_1w6w.htm


    It tells you the different types of classes and their different styles and what they do.
    Courgettes.

  10. #10
    Guest
    Put the following in your InitInstance sub.
    Code:
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
    
       hInst = hInstance; // Store instance handle in our global variable
    
       hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
    
       if (!hWnd)
       {
          return FALSE;
       }
    
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
    	HWND bWnd;
            // Draw the Button
    	bWnd = CreateWindowEx(NULL, "Button", "Button1", WS_CHILD, 0, 0, 64, 64, hWnd, NULL, hInst, NULL);
    	ShowWindow(bWnd, 1);
    
    	ShowWindow(bWnd, nCmdShow);
    	UpdateWindow(bWnd);
       return TRUE;
    }

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Megatron - it's best to keep the stored window handle as a global, so that it can be accessed from other source files. Plus, you'd have to have something like:
    Code:
    int WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPCTSTR lpszCommandLine, UINT nCmdShow) {
        InitInstance(hInstance, nCmdShow);
    }
    You also need to set up a window procedure or your window won't be able to close properly. (the app will still be running with no window open)
    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
  •  



Click Here to Expand Forum to Full Width