[win32] Window to handle text

Pages: 123
Good Day,

I don't know if I writed title right, but I'm looking for an "window" that will handle text I've entered, something like chat, I'll enter message, click ok and then it will appear in that "window", I searched in classes but I haven't found anything, any solutions?
I have no answer to your question, but I would like to try and help you clear up what you are trying to say so the people who do have a solution will find it easier to help you. You want a window with an area for the input and output?

-------------------------------
| Text from input field       |
| when the user clicked       |
| 'send'                      |
|                             |
|                             |
-------------------------------
|                             |
|      Enter Text Here        |
|                             |
-------------------------------
                        | SEND|


Or do you want a parent window with child windows for input and output?

Or am I completely off?
well, I started with win32 just like 4 hours ago, and I have got this

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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <windows.h>

#define IDC_CUSTOM_BUTTON 101
#define IDC_CUSTOM_EDITBOX 102
#define File_Exit 104
#define Help_About 105
#define Help_Info 106
HWND hEdit;

LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, INT nShowCmd)
{
	WNDCLASSEX wClass;
	ZeroMemory(&wClass,sizeof(WNDCLASSEX));
	wClass.cbClsExtra=NULL;
	wClass.cbSize=sizeof(WNDCLASSEX);
	wClass.cbWndExtra=NULL;
	wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
	wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wClass.hIcon=NULL;
	wClass.hIconSm=NULL;
	wClass.hInstance=hInst;
	wClass.lpfnWndProc=(WNDPROC)WinProc;
	wClass.lpszClassName="Window Class";
	wClass.lpszMenuName=NULL;
	wClass.style=0;

	if(!RegisterClassEx(&wClass))
	{
		int nResult = GetLastError();
		MessageBox(NULL, "Window Class Creation Failed!", "Window Class Failed", MB_ICONERROR | MB_OK);
	}

	HWND hWnd = CreateWindowEx(NULL, "Window Class", "Chat Client", WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, NULL, NULL, hInst, NULL);

	if(!hWnd)
	{
		int nResult = GetLastError();
		MessageBox(NULL, "Window Creation Failed!", "Window Creation Failed", MB_ICONERROR | MB_OK);
	}

	ShowWindow(hWnd, nShowCmd);

	MSG msg;
	ZeroMemory(&msg,sizeof(MSG));

	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return 0;
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	case WM_CREATE:
		{
			HWND hWndButton = CreateWindowEx(NULL, "BUTTON", "OK", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON, 517, 386, 100, 24, hWnd, (HMENU)IDC_CUSTOM_BUTTON, GetModuleHandle(NULL), NULL);
			hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD|WS_VISIBLE, 10, 387, 500, 24, hWnd, (HMENU)IDC_CUSTOM_EDITBOX, GetModuleHandle(NULL), NULL);
			HGDIOBJ hfDefault = GetStockObject(DEFAULT_GUI_FONT);
			SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));
			SendMessage(hWndButton, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));
			// menu
			HMENU hMenu, hSubMenu;

			hMenu = CreateMenu();

			hSubMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "File");
			AppendMenu(hSubMenu, MF_STRING, File_Exit, "Exit");

			hSubMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "Help");
			AppendMenu(hSubMenu, MF_STRING, Help_About, "About");
			AppendMenu(hSubMenu, MF_STRING, Help_Info, "Info");

			SetMenu(hWnd, hMenu);
			//icon

			HICON hIcon = (HICON)LoadImage(NULL, "chat.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
			if(hIcon)
				SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
			else
				MessageBox(hWnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);

			HICON hIconSm = (HICON)LoadImage(NULL, "chat.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
			if(hIconSm)
				SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
			else
				MessageBox(hWnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);
		}
		break;
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case IDC_CUSTOM_BUTTON:
				{
					char buffer[256];
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			case File_Exit:
				{
					PostQuitMessage(0);
					return 0;
				}
				break;
			case Help_About:
				{
					MessageBox(hWnd, "SEnergy, Version 1.00\n2010", "About", MB_OK | MB_ICONINFORMATION);
				}
				break;
			case Help_Info:
				{
					MessageBox(hWnd, "Chat Client", "Information", MB_OK | MB_ICONINFORMATION);
				}
			}
			break;
		}
	case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_RETURN:
				{
					char buffer[256];
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			}
			break;
		}
	case WM_RBUTTONDOWN:
		{
			int iPosX = LOWORD(lParam);
			int iPosY = HIWORD(lParam);
			char waCoord[20];
			wsprintf(waCoord, ("%i, %i"), iPosX, iPosY);
			MessageBox(hWnd, waCoord, NULL, MB_OK);
		}
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}


