Hello all,

I'm trying to learn how to make just a basic windows app with some buttons and text windows to make the programs I normally create and interface with through DOS a little more interesting.

I'm following the tutorials at http://www.winprog.org/tutorial and http://www.functionx.com/win32/ .
I can manage to get the most basic stuff like creating windows and adding a menu bar. Next up, I want to try and get dialog boxes, similar to what you might see when you hit the About button on a window. Specifically, http://www.functionx.com/win32/Lesson04.htm outlines what I'm trying to do.

Well, since I understand almost nothing about what exactly the syntax for all of this is, from how to interface with functions to what I need to put in resource files, I'm first trying to copy-paste code and see if it works. Well, as far as I can tell, what I have should be working.

#include "resource.h"

IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
    PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
    GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
    CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                    IDC_STATIC,16,18,144,33
END

This is what I have in my resource file and when I go to compile, I get a syntax error on line 4, the STYLE line. Nothing I look up or read leads me to believe that the syntax here is incorrect, aside from the fact that this is the code given to me from a tutorial. I even tried deleting the STYLE line just to get something to compile and I get another syntax error on the DEFPUSHBUTTON line.

The main code in the .cpp file *should* all be fine, it's taken directly from these tutorials as well, but I'll post it if everything seems fine with this resource file code. Also, I'm compiling in Dev-C++.

If anyone knows what my problem might be and wants to help, I would really appreciate it. This isn't really something I *need* to do but it would be real interesting if I could figure it out.

Hi Ripture,

Here is some code from Dev-C++ that uses a resource file I dug up from a few years back. I just rebuilt the project as C++ (it was C) and it works. The code also has a menu in it where you can go to the File menu & choose Open and the Open File Dialog Box will present itself. On the Help menu a dialog box from a resource file (.rc) is created. Hope it helps you. The main source is Main.cpp, the project name is Form11, the header is Form11.h and the rc file is Form11.rc. Create the Form11 project and put all the files in that dir. Then include them in the project, that is, Main.cpp, Form11.h and Form11.rc.

//Form11.h
#define IDC_STATIC      -1
#define IDR_MAIN_MENU   1240
#define IDM_OPEN        1250
#define IDM_SAVE        1252
#define IDM_EXIT        1254
#define IDM_HELP        1260
#define IDM_ABOUT       1262
#define IDC_NAME        1300
#define IDD_ABOUT       1400
#define IDC_EDITBOX1    1500
#define IDC_BUTTON      1510
//Resource Script
#include <windows.h>
#include "Form11.h"

IDR_MAIN_MENU MENU
{
 POPUP "&File"
 {
  MENUITEM "&Open...",          IDM_OPEN
  MENUITEM "&Save...",          IDM_SAVE
  MENUITEM SEPARATOR
  MENUITEM "E&xit",             IDM_EXIT
 }
 POPUP "&Help"
 {
  MENUITEM "&Help...",          IDM_HELP
  MENUITEM "&About Form8...",   IDM_ABOUT
 }
}

IDD_ABOUT DIALOG DISCARDABLE 30,60,180,36
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Identify Your Sorry Self!"
FONT 8, "MS Sans Serif"
BEGIN
  DEFPUSHBUTTON  "OK",IDOK,120,20,40,14
  PUSHBUTTON     "Cancel",IDCANCEL,75,20,40,14
  LTEXT          "Enter Your Name",IDC_STATIC,7,4,60,8
  EDITTEXT       IDC_NAME,65,4,100,12,ES_AUTOHSCROLL
END
#include <windows.h>
#include <commdlg.h>
#include <string.h>
#include "Form11.h"

typedef struct WindowsEventArguments
{
 HWND hWnd;
 WPARAM wParam;
 LPARAM lParam;
 HINSTANCE hIns;
}WndEventArgs,*lpWndEventArgs;


