當前位置:編程學習大全網 - 編程語言 - c語言簡單彈窗程序,比如彈出窗口可單擊是和否,單擊之後分別顯示不同的語句(單擊輸出妳好,單擊否拜拜)

c語言簡單彈窗程序,比如彈出窗口可單擊是和否,單擊之後分別顯示不同的語句(單擊輸出妳好,單擊否拜拜)

Demo程序,左鍵單擊窗口會彈出對話框:單擊“是”輸出“妳好”,單擊“否”輸出“拜拜”~

#include <windows.h>

#include <stdio.h>

LRESULT CALLBACK WinProc(

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 wndcls;

wndcls.cbClsExtra=0;

wndcls.cbWndExtra=0;

wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);

wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);

wndcls.hIcon=LoadIcon(NULL,IDI_INFORMATION);

wndcls.hInstance=hInstance;

wndcls.lpfnWndProc=WinProc;

wndcls.lpszClassName="Demo";

wndcls.lpszMenuName=NULL;

wndcls.style=CS_HREDRAW | CS_VREDRAW;

RegisterClass(&wndcls);

HWND hwnd;

hwnd=CreateWindow("Demo","Demo",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 WinProc(

HWND hwnd, // handle to window

UINT uMsg, // message identifier

WPARAM wParam, // first message parameter

LPARAM lParam // second message parameter

)

{

switch(uMsg)

{

case WM_LBUTTONDOWN:

HDC hdc;

hdc=GetDC(hwnd);

if (IDYES == MessageBox(hwnd, "妳好 or 拜拜?", "ask", MB_YESNO))

{

TextOut(hdc,0,50,"妳好",strlen("妳好"));

}

else

{

TextOut(hdc,0,50,"拜拜",strlen("拜拜"));

}

ReleaseDC(hwnd,hdc);

break;

case WM_PAINT:

HDC hDC;

PAINTSTRUCT ps;

hDC=BeginPaint(hwnd,&ps);

TextOut(hDC,0,0,"Demo",strlen("Demo"));

EndPaint(hwnd,&ps);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

default:

return DefWindowProc(hwnd,uMsg,wParam,lParam);

}

return 0;

}

  • 上一篇:東方陶瓷風格特點
  • 下一篇:C和python有什麽區別?
  • copyright 2024編程學習大全網