and yes, I wanna that thing like u did on that picture, this is how does my program looks like now: http://filebeam.com/0794fa65684c8360383b23edbbb918bb.jpg

but I've got another 2 problems, maybe you should help me with them, as u can see, I have there

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case VK_RETURN:
				{
					char buffer[256];
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			}
			break;
		}


but if I wanna send message with ENTER, I need to click on button first, cuz it will send only if my edit box is not active, so I need to "deactivate" it when I press enter and then execute that code, I hope u understand :P

second problem:

edit: I did some changes and now I have changed icon of application, but it still don't works when I run it, I mean, I have my icon in explorer but not in that left top corner when I run application :P
Last edited on
I have no idea as I have no experience with win32. The only suggestion I have would be to either ask an admin to move this to the "Windows Programming" board or just scoot over there and create a topic. A link in case:

http://cplusplus.com/forum/windows/
#1 File_Exit shouldn't call PostQuitMessage(0), it should call DestroyWindow()

- DestroyWindow() results in a WM_DESTROY message
- The WM_DESTROY calls PostQuitMessage (as yours already does)

#2 set the hIcon and hIconSm of WNDCLASSEX in WinMain, rather than doing it in
WM_CREATE

#3 it is more common to define the main menu in an .rc file

but you could prob do it in WinMain (if you end up doing a lot of stuff in WinMain, consider factoring out small helper functions)

#4 your command ids are no standard

ID_FILE_EXIT is the convention (if you move on to use MFC or ATL you will find them pre-defined in this way for you)

#5 if RegisterClassEx fails you should not continue

#6 if CreateWindowEx fails you should not continue

#7 for neatness, WM_DESTOY handler could destroy edit control and button

The process will clean up autoatically, but I think it is better to tidy up after myself. i.e. I balance all calls to CreateWindow(Ex) with DestroyWindow

#8 You using ther UNICODE entry point wWinMain

I would either use everything UNICODE or ANSI. Not a mixture.

Consider using the _T() macro with _tWinMain, etc.

#9 to handle VK_RETURN you should set up an accelerator table, rather than trap it in WM_KEYDOWN

About Keyboard Accelerators
http://msdn.microsoft.com/en-us/library/ms646335(VS.85).aspx

(normally done in rc file, too)

#10 I am not sure about you icon problem.

To start with, I would call GetLastError() and have a look at the error code.

Andy
Last edited on
PS If you are using VC++ Express, and therefore don't have the resource editor, see:
http://www.resedit.net/

Andy

PS More options...
http://en.wikipedia.org/wiki/Resource_(Windows)
Last edited on
#1 done

#2 I already changed it to LoadIcon(hInst, MAKEINTRESOURCE(IDI_chatBig)); and did something in resource, it's working now, only that small icon in program (hIconSm) don't works :-/

#3 This is easier and more comfortable way for me :)

#4 you mean 101-109 or names? well, if numbers then I readed in tutorial that I can use any unused number so... and about names, I like it more when they are <menu>_<submenu>

#5 #6 and? how can I continue if it won't create window? O_o

#7 as u said, they are destroyed automatically, so it's waste of time in my opinion :P

#8 I'm using multi-byte character set, not unicode :)

#9 how I said, I started learning win32 like 5 hours ago, so I don't have much experience neither with WM_KEYDOWN or accelerators, so it will be hard for me to discover how to use accelerators w/o tutorial :P

#10 I'll try it :P

btw thanks for that resource editor, maybe I'll start using resource

btw u commented with 10 things, about 7 of that are totally useless and u didn't even mentioned what I was asking, so u just wanted to show me that u are good in c++ or what? I don't care, I just wanna window to handle my text...
Last edited on
Sorry! Got carried away after some other posts... Generally people post large chunks of tet for review, and small ones for specific questions.

To append text to an EDIT control use EN_SETSEL / EN_REPLACESEL

