GetOpenFileName fails to init Dialog. #79
-
I loaded a menu in a c application. Now CommDlg is complaining that it failed to init. Let me know if you need more files. This file is a modified version of the GDIDisplay.c from the Client(C Version). Why does GetOpenFileName fail to init a dialog? #include "GDIDisplay.h"
#include<stdio.h>
#include"resource1.h"
OPENFILENAMEA ofn;
void GDI_DrawAll()
{
}
LRESULT CALLBACK GDI_Windowcallback(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // @suppress("No return")
{
PAINTSTRUCT ps;
HDC hdc = GetDC(hwnd);
switch (msg)
{
case WM_CREATE:
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.hInstance = GetModuleHandle(NULL);
ofn.lpstrFilter = "*.*";
ofn.lpstrFile = "";
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
//SetRect(text_rect,0,0,0,0);
SelectObject(hdc,LTGRAY_BRUSH);
//Rectangle(hdc,text_rect->left,text_rect->top,text_rect->right,text_rect->bottom);
//FillRect(hdc,text_rect,(HBRUSH)RGB(0,255,255));
EndPaint(hwnd,&ps);
break;
case WM_COMMAND:
if (wParam == ID_FILE_OPEN) {
if (GetOpenFileName(&ofn) == 0) {
printf("%i", CommDlgExtendedError());
}
}
//printf("%i\n", wParam);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
}
void GDI_CreateWin(int w, int h)
{
WNDCLASSEX wnd_class;
HMENU menu;
wnd_class.cbSize = sizeof(wnd_class);
wnd_class.style = CS_HREDRAW | CS_VREDRAW;
wnd_class.lpfnWndProc = GDI_Windowcallback;
wnd_class.hInstance = GetModuleHandle(NULL);
wnd_class.cbClsExtra = 0;
wnd_class.cbWndExtra = 0;
wnd_class.hIcon = NULL;
wnd_class.hCursor = NULL;
wnd_class.hbrBackground = GetStockObject(DKGRAY_BRUSH);
wnd_class.lpszMenuName = NULL;
wnd_class.lpszClassName = "GDIWINDOW";
wnd_class.hIconSm = NULL;
if (RegisterClassExA(&wnd_class) == 0) {
MessageBox(NULL, strerror(GetLastError()),"FATAL ERROR" ,MB_ICONERROR);
PostQuitMessage(-1);
}
hwnd = CreateWindow("GDIWINDOW", "Test", WS_OVERLAPPEDWINDOW | WS_VISIBLE , CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, GetModuleHandle(NULL), NULL);
menu = LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1));
if (menu == NULL) {
printf("%i", GetLastError());
//MessageBox(NULL, strerror(GetLastError()), "FATAL ERROR", MB_ICONERROR);
}
else {
SetMenu(hwnd, menu);
}
}
void GDI_EVENT_LOOP()
{
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UpdateWindow(hwnd);
}
void GDI_ShowWin() {
//ShowWindow(hwnd, 5);
} |
Beta Was this translation helpful? Give feedback.
Answered by
Derailedzack
Apr 27, 2021
Replies: 1 comment 1 reply
-
Should I post this somewhere else? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Derailedzack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should I post this somewhere else?