标题:[求助]最简单的windows应用程序!
只看楼主
maoguoqing
Rank: 6Rank: 6
来 自:重庆
等 级:贵宾
威 望:28
帖 子:2980
专家分:19
注 册:2005-12-5
 问题点数:0 回复次数:1 
[求助]最简单的windows应用程序!

#include <windows.h>

LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPreInstance,LPSTR lpszCmdLine,

int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
BOOL bReg;

wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "FirstWindowClass";

RegisterClass(&wc);

hwnd = CreateWindow(
"FirstWindowClass",
"第一个windows应用程序",
WS_OVERLAPPEDWINDOW,
0,
0,
300,
400,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);

ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);

while ((bReg = GetMessage(&msg,NULL,0,0)) != 0)
{
if (bReg == -1)
{
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)

{
PAINTSTRUCT pp;
HDC hdc;

switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;

case WM_LBUTTONDOWN://想在点击鼠标左键时绘制出 "Welcome",这样怎么做不到啊?
hdc=BeginPaint(hWnd,&pp);
RECT rr;
GetClientRect(hWnd,&rr);
DrawText(hdc,"Welcome",strlen("Welcome"),&rr,DT_CENTER);
EndPaint(hWnd,&pp);
return 0;

default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
}

搜索更多相关主题的帖子: windows 应用程序 
2006-03-22 18:53
okey
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-2-12
得分:0 

原因: BeginPaint
EndPaint() 只有用在消息 case WM_PAINT: 中;

今天是我接触Windows编程的第14天,
纯属菜鸟一个,如有雷同,纯属巧合,请多指教

为了符合你的题意:
特修改两个给你,如下:
1,--------------------------------------------------------
#include <windows.h>
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPreInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "FirstWindowClass";
RegisterClass(&wc);
hwnd = CreateWindow(
"FirstWindowClass",
"第一个windows应用程序",
WS_OVERLAPPEDWINDOW,
0,
0,
300,
400,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);

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)
{
PAINTSTRUCT pp;
char * pszchar="i lvoe you i love you";
HDC hdc;
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
case WM_PAINT:
hdc=BeginPaint(hWnd,&pp);
RECT rr;
GetClientRect(hWnd,&rr);
DrawText(hdc,"你好,我是OKEY,请多指教",strlen("Welcome"),&rr,DT_CENTER);
EndPaint(hWnd,&pp);
OutputDebugString(pszchar);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);

}
}



2,----------------------------------------------------------------------
#include <windows.h>
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPreInstance,
LPSTR lpszCmdLine,
int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "FirstWindowClass";
RegisterClass(&wc);
hwnd = CreateWindow(
"FirstWindowClass",
"第一个windows应用程序",
WS_OVERLAPPEDWINDOW,
0,
0,
300,
400,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);

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)
{
PAINTSTRUCT pp;
char * pszchar="i lvoe you i love you";
HDC hdc;
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
hdc = GetDC(hWnd);
RECT rr;
GetClientRect(hWnd,&rr);
DrawText(hdc,"你好,我是OKEY,请多指教",strlen("Welcome"),&rr,DT_CENTER);
ReleaseDC(hWnd,hdc);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);

}
}


when i first saw you , i saw love . and the first time you touch me , i feel love.〆〆
2006-03-23 02:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-52098-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.791069 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved