Click here to Skip to main content
15,913,669 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: pasting from program to notepad Pin
BaldwinMartin24-Nov-03 17:18
BaldwinMartin24-Nov-03 17:18 
GeneralRe: pasting from program to notepad Pin
John R. Shaw24-Nov-03 17:20
John R. Shaw24-Nov-03 17:20 
QuestionDialog box continuous update? Pin
bradleyand24-Nov-03 9:41
bradleyand24-Nov-03 9:41 
AnswerRe: Dialog box continuous update? Pin
Andrey Del Pozo24-Nov-03 10:11
Andrey Del Pozo24-Nov-03 10:11 
GeneralRe: Dialog box continuous update? Pin
bradleyand24-Nov-03 20:41
bradleyand24-Nov-03 20:41 
GeneralWin32 Dialog Box and Date/Time Picker Control Pin
Billy Whizz24-Nov-03 9:40
Billy Whizz24-Nov-03 9:40 
GeneralRe: Win32 Dialog Box and Date/Time Picker Control Pin
BaldwinMartin24-Nov-03 17:21
BaldwinMartin24-Nov-03 17:21 
GeneralRe: Win32 Dialog Box and Date/Time Picker Control Pin
Billy Whizz24-Nov-03 22:56
Billy Whizz24-Nov-03 22:56 
Hi All

This is a small application I have put together to highlight my problem. Basically it consists of a parent window with a button and RichEdit control on it. When you select the RichEdit control a dialog box appears that has a date/time picker on it and another button. Selecting the date/time picker allows you to select a date and on pressing the button on the dialog box the information is transferred to the underlying RichEdit box. The dialog box closes. However, if you then try to select one of the parent window controls with the mouse (the button for instance) the dialog box reappears... Is there something I am (or am not) doing correctly?

Heres the Applications :

#include "stdafx.h"
#include "richedit.h"
#include "resource.h"

#define WINDOW_CLASS_NAME "WINCLASS1"

HWND CreateButton(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance);

HWND CreateRichEdit(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance);

BOOL CALLBACK DateDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

HWND main_window_handle = NULL;
HINSTANCE main_hInstance = NULL;
HINSTANCE relib;
HWND eDate = NULL;

LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;

switch(msg)
{
case WM_CREATE:
{
relib = LoadLibrary("riched32.dll");

//Create a Button on the main form
HWND bDateSelect = CreateButton("Select Date",10,250,100,25,101,
hwnd,main_hInstance);

//Create a RichEdit Box on the main form
eDate = CreateRichEdit("",10,30,200,25,102,
hwnd,main_hInstance);

return (0);
} break;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
case WM_COMMAND:
{
switch(LOWORD(wparam))
{
case 102:
{
if(HIWORD(wparam) == EN_SETFOCUS)
{
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DATE),
hwnd,DateDlgProc);
}
} break;
}
} break;
default:break;
} //End of Switch

return(DefWindowProc(hwnd,msg,wparam,lparam));
}

BOOL CALLBACK DateDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
//Get the information from the DateTimePicker Control and Return it
HWND hwndCtrl = GetDlgItem(hwnd,IDC_DATETIMEPICKER1);

//Store the data
char date_Store[20];
int date_Length = SendMessage(hwndCtrl,WM_GETTEXTLENGTH,0,0);
SendMessage(hwndCtrl,WM_GETTEXT,(WPARAM)date_Length+1,(LPARAM)date_Store);

//Set the text in the RichEdit box for date of birth
SendMessage(eDate,WM_SETTEXT,0,(LPARAM)(LPCTSTR)date_Store);

EndDialog(hwnd,IDOK);
} break;
} break;
default:
return false;
}
return true;
}

//*******************************************************************
//* This function creates a Button
//*******************************************************************

HWND CreateButton(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance)
{
HWND hbuttonTemp; //Handle to temporary Bitmap Button

hbuttonTemp = CreateWindowEx(
WS_EX_CLIENTEDGE,
"BUTTON",
tempText,
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
x, y,
width, height,
hwnd,
(HMENU)identifier,
hInstance,
NULL);

return hbuttonTemp; //Return the handle
}

//*******************************************************************
//* This function creates a RichEdit box
//*******************************************************************

HWND CreateRichEdit(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance)
{
HWND hrichEditTemp;

hrichEditTemp = CreateWindowEx(
NULL,
RICHEDIT_CLASS,
tempText,
WS_CHILD | WS_VISIBLE | ES_SUNKEN | ES_UPPERCASE,
x,y,
width,height,
hwnd,
(HMENU)identifier,
GetModuleHandle(NULL),
NULL);

return hrichEditTemp;

}

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;

winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInstance;
winclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;

//Register the Window Class
if(!RegisterClass(&winclass))
return(0);

//Create the main window
if(!(hwnd=CreateWindow(WINDOW_CLASS_NAME,
"Date and Time Picker Dialog",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,320,320,
NULL,NULL,
hInstance,NULL)))
return(0);

//Save the Window handle in a global
main_window_handle = hwnd;

main_hInstance = hInstance;

//Enter the main event loop
while(1)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT) break;

TranslateMessage(&msg);

DispatchMessage(&msg);
}
}

return(msg.wParam );
}

Any help would be gratefully appreciated.

Cheers

Billy
GeneralRe: Win32 Dialog Box and Date/Time Picker Control Pin
Steve S25-Nov-03 2:50
Steve S25-Nov-03 2:50 
GeneralClistbox parsing,help Pin
thes3cr3t124-Nov-03 9:32
thes3cr3t124-Nov-03 9:32 
GeneralRe: Clistbox parsing,help Pin
BaldwinMartin24-Nov-03 17:27
BaldwinMartin24-Nov-03 17:27 
Questiondetermineing a variable type within the program code? Pin
Anonymous24-Nov-03 9:24
Anonymous24-Nov-03 9:24 
AnswerRe: determineing a variable type within the program code? Pin
igor196024-Nov-03 11:56
igor196024-Nov-03 11:56 
GeneralReports in VC++6.0 Pin
Hesham Amin24-Nov-03 8:54
Hesham Amin24-Nov-03 8:54 
GeneralRe: Reports in VC++6.0 Pin
Ernesto D.24-Nov-03 9:05
Ernesto D.24-Nov-03 9:05 
GeneralRe: Reports in VC++6.0 Pin
Game Tester24-Nov-03 14:04
Game Tester24-Nov-03 14:04 
Generalreceive serial xml data Pin
Anonymous24-Nov-03 8:45
Anonymous24-Nov-03 8:45 
GeneralRe: receive serial xml data Pin
Andrey Del Pozo24-Nov-03 9:39
Andrey Del Pozo24-Nov-03 9:39 
GeneralDll data space Pin
Anonymous24-Nov-03 8:35
Anonymous24-Nov-03 8:35 
GeneralReading raw data Pin
Anonymous24-Nov-03 7:48
Anonymous24-Nov-03 7:48 
GeneralRe: Reading raw data Pin
John M. Drescher24-Nov-03 8:03
John M. Drescher24-Nov-03 8:03 
GeneralRe: Reading raw data Pin
john john mackey24-Nov-03 11:12
john john mackey24-Nov-03 11:12 
GeneralA simple C question Pin
b_girl24-Nov-03 7:35
b_girl24-Nov-03 7:35 
GeneralRe: A simple C question Pin
markkuk24-Nov-03 7:52
markkuk24-Nov-03 7:52 
GeneralRe: A simple C question Pin
b_girl24-Nov-03 8:11
b_girl24-Nov-03 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.