編譯通過了,但是運行后沒反應,行程中已經運行,可是表單就是不顯示
// WIN32 Application.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lPram);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
//MyRegisterClass(&wcex);
static TCHAR szAppName[]=TEXT("HelloWin32");
HWND hwnd=NULL;
MSG msg;
WNDCLASS wndclass;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
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(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=szAppName; //視窗類名
if (!RegisterClass(&wndclass))
{
MessageBox(NULL,"程式沒有在windows NT下運行",szAppName,MB_ICONERROR);
return 0;
}
CreateWindow(szAppName,//表單類名
"Hello ABC", //表單標題
WS_OVERLAPPEDWINDOW,//表單風格
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL,
);
ShowWindow(hwnd,SW_SHOW);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); //翻譯訊息,處理鍵盤
DispatchMessage(&msg); //分發訊息,用于處理哪個表單
}
return msg.wParam; //分發訊息回傳
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lPram)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
switch(message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("Hello"),-1,&rect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lPram);
}
uj5u.com熱心網友回復:
新建專案,型別Win32 Applicationuj5u.com熱心網友回復:
僅供參考:#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hdc;
HFONT hfont,ohfont;
RECT r;
COLORREF oc;
switch(message) {
case WM_CLOSE://按Alt+F4退出
PostQuitMessage(0);
break;
case WM_PAINT:
BeginPaint(hWnd, &ps);
hdc = ps.hdc; // the device context to draw in
GetClientRect(hWnd, &r); // Obtain the window's client rectangle
hfont = CreateFont(200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "宋體");
ohfont=(HFONT)SelectObject(hdc,hfont);
oc=SetTextColor(hdc,0x00C080FF);
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc,r.left+r.right/2-600, r.top+r.bottom/2-100,"最短畫圖程式",12);
SelectObject(hdc,ohfont);
SetTextColor(hdc,oc);
DeleteObject(hfont);
EndPaint(hWnd, &ps);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
WNDCLASS wc = {0};
HBRUSH hbrh;
hbrh=CreateSolidBrush(0x00000000);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = hbrh;
wc.lpszClassName = "minwindowsapp";
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
if (0==RegisterClass(&wc)) return 1;
if (NULL==CreateWindow(wc.lpszClassName,
"Minimal Windows Application",
WS_POPUP|WS_VISIBLE,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInstance,
NULL))
return 2;
while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
DispatchMessage( &msg );
}
DeleteObject(hbrh);
return 0;
}
uj5u.com熱心網友回復:
創建的是win32uj5u.com熱心網友回復:
是win32 applicationuj5u.com熱心網友回復:
hwnd沒賦值uj5u.com熱心網友回復:
CreateWindow(szAppName,//表單類名
改為
hwnd=CreateWindow(szAppName,//表單類名
uj5u.com熱心網友回復:
嗯嗯 謝謝 問題解決~
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/103836.html
標籤:界面