BOOL CALLBACK ModalDlgProc(HWND hwndDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
 char szName[64],szText[64];
 HWND hwndEdit;
 UINT nID;

 switch(message)
 {
  case WM_INITDIALOG:
    hwndEdit=GetDlgItem(hwndDlg,IDC_NAME);
    SetFocus(hwndEdit);
    return FALSE;
  case WM_COMMAND:
    nID = LOWORD(wParam);
    switch(nID)
    {
     case IDOK:
       hwndEdit=GetDlgItem(hwndDlg, IDC_NAME);
       GetWindowText(hwndEdit,szText,64);
       strcpy(szName,"Hello, ");
       strcat(szName,szText);
       strcat(szName,"!");
       MessageBox(hwndDlg,szName,"Form11",MB_OK);
     case IDCANCEL:
       EndDialog(hwndDlg, nID);
       break;
     default:
       break;
    }
    return TRUE;
  default:
    return FALSE;
 }
}


long WndProc_OnCreate(lpWndEventArgs Wea)
{
 HWND hTextBox,hButton;
 DWORD dwStyle;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 dwStyle=WS_CHILD|WS_VISIBLE|WS_BORDER;
 hTextBox=CreateWindow("edit","",dwStyle,10,30,370,20,Wea->hWnd,(HMENU)IDC_EDITBOX1,Wea->hIns,0);
 hButton=CreateWindow("button","Exit",WS_CHILD|WS_VISIBLE,168,75,60,25,Wea->hWnd,(HMENU)IDC_BUTTON,Wea->hIns,0);

 return 0;
}


void WndProc_OnCommand_OnOpen(lpWndEventArgs Wea)
{
 static char szFilter[]="C Files (*.C),CPP Files (*.cpp)\0*.c;*.cpp\0\0";
 static char szTitleName[_MAX_FNAME+_MAX_EXT];
 static char szFileName[_MAX_PATH];
 char lpszBuffer[128];
 OPENFILENAME ofn;
 
 GetCurrentDirectory(128,lpszBuffer);
 memset(&ofn,'\0',sizeof(OPENFILENAME));
 ofn.lStructSize=sizeof(OPENFILENAME);
 ofn.lpstrFilter = szFilter;
 ofn.nMaxFile=_MAX_PATH;
 ofn.nMaxFileTitle=_MAX_FNAME+_MAX_EXT;
 ofn.lpstrInitialDir = lpszBuffer;
 ofn.lpstrDefExt = "Sdb";
 ofn.hInstance=Wea->hIns;
 ofn.hwndOwner = Wea->hWnd;
 ofn.Flags=OFN_HIDEREADONLY | OFN_CREATEPROMPT;
 ofn.lpstrFile=szFileName;
 ofn.lpstrFileTitle=szTitleName;
 GetOpenFileName(&ofn);
 SetWindowText(GetDlgItem(Wea->hWnd,IDC_EDITBOX1),ofn.lpstrFile);

 return;
}


void WndProc_OnCommand_OnSave(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,"You Chose File >> Save","Form8",MB_OK);
}


void WndProc_OnCommand_OnExit(lpWndEventArgs Wea)
{
 SendMessage(Wea->hWnd,WM_DESTROY,0,0L);
}


void WndProc_OnCommand_OnHelp(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,"There Is No Help.","Form8",MB_OK);
}


void WndProc_OnCommand_OnHelpAbout(lpWndEventArgs Wea)
{
 DialogBox(Wea->hIns,MAKEINTRESOURCE(IDD_ABOUT),Wea->hWnd,ModalDlgProc);
}


void WndProc_OnCommand_OnButton_Click(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,"You Clicked The Button And Want To Exit!","Form8",MB_OK);
 SendMessage(Wea->hWnd,WM_DESTROY,0,0L);
}


