main.cpp

#include <windows.h>
#include "Resource.h"

HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_Main),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;
}

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwStart, hwServer, hwClient;

	hwStart = GetDlgItem(hWndDlg,IDC_Start);
	hwServer = GetDlgItem(hWndDlg,IDC_Server);
	hwClient = GetDlgItem(hWndDlg,IDC_Client);

	switch(Msg)
	{
	case WM_INITDIALOG:
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
			if(IDC_Server)
			{
				SendMessage(hwServer, BM_SETCHECK, 1, 0);
				SendMessage(hwClient, BM_SETCHECK, 0, 0);
				SetWindowText(hwStart, "Listen");
				}
			else if(IDC_Client)
			{
				SendMessage(hwClient, BM_SETCHECK, 1, 0);
				SendMessage(hwServer, BM_SETCHECK, 0, 0);
				SetWindowText(hwStart, "Connect");
			}
			else if(IDC_Quit)
			{
				EndDialog(hWndDlg, 0);
				return TRUE;
			}
		}
	}
	return FALSE;
}

Resource.h

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by WIN32D.rc
//
#define IDD_DIALOG1                     101
#define IDD_Main                        101
#define IDI_ICON1                       103
#define IDC_Submit                      1000
#define IDC_Window                      1001
#define ID_Close                        1004
#define IDC_Input                       1005
#define IDC_Server                      1006
#define IDC_Client                      1007
#define IDC_Start                       1008
#define IDC_Quit                        1009

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        104
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1010
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

theres a warning because no case statement but thats fine for now. I cant get the buttons to work. The reason im using if/else if is because if i use case IDC_Server: etc it does all case statements then quits instead of just doing the case statement for that button.

Any ideas what im doing wrong :(

case WM_COMMAND:
		switch(wParam)
		{
			if(IDC_Server)
			{
				SendMessage(hwServer, BM_SETCHECK, 1, 0);
				SendMessage(hwClient, BM_SETCHECK, 0, 0);
				SetWindowText(hwStart, "Listen");
				}
			else if(IDC_Client)
			{
				SendMessage(hwClient, BM_SETCHECK, 1, 0);
				SendMessage(hwServer, BM_SETCHECK, 0, 0);
				SetWindowText(hwStart, "Connect");
			}
			else if(IDC_Quit)
			{
				EndDialog(hWndDlg, 0);
				return TRUE;
			}
		}
	}
	return FALSE;
}

an switch stucture works with 'case' + don't forget to add 'break' at the end

The reason im using if/else if is because if i use case IDC_Server: etc it does all case statements then quits instead of just doing the case statement for that button.

break it off !!!

break it off !!!

yip i kinda figured that out lol :(

#include <windows.h>
#include "Resource.h"

HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	DialogBox(hInstance, MAKEINTRESOURCE(IDD_Main),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;
}

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwStart, hwServer, hwClient, hwStatus, hwChatWindow, hwText, hwIP, hwPort, hwNick;

	hwStart = GetDlgItem(hWndDlg,IDC_Start);
	hwServer = GetDlgItem(hWndDlg,IDC_Server);
	hwClient = GetDlgItem(hWndDlg,IDC_Client);
	hwStatus = GetDlgItem(hWndDlg,IDC_Status);
	hwText = GetDlgItem(hWndDlg,IDC_Text);
	hwChatWindow = GetDlgItem(hWndDlg,IDC_ChatWindow);
	hwIP = GetDlgItem(hWndDlg,IDC_EditIP);
	hwPort = GetDlgItem(hWndDlg,IDC_EditPort);
	hwNick = GetDlgItem(hWndDlg,IDC_EditNick);

	switch(Msg)
	{
	case WM_INITDIALOG:
		SetWindowText(hwStatus, "Status: Disconnected");
		EnableWindow(hwIP, FALSE);
		EnableWindow(hwPort, FALSE);
		EnableWindow(hwNick, FALSE);
		return TRUE;

	case WM_COMMAND:
		switch(wParam)
		{
			case IDC_Server:
				{
					SetWindowText(hwStatus, "Status: Disconnected");
					SendMessage(hwServer, BM_SETCHECK, 1, 0);
					SendMessage(hwClient, BM_SETCHECK, 0, 0);
					SetWindowText(hwStart, "Listen");
					SetWindowText(hwIP, "Need to add IP Function");
					EnableWindow(hwIP, FALSE);
					EnableWindow(hwPort, TRUE);
					EnableWindow(hwNick, TRUE);
					break;
				}
			case IDC_Client:
				{
					SetWindowText(hwStatus, "Status: Disconnected");
					SendMessage(hwClient, BM_SETCHECK, 1, 0);
					SendMessage(hwServer, BM_SETCHECK, 0, 0);
					SetWindowText(hwStart, "Connect");
					EnableWindow(hwIP, TRUE);
					EnableWindow(hwPort, TRUE);
					EnableWindow(hwNick, TRUE);
					break;
				}
			case IDC_Start:
				{
					SetWindowText(hwChatWindow, " ***Disconnected*** \r\n");
					SetWindowText(hwStatus, "Status: Disconnected");
					break;
				}
			case WM_DESTROY:
				{
				PostQuitMessage(0);
				return 0;
				}
		}
	}				
	return FALSE;
}

thats it so far xD

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.