Opening a file and writing to Text box c++ - c++

Okay, so I need this button that, when clicked, opens a user-specified file. After the file is opened, it needs to be read/copied into the text box below that button. Eventually other things need to happen but I'm having trouble just doing that. The following is the code I have so far for creating the GUI, then I'm completely lost on how to proceed.
#include <iostream>
#include <fstream>
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Software Engineering II", /* Title Text */
WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
900, /* The programs width */
500, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
#define ID_LABEL
static HWND hwndLbl1;
static HWND hwndLbl2;
static HWND hwndLbl3;
static HWND hwndLbl4;
bool buttonPressed = false;
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
hwndLbl1 = CreateWindow(TEXT("STATIC"),TEXT("Building File Selection"),
WS_VISIBLE | WS_CHILD,
10,10,150,25,
hwnd, (HMENU) 0, NULL, NULL
);
hwndLbl2 = CreateWindow(TEXT("STATIC"),TEXT("Class File Selection"),
WS_VISIBLE | WS_CHILD,
500,10,150,25,
hwnd, (HMENU) 0, NULL, NULL
);
hwndLbl3 = CreateWindow(TEXT("STATIC"),TEXT("Building No."),
WS_VISIBLE | WS_CHILD,
10, 75, 150, 25,
hwnd, (HMENU) 0, NULL, NULL
);
hwndLbl4 = CreateWindow(TEXT("STATIC"),TEXT("Room No."),
WS_VISIBLE | WS_CHILD,
500,75,150,25,
hwnd, (HMENU) 0, NULL, NULL
);
// Building Room open
CreateWindow(TEXT("button"),TEXT("Open"),
WS_VISIBLE | WS_CHILD,
10,40,80,25,
hwnd, (HMENU) 1, NULL, NULL
);
// Classroom open
CreateWindow(TEXT("button"),TEXT("Open"),
WS_VISIBLE | WS_CHILD,
500, 40, 80, 25,
hwnd, (HMENU) 2, NULL, NULL
);
CreateWindow(TEXT("button"),TEXT("Search"),
WS_VISIBLE | WS_CHILD,
800,100,80,25,
hwnd, (HMENU) 3, NULL, NULL
);
// The information should be read from here.
CreateWindow(TEXT("edit"), TEXT("Text goes here"),
WS_VISIBLE | WS_CHILD | WS_BORDER,
10, 100, 300, 20,
hwnd, (HMENU) 5, NULL, NULL
);
CreateWindow(TEXT("edit"),TEXT("Text goes here"),
WS_VISIBLE | WS_CHILD | WS_BORDER,
500,100,300,20,
hwnd, (HMENU) 5, NULL, NULL
);
CreateWindow(TEXT("edit"),TEXT("Output from Building"),
WS_CHILD | WS_VISIBLE | ES_READONLY | WS_BORDER,
10, 150, 400, 250,
hwnd, (HMENU) 6, NULL, NULL
);
CreateWindow(TEXT("edit"),TEXT("Output from Room file"),
WS_CHILD | WS_VISIBLE | ES_READONLY | WS_BORDER,
500, 150, 380, 250,
hwnd, (HMENU) 7, NULL, NULL
);
CreateWindow(TEXT("button"),TEXT("Continue"),
WS_VISIBLE | WS_CHILD,
500,410,80,25,
hwnd, (HMENU) 8, NULL, NULL
);
CreateWindow(TEXT("button"),TEXT("Show .PRN"),
WS_VISIBLE | WS_CHILD,
600,410,80,25,
hwnd, (HMENU) 9, NULL, NULL
);
CreateWindow(TEXT("button"),TEXT("Show .LOG"),
WS_VISIBLE | WS_CHILD,
700,410,80,25,
hwnd, (HMENU) 10, NULL, NULL
);
CreateWindow(TEXT("button"),TEXT("Show .CSV"),
WS_VISIBLE | WS_CHILD,
800,410,80,25,
hwnd, (HMENU) 11, NULL, NULL
);
break;
// This is where you issue commands for buttons
// To read from files and output them into those 2 text boxes that are ID'd (HMENU) 6 and (HMENU 7.
case WM_COMMAND:
if(LOWORD(wParam) == 1){
FILE * BuildingFile;
buttonPressed = true;
/* ifstream infile;
infile.open ("Bldgs-Rms-Txt-File-2012-08082012.txt");
if(infile.is_open()){
while(infile.good())
print to buildingtextbox (char) infile.get();
//BuildingFile = fopen("Bldgs-Rms-Txt-File-2012-08082012.txt","r"); // In the argument of MessageBox, this is the PARENT WINDOW, which should be the same for all
*/
}
if (LOWORD (wParam) == 2){
FILE * RoomFile;
RoomFile = fopen("cbm_005_003639_201310_08082012.DAT","r");
}
if (LOWORD (wParam) == 6){
std::cout << "chuck";
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}