(http://support.microsoft.com/kb/109550)

And the accelerator handling is what you need to handle the return key.

(In case you don't already know, Petzold's book "Programming Windows" is the standard text for this kind of programming. Including the use of keyboard accelerators)

Andy

PS - Just in case you want to know...

#1 :-)

#2 There are restrictions on the size of icon tha LoadIcon() can load. See MSDN entry for the function. LoadImage() can also load from resource, as well as file, ...

#3, #4 I provided this just for information.

ID_FILE_MENU is menu / item (with ID in front)

By convention, #defines are all upper case, so they look different to actual constants. _ are normally used to split words to make the IDs more readable!)

(If you are working on a personal project you can do whatever you want. In commercial devlopment we follow the conventions so people automatically know where to look.)

#5, #6 I mean that you could return from WinMain immediately if these error occur (well, after reporting the error)

#7 I always balance all allocations and creations. It means I control the behaviour of the program more tightly.

It also helps with some diagnostic tools, which are used to find memory and handles leaks. I know that the allocation (memory, handles, ...) should be back down to zero by the end of WinMain. Once it hits the CRT termination code things can get a bit confusing.

#8 The code you pasted is using wWinMain, which is the UNICODE entry point. This should be WinMain. (_tWinMain maps to either WinMain or wWinMain, depending on #define UNICODE)

#9 You might find something at www.codeproject.com or www.codeguru.com -- both sites feature asorted tutorials

#10 ?

Andy

P.S. There is a historical reason menus, dialogs, etc are defined in res files rather than constructed in code. Localization. There are tools which can read the resource segment of an exe or dll, change the strings and then write it back to the file. With no need to recompile or
or relink. So the rule has always been to put all localizable content in the res file.
Last edited on
andywestken, can u please, add me on msn? senergy@windowslive.com or steam if u have, kinedryl666, I need your help :P
Sorry, I'd rather just continue with the thread [1].

But I have checked my hard drive and found the code for a little app that does pretty much what I think you want to do, given your code and Danny Toledo's diagram. That is, a main window with two edit control (one read-only, one writable) and two button (Submit and Skip in my case) and a menu.

(My app is a lttle vocab tester to help me with my French studies. The app asks me to translate a phrase and then checks my answer.)

Given the limited GUI, I chose to use a dialog, so all my controls are defined in the rc file.

As I said, the accelertor handles the return key (and also the esc key for skip, in my case). When I checked my code -- which a wrote a couple of years ago -- I spotted one issue. The accerator translation must be adjusted to always works with the main window, rather than the HWND in the MSG structure.

Another issue is that read-only edit controls are a different color (usually grey) to normal ones. To make a read-only edit control turn back to white, WM_CTLCOLORSTATIC must be handled by the main window.

If you would like, I could post my code, with the "French" code stripped out.

Andy

[1] I only give my contact details out to real people.
Last edited on
well, I tried to make dialog my main window, I created "login" window, where you need to enter username and password, it's working well with enter, I don't even needed to use vk_return, but I have troubles with second dialog window - this will be chat window with 2 edit boxes, 1 for read-only and one writtable, I had troubles with creating, but now I got it, but it's little buggy... well, there are a lot of things I wanna ask, and a lot of things that I don't know, so that's the reason why I wanna any IM contact on you, it's hard (slow...) when we are talking only on forum... I'm just 16 y old boy learning c++ O_o what should I do with ur contact details? I don't wanna your real name or something, btw here's the code:

http://pastebin.com/eyMFXPSv
The stucture of the code you pasted up on pastebin.com is quite close to how I would do it. But you do need to restore some of the code from the earlier version of your code.

#1 Using a dialog as an application's main window

While the .rc file is now handling the (dialog) window layout, a dialog which is being used as the main window is still required to use a registered WndProc [2]. So you need to restore your call to RegisterClassEx with one tweak. The cdWndExtra member needs to be set to DLGWINDOWEXTRA (I've also changed cbClsExtra to 0, from NULL, as it's a count not a pointer.; and set the style to the standard value : CS_HREDRAW | CS_VREDRAW).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	WNDCLASSEX wClass;
	ZeroMemory(&wClass,sizeof(WNDCLASSEX));
	wClass.cbClsExtra=0;
	wClass.cbSize=sizeof(WNDCLASSEX);
	wClass.cbWndExtra=DLGWINDOWEXTRA;
	wClass.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1); // see note [1]
	wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wClass.hIcon=NULL;
	wClass.hIconSm=NULL;
	wClass.hInstance=hInst;
	wClass.lpfnWndProc=(WNDPROC)WinProc;
	wClass.lpszClassName="Window Class";
	wClass.lpszMenuName=NULL;
	wClass.style=CS_HREDRAW | CS_VREDRAW;

	if(!RegisterClassEx(&wClass))

	...


And you create the main dialog using

HWND hMain = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG2), NULL, NULL);

You don't need pass the dialog proc to the call in this case as it will be using the registered function. Which is a WndProc, not a DialogProc [2].

