PDA

Click to See Complete Forum and Search --> : All VC++ Developers Look Here


Sep 20th, 2000, 01:07 PM
Hi, code some post the directions to make a program that will display a window for me. And then explain the code. thanks.

PsyVision
Sep 21st, 2000, 12:46 PM
........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.

parksie
Sep 21st, 2000, 12:54 PM
http://www.parksie.uklinux.net/RawDlg.zip shows how to use two buttons.

PsyVision
Sep 21st, 2000, 01:17 PM
#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;
}

PsyVision
Sep 21st, 2000, 01:20 PM
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.