long WndProc_OnCommand(lpWndEventArgs Wea)
{
 switch (LOWORD(Wea->wParam))
 {
  case IDM_OPEN:
    WndProc_OnCommand_OnOpen(Wea);
    break;
  case IDM_SAVE:
    WndProc_OnCommand_OnSave(Wea);
    break;
  case IDM_EXIT:
    WndProc_OnCommand_OnExit(Wea);
    break;
  case IDM_HELP:
    WndProc_OnCommand_OnHelp(Wea);
    break;
  case IDM_ABOUT:
    WndProc_OnCommand_OnHelpAbout(Wea);
    break;
  case IDC_BUTTON:
    WndProc_OnCommand_OnButton_Click(Wea);
    break;
 }

 return 0;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)
{
 static WndEventArgs wea;

 switch (iMsg)
 {
  case WM_CREATE:
    wea.hWnd=hwnd, wea.wParam=wParam, wea.lParam=lParam;
    return WndProc_OnCreate(&wea);
  case WM_COMMAND:
    wea.hWnd=hwnd, wea.wParam=wParam, wea.lParam=lParam;
    return WndProc_OnCommand(&wea);
  case WM_DESTROY:
    PostQuitMessage(0);
    return 0;
 }

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

int WINAPI WinMain(HINSTANCE hIns,HINSTANCE hPrIns,PSTR szCmdLn,int iCmdShow)
{
 char szAppName[]="Form11";
 WNDCLASSEX wndclass;
 HWND hwnd;
 MSG msg;

 wndclass.cbSize=sizeof(wndclass);
 wndclass.style=CS_HREDRAW|CS_VREDRAW;
 wndclass.lpfnWndProc=WndProc;
 wndclass.cbClsExtra=0;
 wndclass.cbWndExtra=0;
 wndclass.hInstance=hIns;
 wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW) ;
 wndclass.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
 wndclass.lpszMenuName=MAKEINTRESOURCE(IDR_MAIN_MENU);
 wndclass.lpszClassName=szAppName;
 wndclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
 RegisterClassEx(&wndclass);
 hwnd=CreateWindow(szAppName,"Form11",WS_OVERLAPPEDWINDOW,200,120,400,175,NULL,0,hIns,NULL);
 ShowWindow(hwnd,iCmdShow);
 UpdateWindow(hwnd);
 while(GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }

 return msg.wParam;
}

I personally deplore the Windows Dialog Engine, and only use windows it creates in the most basic and rudimentary manner. I'd highly recommend going with CreateWindowEx() windows in your Win32 programming.

The above code was one of my early 'template' apps. When you do Win32 Sdk programming as I do, over time you amass quite a few template 'starter' apps to get you going when you want to create a new project. Since my coding style has changed some over the years, a lot of my older template apps don't really reflect the way I do things now - especially in regard to the whole UNICODE thing - which I've finally come to terms with and have 'accepted'. Anyway, I just redid this app in my present style. Basically, it shows the things you are trying to learn. Below I'll post it. I changed the names of the files some. This template is now Form2A. I name all my templates like this...

Form1, Form2, Form3, .... Form30, etc.

This evolved from my extensive VB background in my former pre .NET life. Since I've got so many of these when I redo them in my presemt style I append an 'A' to them.

//Form2A.h
#define IDC_STATIC        -1
#define IDR_MAIN_MENU   1240
#define IDM_OPEN        1250
#define IDM_SAVE        1252
#define IDM_EXIT        1254
#define IDM_HELP        1260
#define IDM_ABOUT       1262
#define IDC_NAME        1300
#define IDD_ABOUT       1400
#define IDC_EDITBOX1    1500
#define IDC_BUTTON      1510


typedef struct    WindowsEventArguments               
{
 HWND             hWnd;                               
 WPARAM           wParam;                             
 LPARAM           lParam;                             
 HINSTANCE        hIns;                               
}WndEventArgs, *lpWndEventArgs;


struct EVENTHANDLER
{
 unsigned int    Code;
 long            (*fnPtr)(lpWndEventArgs);
};
//Form2A.rc
#include <windows.h>
#include <tchar.h>
#include "Form2A.h"

IDR_MAIN_MENU MENU
{
 POPUP _T("&File")
 {
  MENUITEM _T("&Open..."),          IDM_OPEN
  MENUITEM _T("&Save..."),          IDM_SAVE
  MENUITEM SEPARATOR
  MENUITEM _T("E&xit"),             IDM_EXIT
 }
 POPUP _T("&Help")
 {
  MENUITEM _T("&Help..."),          IDM_HELP
  MENUITEM _T("&About Form8..."),   IDM_ABOUT
 }
}