The final part of this change need to made to the resource file. Hopefully the resource editor will help you here. You need to define the class associated with the dialog (the one supplied to the call to RegisterWindowEx : "Window Class" in your existing code.

The definition for the dialog in the .rc file should end up with the following line

CLASS "Window Class"

(This need to be added to the definition of the main dialog)

Notes

[1] to get the color you want, with hbrBackground, you've got to add 1.

e.g. (HBRUSH)(COLOR_WINDOW + 1);

(Note that COLOR_WINDOW is white by default; for a grey dialog use COLOR_BTNFACE)

See MSDN entry for into (for RegisterClassEx/etc).

[2] i.e. it must forward on all unhandled message to DefWindowProc

(continued...)
Last edited on
#2 CreateDialog vs DialogBox

CreateDialog is used to create a modeless dialog, which allows other windows to function while it's displayed. It has to be destroyed using DestroyWindow

DialogBox is used to create a modal dialog, which disables the other application windows until is is close. This type of dialog is closed by a call to EndDialog from inside the dialog proc.

You should not mix up the pairs of calls (CreateDialog/DestroyWindow and DialogBox/EndDialog)

DialogBox is very likely using CreateDialog itself, so you can destroy the window using the wrong function. But you will be interupting the modal dialog's own exit routine.

As you are displaying the logon dialog first and then closing it before displaying the main dialog, it would probably be better to display it as modal dialog. The return code from DialogBox is whatever you pass to EndDialog (if the dialog runs OK) so you can use that to control whether the app runs or not.

And I would not have the connect dialog creating the main dialog in it's IDOK handler. It's neater for the connect dialog to finish what it's doing, and then create the main dialog.

So the start of WinMain should be something along the lines of:

1
2
3
4
5
6
7
8
9
10
11
12
13
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, INT nShowCmd)
{
    int nRet = DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONNECT), NULL, ConnectDlgProc);
    if(IDOK != nRet)
        return 0;

    // register class

    // create main dialog

    // run message loop

    ...


Notes

[1] I have altered the WinMain signature to the ANSI one (WinMain, LPSTR rather than wWinMain, LPWSTR -- which are UNICODE)

[2] I have renamed IDD_DIALOG1 to IDD_CONNECT, so I didn't get confused

[3] In this case, ConnectDlgProc should only call EndDialog. So the IDCANCEL handler needs a tweak.
Last edited on
[1] error C2731: 'WinMain' : function cannot be overloaded << that's why I'm still using wWinMain

ok so I did everything like u said (I hope I did it right) but when I compile and run it it will just close automatically, I don't know how to explain it cuz my english is not that good, so I'll explain it as console code :-X

1
2
3
4
int main()
{
return 0;
}


-- this will close right after program has been executed, cuz there is nothing to stop him, like cin.get();

edit: pastebin - http://pastebin.com/MrwPjTxt

edit2: IDD_CONNECT1 // login screen
IDD_DIALOG1 // Main Screen (chat)
Last edited on
#1 If you're building with Visual Studio, check the projects "General" properties. The "Character Set" should say "Use Multi-Byte Character Set". You error suggets that it is set to "Use Unicode ..." (the default for new projects).

If you want to stick with UNICODE, you should prob rework your code to use TCHARS, etc. But adjusting the properties would be far quicker.

#2 You need to change MainDlgProc back to a stripped down version of your previous WinMain. When a dialog is a main window, it's got to forward all unhanded calls to DefWindowProc

It only needs to handled WM_DESTROY and WM_COMMAND so far. But you might want to add WM_INITDIALOG and WM_CTLCOLORSTATIC. And maybe even WM_SIZE.

(This is just your old code, with all the stuff which is no longer needed -- as you're using a resource based dialog -- taken out. Except that IDC_CUSTOM_BUTTON has been replaced with IDOK.)

If you set the MENU property of your dialog, the File/Exit and Help/About should just work!

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
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			return 0;
		}
		break;
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case IDOK:
				{
					char buffer[256];
					// Could use GetDltItemText() here, as you use elsewhere
					HWND hEdit = GetDlgItem(hWnd, IDC_EDIT1);
					SendMessage(hEdit, WM_GETTEXT, sizeof(buffer)/sizeof(buffer[0]), reinterpret_cast<LPARAM>(buffer));
					MessageBox(hEdit, buffer, "Information", MB_ICONINFORMATION);
				}
				break;
			case IDM_EXIT1:
				{
					DestroyWindow(hWnd);
					return 0;
				}
				break;
			case IDM_ABOUT1:
				{
					MessageBox(hWnd, "SEnergy, Version 1.00\n2010", "About", MB_OK | MB_ICONINFORMATION);
				}
				break;
			}
			break;
		}
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Last edited on
I see that you have added IsDialogMessage() to your message loop.