1) You need to preserve the window handles (hWnd)s from the CreateWindow calls.
// Up top
#include <string>
// Class member:
HWND building1text;
// Saving the hWnd on the CreateWindow call
building1text = CreateWindow(TEXT("edit"),TEXT("Output from Building"),
WS_CHILD | WS_VISIBLE | ES_READONLY | WS_BORDER,
10, 150, 400, 250,
hwnd, (HMENU) 6, NULL, NULL
);
2) Then you can use SetWindowText(hWnd, LPCTSTR) to put the text into the text box.
string lineString, totalString;
// open file here
while(infile.good()) {
// concatenate next line from file (works if file contains
// null-terminated lines of stuff
getline(infile, lineString, '\n');
totalString += lineString;
}
SetWindowText(building1text, totalString);
I don't have a compiler set up, but hopefully that works for you. Of course, I don't know how your data file is formatted, either.

Related

How to do an action when button is pressed

I am creating a log in screen for my app, I created the buttons but I dont know how to make my program do something when one of these buttons are pressed.Here is my code(I dont think it will be usefull)
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_CREATE:
CreateWindow(TEXT("button"), TEXT("CONFIRM"), WS_VISIBLE | WS_CHILD, 355, 400, 95, 35, hwnd, NULL, NULL , NULL);
CreateWindow(TEXT("button"), TEXT("SIGN UP"), WS_VISIBLE | WS_CHILD, 50, 400, 95, 35, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("static"), TEXT("USERNAME:"), WS_VISIBLE | WS_CHILD, 50, 40, 80, 15, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("static"), TEXT("EMAIL:"), WS_VISIBLE | WS_CHILD, 85, 100, 45, 15, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("static"), TEXT("PASSWORD:"), WS_VISIBLE | WS_CHILD, 50, 160, 83, 15, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD, 135, 40, 200, 17, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD, 135, 100, 200, 17, hwnd, NULL, NULL, NULL);
CreateWindow(TEXT("edit"), TEXT(""), WS_VISIBLE | WS_CHILD, 135, 160, 200, 17, hwnd, NULL, NULL, NULL);
break;
/* Upon destruction, tell the main thread to stop */
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
/* All other messages (a lot of them) are processed using default procedures */
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc; /* A properties struct of our window */
HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
MSG msg; /* A temporary location for all messages */
/* zero out the struct and set the stuff we want to modify */
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL,"XBM LOGO.png"); /* Load a standard icon */
wc.hIconSm = LoadIcon(NULL, "A"); /* use the name "A" to use the project icon */
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Verification",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
400, /* x */
75, /* y */
500, /* width */
600, /* height */
NULL,NULL,hInstance,NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
/*
This is the heart of our program where all input is processed and
sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
this loop will not produce unreasonably high CPU usage
*/
while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
TranslateMessage(&msg); /* Translate key codes to chars if present */
DispatchMessage(&msg); /* Send it to WndProc */
}
return msg.wParam;
}
NOTE: windows.h and iostream are included but there are not any other libraries
Thank you :)
The first thing you need to change is to assign an ID to your button CreateWindow calls, this is done through the HMENU parameter. The next thing you need to do is handle WM_COMMAND for those IDs and the BN_CLICKED command identifier.
For example, to assign the ID 1 to your Confirm button:
CreateWindow(TEXT("button"), TEXT("CONFIRM"), WS_VISIBLE | WS_CHILD, 355, 400, 95, 35, hwnd, (HMENU)1, NULL, NULL);
Then to handle when that is clicked:
case WM_COMMAND:
{
UINT uID = LOWORD(wParam), uCmd = HIWORD(wParam);
switch(uID)
{
case 1:
if(BN_CLICKED == uCmd)
{
/* Action here */
break;
}
else
return DefWindowProc(hWnd, uMsg, wParam, lParam);
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}

C++ GUI button stuck to the bottom

I'm making a C++ GUI form in windows.h for my mother and I can't figure out how to make the "adaugare" , "iesire", "refresh" etc. buttons to stick to the bottom side of windows form. I want to make them to auto-move when I resize the form, so they can always be at bottom-right side.
Please help me guys because I am a beginner in C++ Gui !
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
ofstream fout;
ifstream fin;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
HWND hwnd; /* This is the handle for our window */
HWND button[5];
HWND banda[100];
HWND tip[100];
HWND lungime[100];
HWND latime[100];
HWND data1[100];
HWND button_valideaza[100];
int button_index[100];
int i = 0, counter = 1;
char buffer[10];
char textEP[20];
char textTip[20];
char textLungime[20];
char textLatime[20];
char textData[20];
char textAll[101];
/* Make the class name into a global variable */
TCHAR szClassName[] = _T("CodeBlocksWindowsApp");
int getIndex(){
fin.open("record.txt", std::ios_base::in);
string line1;
string line;
while(getline(fin, line1)) {
line = line1;
}
char save[line.size()];
strcpy(save, line.c_str());
char *p = strtok(save, " ");
fin.close();
return atoi(p);
}
void refresh() {
}
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx(&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx(
0, /* Extended possibilites for variation */
szClassName, /* Classname */
_T("Flux Artego"), /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
700, /* The programs width */
300, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow(hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage(&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
void scrie() {
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WORD cmd = LOWORD(wParam);
switch (message) /* handle the messages */
{
case WM_CREATE: // fac butoane, label etc
counter = getIndex();
counter++;
fout.open("record.txt", std::ios_base::app);
std::fill_n(button_index, 100, -1);
button[0] = CreateWindow("BUTTON",
"Iesire",
WS_VISIBLE | WS_CHILD | WS_BORDER,
560, 220, 100, 20,
hwnd, (HMENU)1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa
button[1] = CreateWindow("BUTTON",
"Adauga",
WS_VISIBLE | WS_CHILD | WS_BORDER,
450, 220, 100, 20,
hwnd, (HMENU)2, NULL, NULL);
button[2] = CreateWindow("BUTTON",
"Refresh",
WS_VISIBLE | WS_CHILD | WS_BORDER,
340, 220, 100, 20,
hwnd, (HMENU)3, NULL, NULL);
break;
case WM_COMMAND: // fac instructiuni butoane
switch (cmd)
{
case 1:
//::MessageBeep(MB_ICONERROR);
//::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL);
cout << "GoodBye!";
PostQuitMessage(0);
break;
case 2: // Adaug nou record
banda[i] = CreateWindow("EDIT",
"EP",
WS_BORDER | WS_CHILD | WS_VISIBLE,
20, 30 * i, 30, 25,
hwnd, NULL, NULL, NULL);
tip[i] = CreateWindow("EDIT",
"100",
WS_BORDER | WS_CHILD | WS_VISIBLE,
55, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
lungime[i] = CreateWindow("EDIT",
"Lungime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
160, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
latime[i] = CreateWindow("EDIT",
"Latime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
265, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
data1[i] = CreateWindow("EDIT",
"Data",
WS_BORDER | WS_CHILD | WS_VISIBLE,
370, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
button_valideaza[i] = CreateWindow("BUTTON",
"Scrie",
WS_VISIBLE | WS_CHILD | WS_BORDER,
475, 30 * i, 80, 20,
hwnd, (HMENU)(i+5), NULL, NULL);
i++;
break;
case 3: // Refresh
refresh();
break;
case 4: // Compute
break;
default:
if (cmd > 4 && cmd < 103)
{
int index;
if (button_index[cmd-3] == -1){ // daca buton index nu a fost setata
button_index[cmd-3] = counter;
index = counter;
//cout << "Prima apasare a butinului " << cmd-3 << " si primeste index "<<counter<<endl;
counter++;
} else { // a fost setat
index = button_index[cmd-3];
//cout << "Deja apasat butonul "<< cmd-3 << " si are vechiul index " << button_index[cmd-3] << endl;
::MessageBox(hwnd, "Pentru a rescrie apasa pe REFRESH","Suprascriere", MB_OK);
}
int gwtstat = 0;
gwtstat = GetWindowText(banda[cmd-5], &textEP[0], 20);
gwtstat = 0;
gwtstat = GetWindowText(tip[cmd-5], &textTip[0], 20);
gwtstat = 0;
gwtstat = GetWindowText(lungime[cmd-5], &textLungime[0], 20);
gwtstat = 0;
gwtstat = GetWindowText(latime[cmd-5], &textLatime[0], 20);
gwtstat = 0;
gwtstat = GetWindowText(data1[cmd-5], &textData[0], 20);
itoa(index, buffer, 10);
strcpy(textAll, buffer);
strcat(textAll," ");
strcat(textAll,textEP);
strcat(textAll, " ");
strcat(textAll,textTip);
strcat(textAll, " ");
strcat(textAll, textLungime);
strcat(textAll, " ");
strcat(textAll, textLatime);
strcat(textAll, " ");
strcat(textAll, textData);
fout << textAll << "\n";
::MessageBox(hwnd, textAll,"text", MB_OKCANCEL);
}
break;
}
break;
case WM_DESTROY:
fout.close();
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
Unfortunately, there is no mechanism for doing this automatically. You have to write code that listens for sizing events, calculates the appropriate size and position of each control, and moves it accordingly. It is relatively straightforward, once you understand the process, but a fair amount of drudgery, especially when you have a large number of controls to adjust.
Start by adding a handler for the WM_SIZE message to your main window's window procedure. This message gets sent when the window is being resized.
Inside of that handler, you will call either the MoveWindow or SetWindowPos function to change the position of your child windows (i.e., your controls; i.e., your buttons).
Here is some sample code:
case WM_SIZE:
{
const int cxPadding = 12;
const int cyPadding = 12;
// Get client rectangle for parent window.
RECT rcParent;
GetClientRect(hwnd, &rcParent);
RECT rcButton[5];
// Adjust the position of the first button.
// It will be the furthest one to the right.
GetClientRect(button[0], &rcButton[0]);
SetWindowPos(button[0],
NULL,
(rcParent.right - cxPadding - (rcButton[0].right - rcButton[0].left)),
(rcParent.bottom - cyPadding - (rcButton[0].bottom - rcButton[0].top)),
0,
0,
SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
// Adjust the position of the second button.
// It will be the next to the first one.
GetClientRect(button[1], &rcButton[1]);
SetWindowPos(button[1],
NULL,
(rcParent.right - cxPadding - (rcButton[0].right - rcButton[0].left)
- cxPadding - (rcButton[1].right - rcButton[1].left)),
(rcParent.bottom - cyPadding - (rcButton[1].bottom - rcButton[1].top)),
0,
0,
SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
// etc.
}
To reduce flicker when you are repositioning a large number of child controls, you can use the DeferWindowPos function. This requires that you call BeginDeferWindowPos at the beginning, then call DeferWindowPos (just like SetWindowPos) for each control, and then finally call EndDeferWindowPos when you are finished adjusting all controls. See What's the point of DeferWindowPos? on Raymond Chen's blog.
Also, if you are trying to learn Windows API programming, do yourself a huge favor and pick up a copy of Charles Petzold's classic book, Programming Windows (5th edition). Yes, you need the 5th edition. The newer editions cover a different programming language/framework. You can find used copies on Amazon.

Window.h c++ how to get index of a button from an array inside switch

I have one question for you. I just started to learn C++ GUI (windows.h) and I got a problem. I have to do for my mother a program that record some information so I designed a GuI that add a new set of empty field every time I click on "Adaugare" button . Near every set of fields, on right, there is a button named "Scrie" that should get the information from textBoxes and store it into a string. The problem is when I press the button to get the info, I don t know how to make my switch to figure out what field I want to get . Example : I writed 5 records, but I want to modify the first one, so how do I get the index of it even thought I have another 5 set of fields after ?
PLEASE HELP ME GUYS !
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
#include <iostream>
using namespace std;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HWND hwnd; /* This is the handle for our window */
HWND button[5];
HWND banda[100];
HWND tip[100];
HWND lungime[100];
HWND latime[100];
HWND data[100];
HWND button_valideaza[100];
int i = 1;
char textSaved[20];
/* Make the class name into a global variable */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
_T("Flux Artego"), /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
700, /* The programs width */
300, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
void scrie() {
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE: // fac butoane, label etc
button[0] = CreateWindow("BUTTON",
"Iesire",
WS_VISIBLE | WS_CHILD | WS_BORDER,
560, 220, 100, 20,
hwnd, (HMENU) 1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa
button[1] = CreateWindow("BUTTON",
"Adauga",
WS_VISIBLE | WS_CHILD | WS_BORDER,
450, 220, 100, 20,
hwnd, (HMENU) 2, NULL, NULL);
break;
case WM_COMMAND: // fac instructiuni butoane
switch(LOWORD(wParam) )
{
case 1:
//::MessageBeep(MB_ICONERROR);
//::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL);
cout << "GoodBye!";
PostQuitMessage (0);
break;
case 2: // Adaug nou record
banda[i] = CreateWindow("EDIT",
"EP",
WS_BORDER | WS_CHILD | WS_VISIBLE,
20, 30 * i, 30, 25,
hwnd, NULL, NULL, NULL);
tip[i] = CreateWindow("EDIT",
"100",
WS_BORDER | WS_CHILD | WS_VISIBLE,
55, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
lungime[i] = CreateWindow("EDIT",
"Lungime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
160, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
latime[i] = CreateWindow("EDIT",
"Latime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
265, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
data[i] = CreateWindow("EDIT",
"Data",
WS_BORDER | WS_CHILD | WS_VISIBLE,
370, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
button_valideaza[i] = CreateWindow("BUTTON",
"Scrie",
WS_VISIBLE | WS_CHILD | WS_BORDER,
475, 30 * i, 80, 20,
hwnd, NULL, NULL, NULL);
i++;
break;
case 3: // scriu record
int gwtstat = 0;
gwtstat = GetWindowText(banda[i], &textSaved[0], 20);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Use the different command for each "Scrie" Button , set its Menu like that:
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
#include <iostream>
using namespace std;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
HWND hwnd; /* This is the handle for our window */
HWND button[5];
HWND banda[100];
HWND tip[100];
HWND lungime[100];
HWND latime[100];
HWND data1[100];
HWND button_valideaza[100];
int i = 0;
char textSaved[20];
/* Make the class name into a global variable */
TCHAR szClassName[] = _T("CodeBlocksWindowsApp");
int WINAPI WinMain(HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx(&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx(
0, /* Extended possibilites for variation */
szClassName, /* Classname */
_T("Flux Artego"), /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
700, /* The programs width */
300, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow(hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage(&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
void scrie() {
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WORD cmd = LOWORD(wParam);
switch (message) /* handle the messages */
{
case WM_CREATE: // fac butoane, label etc
button[0] = CreateWindow("BUTTON",
"Iesire",
WS_VISIBLE | WS_CHILD | WS_BORDER,
560, 220, 100, 20,
hwnd, (HMENU)1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa
button[1] = CreateWindow("BUTTON",
"Adauga",
WS_VISIBLE | WS_CHILD | WS_BORDER,
450, 220, 100, 20,
hwnd, (HMENU)2, NULL, NULL);
break;
case WM_COMMAND: // fac instructiuni butoane
switch (cmd)
{
case 1:
//::MessageBeep(MB_ICONERROR);
//::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL);
cout << "GoodBye!";
PostQuitMessage(0);
break;
case 2: // Adaug nou record
banda[i] = CreateWindow("EDIT",
"EP",
WS_BORDER | WS_CHILD | WS_VISIBLE,
20, 30 * i, 30, 25,
hwnd, NULL, NULL, NULL);
tip[i] = CreateWindow("EDIT",
"100",
WS_BORDER | WS_CHILD | WS_VISIBLE,
55, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
lungime[i] = CreateWindow("EDIT",
"Lungime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
160, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
latime[i] = CreateWindow("EDIT",
"Latime",
WS_BORDER | WS_CHILD | WS_VISIBLE,
265, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
data1[i] = CreateWindow("EDIT",
"Data",
WS_BORDER | WS_CHILD | WS_VISIBLE,
370, 30 * i, 100, 25,
hwnd, NULL, NULL, NULL);
button_valideaza[i] = CreateWindow("BUTTON",
"Scrie",
WS_VISIBLE | WS_CHILD | WS_BORDER,
475, 30 * i, 80, 20,
hwnd, (HMENU)(i+3), NULL, NULL);
i++;
break;
default:
if (cmd > 2 && cmd < 103)
{
int gwtstat = 0;
gwtstat = GetWindowText(banda[cmd-3], &textSaved[0], 20);
::MessageBox(hwnd, textSaved,"text", MB_OKCANCEL);
}
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

Adding a progress bar and/or internal window to program. (How To?) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to take this code and add a progress bar to show the progress (BUUUUH), and also add a window inside the main one showing the names of the files being currently moved. I am totally lost right now on how to do this. I would love help if anyone can offer some.
enter code here
#include <windows.h>
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "Back Up";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Back It Up", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
545, /* The programs width */
300, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
{
CreateWindow(TEXT("button"), TEXT("Pictures"),
WS_VISIBLE | WS_CHILD ,
20, 50, 80, 25,
hwnd, (HMENU) 1, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Music"),
WS_VISIBLE | WS_CHILD ,
120, 50, 80, 25,
hwnd, (HMENU) 2, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Videos"),
WS_VISIBLE | WS_CHILD ,
20, 100, 80, 25,
hwnd, (HMENU) 3, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Fun Times"),
WS_VISIBLE | WS_CHILD ,
120, 100, 80, 25,
hwnd, (HMENU) 4, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Programs"),
WS_VISIBLE | WS_CHILD ,
20, 150, 80, 25,
hwnd, (HMENU) 5, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("(WiP)"),
WS_VISIBLE | WS_CHILD ,
120, 150, 80, 25,
hwnd, (HMENU) 6, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Quit"),
WS_VISIBLE | WS_CHILD ,
20, 200, 180, 25,
hwnd, (HMENU) 7, NULL, NULL);
CreateWindow(TEXT("Static"), TEXT("Choose what you would like to back up from the options on the left."
" Remember this program is still in developmentso bugs and UI issues are to be expected."
" Future addons include Progress bar, activity terminal, and customizable locations."
" Also please do not disturb the program while it is running, it will not respond."),
WS_VISIBLE | WS_CHILD,
220, 50, 280, 150,
hwnd, (HMENU) NULL, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Back Up All"),
WS_VISIBLE | WS_CHILD,
20, 14, 180, 25,
hwnd, (HMENU) 8, NULL, NULL);
break;
}
case WM_COMMAND:
{
if (LOWORD(wParam) == 1) {
system("robocopy C:/users/jacob/pictures E:/pictures /e /r:3 /w:0");
}
if (LOWORD(wParam) == 2) {
system("robocopy C:/users/jacob/music E:/music /e /r:3 /w:0");
}
if (LOWORD(wParam) == 3) {
system("robocopy C:/users/jacob/videos E:/videos /e /r:3 /w:0");
}
if (LOWORD(wParam) == 4) {
system("robocopy C:/Users/Jacob/Desktop/fun times e:/fun times /e /r:3 /w:0");
}
if (LOWORD(wParam) == 5) {
system("robocopy C:/Users/Jacob/Desktop/programs e:/programs /e /r:3 /w:0");
} /*
if (LOWORD(wParam) == 6) {
system("robocopy C:/Users/jacob/documents e:/documents /e /r:3 /w:0");
} */
if (LOWORD(wParam) == 7) {
PostQuitMessage(0);
}
if (LOWORD(wParam) == 8 ) {
system("robocopy C:/users/jacob/pictures E:/pictures /e /r:3 /w:0");
system("robocopy C:/users/jacob/music E:/music /e /r:3 /w:0");
system("robocopy C:/users/jacob/videos E:/videos /e /r:3 /w:0");
system("robocopy C:/Users/Jacob/Desktop/fun times e:/fun times /e /r:3 /w:0");
system("robocopy C:/Users/Jacob/Desktop/programs e:/programs /e /r:3 /w:0");
}
break;
}
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
enter code here
add a progress bar to show the progress
Read up about the Progress Bar control.
You already know how to create a window and subwindows. Creating a ProcessBar is no different than creating a Button, or any other control, using CreateWindow/Ex().
add a window inside the main one showing the names of the files being currently moved.
That is more difficult. You are executing an external command to move the files, so you don't have direct access to its status information. You would have to replace system() with CreateProcess() so you can redirect its output:
Creating a Child Process with Redirected Input and Output
Once you have access to the output, you can parse it as needed and display it however you want, such as in a multi-line Edit control, a ListBox control, a ListView control, etc.
Alternatively, use FindFirstFile() and FindNextFile() in a recursive loop to iterate the source folder yourself, using CreateDirectory() and CopyFileEx() as needed. Then you will have direct access to each filename and progress information for each file. Then you do not need to use a redirected robocopy process anymore, and have more control over the iterating and copying.

c++ winapi impossible to create 2 controls

I'm trying to create window that contain richedit control and listbox control,
the problem is that the second control which I create, doesn't show up.
I mean:
case WM_CREATE: // In main window procedure
{
/* Center the main window */
This->CenterWindow(hwnd);
/* Initialize the clients list */
This->InitListClients(hwnd);
/* Initialize the server log */
This->InitEditLog(hwnd);
return 0;
}
If InitListClients function will be first, only the listbox will show up,
if InitEditLog will be first, only the richedit will show up.
Here are the functions:
void ApostleServer::InitEditLog(HWND &_hwnd)
{
LoadLibrary(TEXT("Riched32.dll"));
hEditLog = CreateWindowEx(WS_EX_STATICEDGE, "richedit", "bla", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 10, 10, 390, 310, _hwnd, NULL, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
}
void ApostleServer::InitListClients(HWND &_hwnd)
{
hListClients = CreateWindowEx(WS_EX_STATICEDGE, "listbox", "bla", WS_CHILD | WS_VISIBLE | LBS_NOTIFY, 550, 20, 150, 150, _hwnd, NULL, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
}
I'm kinda newbie with winapi and I couldn't find solution for this problem.
Thanks.
EDIT:
As I commented, the cause of the problem is the use of class members.
Here is a whole code that I've wrote and has the same problem:
#include <Windows.h>
#include <stdlib.h>
class Server
{
public:
/* Fields */
MSG* msg;
WNDCLASSW* wc;
HWND hListClients;
HWND hEditLog;
/* Methods */
void InitEditLog(HWND &_hwnd)
{
LoadLibrary(TEXT("Riched32.dll"));
hEditLog = CreateWindowExW(WS_EX_STATICEDGE, L"richedit", L"Text", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 10, 10, 390, 306, _hwnd, (HMENU)2, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
}
void InitListClients(HWND &_hwnd)
{
// Here I'm using hListClients class member, and that what cause the problem (I will see only the list on the window)
hListClients = CreateWindowExW(WS_EX_STATICEDGE, L"listbox", L"asd", WS_CHILD | WS_VISIBLE | LBS_NOTIFY, 410, 10, 160, 306, _hwnd, (HMENU)1, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
// If I was only creating the listbox (without returning handler), I will see the listbox and the richedit.
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
Server* This = (Server*)GetWindowLongW(hwnd, GWL_USERDATA);
switch(msg)
{
case WM_CREATE:
{
/* Initialize the clients list */
This->InitListClients(hwnd); // Attention that I called this function first.
/* Initialize the server log */
This->InitEditLog(hwnd);
// If I would call this function first, I will see only the richedit.
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
Server(HINSTANCE &_hInstance)
{
msg = new MSG;
wc = new WNDCLASSW;
wc->style = CS_HREDRAW | CS_VREDRAW;
wc->cbClsExtra = 0;
wc->cbWndExtra = 0;
wc->lpszClassName = L"ApostleServer";
wc->hInstance = _hInstance;
wc->hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc->lpszMenuName = NULL;
wc->lpfnWndProc = WndProc;
wc->hCursor = LoadCursor(NULL, IDC_ARROW);
wc->hIcon = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassW(&(*wc));
CreateWindowW(wc->lpszClassName, L"Apostle Server", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 600, 400, 0, 0, _hInstance, 0);
while(GetMessage(&(*msg), NULL, 0, 0))
{
TranslateMessage(&(*msg));
DispatchMessage(&(*msg));
}
}
};
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
Server* srvr = new Server(hInstance);
return 0;
}
Problem solved by creating the controls on WM_CREATE message (but not to set control handlers!), and set the control handlers after the creation of the main window.
WM_CREATE message:
case WM_CREATE:
{
/* Center the main window */
This->CenterWindow(hwnd);
/* Initialize the clients list */
This->InitListClients(hwnd);
/* Initialize the server log */
This->InitEditLog(hwnd);
return 0;
}
After main window creation:
RegisterClassW(&(*wc));
hMainWindow = CreateWindowW(wc->lpszClassName, L"Apostle Server", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 600, 400, 0, 0, _hInstance, 0);
/* Set controls handlers */
hListClients = GetDlgItem(hMainWindow, IDC_LISTCLIENTS);
hEditLog = GetDlgItem(hMainWindow, IDC_EDITLOG);
InitEditLog and InitListClients functions:
void ApostleServer::InitEditLog(HWND &_hwnd)
{
LoadLibrary(TEXT("Riched32.dll"));
CreateWindowExW(WS_EX_STATICEDGE, L"richedit", L"Text", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 10, 10, 390, 306, _hwnd, (HMENU)IDC_EDITLOG, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
}
void ApostleServer::InitListClients(HWND &_hwnd)
{
CreateWindowExW(WS_EX_STATICEDGE, L"listbox", L"asd", WS_CHILD | WS_VISIBLE | LBS_NOTIFY, 410, 10, 160, 306, _hwnd, (HMENU)IDC_LISTCLIENTS, (HINSTANCE)GetWindowLong(_hwnd, GWL_HINSTANCE), NULL);
}