Thread: C window code - How easy is it to intergrate cmd code

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    93

    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?

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    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.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    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?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    http://cboard.cprogramming.com/searc...archid=1625823

    Does the code you posted make sense to you?

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    vBulletin Message
    Sorry - no matches. Please try some different terms.
    Apparently not, no.
    Last edited by spadez; 04-18-2009 at 09:22 PM.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Hmm okay I guess the search results are only visible to me...

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

    Apparently not, no.
    That is the problem. How are you planning to use it in your code if you don't understand it?

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    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?

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Yes, the point is
    Judging by the quality of your code
    may not be referring to the code you posted in this thread.

  9. #9
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    Thats nice that you spent time trawling through my posts, but the question is:

    How easy is it to intergrate cmd code into a windowed program

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    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

  11. #11
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    This is just BobS0327's post reworded btw
    Does it need to be said twice then?

    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.

  12. #12
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    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?"

  13. #13
    Registered User
    Join Date
    Feb 2009
    Posts
    93
    Is the complexity of making a simple window app really comparable?

    Bob hit the nail on the head with:

    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)

  14. #14
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Is the complexity of making a simple window app really comparable.
    No, it's an exaggeration for an example.

    you do not have the experience necessary
    I just gave a bit more detail -
    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.

  15. #15
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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