Thread: winAPI with C

  1. #1
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Smile winAPI with C

    Hi all
    Well i wanted to ask you guys if there is nay apllication or programming tech that i can use with C to produce winAPI..Like creating text box and stuff like that using C.Some one told me that i can use MFC..But i dont even know what MFC stands for ..Help me out guys..

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Do you at least know the basics of windows programming?

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by The Dog
    Do you at least know the basics of windows programming?

    LOL...what do you think?!!

    datainjector.....do a board search...this question comes up every few days.....

  4. #4
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356

    Cool well thats what i want u to help me oput with The Dog

    Well i was just curious .If it is possible to inserte text box and stuff like that in ur C code...or is it possible in C programming lang...
    First of all i dont even know what the hell is windows programming ..enlighten me on it

  5. #5
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Originally posted by Fordy
    LOL...what do you think?!!
    ^^^^^^^^
    ???????????

    Perhaps i should ask datainjector to re-phrase or clarify what
    it is that he/she's looking for.

  6. #6
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Well, it's not hard to create a windows program with C.

    Basically, what happens is the following:

    1) You create an instance of a window class.

    //or create your own class.The term class is always used even
    //though the standard window class is a structure.

    2) You register the instance of that class.
    3) You create a window using the window class that you declared
    4) You show the window
    5) Now you enter a loop.

    // This loop will get messages from the window and send it to
    // a function known as a windows procedure. In the function,
    // The proper course of action takes place depending on message
    // Normal messages would be like, when click a button.

    Here's an example :

    Code:
    #include "resource.h"
    
    // Global Variables:
    HINSTANCE hInst;				
    TCHAR szWindowClass[MAX_LOADSTRING];						
    // Foward declarations of functions included in this code module:
    ATOM	MyRegisterClassHINSTANCE hInstance);
    BOOL	InitInstance(HINSTANCE, int);
    LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	// TODO: Place code here.
    	MSG msg;
    	
    	MyRegisterClass(hInstance);
    
    	// Perform application initialization:
    	if (!InitInstance (hInstance, nCmdShow)) 
    	{
    		return FALSE;
    	}
    
    	// Main message loop:
    	while (GetMessage(&msg, NULL, 0, 0)) 
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    	WNDCLASSEX wcex; //This is the instance
    
    	wcex.cbSize = sizeof(WNDCLASSEX); 
    
    	wcex.style= CS_HREDRAW | CS_VREDRAW;
    	wcex.lpfnWndProc	= (WNDPROC)WndProc;
    	wcex.cbClsExtra= 0;
    	wcex.cbWndExtra= 0;
    	wcex.hInstance= hInstance;
    	wcex.hIcon= LoadIcon(hInstance, (LPCTSTR)I_WIND2);
    	wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
    	wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
    	wcex.lpszMenuName=NULL;
    	wcex.lpszClassName= szWindowClass;
    	wcex.hIconSm= NULL;
    	return RegisterClassEx(&wcex); //Registering it
    }
    
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
       HWND hWnd;
    
       hInst = hInstance; // Store instance handle in global variable
    //Create the window
       hWnd = CreateWindow(szWindowClass, szTitle,
                                             WS_OVERLAPPEDWINDOW,
                                             0,0,100,100,
                                             NULL, NULL, hInstance, NULL);
    
       if (!hWnd)
       {
          return FALSE;
       }
    //Show the window
       ShowWindow(hWnd, nCmdShow);
       UpdateWindow(hWnd);
    
       return TRUE;
    }
    
    //
    //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  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;
    	
                    switch (message) 
    	{
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hWnd, 
                                                              message, wParam, lParam);
       }
       return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WinAPI & threading
    By @nthony in forum Windows Programming
    Replies: 17
    Last Post: 10-15-2007, 04:41 PM
  2. do i still need winAPI
    By datainjector in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2003, 01:43 AM
  3. references for the winapi
    By stallion in forum Windows Programming
    Replies: 9
    Last Post: 01-28-2003, 02:56 AM
  4. WINAPI: Meaning of HDC ?
    By Mecnels in forum Windows Programming
    Replies: 1
    Last Post: 01-21-2002, 10:06 AM
  5. C++ and WinAPI?
    By Matt2u in forum C++ Programming
    Replies: 9
    Last Post: 01-09-2002, 12:57 AM