As this uses an accelerator table to map <return> => IDOK and <esc> => IDCANCEL, you don't need to bother with HandleAccelerator() for now. But if you want to define custom or additional hotkeys in the future, you will need to look into in.

The following code shows how to read text from one edit control and append it to another.. It needs to be called from the IDOK handler and passed the handle to the dialog.

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
// Handles "Send" button
//
// hWnd is the handle to the dialog
// Code is not ignoring space only lines
// _ASSERTE is defined in <crtdbg.h> (CRT debug functions, etc)
int
Command_Send(HWND hWnd)
{
    // get handles to the edit controls:
    // - IDC_EDIT1 is the o/p
    // - IDC_EDIT2 the input
    //
    // (IDC_EDIT1 need to have ES_MULTILINE but not ES_AUTOHSCROLL
    // (auto-scroll stops text wrapping) and should prob have ES_READONLY,
    // but then you might want to handle WM_CTLCOLORSTATIC
    HWND hwndOutput = GetDlgItem(hWnd, IDC_EDIT1);
    _ASSERTE(NULL != hwndOutput);
    HWND hwndInput  = GetDlgItem(hWnd, IDC_EDIT2);
    _ASSERTE(NULL != hwndInput);

    const int bufferLen = 1024;

    int textLen = SendMessage(hwndInput, WM_GETTEXTLENGTH, 0, 0);
    _ASSERTE(bufferLen > textLen);

    if(0 < textLen)
    {
        // get text from i/p window
        char achMessage[bufferLen] = {0};
        SendMessage(hwndInput, WM_GETTEXT, bufferLen, (LPARAM)achMessage);

        // add endline (Edit needs \r\n)
        lstrcat(achMessage, "\r\n");

        // set a zero length selection at end of text in the i/p window and then replace it
        textLen = SendMessage(hwndOutput, WM_GETTEXTLENGTH, 0, 0);
        _ASSERTE(0 <= textLen);
        SendMessage(hwndOutput, EM_SETSEL, textLen, textLen);
        SendMessage(hwndOutput, EM_REPLACESEL, TRUE, (LPARAM)achMessage);

        // clear i/p window
        const char achBlank[] = "";
        SendMessage(hwndInput, WM_SETTEXT, 0, (LPARAM)achBlank);
    }

    return 0;
}
Last edited on
well, I just changed return TRUE to return DefWindowProc(hMain, msg, wParam, lParam); in MainDlgProc and deleted WM_INITDIALOG, this is how does it looks now:

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
BOOL CALLBACK MainDlgProc(HWND hMain, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:
		{
			PostQuitMessage(0);
			break;
		}
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case IDOK:
				{
					char buffer[512];
					GetDlgItemText(hMain, IDC_EDIT1, buffer, sizeof(buffer)/sizeof(buffer[0]));
					MessageBox(hMain, buffer, NULL, MB_OK);
					break;
				}
				break;
			}
			break;
		}
	}
	return DefWindowProc(hMain, msg, wParam, lParam);
}


but I don't know how this should help me, cuz my window will close again right after executing program
Checking your pasted code, the window class looks kike it defined for the wrong dialog.

CLASS "Window Class"

Needs to be defined for the main window (which uses MainDlgProc), not the connect dialog, which uses the modal loop (DialogBox has it's own loop off somewhere else).

Also, compare your MainDlgProc with your earlier WinProc. You generally need to return 0 if you handle a message, and 0 if you don't.

See MSDN for a message code to find out the details. WM_INITDIALOG has custom rules, as does WM_CTLCOLORSTATIC.

Andy
ok so I changed CLASS to main dlg, it's "working" now, after I start program it looks ... weird...

http://filebeam.com/953f33143c0c74886eab7b3049dcead6.jpg

and when I press connect (I changed username and password to "" so I don't need to enter it there) and after clicking on "connect" second dialog (main window) will appear but after that it will close instantly...

http://pastebin.com/pMT1vsvu

I'm really confused and I have no idea what should I do :-X and I thanks you for your patience with me
Remove the following from ConnectDlgProc


1
2
3
4
5
        case WM_DESTROY:
                {
                        PostQuitMessage(0);
                        break;
                }


(PostQuitMessage tells the app to exit. Only the main loop should do this)

I have never see a dialog which look like that (drawn twice?)

I have compiled your code (plus corrections) and it works fine for me now. (I had already removed the above bit of code)
Last edited on
Pages: 123