Jump to content

Search the Community

Showing results for tags 'GetOpenFileName'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • The General Stuff
    • Announcements
    • Introduce Yourself!
    • General Discussion
  • Microsoft Software Products
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows Server
    • Older Windows NT-Family OSes
    • Windows 9x/ME
    • Other Microsoft Products
  • Unattended Windows Discussion & Support
    • Unattended Windows
    • Other Unattended Projects
  • Member Contributed Projects
    • Nuhi Utilities
    • Member Projects
    • Other Member Contributed Projects
    • Windows Updates Downloader
  • Software, Hardware, Media and Games
    • Forum Categories
    • Mobile Devices
  • Customizing Windows and Graphics
    • Customizing Windows
    • Customizing Graphics
  • Coding, Scripting and Servers
    • Web Development (HTML, Java, PHP, ASP, XML, etc.)
    • Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
    • Server - Side Help (IIS, Apache, etc.)

Calendars

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype

Found 1 result

  1. I want to make my programs compatible with all versions of Windows from Windows 95 to Windows 8. I'm currently working on a small word processor and I need to have working open and save file requesters. However, I can't seem to get the GetOpenFileName function to work properly. This is the code for a simple bitmap viewer program I made. It runs fine on Windows 98, XP, Vista, and 7, but on Windows 95, GetOpenFileName fails, and CommDlgExtendedError() returns error code 1 (CDERR_STRUCTSIZE). Now, I specified sizeof(ofn) for ofn.lStructSize, which should be valid, and it is on other Windows versions. Any ideas why this happens? #include <windows.h>#include <stdio.h>#include <commctrl.h>#define MSGBOX_ERROR(MESSAGE) MessageBox(NULL, MESSAGE, NULL, MB_OK|MB_ICONERROR)#define COMMAND_EXIT 9000#define COMMAND_OPEN 9001#define COMMAND_STRETCH 9002LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ static BOOL IsStretched; static HBITMAP hBmp; switch(msg) { case WM_PAINT: { if(hBmp==NULL) //Leave WM_PAINT to DefWindowProc if no bitmap is loaded. goto defwndproc; RECT client_rect; GetClientRect(hwnd,&client_rect); BITMAP bmp; PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); HDC hdcmem = CreateCompatibleDC(hdc); HBITMAP hbmOld = SelectObject(hdcmem, hBmp); GetObject(hBmp,sizeof(bmp),&bmp); if(IsStretched) StretchBlt(hdc,0,0,client_rect.right-client_rect.left,client_rect.bottom-client_rect.top,hdcmem,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY); else BitBlt(hdc,0,0,bmp.bmWidth,bmp.bmHeight,hdcmem,0,0,SRCCOPY); SelectObject(hdcmem, hbmOld); DeleteDC(hdcmem); EndPaint(hwnd, &ps); break; } case WM_CREATE: { HMENU hMenuBar = CreateMenu(); HMENU hFileMenu = CreatePopupMenu(); HMENU hViewMenu = CreatePopupMenu(); AppendMenu(hFileMenu,MF_STRING,COMMAND_OPEN,"&Open"); AppendMenu(hFileMenu,MF_SEPARATOR,0,NULL); AppendMenu(hFileMenu,MF_STRING,COMMAND_EXIT,"&Exit"); AppendMenu(hViewMenu,MF_STRING|MF_UNCHECKED,COMMAND_STRETCH,"&Stretch to fit window"); AppendMenu(hMenuBar,MF_STRING|MF_POPUP,(UINT)hFileMenu,"&File"); AppendMenu(hMenuBar,MF_STRING|MF_POPUP,(UINT)hViewMenu,"&View"); SetMenu(hwnd,hMenuBar); IsStretched = FALSE; break; } case WM_SIZE: if(IsStretched) InvalidateRect(hwnd,NULL,FALSE); break; case WM_COMMAND: switch(LOWORD(wParam)) { case COMMAND_OPEN: { OPENFILENAME ofn; char szFile[MAX_PATH]; ZeroMemory(&ofn,sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFile = szFile; ofn.lpstrFile[0] = '\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = "Windows Bitmap (*.bmp)\0*.bmp\0All Files\0*.*\0"; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST; GetOpenFileName(&ofn); //Testing to see if GetOpenFileName worked if(fopen(ofn.lpstrFile,"r")==NULL) { char errorbuf[20]; sprintf(errorbuf,"Failed to open a file. Error code: %hu",(unsigned short)CommDlgExtendedError()); MSGBOX_ERROR(errorbuf); return 0; } hBmp = LoadImage(NULL,szFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); if(!hBmp) MSGBOX_ERROR("Failed to load bitmap."); InvalidateRect(hwnd,NULL,FALSE); UpdateWindow(hwnd); break; } case COMMAND_EXIT: goto close; case COMMAND_STRETCH: IsStretched = !IsStretched; InvalidateRect(hwnd,NULL,TRUE); break; } break; case WM_CLOSE: close: ExitProcess(0); default: defwndproc: return DefWindowProc(hwnd,msg,wParam,lParam); } return 0;}int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ InitCommonControls(); WNDCLASS rwc; rwc.style = 0; rwc.lpfnWndProc = MainWndProc; rwc.cbClsExtra = 0; rwc.cbWndExtra = 0; rwc.hInstance = hInst; rwc.hIcon = NULL; rwc.hCursor = LoadCursor(NULL, IDC_ARROW); rwc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1); rwc.lpszMenuName = NULL; rwc.lpszClassName = "yo mama"; RegisterClass(&rwc); HWND hMainWnd = CreateWindow("yo mama", "Bitmap Viewer", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 450, 450, 0, 0, hInst, 0); ShowWindow(hMainWnd,nCmdShow); UpdateWindow(hMainWnd); MSG msg; msgloop: GetMessage(&msg,NULL,0,0); TranslateMessage(&msg); DispatchMessage(&msg); goto msgloop;}
×
×
  • Create New...