open通用对话框,运行没错误显示不出来!各位大虾帮我看看是那里的错误啊!谢!
#include <windows.h>
#include <commdlg.h>
#include "resource.h"
OPENFILENAME ofn;
HINSTANCE hInst;
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevinstance,LPSTR lpCmdLine,int nShowCmd){
WNDCLASS wc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_ERROR);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="jingwei";
wc.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wc.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wc);
HWND hwnd;
hwnd=CreateWindow(TEXT("jingwei"),TEXT("计算器"),WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,0,0,250,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nShowCmd);
UpdateWindow(hwnd);
hInst=hInstance;
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
RECT rect_box;
static char szFilter[]="Text Files (&.txt)\0*.txt\0All Files (*.*)\0*.*\0";
static char lpstrFileName[]="";
switch(msg){
case WM_CREATE:
ofn.lStructSize=sizeof(OPENFILENAME);
ofn.hwndOwner=hwnd;
ofn.hInstance=NULL;
ofn.lpstrFilter=szFilter;
ofn.lpstrCustomFilter=NULL;
ofn.nMaxCustFilter=0;
ofn.nFilterIndex=0;
ofn.lpstrFile=NULL;
ofn.nMaxFile=0;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
ofn.lpstrInitialDir=NULL;
ofn.lpstrTitle=NULL;
ofn.Flags=0;
ofn.nFileOffset=0;
ofn.nFileExtension=0;
ofn.lpstrDefExt=NULL;
ofn.lCustData=0;
ofn.lpfnHook=NULL;
ofn.lpTemplateName=NULL;
GetClientRect(hwnd,&rect_box);
MoveWindow(hwnd,GetSystemMetrics(SM_CXFULLSCREEN)/2-rect_box.right/2,GetSystemMetrics(SM_CYFULLSCREEN)/2-rect_box.bottom/2,250,300,TRUE);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_OPEN:
ofn.lpstrFile=lpstrFileName;
ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
ofn.lpstrTitle="open";
GetOpenFileName(&ofn);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}