子窗口没法显示,求救 高手们 搞了一天了
#include<windows.h>
#include<string.h>
#include<tchar.h>
#include"resource.h"
#include"fstream"
using namespace std;
//--------------------------------------------函数声明
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//LRESULT CALLBACK lpWndProc(HWND,UINT,WPARAM,LPARAM);
ATOM MyRegisterClass(HINSTANCE);
ATOM MyRegisterChildClass(HINSTANCE);
//-------------------------------------------全局变量
FILE *fp;
HDC hdc;
HDC hdcmem;
HBITMAP hBm;//位图句柄
BITMAP bm;
WNDCLASSEX wndclass;
WNDCLASSEX ChildWndclass;
HWND childhwnd;
PAINTSTRUCT pt;
//------------------------------------------windows程序入口函数
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow
)
{
HWND hwnd;
MSG Msg;
wchar_t lpszTitle[]=_T("视差");
MyRegisterClass(hInstance);
MyRegisterChildClass(hInstance);
hwnd=CreateWindow(_T("SS"),
_T("视差"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
hBm=LoadBitmap(hInstance,(LPCWSTR)IDB_BITMAP4);
GetObject(hBm,sizeof(BITMAP),(LPVOID)&bm);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//--------------------------------------------父窗口消息处理函数
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
HINSTANCE hInstance=wndclass.hInstance;
switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);//获取内存设备环境句柄
ReleaseDC(hwnd,hdc);
case WM_PAINT:
hdc=BeginPaint(hwnd,&pt);
SelectObject(hdcmem,hBm);//把位图选入内存设备环境句柄
BitBlt(hdc,0,0,bm.bmWidth+1000,bm.bmHeight,hdcmem,0,0,SRCCOPY);//把位图从内存设备环境句柄拷贝到设备环境句柄中,实现位图输出
EndPaint(hwnd,&pt);
//把像素值存入数组里,然后写入文件 bmp.txt
// read_BITMAPFILEHEADER()
fp=fopen("DSC00580.bmp","rb");
break;
case WM_DESTROY:
DeleteObject(hBm);
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN://单击左键,显示子窗口;
childhwnd=CreateWindow(_T("S"),_T("A"),
WS_CHILD|WS_VISIBLE ,
40,
40,
400,
400,
hwnd,
NULL,
hInstance,
NULL
);//调试时这有错,但是看不出来哦
SetParent(childhwnd,hwnd);
ShowWindow(childhwnd,SW_SHOW);
//UpdateWindow(childhwnd);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
//-----------------------------------------注册父窗口类
ATOM MyRegisterClass(HINSTANCE hInstance)
{
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style=0;
wndclass.lpfnWndProc=WndProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.hIconSm=NULL;
wndclass.lpszClassName=_T("SS");
return RegisterClassEx(&wndclass);
}
//------------------------------------------注册子窗口类
ATOM MyRegisterChildClass(HINSTANCE hInstance)
{
ChildWndclass.cbSize = sizeof(WNDCLASSEX);
ChildWndclass.style=0;
ChildWndclass.lpfnWndProc=NULL;
ChildWndclass.cbClsExtra=0;
ChildWndclass.cbWndExtra=0;
ChildWndclass.hInstance=0;
ChildWndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
ChildWndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
ChildWndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
ChildWndclass.lpszMenuName=NULL;
ChildWndclass.hIconSm=NULL;
ChildWndclass.lpszClassName=_T("S");
return RegisterClassEx(&ChildWndclass);
}
能显示父窗口,课我单击左键时无法显示子窗口,一单击,告诉我:什么什么访问冲突!!
childhwnd=CreateWindow(_T("S"),_T("A"),
WS_CHILD|WS_VISIBLE ,
40,
40,
400,
400,
hwnd,
NULL,
hInstance,
NULL
);//调试时这有错,但是看不出来哦
错误应该在这把,我猜的哦