IDD_ABOUT DIALOG DISCARDABLE 30,60,180,36
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION _T("Identify Your Sorry Self!")
FONT 8, _T("MS Sans Serif")
BEGIN
  DEFPUSHBUTTON  _T("OK"),IDOK,120,20,40,14
  PUSHBUTTON     _T("Cancel"),IDCANCEL,75,20,40,14
  LTEXT          _T("Enter Your Name"),IDC_STATIC,7,4,60,8
  EDITTEXT       IDC_NAME,65,4,100,12,ES_AUTOHSCROLL
END
//Main.cpp
#include <windows.h>
#include <tchar.h>
#include <commdlg.h>
#include <string.h>
#include "Form2A.h"
EVENTHANDLER  EventHandler[3];

BOOL CALLBACK ModalDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
 TCHAR szName[64],szText[64];
 HWND hwndEdit;
 UINT nID;

 switch(message)
 {
  case WM_INITDIALOG:
    hwndEdit=GetDlgItem(hwndDlg,IDC_NAME);
    SetFocus(hwndEdit);
    return FALSE;
  case WM_COMMAND:
    nID = LOWORD(wParam);
    switch(nID)
    {
     case IDOK:
       hwndEdit=GetDlgItem(hwndDlg, IDC_NAME);
       GetWindowText(hwndEdit,szText,64);
       _tcscpy(szName,_T("Hello, "));
       _tcscat(szName,szText);
       _tcscat(szName,_T("!"));
       MessageBox(hwndDlg,szName,_T("Form2A"),MB_OK);
     case IDCANCEL:
       EndDialog(hwndDlg, nID);
       break;
     default:
       break;
    }
    return TRUE;
  default:
    return FALSE;
 }
}


long fnWndProc_OnCreate(lpWndEventArgs Wea)
{
 HWND hTextBox,hButton;
 DWORD dwStyle;

 Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance;
 dwStyle=WS_CHILD|WS_VISIBLE|WS_BORDER;
 hTextBox=CreateWindow(_T("edit"),_T(""),dwStyle,10,30,370,20,Wea->hWnd,(HMENU)IDC_EDITBOX1,Wea->hIns,0);
 hButton=CreateWindow(_T("button"),_T("Exit"),WS_CHILD|WS_VISIBLE,168,75,60,25,Wea->hWnd,(HMENU)IDC_BUTTON,Wea->hIns,0);

 return 0;
}


void WndProc_OnCommand_OnOpen(lpWndEventArgs Wea)
{
 static TCHAR szFilter[]=_T("C Files (*.C),CPP Files (*.cpp)\0*.c;*.cpp\0\0");
 static TCHAR szTitleName[_MAX_FNAME+_MAX_EXT];
 static TCHAR szFileName[_MAX_PATH];
 TCHAR lpszBuffer[128];
 OPENFILENAME ofn;
 
 GetCurrentDirectory(128,lpszBuffer);
 memset(&ofn,_T('\0'),sizeof(OPENFILENAME));
 ofn.lStructSize=sizeof(OPENFILENAME);
 ofn.lpstrFilter = szFilter;
 ofn.nMaxFile=_MAX_PATH;
 ofn.nMaxFileTitle=_MAX_FNAME+_MAX_EXT;
 ofn.lpstrInitialDir = lpszBuffer;
 ofn.lpstrDefExt = _T("cpp");
 ofn.hInstance=Wea->hIns;
 ofn.hwndOwner = Wea->hWnd;
 ofn.Flags=OFN_HIDEREADONLY | OFN_CREATEPROMPT;
 ofn.lpstrFile=szFileName;
 ofn.lpstrFileTitle=szTitleName;
 GetOpenFileName(&ofn);
 SetWindowText(GetDlgItem(Wea->hWnd,IDC_EDITBOX1),ofn.lpstrFile);

 return;
}


void WndProc_OnCommand_OnSave(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,_T("You Chose File >> Save"),_T("Form2A"),MB_OK);
}


void WndProc_OnCommand_OnExit(lpWndEventArgs Wea)
{
 SendMessage(Wea->hWnd,WM_DESTROY,0,0L);
}


void WndProc_OnCommand_OnHelp(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,_T("There Is No Help."),_T("Form2A"),MB_OK);
}


void WndProc_OnCommand_OnHelpAbout(lpWndEventArgs Wea)
{
 DialogBox(Wea->hIns,MAKEINTRESOURCE(IDD_ABOUT),Wea->hWnd,ModalDlgProc);
}


void WndProc_OnCommand_OnButton_Click(lpWndEventArgs Wea)
{
 MessageBox(Wea->hWnd,_T("You Clicked The Button And Want To Exit!"),_T("Form2A"),MB_OK);
 SendMessage(Wea->hWnd,WM_CLOSE,0,0L);
}


long fnWndProc_OnCommand(lpWndEventArgs Wea)
{
 switch (LOWORD(Wea->wParam))
 {
  case IDM_OPEN:
    WndProc_OnCommand_OnOpen(Wea);
    break;
  case IDM_SAVE:
    WndProc_OnCommand_OnSave(Wea);
    break;
  case IDM_EXIT:
    WndProc_OnCommand_OnExit(Wea);
    break;
  case IDM_HELP:
    WndProc_OnCommand_OnHelp(Wea);
    break;
  case IDM_ABOUT:
    WndProc_OnCommand_OnHelpAbout(Wea);
    break;
  case IDC_BUTTON:
    WndProc_OnCommand_OnButton_Click(Wea);
    break;
 }

 return 0;
}


long fnWndProc_OnClose(lpWndEventArgs Wea)
{
 DestroyWindow(Wea->hWnd);
 PostQuitMessage(0);

 return 0;
}


void AttachEventHandlers(void)  
{
 EventHandler[0].Code=WM_CREATE,    EventHandler[0].fnPtr=fnWndProc_OnCreate;         
 EventHandler[1].Code=WM_COMMAND,   EventHandler[1].fnPtr=fnWndProc_OnCommand;         
 EventHandler[2].Code=WM_CLOSE,     EventHandler[2].fnPtr=fnWndProc_OnClose; 
}


long __stdcall fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
 WndEventArgs Wea;
   
 for(unsigned int i=0; i<3 ;i++)
 {
     if(EventHandler[i].Code==msg)
     {
        Wea.hWnd=hwnd,Wea.lParam=lParam,Wea.wParam=wParam;
        return (*EventHandler[i].fnPtr)(&Wea);
     }
 } 

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


int __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrIns, PSTR szCmdLn, int iCmdShow)
{
 TCHAR szAppName[]="Form2A";
 WNDCLASSEX wc;
 HWND hwnd;
 MSG msg;

 AttachEventHandlers();
 wc.lpfnWndProc=fnWndProc,                        wc.lpszClassName=szAppName;
 wc.cbSize=sizeof(wc),                            wc.style=CS_HREDRAW|CS_VREDRAW;
 wc.cbClsExtra=0,                                 wc.cbWndExtra=0;
 wc.hInstance=hIns,                               wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
 wc.hCursor=LoadCursor(NULL,IDC_ARROW),           wc.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
 wc.lpszMenuName=MAKEINTRESOURCE(IDR_MAIN_MENU),  wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
 RegisterClassEx(&wc);
 hwnd=CreateWindow(szAppName,"Form2A",WS_OVERLAPPEDWINDOW,200,120,400,175,NULL,0,hIns,NULL);
 ShowWindow(hwnd,iCmdShow);
 while(GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }

 return msg.wParam;
}

Cool! Thanks for the tip about CreateWindowEx(). I tried compiling the code and for some reason, toggling plain text on so I could copy it turned line 140 into "case IDM_ABOUT<b></b>:" but after correcting that, it worked fine. What I still don't understand though is why yours compiles and mine gives syntax errors when our dialog section of the resource file (the IDD_ABOUT DIALOG part) is nearly identical!

