Related
I have a callback function:
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if(msg == WM_DESTROY || msg == WM_CLOSE) {
std::cout << "Close or get DESTROYED!\n";
}
if(g_mApp)
return g_mApp->MsgProc(hwnd, msg, wParam, lParam);
else
return DefWindowProc(hwnd, msg, wParam, lParam);
}
However, "Close or get Destroyed" isn't printed when I click on the X button or press Alt+F4. Infact, I am unable to move the window by the mouse!
Some other functions:
int GLApp::run() {
__int64 prevTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTime);
__int64 countsPerSec = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&countsPerSec);
float secondsPerCount = 1.0f / countsPerSec;
MSG msg = {0};
while(msg.message != WM_QUIT) {
if(!PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
__int64 curTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&curTime);
float deltaTime = (curTime - prevTime) * secondsPerCount;
update(deltaTime);
render();
calculateFPS(deltaTime);
prevTime = curTime;
}
}
shutdown();
return static_cast<int>(msg.wParam);
}
bool GLApp::initWindow() {
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.hInstance = m_hAppInstance;
wcex.lpfnWndProc = MainWndProc;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wcex.lpszClassName = "GLAPPWNDCLASS";
wcex.lpszMenuName = NULL;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcex)) {
return outErrorMessage("Failed to register GLAPPWNDCLASS");
}
// ADJUST WINDOW RECT FOR REQUESTED CLIENT SIZE
RECT r;
r.left = r.top = 0;
r.right = m_ClientWidth;
r.bottom = m_ClientHeight;
AdjustWindowRect(&r, m_WindowStyle, FALSE);
int width = r.right - r.left;
int height = r.bottom - r.top;
int x = GetSystemMetrics(SM_CXSCREEN)/2 - width / 2;
int y = GetSystemMetrics(SM_CYSCREEN)/2 - height / 2;
m_hAppWnd = CreateWindow("GLAPPWNDCLASS", m_AppTitle, m_WindowStyle, x, y, width, height, NULL, NULL, m_hAppInstance, NULL);
if(!m_hAppWnd) return outErrorMessage("Failed to create window from GLAPPWNDCLASS");
ShowWindow(m_hAppWnd, SW_SHOW);
return true;
}
g_mApp is my own object for implementing the window. initWindow() and run() are called only once respectively. The full class if you will:
#include "GLApp.h"
#include <iostream>
namespace {
GLApp* g_mApp = NULL;
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if(msg == WM_DESTROY || msg == WM_CLOSE) {
std::cout << "Close or get DESTROYED!\n";
}
if(g_mApp)
return g_mApp->MsgProc(hwnd, msg, wParam, lParam);
else
return DefWindowProc(hwnd, msg, wParam, lParam);
}
GLApp::GLApp(void)
{
}
GLApp::GLApp(HINSTANCE hInstance) {
m_hAppInstance = hInstance;
m_hAppWnd = NULL;
m_hDevContext = NULL;
m_hGLRenderContext = NULL;
m_ClientWidth = 800;
m_ClientHeight = 600;
m_AppTitle = "OpenGL Application";
m_WindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX;
m_FPS = 0.0f;
g_mApp = this;
}
GLApp::~GLApp()
{
}
int GLApp::run() {
__int64 prevTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTime);
__int64 countsPerSec = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&countsPerSec);
float secondsPerCount = 1.0f / countsPerSec;
MSG msg = {0};
while(msg.message != WM_QUIT) {
if(!PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else {
__int64 curTime = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&curTime);
float deltaTime = (curTime - prevTime) * secondsPerCount;
update(deltaTime);
render();
calculateFPS(deltaTime);
prevTime = curTime;
}
}
shutdown();
return static_cast<int>(msg.wParam);
}
bool GLApp::init() {
return initWindow() && initGL();
}
bool GLApp::initWindow() {
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.hInstance = m_hAppInstance;
wcex.lpfnWndProc = MainWndProc;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wcex.lpszClassName = "GLAPPWNDCLASS";
wcex.lpszMenuName = NULL;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wcex)) {
return outErrorMessage("Failed to register GLAPPWNDCLASS");
}
// ADJUST WINDOW RECT FOR REQUESTED CLIENT SIZE
RECT r;
r.left = r.top = 0;
r.right = m_ClientWidth;
r.bottom = m_ClientHeight;
AdjustWindowRect(&r, m_WindowStyle, FALSE);
int width = r.right - r.left;
int height = r.bottom - r.top;
int x = GetSystemMetrics(SM_CXSCREEN)/2 - width / 2;
int y = GetSystemMetrics(SM_CYSCREEN)/2 - height / 2;
m_hAppWnd = CreateWindow("GLAPPWNDCLASS", m_AppTitle, m_WindowStyle, x, y, width, height, NULL, NULL, m_hAppInstance, NULL);
if(!m_hAppWnd) return outErrorMessage("Failed to create window from GLAPPWNDCLASS");
ShowWindow(m_hAppWnd, SW_SHOW);
return true;
}
bool GLApp::initGL() {
// CREATE OUR DEVICE CONTEXT
m_hDevContext = GetDC(m_hAppWnd);
// CREATE PIXEL FORMAT DESCRIPTOR
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cStencilBits = 8;
int format = ChoosePixelFormat(m_hDevContext, &pfd);
if(!SetPixelFormat(m_hDevContext, format, &pfd)) {
return outErrorMessage("Failed to set pixel format");
}
// CREATE RENDER CONTEXT
m_hGLRenderContext = wglCreateContext(m_hDevContext);
if(!wglMakeCurrent(m_hDevContext, m_hGLRenderContext)) {
return outErrorMessage("Failed to create and activate render context");
}
// INITIALIZE GLEW
if(glewInit() != GLEW_OK) {
return outErrorMessage("Failed to initialize GLEW");
}
return true;
}
LRESULT GLApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_CLOSE: {
DestroyWindow(hwnd);
return 0;
}
case WM_DESTROY: {
PostQuitMessage(0);
return 0;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
void GLApp::calculateFPS(float dt) {
}
void GLApp::shutdown() {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hGLRenderContext);
ReleaseDC(m_hAppWnd, m_hDevContext);
}
This is how it is implemented:
#include "GLApp.h"
#include <iostream>
class TestApp : public GLApp {
public:
TestApp(HINSTANCE hInstance);
~TestApp();
// OVERRIDES
bool init() override;
void update(float dt) override;
void render() override;
LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) override;
};
TestApp::TestApp(HINSTANCE hInstance) : GLApp(hInstance) {
}
TestApp::~TestApp() {}
bool TestApp::init() {
return GLApp::init();
}
void TestApp::update(float dt) {
}
void TestApp::render() {
}
LRESULT TestApp::MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
default:
return GLApp::MsgProc(hwnd, msg, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow) {
TestApp app(hInstance);
if(!app.init()) {
return 1;
}
return app.run();
}
bool outErrorMessage(const char* message) {
MessageBox(NULL, message, NULL, MB_OK);
return false;
}
!PeekMessage is wrong, if it returns non-zero you got a message you need to handle.
I find different examples in the Internet of how to program a PropertySheet in WinAPI, but they are not complete.
The code I am using is shown below. I have a PropertySheet with 3 Tabs, each one with a Dialog.
The different Dialogs are called, when I click the Tabs, so far it is working.
However, when I leave the PropertySheet pressing OK button, how do I get the contents in the Textboxes etc. of each Dialog?
Normally I used to do that in the DialogProc when WM_COMMAND/IDOK was received using:
GetDlgItemText( hDlg,IDC_TEXTBOX1, buf, 100);
But in the PropertySheet there is only one OK Button for all dialogs, no WM_COMMAND/IDOK is received in the DialogProc.
What shall I do?
Resource_file:
IDD_DIALOG_1 DIALOGEX 0, 0, 385, 186
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
BEGIN
LTEXT "param",IDC_STATIC,6,23,39,10
EDITTEXT IDC_TEXTBOX1,48,20,237,15
END
C Source:
LRESULT CALLBACK
Dialog1(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
char buf[500];
char* ptr;
int p; // =lParam, rin of edited person
int f;
switch (message)
{
case WM_INITDIALOG:
{
SetDlgItemText(hDlg, IDC_TEXTBOX1, "something");
return 0;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK: // never reached (OK Button belongs to the PropertySheet!)
}
}
}
return FALSE;
} /* Dialog1 */
INT_PTR DoPropertySheet(HWND hwndOwner, LPARAM p)
{
PROPSHEETPAGE psp[3];
PROPSHEETHEADER psh;
memset(psp,0,sizeof(psp));
for(int i=0;i<3; i++)
{
psp[i].dwSize = sizeof(PROPSHEETPAGE);
psp[i].dwFlags = PSP_USETITLE;
psp[i].hInstance = hInstance;
psp[i].lParam = p;
}
psp[0].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_1);
psp[0].pfnDlgProc = (DLGPROC)Dialog1;
psp[1].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_2);
psp[1].pfnDlgProc = (DLGPROC)Dialog2;
psp[2].pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_3);
psp[2].pfnDlgProc = (DLGPROC)Dialog3;
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
psh.hwndParent = hwndOwner;
psh.hInstance = hInstance;
psh.pszIcon = 0;
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = (LPCPROPSHEETPAGE) &psp;
psh.pfnCallback = NULL;
if (PropertySheet(&psh)) // 0:cancel, otherwise:1
{
//get contens of propertySheet here?? how??
}
return 0;
}
when user press OK or Apply all your pages got PSN_APPLY notification code. so you need look for WM_NOTIFY with PSN_APPLY code
when user press cancel you got PSN_RESET notification
INT_PTR CALLBACK PPDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
union {
LPARAM lp;
NMHDR* hdr;
PSHNOTIFY* psn;
};
switch (umsg)
{
case WM_NOTIFY:
lp = lParam;
switch (hdr->code)
{
case PSN_APPLY:
DbgPrint("apply");
break;
case PSN_RESET:
DbgPrint("cancel\n");
break;
}
break;
}
return 0;
}
I've started Direct2D from a very simple example.
Acquire the factory and ID2D1HwndRenderTarget, then handle WM_PAINT message to draw just a background with a solid color using "Clear" function.
It's work fine, until I start to move the window. When the window is moving it turns gray like nothing is drawing. I've tried to draw an ellipse, and the result is the same.
How could one present the window content with the window moving?
P.S. In case the code is needed
#include <Windows.h>
#include <d2d1_1.h>
#pragma comment(lib,"d2d1")
ID2D1Factory * d2factory_ptr = NULL;
ID2D1HwndRenderTarget * renderTarget_ptr = NULL;
LRESULT CALLBACK mainWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(
HINSTANCE hInstance
, HINSTANCE prevInstance
, LPWSTR cmd
, int nCmdShow
) {
WNDCLASSEX wndClassStruct;
ZeroMemory(&wndClassStruct, sizeof(WNDCLASSEX));
wndClassStruct.cbSize = sizeof(WNDCLASSEX);
wndClassStruct.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndClassStruct.style = CS_HREDRAW | CS_VREDRAW;
wndClassStruct.hInstance = hInstance;
wndClassStruct.lpfnWndProc = mainWinProc;
wndClassStruct.lpszClassName = TEXT("MainWnd");
RegisterClassEx(&wndClassStruct);
RECT windowRect = { 0,0,640,480};
AdjustWindowRectEx(&windowRect, WS_OVERLAPPEDWINDOW, 0, WS_EX_APPWINDOW);
HWND hWnd = CreateWindowEx(WS_EX_APPWINDOW, TEXT("MainWnd"), TEXT("Direct 2D Test Window"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE, CW_USEDEFAULT, 0, windowRect.right-windowRect.left, windowRect.bottom-windowRect.top, NULL, NULL, hInstance, 0);
{
D2D1_FACTORY_OPTIONS fo;
ZeroMemory(&fo, sizeof(D2D1_FACTORY_OPTIONS));
IID const factoryIID = IID_ID2D1Factory1;
HRESULT res = S_OK;
if (S_OK != (res = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factoryIID, &fo, &d2factory_ptr))) {
return 0;
}
RECT clientRect;
GetClientRect(hWnd, &clientRect);
D2D1_RENDER_TARGET_PROPERTIES renderTargetProps;
ZeroMemory(&renderTargetProps, sizeof(D2D1_RENDER_TARGET_PROPERTIES));
renderTargetProps.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
renderTargetProps.pixelFormat = (D2D1_PIXEL_FORMAT) { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED };
renderTargetProps.dpiX = 0;
renderTargetProps.dpiY = 0;
renderTargetProps.usage = D2D1_RENDER_TARGET_USAGE_FORCE_BITMAP_REMOTING;
renderTargetProps.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
D2D1_HWND_RENDER_TARGET_PROPERTIES hwndRenderProps;
ZeroMemory(&hwndRenderProps, sizeof(D2D1_HWND_RENDER_TARGET_PROPERTIES));
hwndRenderProps.hwnd = hWnd;
hwndRenderProps.pixelSize = (D2D1_SIZE_U) { clientRect.right - clientRect.left, clientRect.bottom - clientRect.top };
hwndRenderProps.presentOptions = D2D1_PRESENT_OPTIONS_NONE;
if (S_OK != (res = d2factory_ptr->lpVtbl->CreateHwndRenderTarget(d2factory_ptr, &renderTargetProps, &hwndRenderProps, &renderTarget_ptr))) {
return 0;
}
}
ShowWindow(hWnd, nCmdShow);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DestroyWindow(hWnd);
if(NULL != renderTarget_ptr)
renderTarget_ptr->lpVtbl->Base.Base.Base.Release((IUnknown*)renderTarget_ptr);
if (NULL != d2factory_ptr)
d2factory_ptr->lpVtbl->Base.Release((IUnknown*)d2factory_ptr);
return 0;
}
LRESULT onPaintMainWindow() {
ID2D1RenderTargetVtbl renderTargetFuncs = renderTarget_ptr->lpVtbl->Base;
ID2D1RenderTarget * This = (ID2D1RenderTarget*)renderTarget_ptr;
D2D1_TAG tag1, tag2;
D2D1_COLOR_F backgroundClr = (D2D1_COLOR_F) { 0.0, 0.5, 1.0, 1.0 };
renderTargetFuncs.BeginDraw(This);
renderTargetFuncs.Clear(This, &backgroundClr);
renderTargetFuncs.EndDraw(This, &tag1, &tag2);
return 0;
}
LRESULT CALLBACK mainWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (WM_PAINT == uMsg)
return onPaintMainWindow();
if (WM_DESTROY == uMsg) {
PostQuitMessage(0); return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Configure your WNDCLASSEX to not have a background brush.
Replace this line:
wndClassStruct.hbrBackground = (HBRUSH)COLOR_WINDOW;
With this:
wndClassStruct.hbrBackground = GetStockObject(NULL_BRUSH);
Alternatively, you can modify mainWndProc to swallow the WM_ERASEBKGND messages. It achieves the same effect by not allowing the window to erase itself before issuing a WM_PAINT.
LRESULT CALLBACK mainWinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
if (WM_PAINT == uMsg)
return onPaintMainWindow();
if (uMsg == WM_ERASEBKGND)
{
// ignore requests to erase the background since the wm_paint
// handler is going to redraw the entire window.
return 0;
}
if (WM_DESTROY == uMsg) {
PostQuitMessage(0); return 0;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
I found that Microsoft Application Verifier is changing behavior in an unexpected way. I have a program that performs superclassing on system EDIT control. When I run it under Application Verifier with Basics/Heaps/UseLFHGuardPages=TRUE (because I'm on Windows 7 which uses Low Frag Heap), the EDIT WindowProc returns 0 (FALSE) on WM_NCCREATE, preventing the control from being created. This breaks the entire application, as it cannot go forward.
This is a minimalist source that can be used to reproduce problem on Application Verifier:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK DialogWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
static WNDCLASS wcEDIT;
LRESULT CALLBACK EditWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
LRESULT result = CallWindowProc(wcEDIT.lpfnWndProc, hWnd, Msg, wParam, lParam);
if (Msg == WM_NCCREATE && result == 0) {
puts("UNEXPECTED: WindowProc of EDIT returned 0 (FALSE) on WM_NCCREATE");
}
return result;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASS wcDialog;
memset(&wcDialog, 0, sizeof wcDialog);
wcDialog.hInstance = hInstance;
wcDialog.lpszClassName = "MyDialog";
wcDialog.lpfnWndProc = DialogWindowProc;
wcDialog.style = CS_DBLCLKS;
if (RegisterClass(&wcDialog) == 0) {
printf("Unable to register class %s\n", wcDialog.lpszClassName);
return 0;
}
HWND hForm;
{
const char *lpClassName = wcDialog.lpszClassName;
const char *lpWindowName = NULL;
DWORD dwStyle = WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_THICKFRAME|WS_SYSMENU|WS_DLGFRAME|WS_BORDER|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
DWORD dwExStyle = 0;
int X = 0;
int Y = 0;
int nWidth = 320;
int nHeight = 240;
HWND hWndParent = 0;
HMENU hMenu = 0;
LPVOID lpParam = NULL;
hForm = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
if (hForm == 0) {
printf("Unable to create window of class %s\n", wcDialog.lpszClassName);
return 0;
}
}
memset(&wcEDIT, 0, sizeof wcDialog);
wcEDIT.lpszClassName = "EDIT";
if (!GetClassInfo(NULL, wcEDIT.lpszClassName, &wcEDIT)) {
printf("Unable to get class info of %s\n", wcEDIT.lpszClassName);
return 0;
}
WNDCLASS wcMyEDIT;
memcpy(&wcMyEDIT, &wcEDIT, sizeof WNDCLASS);
wcMyEDIT.hInstance = hInstance;
wcMyEDIT.lpszClassName = "MyEDIT";
wcMyEDIT.lpfnWndProc = EditWindowProc;
wcMyEDIT.style |= CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
if (RegisterClass(&wcMyEDIT) == 0) {
printf("Unable to register class %s\n", wcMyEDIT.lpszClassName);
return 0;
}
HWND hEdit;
{
const char *lpClassName = wcMyEDIT.lpszClassName;
const char *lpWindowName = NULL;
DWORD dwStyle = WS_CLIPSIBLINGS|WS_CHILD|ES_AUTOVSCROLL|ES_AUTOHSCROLL;
DWORD dwExStyle = WS_EX_CLIENTEDGE;
int X = 0;
int Y = 0;
int nWidth = 121;
int nHeight = 21;
HWND hWndParent = hForm;
HMENU hMenu = 0;
LPVOID lpParam = NULL;
hEdit = CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
if (hEdit == 0) {
printf("Unable to create window of class %s\n", wcMyEDIT.lpszClassName);
return 0;
}
}
puts("success");
return 0;
}
I'm getting an error CDERR_DIALOGFAILURE from GetOpenFileName. here's the code...
// In WndProc
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
switch (message)
{
case WM_CREATE:
hInstance = (HINSTANCE) GetWindowLong (hWnd, GWL_HINSTANCE);
// In message processing within WndProc
case ID_READ_LOG_FILE:
{
OPENFILENAME ofn;
char fn[MAX_PATH]="\0";
char filter[32]="Text Files\0*.TXT;\0\0";
char title[]="Open Log File";
char defext[]="TXT";
int status;
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.hInstance = hInstance;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 0;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.lpstrFile = fn;
ofn.nMaxFile = sizeof(fn);
ofn.lpstrFileTitle = NULL;
if (ReadLogFileLastDir[0] == '\0')
{
SHGetSpecialFolderPath (NULL,ReadLogFileLastDir,0x0005,false);
};
ofn.lpstrInitialDir = ReadLogFileLastDir;
ofn.lpstrTitle = title;
ofn.Flags = OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST |
OFN_EXPLORER |
OFN_ENABLETEMPLATE |
OFN_ENABLESIZING |
OFN_ENABLEHOOK ;
ofn.lpstrDefExt = NULL;
ofn.lpfnHook = HookFileOpen;
ofn.lCustData = 1234; // just for fun
ofn.lpTemplateName = MAKEINTRESOURCE(IDD_HOOKFILEOPEN);
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = defext;
status = GetOpenFileName (&ofn);
if (status == 0)
{
DWORD iStat, z;
iStat = CommDlgExtendedError();
if (iStat == CDERR_DIALOGFAILURE)
// The dialog procedure looks like this but never gets called.
UINT_PTR CALLBACK HookFileOpen (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
I don't know exactly what is needed but I modified the dialog making it a child with clip siblings and eliminated all other styles and extended styles and now it works.