为什么我这个程序 上来就直接调用 paint了??
为什么我这个上来就直接调用paint了??到底问题出在那我本来想拉动边框才调用的#include<windows.h>#include<stdio.h>LRESULTCA...
为什么我这个上来就直接调用paint了?? 到底问题出在那 我本来想 拉动边框 才调用的
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
){
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName="hanyecheng";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("hanyecheng","第一次",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
){
switch(uMsg) {
case WM_CHAR:
char S[20];
sprintf(S,"char is%d",wParam);
MessageBox(hwnd,S,"弹出",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"鼠标左键","鼠标",MB_OK);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,20,20,"我第一次使用DC",strlen("我第一次使用DC"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT PS;
hDC=BeginPaint(hwnd,&PS);
TextOut(hDC,20,20,"第二次使用DC",strlen("第二次使用DC") );
EndPaint(hwnd,&PS);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的退出","退出按钮",MB_YESNO)){
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
} 展开
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
){
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WindowProc;
wndclass.lpszClassName="hanyecheng";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
HWND hwnd;
hwnd=CreateWindow("hanyecheng","第一次",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
){
switch(uMsg) {
case WM_CHAR:
char S[20];
sprintf(S,"char is%d",wParam);
MessageBox(hwnd,S,"弹出",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"鼠标左键","鼠标",MB_OK);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,20,20,"我第一次使用DC",strlen("我第一次使用DC"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT PS;
hDC=BeginPaint(hwnd,&PS);
TextOut(hDC,20,20,"第二次使用DC",strlen("第二次使用DC") );
EndPaint(hwnd,&PS);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的退出","退出按钮",MB_YESNO)){
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询