Sign in to follow this  

Pop up window

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

if you didnt want the user to beable to copy the text you would just use the standard MessageBox function. however in your case it seems that youll need to write your own special window for this.

use CreateWindow to create the parent window which will be the size and shape of the standard messagebox, then use CreateWindow again to create a child window (hint use the style WM_CHILD) and create a text edit area, i belive then you can make it read only, so they can select it but not click inside the text or modify it. there might be a better way than this, and if so, someone else below me will say it im sure :).

all the styles and types of windows you can create are listed below the CreateWindow function in the msdn platform sdk, so then its simply a matter of pluggin in the right argumnets to get the results you want.

good luck

Share this post


Link to post
Share on other sites
Uh...

When you say you want the user to be able to copy the text, do you mean by pressing Ctrl+C, or do you intend to provide a "Copy Text to Clipboard" function? I'd recommend the latter as it's so much more elegant.

Create your window with the WS_POPUP (for a captionless window) or WS_CHILD window styles. Place the text in a label (use the Designer [VS 7.x+] or Resource Editor [VS 4+]), and then use the SetClipboardData API to respond to the button click event and place the label text on the clipboard.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I wrote a code that displays window from a dialog and the source code should looks like that:

#include

#include
#include

#include "..\resource.h"

HINSTANCE hInst;

HWND MainWindow;

char* ClassName = "klasa";

LRESULT CALLBACK MainWndProc ( HWND, UINT, WPARAM, LPARAM );
BOOL CALLBACK MainWndProc1 ( HWND, UINT, WPARAM, LPARAM );

int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE, LPSTR, int ) {
MSG uMsg;

WNDCLASS WndCl;

WndCl.style = CS_HREDRAW | CS_VREDRAW;
WndCl.hInstance = hInstance;
WndCl.lpszClassName = ClassName;
WndCl.lpfnWndProc = MainWndProc;
WndCl.hIcon = LoadIcon ( NULL, IDI_APPLICATION );
WndCl.hCursor = LoadCursor ( NULL, IDC_ARROW );
WndCl.cbClsExtra = 0;
WndCl.cbWndExtra = 0;
WndCl.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );

if ( !RegisterClass ( &WndCl ) )
return 0;

hInst = hInstance;

InitCommonControls ( );

DialogBox ( hInst, ( LPCTSTR ) IDD_ZAKLADKA, MainWindow, ( DLGPROC ) MainWndProc1 );

ShowWindow ( MainWindow, SW_NORMAL );
UpdateWindow ( MainWindow );

while ( GetMessage ( &uMsg, NULL, 0, 0 ) ) {
if ( !IsDialogMessage ( MainWindow, &uMsg ) ) {
TranslateMessage ( &uMsg );
DispatchMessage ( &uMsg );
}
}

return ( uMsg.wParam );
}

LRESULT CALLBACK MainWndProc ( HWND Window, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
switch ( uMsg ) {
case WM_COMMAND:
switch ( LOWORD ( wParam ) ) {
case ID_ABOUT:
MessageBox ( NULL, "", "", MB_OK );
break;
}
case WM_CLOSE:
EndDialog ( Window, LOWORD ( wParam ) );
PostQuitMessage ( 0 );
return TRUE;
}

return DefWindowProc ( Window, uMsg, wParam, lParam );
}

BOOL CALLBACK MainWndProc1 ( HWND Window, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
switch ( uMsg ) {
case WM_INITDIALOG: {
return 0;

case WM_COMMAND:
switch ( LOWORD ( wParam ) ) {
}
break;

case WM_CLOSE:
EndDialog ( Window, LOWORD ( wParam ) );
PostQuitMessage ( 0 );
return TRUE;
}

return FALSE;
}

But in this code i found one bug. i cannot handle accelerators and i don`t know why.

Share this post


Link to post
Share on other sites
Quote:
Original post by The C modest god
I have been able to make the Ok button close the window,
but how do I insert text to the edit box?

SetDlgItemText(), which just wraps WM_SETTEXT - Which is what Oluseyi meant

Share this post


Link to post
Share on other sites
I have put text inside the edit box.
However, whenever I have put endl in the string the edit box shows a strange character and doest go a line bellow.
How do I do going down a line in the edit box?
If I just write the string into the text edit, when the text reaches the end of the box it doesnt go down but continues into an unseen area.
How do I deal with it?

Share this post


Link to post
Share on other sites
Right click on the edit box in the resource editor, goto "Properties" and check the "Multiline" checkbox on the uh... second tab (I think).
Also, for writing a newline to a multiline edit box, you need to do "\r\n", not just "\n".

Share this post


Link to post
Share on other sites

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this