The only thing I could see different is that you also included windows.h into your resource file. I gave that a try and my syntax error then moved down to line 10 (the GROUPBOX line). I'll try to see if something was wrong with that line because removing it allowed the program to finally compile.

Wooh, I have to say after looking at the second code you posted, I have no idea where to start looking to understand it. When all you've done is some petty low-level C++ stuff just dealing with primitives and classes etc, trying to understand all of the intricacies of the windows API is fairly daunting.

I'm not trying to go too far with this, I just wanted to see if I could manage to make something extremely basic but usable as an interface with these simple programs I write.

Wooh, I have to say after looking at the second code you posted, I have no idea where to start looking to understand it. When all you've done is some petty low-level C++ stuff just dealing with primitives and classes etc, trying to understand all of the intricacies of the windows API is fairly daunting.

I'm not trying to go too far with this, I just wanted to see if I could manage to make something extremely basic but usable as an interface with these simple programs I write.

Hi Ripture!

Glad to hear you are on the right track. I wasn't sure what was wrong with your code but I suspected the problem might be elsewhere in other code, that's why I posted a full example I was pretty sure would compile cleanly for you. Most problems with menus & dialogs in resource files stem from coding errors in the main program that tries to load the resource; particularly the naming of files and the .lpszMenuName field in the WNDCLASSEX struct.

What's confusing you in the second app I posted is my method (which I learned from Douglas Boling who writes Windows CE books - and he ascribes the technique to Ray Duncan where he learned it) of attaching the functions that handle Windows messages to the messages themselves that are coming through the program's Window Procedure. The setup involves C function pointers. Its the slickest way I've ever found to modularize my code.

Windows Api programming is rather involved. Charles Petzold is the emminant author in this field, and he says that for someone expert in the C programming language, it takes 6 months to become proficient at Sdk style Windows coding.

Wow, that's nuts. Well I don't feel too bad now! XD

I just need to keep looking up definitions in the MSDN and a few more tutorials to get this the way I need. I got the dialog stuff working alright, I can place buttons and text.

Now I need to figure out how to place buttons into my main program window. I also would really like to use something like edit boxes for text in the window that only the program can write to. I could use that to relay program status information or whatever I need. I feel like that is going to be a pain to figure out how to do.

Thanks by the way for taking the time to respond to me here. Daniweb's always been a great place to go for help.

Hi Again Ripture!

The answer to your question about putting buttons and textboxes on the program's main window can be seen in my procedure fnWndProc_OnCreate() in the above code. I'll reproduce it here...

long fnWndProc_OnCreate(lpWndEventArgs Wea){ HWND hTextBox,hButton; DWORD dwStyle;  Wea->hIns=((LPCREATESTRUCT)Wea->lParam)->hInstance; dwStyle=WS_CHILD|WS_VISIBLE|WS_BORDER; hTextBox=CreateWindow(_T("edit"),_T(""),dwStyle,10,30,370,20,Wea->hWnd,(HMENU)IDC_EDITBOX1,Wea->hIns,0); hButton=CreateWindow(_T("button"),_T("Exit"),WS_CHILD|WS_VISIBLE,168,75,60,25,Wea->hWnd,(HMENU)IDC_BUTTON,Wea->hIns,0);  return 0;}

One of the 1st messages a window receives is the WM_CREATE message. This message occurs at the point of the CreateWindow() call in WinMain(). In fact, that CreateWindow() call in WinMain() does not return until the WM_CREATE message returns in the Window Procedure. It is in the WM_CREATE processing code (fnWndProc_OnCreate() above) where I usually put additional CreateWindow() calls that create the child window controls, ie, edit boxes, buttons, listboxes, grids, etc., that decorate the main window of the app. These child window controls have their own classname such as "button", "edit", etc. You can see the CreateWindow() calls above that created the edit box and button on my program's main form/dialog/window.

added later - for some reason unfanthomable to me code tags don't seem to be working. i've tried to fix the above cat's breakfast five times to no avail. sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.