C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-18-2009, 10:46 AM   #1
Registered User
 
Join Date: Feb 2009
Posts: 88
C window code - How easy is it to intergrate cmd code

Hi,

As a project im required to make a cmd program. The teacher said it would be better if we are able to intergrate it into a windowed program but didnt give us any information on it.

If i have a CSV reader code working in cmd and i have this working window code:

Code:
// kjljl.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "kjljl.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_KJLJL, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_KJLJL));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage are only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_KJLJL));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_KJLJL);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
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);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		// TODO: Add any drawing code here...
		EndPaint(hWnd, &ps);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(lParam);
	switch (message)
	{
	case WM_INITDIALOG:
		return (INT_PTR)TRUE;

	case WM_COMMAND:
		if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
		{
			EndDialog(hDlg, LOWORD(wParam));
			return (INT_PTR)TRUE;
		}
		break;
	}
	return (INT_PTR)FALSE;
}
How easy would it be to display my CSV output in the window instead of in cmd?
spadez is offline   Reply With Quote
Old 04-18-2009, 07:00 PM   #2
Registered User
 
Join Date: Mar 2005
Location: Mountaintop, Pa
Posts: 1,059
Quote:
Originally Posted by spadez View Post
Hi,

As a project im required to make a cmd program. The teacher said it would be better if we are able to intergrate it into a windowed program but didnt give us any information on it.

If i have a CSV reader code working in cmd and i have this working window code:


How easy would it be to display my CSV output in the window instead of in cmd?
My gut feeling is that your instructor does not want you to write a Windows GUI app that scolls CSV data in a window. To do this, you would need a solid understanding of the WIN32 API. Judging by the quality of your code, you do NOT have the experience necessary to embark on a WIN32 window scrolling app.

I would suggest that you discuss this project with your instructor for a clarification of the requirments. If in fact, a WIN32 GUI window scrolling app is required, then post your request in the Windows forum. Your instructor should also provide a lot more info on WIN32 GUI apps, particulary in the area of the various scrolling mechanisms that can be used in order to allow the students a reasonable chance of successfully completing the project.
BobS0327 is offline   Reply With Quote
Old 04-18-2009, 07:56 PM   #3
Registered User
 
Join Date: Feb 2009
Posts: 88
I very much appreciate the use of bold, underline, caps and red text to tell me i dont not have the skills required.

The code posted above is not mine, it is an example code from a microsoft vs tutorial site. Are you saying their code is bad?
spadez is offline   Reply With Quote
Old 04-18-2009, 08:38 PM   #4
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
http://cboard.cprogramming.com/searc...archid=1625823

Does the code you posted make sense to you?
cyberfish is offline   Reply With Quote
Old 04-18-2009, 09:20 PM   #5
Registered User
 
Join Date: Feb 2009
Posts: 88
Quote:
vBulletin Message
Sorry - no matches. Please try some different terms.
Apparently not, no.

Last edited by spadez; 04-18-2009 at 09:22 PM.
spadez is offline   Reply With Quote
Old 04-18-2009, 09:22 PM   #6
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
Hmm okay I guess the search results are only visible to me...

Click your user name > Statistics > "Find all posts by spadez".

Quote:
Apparently not, no.
That is the problem. How are you planning to use it in your code if you don't understand it?
cyberfish is offline   Reply With Quote
Old 04-18-2009, 09:24 PM   #7
Registered User
 
Join Date: Feb 2009
Posts: 88
I really dont need to spend time looking for posts made by spadez as I am the one who created them after all.

Are you trying to make some sort of point?
spadez is offline   Reply With Quote
Old 04-18-2009, 09:25 PM   #8
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
Yes, the point is
Quote:
Judging by the quality of your code
may not be referring to the code you posted in this thread.
cyberfish is offline   Reply With Quote
Old 04-18-2009, 09:28 PM   #9
Registered User
 
Join Date: Feb 2009
Posts: 88
Thats nice that you spent time trawling through my posts, but the question is:

