Another Where-to-begin question

I've done C programming in the distant past, and have also done some Windows programming in Fortran 95. But now I have a Visual C++ 6.0 compiler, and want to basically put up a window, put a message box in it, put in some checkboxes, two dropdown boxes, etc.

When I look at the documentation, I get deluged with talk of Classes, Properties, etc. that I'm not familiar with.

I've run a simple program that puts up a message box, using a lot of defaults. It works. Now I want to write a program that puts up a window, puts a message box in it near the left side, and puts in a few checkboxes on the right side.

Do I have to take a four-semester course to do this? Or can I get some relatively simple hints?

The simple messagebox program:

-----------------------------------------

#include <stdio.h>
#include <windows.h>

main()
{
MessageBox(NULL, "She sells sea shells by the sea shore.", "Message", MB_OK);
return 0;
}

-----------------------------------------

It puts the message box in the middle of the screen. How do I make it put it near the left side of the screen?

And, for a more advanced program, how do I first open a medium-sized window, and then put that message box inside it, near the left side? And then put a few checkboxes near the right side?

Thank you for any help or suggestions!
A lot of folks started learning low level (no class frameworks) Windows programming from Charles Petzold's "Programming Windows" books. Another good place to start is the "Forger's Win32" tutorials. Do a google on it. I've posted some introductory stuff with working examples and explanations here...

http://www.jose.it-berater.org/smfforum/index.php?board=380.0

The GUI stuff starts at Program Example #37. Later when I have time I'll post a VC6 example or two for you if you want. Most folks will tell you to get rid of VC6 but I still occasionally use it. In fact, if I do COM programming its the only thing I'll use. Just thought I'd mention that.

What you want to do is easy (once you know how to do it!).
Last edited on
Here's your VC6 (C++) Check Box program to get you started. You need to set the project up as a "Win32" project without MFC support and choose an "Empty Project". Then go to the file menu and choose "Add File" and select "C++ Source File". Name it "Main.cpp". Past this into it...

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
//Main.cpp
#include <windows.h >
#define CHECK_BOX_C                     1500
#define CHECK_BOX_C_PLUS_PLUS           1505
#define CHECK_BOX_PowerBASIC            1510
#define CHECK_BOX_Visual_Basic_6        1515
#define CHECK_BOX_Visual_Basic_NET      1520
   
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
 switch(msg)
 {
  case WM_CREATE:
    {
       HINSTANCE hIns;
       HWND hCtl;
       hIns=((LPCREATESTRUCT)lParam)->hInstance;
       hCtl=CreateWindow("button","C Programming Language",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,10,40,250,25,hwnd,(HMENU)CHECK_BOX_C,hIns,0);
       hCtl=CreateWindow("button","C++ Programming Language",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,10,70,250,25,hwnd,(HMENU)CHECK_BOX_C_PLUS_PLUS,hIns,0);
       hCtl=CreateWindow("button","PowerBASIC",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,10,100,250,25,hwnd,(HMENU)CHECK_BOX_PowerBASIC,hIns,0);
       hCtl=CreateWindow("button","Visual Basic 6",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,10,130,250,25,hwnd,(HMENU)CHECK_BOX_Visual_Basic_6,hIns,0);
       hCtl=CreateWindow("button","Visual Basic .NET",WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,10,160,250,25,hwnd,(HMENU)CHECK_BOX_Visual_Basic_NET,hIns,0);    
       return 0;
    }
  case WM_PAINT:
    {
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        SetBkMode(hDC,TRANSPARENT);
        TextOut(hDC,10,0,"Which Programming Languages Have You Used Today?",48);
        EndPaint(hwnd,&ps);    
        return 0;
    }
  case WM_CLOSE:
    {
       MessageBox(hwnd,"Window Procedure Received WM_CLOSE Message!","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)
{
 char szClassName[]="CheckBoxes";
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 wc.lpszClassName=szClassName,                wc.lpfnWndProc=fnWndProc;
 wc.cbSize=sizeof (WNDCLASSEX),               wc.style=CS_DBLCLKS;
 wc.hIcon=LoadIcon(NULL,IDI_APPLICATION),     wc.hInstance=hInstance;
 wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION),  wc.hCursor=LoadCursor(NULL,IDC_ARROW);
 wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW,    wc.cbWndExtra=0;
 wc.lpszMenuName=NULL,                        wc.cbClsExtra=0;
 RegisterClassEx(&wc),
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,350,250,400,275,HWND_DESKTOP,0,hInstance,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }

 return messages.wParam;
}
Topic archived. No new replies allowed.