-
October 18th, 2012, 06:51 AM
#1
How to Activate WM_CHAR Message with Edit Box (from DIALOG)
I try to build one application as following:
The Main Window With Window Class = CLASS1 ; and With Window Proc =wnproc()
Then I create a dialog (Child window) By Using Function : CreateDialog(..,..,..) with window proc = wndProcDlg().
Then I add one Edit Box Class inside the dialog;
My Problem is when I add WM_CHAR inside window Proc of Dialog , It is not working!!??
Then I do not know how can I manage the character that I want to let user add inside Edit Box ;
I want to add in Edit box only 5 Digit with floating point (Example : 33.25)
Kindly see the code and Help
Code:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Design RC Rectangle Section as Per ACI 318-11 Code
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include "stdafx.h"
#include "Win32Project11.h"
#include <string>
#include <math.h>
#include <wchar.h>
//#include <stdlib.h>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
static HWND hdlgmodeles;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Globale Variable Define Concrete Section ~~~~~~~~~~~~~~~~~~
int Width ; // Width of Section
int Height ; // Height of Section
int fc ; // Strength of concrete ACI code
int Fy ; // Strength of Reinforcemnt ACI code
double Mu ; // Moment Mu of Load
double Qu ; // Shear Strngth
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Forward declarations of functions included in this code module: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);//wind Proc of Main Window
INT_PTR CALLBACK wndprocDesign(HWND, UINT, WPARAM, LPARAM);//Wind Proc of Dlg
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WIN32PROJECT11, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT11));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return (int) msg.wParam;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT11));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32PROJECT11);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Wind Proc of Main Window Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
//SendMessage(hWnd,IDM_ABOUT,0,0);
switch (message)
{
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
int a;
a= wParam;
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
if (hdlgmodeles ==NULL)
{
hdlgmodeles= CreateDialog(hInst,MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, wndprocDesign);
ShowWindow(hdlgmodeles,SW_SHOW);
}
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~~~~WndProc for Dialog Box ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BOOL CALLBACK wndprocDesign(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
int iD;iD=GetDlgCtrlID(hDlg);
// SendDlgItemMessageA(hDlg,EDIT_HEIGHT,ES_CENTER,wParam,lParam);
return (INT_PTR)TRUE;
case WM_CHAR:
/// Here is problem WM_CHAR NOT WORKING ??!!!
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
TCHAR txtHeight[10] ; // Get Height from Text Box TCHAR txtWidth [10] ; // Get Width from Text Box
TCHAR txtFc[10] ; // Get fc from Text Box
TCHAR txtFy[10] ; // Get Fy from Text Box
TCHAR txtMu[10] ; // Get Mu from Text Box
TCHAR txtQu[10] ; // Get Qu from Text Box
GetDlgItemText(hDlg,EDIT_HEIGHT,txtHeight,10); //
GetDlgItemText(hDlg,EDIT_WIDTH,txtWidth, 10); //
GetDlgItemText(hDlg,EDIT_Fc,txtFc, 10); // G
GetDlgItemText(hDlg,EDIT_Fy,txtFy, 10); // G
GetDlgItemText(hDlg,EDIT_Mu,txtMu, 10); //
GetDlgItemText(hDlg,EDIT_Qu,txtQu, 10); //
Height = _wtof(txtHeight); // To convert TCHAR to // /
Width = _wtof(txtWidth ); // To convert TCHAR
fc = _wtof(txtFc );
Fy = _wtof(txtFy );
Mu = _wtof(txtMu );
Qu = _wtof(txtQu );
return (INT_PTR)TRUE;
}
break;
}
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|