Results 1 to 5 of 5

Thread: All VC++ Developers Look Here

  1. #1
    Guest

    Post

    Hi, code some post the directions to make a program that will display a window for me. And then explain the code. thanks.

  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    Sorry........

    ........I know it was late, i have now sent it. Before it was messed up but i have found the original file. It only shows how to create one button. I will write another post showing how to implement the code.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    http://www.parksie.uklinux.net/RawDlg.zip shows how to use two buttons.
    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

  4. #4
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    Win 32 App

    #include <windows.h>

    HWND hWnd_MainWnd;
    HWND hWnd_Button;
    HWND hWnd_NewButton;

    LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch(uMsg) {
    case WM_CLOSE:
    PostQuitMessage(0);
    return FALSE;

    case WM_COMMAND:
    if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == hWnd_Button)
    {
    MessageBox(hWnd_MainWnd, "Hello Fred","Hello",MB_OK);
    }

    if(LOWORD(wParam) == BN_CLICKED && (HWND)lParam == hWnd_NewButton)
    {
    MessageBox(hWnd_MainWnd, "Hello Eric","Hello",MB_OK);
    }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    hWnd_MainWnd = 0;

    WNDCLASSEX wndClass;

    wndClass.cbSize = sizeof(WNDCLASSEX);
    wndClass.style = 0;
    wndClass.lpfnWndProc = WindowProc;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hInstance = hInstance;
    wndClass.hIcon = NULL;
    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = "TESTCLASS";
    wndClass.hIconSm = NULL;

    RegisterClassEx(&wndClass);
    hWnd_MainWnd = CreateWindowEx(0, "TESTCLASS", "My Test Window", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL, NULL, hInstance, NULL);

    hWnd_Button = CreateWindowEx(0, "BUTTON", "Say Hello Fred", WS_CHILD | WS_VISIBLE, 20, 20, 100, 30, hWnd_MainWnd, NULL, hInstance, NULL);

    hWnd_NewButton = CreateWindowEx(0, "BUTTON", "Say Hello Eric", WS_CHILD | WS_VISIBLE, 130, 20, 100, 30, hWnd_MainWnd, NULL, hInstance, NULL);

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg); // Translate keycodes
    DispatchMessage(&msg); // Send to requisite window procedure
    }

    return msg.wParam;
    }

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    Dialog Box Style

    Add a Button To The Form With ID as IDC_HELLO:

    ----------------------------------------------

    #include <windows.h>

    #include "resource.h"

    HWND hWnd_MainDlg;
    ///////////////////////////////////////////////////////////////////////////

    int CALLBACK DlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch(uMsg) {
    case WM_CLOSE: // Sent by Windows when the window has been closed
    DestroyWindow(hWndDlg); // Destroy the window
    PostQuitMessage(0); // We've finished so quit the app
    return TRUE; // Since we handled the message, return TRUE

    case WM_COMMAND: // Send when Dialogue Box item received an event.
    switch(wParam) { // wParam contains the dialogue ID
    case IDC_MAINBTN: // Our button
    MessageBox(hWndDlg, "Button Pressed", "Event", MB_OK);
    case IDC_HELLO:
    MessageBox(hWndDlg, "Hello", "Hello", MB_OK);
    }
    return TRUE; // Handled, so true
    }
    return FALSE; // Not handled, so let the default action do it.
    }

    ///////////////////////////////////////////////////////////////////////////

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    hWnd_MainDlg = 0;

    // Create the dialogue box from a resource
    hWnd_MainDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);

    // If successful, show the window. Otherwise exit
    if(hWnd_MainDlg) {
    ShowWindow(hWnd_MainDlg, SW_SHOW);
    } else {
    return 0;
    }

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg); // Translate keycodes
    DispatchMessage(&msg); // Send to requisite window procedure
    }

    return msg.wParam; // Contains the code passed to PostQuitMessage()
    }


    P:S Both of these two posts are re does of main.cpp of both test showing how to do more than 1 control.

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