Pa help po Hindi ko mapagana ung WM_KEYDOWN ng edittext sa DialogBox sa WinApi C++. code::Blocks ver 16 ang gamit ko po. Gusto ko lang po ma try kung pano ito gagana sa DialogBox
Eto po ung code
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
WNDPROC g_oldDlgdProc;
LRESULT CALLBACK DlgWindowsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void ChangeDialogClass(HWND hwnd);
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{ //1
case WM_INITDIALOG:
{ //2
ChangeDialogClass( GetDlgItem(hwndDlg, IDED1));
} //2
return TRUE;
case WM_CLOSE:
{ //3
EndDialog(hwndDlg, 0);
} //3
return TRUE;
case WM_COMMAND:
{ //4
switch(LOWORD(wParam))
{ //5
case IDBU1:
{ //6
} //6
break;
case IDED1:
{ //7
} //7
} //5
} //4
return TRUE;
}//1
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
return 1;
}
LRESULT CALLBACK DlgWindowsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char sOu[200];
if (message == WM_KEYDOWN)
{
int key = (int) wParam;
sprintf(sOu, "KEYDOWN %d", key );
MessageBox(hWnd, sOu, "MES", MB_OK);
}
return g_oldDlgdProc(hWnd, message, wParam, lParam);
}
void ChangeDialogClass(HWND hwnd)
{
g_oldDlgdProc = (WNDPROC)GetWindowLong(hwnd, GWL_ID);
SetWindowLong(hwnd, GWL_ID, (LONG)&DlgWindowsProc);
}
///////////////////////////////////////////////
//Sa resource.rc
// Generated by ResEdit 1.5.10
// Copyright (C) 2006-2012
// You do not have permission to view the full content of this post. Log in or register now.
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 400, 300
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
EDITTEXT IDED1, 30, 50, 100, 20
EDITTEXT IDED2, 140, 50, 100, 20
PUSHBUTTON "PRESS", IDBU1, 30, 200, 100, 20
}
//
// Manifest resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
1 RT_MANIFEST ".\\manifest.xml"
///////////////////////////////////////
//sa resource.h
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 100
#define IDBU1 111
#define IDED1 112
#define IDED2 113
Eto po ung code
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include "resource.h"
HINSTANCE hInst;
WNDPROC g_oldDlgdProc;
LRESULT CALLBACK DlgWindowsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void ChangeDialogClass(HWND hwnd);
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{ //1
case WM_INITDIALOG:
{ //2
ChangeDialogClass( GetDlgItem(hwndDlg, IDED1));
} //2
return TRUE;
case WM_CLOSE:
{ //3
EndDialog(hwndDlg, 0);
} //3
return TRUE;
case WM_COMMAND:
{ //4
switch(LOWORD(wParam))
{ //5
case IDBU1:
{ //6
} //6
break;
case IDED1:
{ //7
} //7
} //5
} //4
return TRUE;
}//1
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst=hInstance;
InitCommonControls();
DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
return 1;
}
LRESULT CALLBACK DlgWindowsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char sOu[200];
if (message == WM_KEYDOWN)
{
int key = (int) wParam;
sprintf(sOu, "KEYDOWN %d", key );
MessageBox(hWnd, sOu, "MES", MB_OK);
}
return g_oldDlgdProc(hWnd, message, wParam, lParam);
}
void ChangeDialogClass(HWND hwnd)
{
g_oldDlgdProc = (WNDPROC)GetWindowLong(hwnd, GWL_ID);
SetWindowLong(hwnd, GWL_ID, (LONG)&DlgWindowsProc);
}
///////////////////////////////////////////////
//Sa resource.rc
// Generated by ResEdit 1.5.10
// Copyright (C) 2006-2012
// You do not have permission to view the full content of this post. Log in or register now.
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "resource.h"
//
// Dialog resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
DLG_MAIN DIALOG 0, 0, 400, 300
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Ms Shell Dlg"
{
EDITTEXT IDED1, 30, 50, 100, 20
EDITTEXT IDED2, 140, 50, 100, 20
PUSHBUTTON "PRESS", IDBU1, 30, 200, 100, 20
}
//
// Manifest resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
1 RT_MANIFEST ".\\manifest.xml"
///////////////////////////////////////
//sa resource.h
#ifndef IDC_STATIC
#define IDC_STATIC (-1)
#endif
#define DLG_MAIN 100
#define IDBU1 111
#define IDED1 112
#define IDED2 113