native window form application

how to create simple window from application having simple out put displayed by a button?
Are yoyu using Visual Studio?
If you're talking about a form application, as in an app using the .Net Forms Library, then it sounds like you're talking about a managed C++/CLI rather than a native (aka unmanaged) C++ app.

Is this the case?

Andy
i want to made a window form application having text boxes buttons and codes are written natively not CLI
i m using visul c++ 2008
Here's a basic program and it'll work in VC++ 2008 no problem. Actually, its from this link where I have a basic GUI tutorial ...

http://www.jose.it-berater.org/smfforum/index.php?topic=3389.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//Main.cpp
#include <windows.h>
#include <tchar.h>

LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
  case WM_CREATE:      //This message is only received one time at program start up.  Think of it
    {                  //as a constructor call.
       MessageBox(hwnd,_T("Window Procedure Received WM_CREATE Message!"),_T("Message Report!"),MB_OK);
       return 0;
    }
  case WM_LBUTTONDOWN: //This message comes through when you click the form with your left mouse button.
    {
       MessageBox(hwnd,_T("Window Procedure Received WM_LBUTTONDOWN Message!"),_T("Message Report!"),MB_OK);
       return 0;
    }
  case WM_PAINT:       //This message comes through whenever any part of the window becoms 'invalid'.
    {                  //At program start up the whole window is invalid so must be drawn.
       TCHAR szBuffer[]=_T("Click Anywhere On Form (And Oh Yeah...Hello, World!)");
       //LPCTSTR szBuffer=_T("Click Anywhere On Form (And Oh Yeah...Hello, World!)"); // << can use this too
       PAINTSTRUCT ps;
       HDC hDC;
       hDC=BeginPaint(hwnd,&ps);
       SetBkMode(hDC,TRANSPARENT);
       TextOut(hDC,40,20,szBuffer,_tcslen(szBuffer));
       EndPaint(hwnd,&ps);
       return 0;
    }
  case WM_CLOSE:       //This message comes through when you click the [x] close button in the upper right
    {                  //corner of your window.
       MessageBox(hwnd,_T("Window Procedure Received WM_CLOSE Message!"),_T("Message Report!"),MB_OK);
       DestroyWindow(hwnd);
       PostQuitMessage(0);
       return 0;
    }
 }

 return (DefWindowProc(hwnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int iShow)
{
 TCHAR szClassName[]=_T("Form1");
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 wc.lpszClassName  =  szClassName;                     //Important Field!  Character string identifying window class
 wc.lpfnWndProc    =  fnWndProc;                       //Important Field!  Function Pointer.  Address of Window Procedure
 wc.cbSize         =  sizeof (WNDCLASSEX);             //Those top two fields I just listed are very important.  The
 wc.style          =  0;                               //others are of course necessary too, but fully understanding all
 wc.hIcon          =  LoadIcon(NULL,IDI_APPLICATION);  //the implications of the .szClassName and .lpfnWndProc fields will
 wc.hInstance      =  hInstance;                       //go a long way to helping you understand Win32 coding. The
 wc.hIconSm        =  0;                               //.hBrushBackground field will be the color of the Window's
 wc.hCursor        =  LoadCursor(NULL,IDC_ARROW);      //background.  The .cbWndExtra field is very useful as it allows
 wc.hbrBackground  =  (HBRUSH)COLOR_BTNSHADOW;         //you to associate object (Window) data to the instantiated Window's
 wc.cbWndExtra     =  0;                               //internal structure, i.e., accomodate member data.
 wc.cbClsExtra     =  0;
 wc.lpszMenuName   =  NULL;
 RegisterClassEx(&wc),
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,350,250,450,300,HWND_DESKTOP,0,hInstance,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))                 //All important message pump.  This logic continually retrieves
 {                                                     //messages from the program's message queene and dispatches them
    TranslateMessage(&messages);                       //to the Window Procedure for processing.
    DispatchMessage(&messages);
 }

 return messages.wParam;
}


Before it will work, you need to know how to set up a native Win32 project in Visual Studio 2008. If you don't know how to do that post back.
@muddaser

You're mixing the terminology up: you can have a native Windows app or a Windows Form app (which uses the .Net Forms library). There is no such thing as a "native Form application"

So you want a native Windows application.

freddie1's code is pretty much the standard "Hello world" of native Windows apps, plus a few message boxes.

Except that:

#1 WM_CREATE is called when the window is created, not at program startup (once for each instance of a window class)

#2 the WM_CLOSE handler should not call PostQuitMessage, that should be called by the WM_DESTROY handler

1
2
3
4
5
6
7
8
9
10
11
12
13
  case WM_DESTROY:      //This message received once for each window that is destroyed. Think of it
    {                   //as a destructor call.
       MessageBox(hwnd,_T("Window Procedure Received WM_DESTROY Message!"),_T("Message Report!"),MB_OK);
       PostQuitMessage(0);
       return 0;
    }

  case WM_CLOSE:       //This message comes through when you click the [x] close button in the upper right
    {                  //corner of your window.
       MessageBox(hwnd,_T("Window Procedure Received WM_CLOSE Message!"),_T("Message Report!"),MB_OK);
       DestroyWindow(hwnd);
       return 0;
    }


#3 you need to add 1 to the color contant, for the background brush, to get the right value (just one of those things...)

wc.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW + 1);

#4 You should restore the changes you make to the GDI DC in the WM_PAINT handler

1
2
3
4
5
6
7
8
9
10
11
  case WM_PAINT:       //This message comes through whenever any part of the window becoms 'invalid'.
    {                  //At program start up the whole window is invalid so must be drawn.
       const TCHAR achMsg[]=_T("Click Anywhere On Form (And Oh Yeah...Hello, World!)");
       PAINTSTRUCT ps={0};
       HDC hDC=BeginPaint(hwnd,&ps);
       int oldBkMode=SetBkMode(hDC,TRANSPARENT); // remember old mode
       TextOut(hDC,40,20,achMsg,_tcslen(achMsg));
       SetBkMode(hDC,oldBkMode); // restore
       EndPaint(hwnd,&ps);
       return 0;
    }


And note that what you create with CreateWindowEx is a window, not a form (as the name of the functions tells us).

Andy

PS For a bit more info, see

Creating Win32-Based Applications (C++)
http://msdn.microsoft.com/en-us/library/bb384843.aspx

Last edited on
Topic archived. No new replies allowed.