Quote:
How easy is it to intergrate cmd code into a windowed program
spadez is offline   Reply With Quote
Old 04-18-2009, 09:35 PM   #10
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
The level of complexity of your code in other threads, if taken as an indication of your experience, suggests that you are not ready for this complex WinAPI stuff yet. So, to answer your question, it will be extremely difficult/impossible given your current experience (and presumably knowledge).

This is just BobS0327's post reworded btw .

That's why BobS0327 said (and I agree) this is probably not the intent of your prof/instructor, and it would be a good idea to seek clarification from him/her.

Last edited by cyberfish; 04-18-2009 at 09:37 PM. Reason: typo
cyberfish is offline   Reply With Quote
Old 04-18-2009, 09:41 PM   #11
Registered User
 
Join Date: Feb 2009
Posts: 88
Quote:
This is just BobS0327's post reworded btw
Does it need to be said twice then?

Quote:
The level of complexity of your code in other threads, if taken as an indication of your experience, suggests that you are not ready for this complex WinAPI stuff yet. So, to answer your question, it will be extremely difficult/impossible given your current experience (and presumably knowledge).
Ok, thank you. Forgive the attitude, but should I feel like you are trying to insult my coding ability after only trying to ask a simple question? No.
spadez is offline   Reply With Quote
Old 04-18-2009, 09:46 PM   #12
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
I apologize if it sounded like an insult. That was not the intention.

Lack of experience is nothing wrong. All of us have been there, and I am still there.

Out of curiosity, how would you respond, then, if someone who perceivably have only done a few hours of programming ask you "How easy is it to write a 3D MMORPG?"
cyberfish is offline   Reply With Quote
Old 04-18-2009, 09:50 PM   #13
Registered User
 
Join Date: Feb 2009
Posts: 88
Is the complexity of making a simple window app really comparable?

Bob hit the nail on the head with:

Quote:
you do not have the experience necessary
What I didnt understand is how he could criticise code that came from a microsoft VS tutorial (if it was that code he was referring to)
spadez is offline   Reply With Quote
Old 04-18-2009, 09:59 PM   #14
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,012
Quote:
Is the complexity of making a simple window app really comparable.
No, it's an exaggeration for an example.

Quote:
you do not have the experience necessary
I just gave a bit more detail -
Quote:
it will be extremely difficult/impossible given your current experience
because difficult is not the same as (nearly) impossible. Something "difficult" can be done if one sets his/her mind to it. Impossible means it's not possible with reasonable amount of work and/or time. I'm suggesting it's in the latter category.

How would you suggest I convey this information in the future then so no one will be offended? (this is a genuine question, since English is really not my forte, and I don't want to unintentionally offend anyone) Thanks.
cyberfish is offline   Reply With Quote
Old 04-19-2009, 03:22 PM   #15
Registered User
 
Join Date: Mar 2005
Location: Mountaintop, Pa
Posts: 1,059
Quote:
Originally Posted by spadez View Post
I very much appreciate the use of bold, underline, caps and red text to tell me i dont not have the skills required.

The code posted above is not mine, it is an example code from a microsoft vs tutorial site. Are you saying their code is bad?
Yep, it's someone's modified version of a MS app. The ATOM MyRegisterClass(HINSTANCE hInstance) function has issues that MS would not introduce into any code. The function has a high probabilty of failure. This is totally unlike any MS tutorial I've ever seen.

Can someone help me, I'm trying to learn C?. Need I say more?

The mods should move this script kiddies post over to the Windows forum where it belongs.
BobS0327 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Button positioning Lionmane Windows Programming 76 10-21-2005 05:22 AM
OpenGL Window Morgul Game Programming 1 05-15-2005 12:34 PM
my wndProc is out of scope Raison Windows Programming 35 06-25-2004 07:23 AM
opengl code not working Unregistered Windows Programming 4 02-14-2002 10:01 PM
Winamp Vis if anyone can help Unregistered Windows Programming 6 01-27-2002 12:43 AM


All times are GMT -6. The time now is 08:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22